Skip to content

Instantly share code, notes, and snippets.

View scripting's full-sized avatar

Dave Winer scripting

View GitHub Profile
@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 / 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: {
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 / 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)
}
@scripting
scripting / config.json
Created September 27, 2017 19:25
Example of config.json for my.this.how
{
"localPath": "/home/ubuntu/Dropbox/Nodescripts2/littleoutliner/publicFiles"
}
@scripting
scripting / config.json
Created September 18, 2017 17:09
The config.json file I use on my desktop to store stuff on scripting.com.
{
"watchFolder": "/Users/davewiner/publicFolder/",
"s3Folder": "/scripting.com/publicfolder/",
"urlS3Folder": "http://scripting.com/publicfolder/"
}
@scripting
scripting / example.js
Last active September 6, 2017 13:58
Code that's part of "Instant Dave" that makes links open in an external window
//see blog post here -- http://scripting.com/2017/09/06.html#a094746
function openLinksInExternalWindow () {
$(document).off ("click", 'a[href^="http"]'); //remove pre-existing click handlers
$(document).on ("click", 'a[href^="http"]', function (event) {
event.preventDefault ();
electron.shell.openExternal (this.href);
});
}
@scripting
scripting / helloworld.js
Created August 9, 2017 15:05
Hello world for S3 in JavaScript
var AWS = require ("aws-sdk");
var s3 = new AWS.S3 ();
const params = {
Bucket: "bloatware.org",
Key: "/testing/hello.txt",
Body: "Hello World",
ContentType: "text/plain",
ACL: "public-read"
};
s3.putObject (params, function (err, data) {
@scripting
scripting / permissions.json
Created August 9, 2017 13:30
Permissions used in a Scripting News howto
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": ["arn:aws:s3:::bloatware.org"]
},
{
"Effect": "Allow",
@scripting
scripting / tweetsInMyRss.xml
Last active June 28, 2017 14:46
A fragment of the Scripting News RSS feed showing how a tweeted item is represented.
<item>
<description>Instead of Trump growing to fill the presidency, he's shrinking the presidency to fit Trump.</description>
<pubDate>Wed, 28 Jun 2017 14:00:37 GMT</pubDate>
<link>http://scripting.com/2017/06/28.html#a100637</link>
<guid>http://scripting.com/2017/06/28.html#a100637</guid>
<source:outline created="Wed, 28 Jun 2017 14:00:37 GMT" type="tweet" tweetId="880063536352899074" tweetUserName="davewiner" permalink="http://scripting.com/2017/06/28.html#a100637" text="Instead of Trump growing to fill the presidency, he's shrinking the presidency to fit Trump." />
</item>
<item>