Skip to content

Instantly share code, notes, and snippets.

@deleteme
deleteme / poll.coffee
Created April 21, 2014 18:54
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
@deleteme
deleteme / deploy.coffee
Created September 16, 2014 18:47
A proof of concept for deploying in two phases
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
@deleteme
deleteme / define.coffee
Created October 1, 2014 18:15
ds.define() registers a module under a name. The module's function is called on demand by require().
ds.define = do ->
modules = {
ds
$
_: _.noConflict()
Backbone
Breakpoints
Raven: window.Raven
key: key.noConflict()
@deleteme
deleteme / parallel.coffee
Created October 6, 2014 16:35
Parallel Tests
266s Total: 131s Deploying, 126s Building, 9s in Build Queue.
126s Building
Build 100s
------------------------------------------->
Python Unit Tests
--->
# 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>All work and no play makes Jack a dull boy.</title>
<style type="text/css" media="screen">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>All work and no play makes Jack a dull boy.</title>
<style type="text/css" media="screen">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>All work and no play makes Jack a dull boy.</title>
<style type="text/css" media="screen">
[extensions]
fetch =
[ui]
ssh = ssh -C
username = Wes Rogers <wes@cocodesign.com>
[extensions]
hgext.extdiff =
var InteractiveRadioField = Class.create({
initialize: function(name, pairs, activateFunction, inactivateFunction){
this.name = name;
this.fields = $$('input[type=radio][name=' + this.name + ']');
this.pairs = $H(pairs);
this.activateFunction = activateFunction;
this.inactivateFunction = inactivateFunction;
this.changed = false;
this.elementsToBeShown = $$(this.pairs.map(function(pair){
return '#' + pair.key;