Skip to content

Instantly share code, notes, and snippets.

View scripting's full-sized avatar

Dave Winer scripting

View GitHub Profile
@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 / 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 / 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 / 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 6, 2018 16:13
Example of config.json used to redirect a single file in PagePark
{
"#pagePark": {
"urlRedirect": "http://scripting.com/"
}
}
@scripting
scripting / rpcCall.json
Last active June 11, 2018 18:16
Egregious hack to add date and base64 types to JSON for XML-RPC
{
"methodCall": {
"methodName": "examples.echoParams",
"params": [
"#dateTime=2018-06-10T19:41:06.199Z",
"#base64=aGVsbG8gd29ybGQ="
]
}
}
@scripting
scripting / config.json
Created July 6, 2018 14:44
A config.json for PagePark that sets the default type for files that don't have extensions.
{"defaultType": "text/html"}
@scripting
scripting / userData.json
Created August 2, 2018 19:25
An example of the data that Twitter gives an app about a user (me)
{
"id": 3839,
"id_str": "3839",
"name": "scripting.com",
"screen_name": "davewiner",
"location": "New York",
"profile_location": null,
"description": "American software developer, blogger, inventor of new media types.",
"url": "https://t.co/ztgzDGiyOj",
"entities": {
@scripting
scripting / package.json
Last active September 12, 2018 02:26
Getting the contents of a GitHub repository using the contents API
{
"name": "repocontents",
"description": "Code to get the contents of a respository.",
"author": "Dave Winer <[email protected]>",
"version": "0.4.0",
"main": "repocontents.js",
"scripts": {
"start": "node repocontents.js"
},
"dependencies" : {
@scripting
scripting / yamlize.js
Last active September 23, 2018 00:46
Convert between YAML and JSON and vice versa
const utils = require ("daveutils");
const yaml = require ("js-yaml");
function yamlIze (jsontext) {
var jstruct = JSON.parse (jsontext);
const delimiter = "---\n";
var text = jstruct.text;
delete jstruct.text;
var s = delimiter + yaml.safeDump (jstruct) + delimiter + text;