Instantly share code, notes, and snippets.

View toggle-event-listener.js
const handlers = new WeakMap();
/*
{
[element]: {
[type]: [...handlers]
}
}
*/
function getHandlersForElement(element) {
return handlers.get(element);
View pre-commit
#!/bin/bash
# Pre-commit Git hook to run JSHint on JavaScript files.
#
# If you absolutely must commit without testing,
# use: git commit --no-verify
passed=1
filenames=($(git diff --cached --name-only HEAD))
which jshint &> /dev/null
View keybase.md

Keybase proof

I hereby claim:

  • I am deleteme on github.
  • I am deleteme (https://keybase.io/deleteme) on keybase.
  • I have a public key whose fingerprint is 6C75 C5B3 540B 01AD DDD1 2181 8A68 B091 45F1 CF4A

To claim this, I am signing this object:

View preload.coffee
images = [
'http://cdn.discogs.com/yqU-8wqol13SCGfPg2sYy9gBjb4=/100x100/filters:strip_icc():format(jpeg):mode_rgb()/discogs-images/R-3996200-1351777283-1914.jpeg.jpg',
'http://cdn.discogs.com/U2oncEZe50hAlYSoFbVOkIf1Y0s=/fit-in/300x300/filters:strip_icc():format(jpeg):mode_rgb()/discogs-images/R-3578188-1440480186-6359.jpeg.jpg'
]
_preload = (src)->
new Promise (resolve, reject)->
image = document.createElement 'img'
image.src = src
image.onload = -> resolve image
View shuffle.coffee
# fisher yates shuffle algorithm
# http://en.wikipedia.org/wiki/Fisher–Yates_shuffle
Array::shuffle = ->
copy = @copy()
i = @length
while --i
j = Math.floor(Math.random() * (i + 1))
temp = copy[i]
copy[i] = copy[j]
copy[j] = temp
View parallel.coffee
266s Total: 131s Deploying, 126s Building, 9s in Build Queue.
126s Building
Build 100s
------------------------------------------->
Python Unit Tests
--->
View define.coffee
ds.define = do ->
modules = {
ds
$
_: _.noConflict()
Backbone
Breakpoints
Raven: window.Raven
key: key.noConflict()
View deploy.coffee
Q = require 'q'
exec = Q.denodify require('child_process').exec
nodes = for i in [1..10]
-> exec "deploy.sh -n=#{ i }"
makeDeploySet = (start, end)
->
set = (deploy() for deploy in nodes[start..end])
$.when.apply null, set
View poll.coffee
# Periodically call the condition promise, resolves when the condition resolves
poll = (condition, interval=1000, timeout=60000)->
promise = Q.promise (resolve, reject)->
start = _.now()
test = ->
_duration = _.now() - start
if _duration > timeout
reject "Polling timeout of #{ timeout }ms exceeded."
else
Q.fcall(condition).then resolve
View poor mans modules.js
// define ds, which adds to a queue
// must be included in <head>, before anything else.
function ds(){
(ds.q = ds.q || []).push(arguments);
return ds;
}
// process queue, included at the end of vendored js
function run(args){
var module = args[0]();