Skip to content

Instantly share code, notes, and snippets.

View scripting's full-sized avatar

Dave Winer scripting

View GitHub Profile
@scripting
scripting / systemScript.ftsc
Last active September 29, 2017 20:05
Example of the kind of code I routinely write for system scripting
local (sourcefolder = user.prefs.dropboxfolder + "public:misc:nodeeditor:fargo.io-code-publisher:");
local (githubfolder = user.prefs.githubfolder + "fargoPublisher:");
local (montaukfolder = user.prefs.dropboxfolder + "montauk:fargopub:");
on copyone (f1, f2) {
file.surefilepath (f2);
try {
if file.readwholefile (f1) != file.readwholefile (f2) {
file.copy (f1, f2)
}
function runUserScript (s, scriptName) {
var now = new Date ();
function msg (s) {
var package = {
text: s,
path: scriptName
};
bullMancuso.send ("callback", "msg", utils.jsonStringify (package));
}
function persist (objectName) {
@scripting
scripting / uploadToGithub.js
Created November 22, 2017 21:58
A simple JavaScript demo app, running in Node, creates a new file in a repo on GitHub using the REST API
const request = require ("request");
const fs = require ("fs");
var myPost = {
username: "scripting",
repo: "test1",
path: "ideas/plot.html",
content: "<!DOCTYPE html>\n<html><body>A programmer writes a demo app. Everyone lives happily ever after.</body></html>",
type: "text/html",
committer: {
@scripting
scripting / codeQueues.js
Last active January 13, 2018 18:49
Code that manages queues for River5, for review. See the blog post linked to in the first comment.
function readRiverFile (relpath, callback) {
var f = config.dataFolder + relpath;
if (riverQueues [f] === undefined) {
riverQueues [f] = [callback];
fs.readFile (f, function (err, data) {
if (err) {
console.log ("readRiverFile: err.message == " + err.message);
}
else {
var theQueue = riverQueues [f];
@scripting
scripting / codeQueues2.js
Last active January 14, 2018 16:07
Code that manages queues for River5, for review. See the blog post linked to in the first comment. (Revision to earlier gist.)
function readRiverFile (relpath, afterReadCallback, callback) {
var f = config.dataFolder + relpath;
if (riverQueues [f] === undefined) {
riverQueues [f] = [callback];
fs.readFile (f, function (err, jsontext) {
var jstruct = undefined;
if (!err) {
try {
jstruct = JSON.parse (jsontext);
}
@scripting
scripting / readXmlFeed.js
Last active January 16, 2018 18:09
New way to read XML feeds in River5, see first comment for pointer to context
function readXmlFeed (urlfeed) { //1/16/18 by DW
//Instead of processing items as they come in, gather them into an array, and process them at the end.
var req = myRequestCall (urlfeed);
var feedparser = new FeedParser ();
var feedItems = new Array ();
req.on ("response", function (response) {
var stream = this;
serverStats.ctActiveThreads--;
if (response.statusCode == 200) {
stream.pipe (feedparser);

What is feedBase?

A project to get lots of feeds into a database.

How it works

Each feedBase user has a single OPML file containing their subscriptions. You can edit the file whenever you like. When your list changes your subscriptions are added to a database of the subscriptions of all other Scripting News readers. From that we compile a top 100 list so we can see who everyone else subscribes to and find other interesting sites. Periodically we read the feeds to keep our database of info about them up to date.

exports.parseString = parseFeedString;
var myProductName = "daveReadFeed"; myVersion = "0.4.0";
const request = require ("request");
const feedParser = require ("feedparser");
const utils = require ("daveutils");
const stream = require ("stream");
const Iconv = require ("iconv").Iconv;
const Iconv = require ("iconv").Iconv;
const request = require ("request");
const urlTestFeed = "https://www.presseportal.de/rss/dienststelle_110972.rss2";
request (urlTestFeed, function (err, response, theString) {
var iconv = new Iconv ("ISO-8859-1", "UTF-8");
theString = iconv.convert (theString.toString ()).toString ();
console.log (theString);
});
@scripting
scripting / derefurl.js
Last active April 2, 2018 15:36
A simple Node function to dereference a URL, to find out what it points to through redirects.
const request = require ("request");
function derefUrl (url, callback) {
var theRequest = {
method: "HEAD",
url: url,
followAllRedirects: true
};
request (theRequest, function (err, response) {
if (err) {