Skip to content

Instantly share code, notes, and snippets.

View bwestergard's full-sized avatar

Björn Westergard bwestergard

  • Mt. Pleasant, Washington, D.C.
View GitHub Profile
var env = process.env;
var cfg = {
foo: env.FOO_QUEUE || 'foo',
pattern: env.BIND_QUEUE_PATTERN,
amqpUrl: env.RABBIT_MQ_URL
};
cfg.channel = {
// Channel method to invoke
[
{
"id": 0,
"description": "Science In Action",
"tags": "read philosophy",
"dependencies": [6]
},
{
"id": 1,
"description": "Conscience of the Revolution",
@bwestergard
bwestergard / example.js
Last active August 29, 2015 14:26
Ramda "supercompiler"
// Ramda provides one, but just for verbosity
var add = function (x,y) { return x + y; };
var square = function (x) { return x * x; };
// Redundant looping
var sumSquares = R.pipe(
R.map(square),
R.reduce(add, 0)
);
@bwestergard
bwestergard / bookmark.py
Created January 11, 2012 15:18
A python script to let you read a book (e.g. a dictionary, an encyclopedia) in random order, keeping track of which pages have already been read.
import sys,random
'''
USAGE
Let's say you want to read The Oxford Companion to Lulz, which has 819 pages. You would create a file with one line, "1:819", and save it as lulz.txt. Then you would run:
python bookmark.py lulz.txt
This would return a random page that you haven't yet read. Let's say it was 42. You then read from 42 to 50. You record this fact by running:
@bwestergard
bwestergard / bibliography.md
Last active November 27, 2015 22:30
Surplus Population Bibliography
@bwestergard
bwestergard / ubi.md
Last active December 15, 2015 19:23
Basic Income Bibliography
@bwestergard
bwestergard / x.js
Last active December 25, 2015 22:39
Cassini Do It Yourself (Attempted Fix)
// Cassini projection
// just a transverse equirectangular projection
// implemented from wikipedia description
d2r = Math.PI / 180;
return Math.asin(Math.sin(x * d2r) * Math.cos(y * d2r));
udpPort.send({
address: '/s_new',
args: ['ping', 400]
}, '127.0.0.1', 57110)
@bwestergard
bwestergard / tco.js
Last active December 4, 2016 21:39
Lazy Streams in Node
"use strict";
// http://stackoverflow.com/questions/23260390/node-js-tail-call-optimization-possible-or-not
// Tested and working with node v7.2.0. Both of the following work:
// node --harmony_tailcalls tco.js
// node --harmony tco.js
const natsFrom = (n) => [n, () => natsFrom(n+1)]
const kth = ([hd, tl], k) => k === 0 ? hd : kth(tl(), k - 1)