Rosetta Code:Village Pump/tasks descriptions only: Difference between revisions

m
Already a task
(javascript/DOM approach)
m (Already a task)
 
(8 intermediate revisions by 3 users not shown)
Line 5:
I'm going on a long plane trip. I'd like to take a printout of all the tasks but without the solutions. I have in mind to solve some of the solutions on paper whilst airborne, taking the list of solutions and the programming language manual.
[[User:Axtens|Axtens]] ([[User talk:Axtens|talk]]) 07:04, 27 March 2015 (UTC)
:Not sure it is what you were thinking, but I want this for a [[specific]] Language. How can that be done?
:--[[User:RLRandallx|RLRandallx]] 21:55, 20 May 2016 (UTC)
 
:Sounds like a good idea for a task "Extract task description from an RC task" (i.e. down to the first <nowiki>{{header|...}}</nowiki> :-)
Line 26 ⟶ 28:
:I hope this helps. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 14:58, 27 March 2015 (UTC)
 
:I feel this task should be a builtin task for the website. Could someone please add it to the Main Menu? The essential code is above.
:--[[User:RLRandallx|RLRandallx]] 21:07, 20 May 2016 (UTC)
 
::I was just fiddling inside of my webbrowser and came up with the following javascript-ish pseudocode. A solution using JScript or VBScript inside (gasp) Internet Explorer would seem to be the go. (Doing it on Linux might be a bit trickier.)
 
::<lang javascript>
Line 45 ⟶ 49:
 
::The while loop should handle the different amounts of text between the infobox markup and the beginning of the contents table. [[User:Axtens|Axtens]] ([[User talk:Axtens|talk]]) 09:53, 16 April 2015 (UTC)
 
::Here's a SlimerJS solution. Not perfect but seems to work reasonably well (it's funny watching all the little windows open and close.) A little annoyingly, SlimerJS doesn't implement innerText, so there are the odd occasions where there's markup in the file. Also, occasionally there's a TABLE that's not the contents before the contents, thus truncating the description.
::<lang javascript>var fs = require('fs');
 
function innerCall(nam, ref) {
var ipage = require("webpage").create();
ipage.open(ref, function () {
var description = ipage.evaluate( function () {
var start = document.getElementsByClassName("infobox")[0];
var cursor = start.nextElementSibling;
var desc = "";
while (cursor.tagName !== "TABLE") {
there = cursor;
desc = desc + there.innerHTML + "\n";
cursor = cursor.nextElementSibling;
}
return desc;
});
var fileName = nam + ".txt";
fileName = fileName.replace(/\//g,"_");
fs.write(fileName,description);
//console.log(nam + " " + ref + "\n" + description);
ipage.close();
});
}
 
 
var page = require("webpage").create();
page.open("http://rosettacode.org/wiki/Category:Programming_Tasks", function () {
var anchors = page.evaluate(function () {
return document.getElementById("mw-pages").getElementsByTagName("a");
});
for (var i = 0; i < anchors.length; i++ ) {
//console.log(anchors[i].innerHTML + ' ' + anchors[i].href);
innerCall(anchors[i].innerHTML, anchors[i].href);
slimer.wait(100);
}
page.close();
//phantom.exit();
});</lang>
 
::I would have used PhantomJs but had trouble building it and lost patience rapidly. [[User:Axtens|Axtens]] ([[User talk:Axtens|talk]]) 15:21, 16 April 2015 (UTC)
 
::Ah silly me, I should have done a 'sudo apt install phantomjs'. Trying that now. Meanwhile, I'm happy to make this a challenge. Worthwhile? [[User:Axtens|Axtens]] ([[User talk:Axtens|talk]]) 15:41, 16 April 2015 (UTC)
 
::One could try to make this itself a programming task 🤔 [[User:Rainb|Rainb]] ([[User talk:Rainb|talk]]) 12:45, 30 January 2019 (UTC)
 
:::Indeed one could; and maybe call it something like [[Rosetta_Code/Tasks_without_examples]], except that already exists. --[[User:Thundergnat|Thundergnat]] ([[User talk:Thundergnat|talk]]) 16:42, 30 January 2019 (UTC)
10,327

edits