User talk:Badmadevil

Revision as of 08:52, 14 June 2008 by rosettacode>Badmadevil (→‎Not Implemented Tasks by Language: regexp version, remove unsed http.js)

Welcome to Rosetta Code! I founded RC around a year ago, and still do most of the administrative work. Thanks for your code contributions. I'm curious, though, how did you hear about RC? --Short Circuit 10:44, 23 February 2008 (MST)

Hi, thanks. I heard from a forward message posted at Digital Mars D newsgroup about a month ago. -badmadevil 03:03, 24 February 2008 (MST)

Mylang

Good job with the mylang templates. I had done as well as I could before, but these are better. --Mwn3d 13:52, 22 March 2008 (MDT)

thank for appreciation :) --badmadevil 07:54, 23 March 2008 (MDT)

Not Implemented Tasks by Language

Hello. IIRC, it has been mentioned an idea to display a page of tasks not implemented by a specific language (It is from Ian Osgood's wishlist), it seems no such page at Rosetta Code yet. I've coded a dirty hack of such page using client-side javascript. It use xmlhttprequest to get the contents of Solutions_by_Programming_Task & the language specified page that contains tasks such language has been completed, then by using RegExp, extracting links under some specify id/tag, the links of set different of these 2 page are tasks that not implemented.

Sources:

<html>
<title>Not Implemented Task by Langauge</title>
<!--script src="/http.js"></script--> 
<!--script src="http.js"></script--> 
<script>

<javascript>/**

**   C o n f i g
**/

// javascript's XMLHTTPRequest doesn't allow cross site request, // so this script's location's host has to be same as the Category pages. // the prefix change to 'http://rosettacode.org/wiki/Category:' should be ok //var mySitePrefix = 'http://www.lynx.ran/wiki/' ; var mySitePrefix = 'http://rosettacode.org/wiki/Category:' ;

// set to true if mySitePrefix is inside rosetta site, should allow reach C++, // C# etc. pages. //var usesafeurl = false ; var usesafeurl = true ;

// this is maximum length of '<a .. /a>' plus
  • , Capital Heading's HTML // sources in next link capture string in o.getlink function. Currently, it is // about 340 (found by trail and error). // Modify this value if longer name of new task is added. var preFetchLen = 400 ; // To test in a loacl web server (eg. http://localhost): // 1.mkdir wiki in root dir of localhost, // save http://rosettacode.org/wiki/Category:<CATEGORYNAME> to // localhost/wiki/<CATEGORYNAME>/index.htm, // 2.<CATEGORYNAME> should at leat include Solutions_by_Programming_Task & // Solutions_by_Programming_Language, then include some other languages // categories, eg. C, Java, Python, etc. to start testing. // 3.place http.js where this html can located, // 4.no query string should be in url of this html, var working = "<none>" ; var NA = "N/A" ; function Page(url, ID) { var o = new Object ; o.url = url ; o.ID = ID ; o.cnt = 0 ; o.htm = NA ; o.lnk = new Array() ; o.request = function() { HTTP.getText(o.url, o.setHtm)} // NOTE: // GLOBAL RegExp is not use, for I can't handle it right, or the performance is bad. o.setHtm = function(txt) { var head = 0 ; var tail = 0 ; working = o.url + '
    '; head = txt.search(o.ID + '">') ; if(head >= 0) { tail = txt.search('printfooter') ; if(tail >= 0) { o.htm = txt.slice(head + o.ID.length + 2,tail - 12) ; o.getlink() ; } } } o.getlink = function() { if(o.htm != NA) { var re = /href="(.*)"\s*title="(.*)"\s*>.+</ ; var start = 0 ; var head = 0 ; var tail = 0. ; var htmlen = o.htm.length ; while(start >= 0 && start < htmlen) { var part = o.htm.slice(start, Math.min(start + preFetchLen, htmlen)) ; head = part.search('<a') ; if(head >= 0) { tail = part.search('a>') ; if(tail >= 0) { var mh = part.slice(head, tail).match(re) ; if(mh) { o.lnk[mh[1]] = mh[2] ; o.cnt++ ; } } } if(head < 0 || tail < 0) start = -1 ; else start += (tail + 1) ; } } } return o ; } var scriptUrl ; with(window.location) scriptUrl = protocol + '//' + host + pathname ; var rosettaUrl = 'http://rosettacode.org' var langID = getLangID() ; var langurl = langID != NA && usesafeurl ? safeurl() : mySitePrefix + langID ; var task = Page(mySitePrefix + 'Solutions_by_Programming_Task', "mw-pages") ; var lang = Page(langurl, "mw-pages") ; var list = Page(mySitePrefix + 'Solutions_by_Programming_Language', "mw-subcategories") ; var tasklist ; var langlist ; var timeoutCnt = 5 ; var count = 0 ; function getLangID() { var langid = window.location.search.slice(1) ; if(langid.length == 0) return NA ; return langid ; } function safeurl(langname) { if(!langname) langname = langID ; return rosettaUrl + '/w/index.php?title=' + langname ; } function process() { tasklist = document.getElementById("tasklist") ; langlist = document.getElementById("langlist") ; tasklist.innerHTML = "...loading..." ; langlist.innerHTML = "...loading..." ; task.request() ; list.request() ; if(langID != NA) { lang.request() ; document.title = 'Not Implemented Tasks by Langauge ' + langID ; } waitLoad() ; } function waitLoad() { timeoutCnt-- ; // tasklist.innerHTML = makeStatus() + '
    ...loading ' + working + 'timeout in ' // + timeoutCnt + ' sec...' ; tasklist.innerHTML = '...loading ' + working + 'timeout in ' + timeoutCnt + ' sec...' ; if(timeoutCnt > 0 && ((langID != NA && lang.htm == NA) || task.htm == NA || list.htm == NA)) return setTimeout(waitLoad,1000) ; if(langID == NA) return failLoad() ; if(timeoutCnt <= 0) return failLoad() ; if(task.cnt == 0 || list.cnt == 0 || lang.cnt == 0) return failLoad() ; doParse() ; } function failLoad() { // this part may be simplified to display just a short err message var errmsg = "" ; if(lang.htm == NA) { // may be not known language if(langID == NA) errmsg += 'Language ID not known.' ; else errmsg += 'Error Page - url : ' + alink(scriptUrl + '?' + langID,langID,langID, true)  ; } errmsg += '
    ' ; with(lang) if(htm == NA) errmsg += 'fail to load this url : ' + alink(url, url, url) + '
    ' ; with(list) if(htm == NA) errmsg += 'fail to load this url : ' + alink(url, url, url) + '
    ' ; with(task) if(htm == NA) errmsg += 'fail to load this url : ' + alink(url, url, url) + '
    ' ; tasklist.innerHTML = errmsg + makeStatus()  ; var taskdom = "" if(task.cnt > 0 && lang.cnt > 0) taskdom = makeTask() ; try { if(taskdom == "") taskdom = task.htm ; } catch(e) { taskdom = "" ; } if(taskdom != "") taskdom = makeMenu() + '
    ' + taskdom ; else taskdom = makeMenu() + '
    Tasks Page not found/load.' ; var listdom = "" ; if(list.cnt >0) listdom = makeList(); try { if(listdom == "") listdom = list.htm ; } catch(e) { listdom = "" ; } if(listdom != "") listdom = '
    ' + makeReturn() + '
    ' + listdom ;
     else
    
    listdom = '
    ' + makeReturn() + '
    Languages List Page not found/load.' ;
     langlist.innerHTML = taskdom + listdom ;
    

    } function doParse() {

     var taskdom = makeTask() ;
    
    tasklist.innerHTML = makeMenu() + '

    Tasks not implemented by ' + alink(rosettaUrl + '/wiki/' + langID, langID,langID, true) + '



    There are ' +
       count + ' not implemented tasks out of ' + task.cnt +
       ' total tasks. ' + '(' + lang.cnt +
       ' completed tasks, implementations & puzzles etc.)
    ' + taskdom ;
    langlist.innerHTML = makeReturn() + '
    ' + makeList() ;

    } function alink(url, tip, txt, normalsize, nameanchor) {

     var extra = normalsize ? "" : ' style="font-size:smaller;"';
     extra += nameanchor ? ' name="' + nameanchor + '"' : "" ;
     return '<a href="' + url +  '" title="' + tip + '"' + extra + '>' +
       unescape(txt) + '</a>' ;
    

    } function makeMenu() {

     var backLink ;
     if(langID == NA) {
       backLink = alink(list.url, "Solution by Languages",
         'Return to Category : Solution by Languages') ;
     } else {
       backLink = alink(safeurl(), safeurl(), 'Return to Category : ' + langID)
     }
     var tx = 'otherlanguages' ;
     return alink('#' + tx, tx, 'Select other languages', true, 'returntop') +
    
    '  |  ' + backLink + '
    ' ;

    } function makeReturn() {

     var tx = 'returntop' ;
    

    // return alink('#' + tx, tx, 'TOP', true, 'otherlanguages') + // '  |  ' + makeStatus() ;

     return alink('#' + tx, tx, 'TOP', true, 'otherlanguages')  ;
    

    } function makeStatus() {

     return '(total / langs / taskss) - pages length : ' +
       task.htm.length + ' / ' + list.htm.length + ' / ' +
       lang.htm.length  + '  |  link count : ' + task.cnt +
       ' / ' + list.cnt + ' / ' + lang.cnt  ;
    

    } function makeList() {

     var backLink ;
     if(langID == NA) {
       backLink = alink(list.url, "Solution by Languages",
         '&#8251') ;
     } else {
       backLink = alink(safeurl(), langID, '&#8251')
     }
     if(list.cnt == 0) return "" ;
    
    var html = '

    Not Implemented Tasks by Other Languages (click ' + backLink + ' to visit Normal Category' + ') :

    ' ;
     splitCnt = 0 ;
     var cols = 6 ;
     var wd = 'width="' + Math.floor(100/cols) + '%"' ;
     for(i in list.lnk)
       if(list.lnk[i]){
         var txt = list.lnk[i] ;
         var uri = i ;
         var langTag = txt.split(':') ;
         var langUri = uri.split(':') ;
         if(langTag.length == 2) {
           if(splitCnt >= cols) {
             splitCnt = 1 ;
    
    html += '' ; } else splitCnt++ ; var langId = langTag[1] ; var langUr = langUri[1] ; html += '' ; } } html += '
    ' + alink(safeurl(langUr), txt,"&#8251") + ' ' + alink(scriptUrl + '?' + langUr, langId,langId) + '
    ' ;
     return html ;
    

    } function makeTask() {

    var html = '
    ' ;
     var capital = "?" ;
     var heading ;
     for(i in task.lnk)
       if(!lang.lnk[i]) count++ ;
     if(count > 0) {
       var splitCnt = 0 ;
       for(i in task.lnk)
         if(!lang.lnk[i]) {
           splitCnt++ ;
           var lnk = rosettaUrl + i ;
           var txt = task.lnk[i] ;
           heading = capital ;
           capital = txt.charAt(0) ;
           if(splitCnt*3 > count + 2)  {
             splitCnt = 0 ;
    
    html += '
    '
             if(capital == heading)
    
    html += '

    ' + heading + ' cont.

      ' ; } if(heading.charAt(0) != capital.charAt(0)) { if(heading != "?") html += '
    ' html += '

    ' + capital + '

      ' } html += '
    • ' + alink(lnk, txt, txt) + '
    • ' ; } html += '
    ' ;
     } else
       return "" ;
    
    html += '


    ' ;
     return html ;
    

    }</javascript>

    </script>
    <!-- from http://examples.oreilly.com/jscript5/ , unused parts removed-->
    <script>
    

    <javascript>/**

    * http.js: utilities for scripted HTTP requests
    *
    * From the book JavaScript: The Definitive Guide, 5th Edition,
    * by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN: 0596101996)
    */
    

    // Make sure we haven't already been loaded var HTTP; if (HTTP && (typeof HTTP != "object" || HTTP.NAME))

     throw new Error("Namespace 'HTTP' already exists");
    

    // Create our namespace, and specify some meta-information HTTP = {}; HTTP.NAME = "HTTP"; // The name of this namespace HTTP.VERSION = 1.0; // The version of this namespace

    // This is a list of XMLHttpRequest creation factory functions to try HTTP._factories = [

     function() { return new XMLHttpRequest(); },
     function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
     function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
    

    ];

    // When we find a factory that works, store it here HTTP._factory = null;

    /**

    * Create and return a new XMLHttpRequest object.
    *
    * The first time we're called, try the list of factory functions until
    * we find one that returns a nonnull value and does not throw an
    * exception.  Once we find a working factory, remember it for later use.
    */
    

    HTTP.newRequest = function() {

     if (HTTP._factory != null)
       return  HTTP._factory();
    
     for(var i = 0; i < HTTP._factories.length; i++) {
       try {
         var factory = HTTP._factories[i];
         var request = factory();
         if (request != null) {
           HTTP._factory = factory;
           return request;
         }
       }
       catch(e) {
         continue;
       }
     }
    
     // If we get here, none of the factory candidates succeeded,
     // so throw an exception now and for all future calls.
     HTTP._factory = function() {
       throw new Error("XMLHttpRequest not supported");
     }
     HTTP._factory(); // Throw an error
    

    }

    /**

    * Use XMLHttpRequest to fetch the contents of the specified URL using
    * an HTTP GET request.  When the response arrives, pass it (as plain
    * text) to the specified callback function.
    *
    * This function does not block and has no return value.
    */
    

    HTTP.getText = function(url, callback) {

     var request = HTTP.newRequest();
     request.onreadystatechange = function() {
       if (request.readyState == 4 && request.status == 200)
         callback(request.responseText);
     }
     request.open("GET", url);
     request.send(null);
    

    };</javascript>

    </script>
    <body onLoad="process();" >
    <table width="100%">
    <tr><td valign=top><div id="tasklist">
    </div></td></tr>
    <tr><td><hr /><td></tr>
    <tr><td valign=top><div id="langlist">
    </div></td></tr>
    </table>
    </body>
    </html>
    
  • Hope it can be a temporary solution. -- badmadevil 02:52, 14 June 2008 (MDT)

    Return to the user page of "Badmadevil".