Skip to content

Instantly share code, notes, and snippets.

View scripting's full-sized avatar

Dave Winer scripting

View GitHub Profile
@scripting
scripting / s3FolderExists.js
Created June 5, 2018 17:44
JS code to ask AWS if an S3 path is a folder with files in it
function s3FolderExists (s3path, callback) {
var flHaveCalledBack = false;
var splitpath = s3.splitPath (s3path);
var pathToLookFor = splitpath.Key + "/";
s3.listObjects (s3path, function (obj) {
if (obj.flLastObject === undefined) {
if (utils.beginsWith (obj.Key, pathToLookFor)) {
if (!flHaveCalledBack) {
callback (true);
flHaveCalledBack = true;
@scripting
scripting / config.json
Created June 4, 2018 17:34
An example of a PagePark config.json file that specified a path on S3 to serve from
{
"s3ServeFromPath": "/publicfolder.io"
}
@scripting
scripting / iconvLiteExample.js
Last active April 18, 2018 16:24
Using iconv-lite to do character conversion of HTTP requests
const iconv = require ("iconv-lite");
const request = require ("request");
const utils = require ("daveutils");
var feedUrl = "https://www.presseportal.de/rss/dienststelle_110972.rss2";
function getCharset (httpResponse) {
var contentType = httpResponse.headers ["content-type"];
if (contentType !== undefined) {
var encoding = utils.trimWhitespace (utils.stringNthField (contentType, ";", 2));
@scripting
scripting / iconv-lite-test.js
Created April 18, 2018 16:06
This is the code that doesn't work. Helllp.
const iconv = require ("iconv-lite");
const request = require ("request");
const utils = require ("daveutils");
var feedUrl = "https://www.presseportal.de/rss/dienststelle_110972.rss2";
function getCharset (httpResponse) {
var contentType = httpResponse.headers ["content-type"];
if (contentType !== undefined) {
var encoding = utils.trimWhitespace (utils.stringNthField (contentType, ";", 2));
@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) {
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);
});
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;

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.

@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);
@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);
}