Skip to content

Instantly share code, notes, and snippets.

window.addEventListener "DOMContentLoaded", ->
body = $ "body"
canvas = $ "#canvas"
chalkboard = $ "#chalkboard"
close = $ "#close"
ledge = $ "#ledge"
lightswitch = $ "#lightswitch"
output = $ "#output"
shade = $ "#shade"
share = $ "#share"
require "coffee-script"
require "benchmark"
Benchmark.bmbm do |x|
x.report("evaluate") do
100.times { CoffeeScript.evaluate "a = 1" }
end
end
var dom = require("jsdom/jsdom/level2/core").dom.level2.core;
var browser = require("jsdom/jsdom/browser");
exports.createWindow = function() {
var bom = browser.browserAugmentation(dom);
var window = browser.windowAugmentation(dom);
for (var key in bom) window[key] = bom[key];
return window;
}
@sstephenson
sstephenson / back_forward.js
Created December 13, 2010 21:55
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@sstephenson
sstephenson / nodette.coffee
Created December 23, 2010 23:26
Sandboxed CommonJS module contexts for Node
{Script} = process.binding 'evals'
natives = process.binding 'natives'
Path = require 'path'
FS = require 'fs'
globals = {
Buffer, process, console,
setTimeout, clearTimeout,
setInterval, clearInterval
@sstephenson
sstephenson / gist:771090
Created January 8, 2011 19:41
Automatic *.test host resolution in OS X
$ sudo su -
# mkdir /etc/resolver
# cat > /etc/resolver/test
nameserver 127.0.0.1
port 2155
^D
^D
$ brew install dnsmasq
$ dnsmasq --port=2155 --no-resolv --address=/.test/127.0.0.1
$ ping foo.test
> package = stitch.createPackage({ paths: ['basecamp-mobile/lib'] })
> package.findRequires(function(err, requires) { console.log(requires) })
> [ 'cinco/application',
'cinco/date_time',
'cinco/collection',
'cinco/util',
'basecamp/collections/collection',
'basecamp/models/comment',
'basecamp/models/company',
'basecamp/models/milestone',
@sstephenson
sstephenson / let.tcl
Created March 17, 2011 14:04
Lexical scoping in Tcl
#!/usr/bin/env TEST=1 tclsh
# Lexical scoping in Tcl
proc let {block args} {
try {
set captured_vars [uplevel [list capture [block args]]]
set all_var_names [uplevel {info vars}]
foreach var [block args] value $args {
uplevel [list catch [list unset $var]]
@sstephenson
sstephenson / config.ru
Created April 8, 2011 04:46
Rackup file for Rails 2.3 apps
require File.dirname(__FILE__) + '/config/environment'
run ActionController::Dispatcher.new
@sstephenson
sstephenson / gist:921992
Created April 15, 2011 16:33
REE vs 1.9.2 for a small Rails 3 app
ree-1.8.7-2010.02
-----------------
units: Finished in 0.930402 seconds.
functionals: Finished in 12.241386 seconds.
integration: Finished in 1.648589 seconds.
rake 20.19s user 4.96s system 98% cpu 25.588 total
ruby-1.9.2p180
--------------
units: Finished in 1.504977 seconds.