Skip to content

Instantly share code, notes, and snippets.

View scripting's full-sized avatar

Dave Winer scripting

View GitHub Profile
@scripting
scripting / MP3 download snippet
Last active August 29, 2015 14:18
This code doesn't work. Trying to figure out why! :-)
var requestSettings = {
method: 'GET',
url: theEnclosure.url,
encoding: null
};
request (requestSettings, function (error, response, body) {
if (!error && (response.statusCode == 200)) {
fs.writeFile ("podcast.mp3", body, function (err) {
console.log (body.length + " bytes written to file.");
@scripting
scripting / koreanCharFiles.txt
Last active August 29, 2015 14:17
Why do these random files keep showing up in my repos??
I'm using the Mac GitHub client, and these weird files keep showing up and I have to delete them before anything will work.
Here's a screen shot.
http://scripting.com/2015/03/21/koreanchars.png
As far as I know I'm not doing anything to create them.
Any clues would be much appreciated.
@scripting
scripting / opGetMywordJstruct.js
Last active August 29, 2015 14:16
A code fragment that gets the myword.io compatible JSON from the bar cursor outline
function opGetBarCursor () { //11/12/14 by DW
return ($(getActiveOutliner ()).concord ().op.getCursorRef ());
}
function dateToNumber (theDate) { //2/15/15 by DW
return (Number (new Date (theDate)));
}
function opGetMywordJstruct (theNode) { //2/15/15 by DW
if (theNode == undefined) {
theNode = opGetBarCursor ();
}
@scripting
scripting / xmlQuestion.js
Last active August 29, 2015 14:16
Question about serializing XML structures in JavaScript. See comment below for explanation.
function xmlVisit (adrx, callback, level, path) {
if (level === undefined) {
level = 0;
}
if (path === undefined) {
path = "";
}
$(adrx).children ("outline").each (function () {
var flvisitsubs = true, name = xmlGetNodeName (this);
@scripting
scripting / test.js
Created February 19, 2015 00:39
Example script for PagePark pages that need to do something asynchronous, like reading a file over the web.
httpReadUrl ("http://scripting.com/misc/uppertext.txt", function (s) {
httpReturn (s.toUpperCase (), "text/plain");
});
undefined; //return undefined so PagePark knows not to return a value
@scripting
scripting / readOpml.js
Last active August 29, 2015 14:15
A routine that builds on Dan MacTough's opmlparser package for node.js. I think this should be part of what's released in opmlparser. It's a higher level interface, and much easier for the app that's using opmlparser to deal with. It actually generates a JavaScript tree structure from the OPML.
function readOpml (urloutline, callback) {
var outlineArray = new Array ();
var req = request (urloutline);
var opmlparser = new opmlParser ();
req.on ("response", function (res) {
var stream = this;
if (res.statusCode == 200) {
stream.pipe (opmlparser);
}
@scripting
scripting / buildLiveblogOpml
Created January 30, 2015 18:26
A Frontier script that generates the OPML subscription list for liveblog.co. An example script for Marco.
on buildLiveblogOpml () {
«Changes
«1/30/15; 12:19:27 PM by DW
«Created.
local (jsontext = tcp.httpreadurl ("http://liveblog.co/prefs/userwhitelist.json"), jstruct);
json.compile (jsontext, @jstruct);
«scratchpad.jstruct = jstruct
local (xstruct = nodeEditorSuite.data.opmlShellStruct, now = clock.now ());
local (adrbody = xml.opml.getBodyAddress (@xstruct), adritem, name, i);
@scripting
scripting / config.json
Created January 18, 2015 15:47
Example config.json file for PagePark.
{
"urlSiteRedirect": "http://nodestorage.io"
}
@scripting
scripting / config.json
Created January 17, 2015 09:37
An example of a config.json file used for the tweetsToRss app.
{
"folder": "feeds/",
"items": [
{
"username": "Circa",
"feedname": "circa.xml"
},
{
"username": "reportedly",
"feedname": "reportedly.xml"
@scripting
scripting / pageParkScript.js
Last active June 18, 2017 12:27
A script I have running as an endpoint on my PagePark server.
var s = "<ul>";
for (var i = 1; i <= 10; i++) {
s += "<li>" + i + "</li>";
}
s += "</ul>";
s;