Skip to content

Instantly share code, notes, and snippets.

View apaleslimghost's full-sized avatar
💚
a pale slim ghost

Kara Brightwell apaleslimghost

💚
a pale slim ghost
View GitHub Profile
# ## Function: sequence
#
# Evaluates each action in sequence, left to right, collecting the
# results.
#
# + type: (Monad m) => m -> [m a] -> m [a]
export sequence = (m, ms) --> do
return ms.reduce perform, m.of []
# where:
function perform(m1, m2) => do
@apaleslimghost
apaleslimghost / transform.md
Created January 23, 2014 17:54
Potentially useful browserify transform

Config

{
	"jquery": {
		"commonjs": "jquery-browser",
		"requirejs": "jquery",
		"global": "jQuery"
	}
}
@apaleslimghost
apaleslimghost / convert.ls
Created February 9, 2014 21:08
Convert Tumblr dump to Jekyll posts
{posts, blog} = require './download.json'
pandoc = require \pandoc
fs = require \fs
photos = (.join '') . (.map -> """<img src="#{it.original_size.url}" width="#{it.original_size.width}" height="#{it.original_size.height}" alt="#{it.caption}">""")
pad = (n, s)->
p = n - s.to-string!length
('0' * p) + s
fit = (coins, amt)-->
maximum filter (<= amt), coins
fit-sterling = fit [1 2 5 10 20 50 100 200]
change = (fit, amt)-->
| amt is 0 => []
| otherwise => let coin = fit amt
[coin] ++ change fit, (amt - coin)
@apaleslimghost
apaleslimghost / gatedAsync.js
Created May 30, 2014 14:18
Wrapper to ensure an async function runs in series when called multiple times
function gatedAsync(fn) {
var running = false, queue = [];
return function(...args) {
if(running) {
queue.push([run, args]);
} else {
run(...args);
}
function run(...args) {
@apaleslimghost
apaleslimghost / undep.sh
Created July 1, 2014 10:31
Find out which modules have no dependents
readonly files="path/to/scripts/entry.js"
readonly base="path/to/scripts"
readonly opts="-t whatever"
list_deps() {
local entries=$1
local opts=$2
browserify $opts --list $entries \
| sed "s:$(pwd)::" \
{Status, Header}:handle = require \oban
{get, route} = require \livewire
ok = ([Status 200] ++)
not-found = ([Status 404] ++)
with-header = (k,v,s)--> [Header k,v] ++ s
handle route [
get '/' -> ok "hello world"
(req)-> not-found "#{req.url} not found"
@apaleslimghost
apaleslimghost / resources.ls
Created July 9, 2014 11:29
what resourceful routes look like in sodor
{root, post, put, delete} = require \sodor
module.exports =
index: root ->
new: ->
create: post root ->
show: root (id)->
edit: (id)->
update: put root (id)->
destroy: delete root (id)->
@apaleslimghost
apaleslimghost / bind.js
Created October 20, 2014 14:11
Sweet.js bound access macro
macro (~) {
rule infix { $l:expr | $r:ident } => { (ref = $l, ref.$r.bind(ref)) }
rule infix { $l:expr | $r:expr } => { (ref = $l, ref[$r].bind(ref)) }
}
var c = a~b;
a({
b: c~(foo)
});
@apaleslimghost
apaleslimghost / do.js
Last active August 29, 2015 14:07
Generators for do-notation
var sequence = (M, ms)=> ms.reduce(
(m1, m2)=> do(M, function*() {
var x = yield m1;
var xs = yield m2;
return x.concat(xs);
}), M.of([]));
// should be eqv to
var sequence = (M, ms)=> ms.reduce(