Published as a proper npm module!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require-watcher.coffee | |
# Watches files that have been require()'d, and if they change, exits the | |
# current process, assuming that node-supervisor will then restart it. | |
fs = require 'fs' | |
# watch handler to exit the process on file changes: | |
watchFile = (filename) -> | |
fs.watchFile filename, (oldStat, newStat) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app-dev.js | |
// Helper script to register CoffeeScript and Streamline extension handlers | |
// before running an app during development. | |
// | |
// Uses https://github.com/aseemk/coffee-streamline for efficient require(), | |
// caching compiled files between runs. Sweet! | |
// | |
// Usage: instead of `_coffee app`, just do `node app-dev app`. | |
// | |
// Also works great w/ node-dev <https://github.com/fgnass/node-dev>: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WARNING: This will no longer work with CoffeeScript 1.3.2 in IE: | |
# http://coffeescript.org/#changelog | |
class Animal | |
@is: (node) -> | |
if not @TYPE then return true | |
node.type is @TYPE | |
@isnt: (node) -> | |
not @is node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async = (_) -> | |
setTimeout _, 1000 | |
switch true | |
when true | |
alert 'about to start async' | |
async _ | |
# this never executes! | |
alert 'done w/ async' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var __global = typeof global !== 'undefined' ? global : window; | |
function __cb(_, fn){ var ctx = __global.__context; return function(err, result){ __global.__context = ctx; if (err) return _(err); try { return fn(null, result); } catch (ex) { return __propagate(_, ex); } } } | |
function __future(fn, args, i){ var done, err, result; var cb = function(e, r){ done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r){ cb(e, r); }; fn.apply(this, args); return function(_){ if (done) _.call(this, err, result); else cb = _.bind(this); } .bind(this); } | |
function __propagate(_, err){ try { _(err); } catch (ex) { __trap(ex); } } | |
function __trap(err){ if (err) { if (__global.__context && __global.__context.errorHandler) __global.__context.errorHandler(err); else console.error("UNCAUGHT EXCEPTION: " + err.message + "\n" + err.stack); } } | |
/* 1 */ this.register = function __1(user, thing, oldStatus, newStatus, _) { | |
if (!_) { | |
return __future.call(thi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# async simulation helper: | |
async = (_) -> | |
setTimeout _, 500 | |
# assume we're dealing with a status change event | |
type = 'event' | |
kind = 'statusChange' | |
# assume we initially have no user or target | |
user = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var __global = typeof global !== 'undefined' ? global : window; | |
function __cb(_, fn){ var ctx = __global.__context; return function(err, result){ __global.__context = ctx; if (err) return _(err); try { return fn(null, result); } catch (ex) { return __propagate(_, ex); } } } | |
function __future(fn, args, i){ var done, err, result; var cb = function(e, r){ done = true; err = e, result = r; }; args = Array.prototype.slice.call(args); args[i] = function(e, r){ cb(e, r); }; fn.apply(this, args); return function(_){ if (done) _.call(this, err, result); else cb = _.bind(this); } .bind(this); } | |
function __nt(_, fn){ var i = 0; var cb = __cb(_, fn); var safeCb = function(){ try { cb(); } catch (ex) { __propagate(cb, ex); } }; if (typeof process != "undefined" && typeof process.nextTick == "function") return function(){ if (++i % 20 == 0) process.nextTick(safeCb); else cb(); }; else return function(){ if (++i % 20 == 0) setTimeout(safeCb); else cb(); }; } | |
function __propagate(_, err){ try { _(err); } catch (ex) { __trap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// arguments_.js | |
// Tests Streamline's ability to handle `arguments` objects which contain a | |
// Streamline (underscore) callback parameter. | |
var THIS = 'context'; | |
var COOKIE = 'cookie' | |
var innerHasExited = false; | |
var outerHasExited = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% # XXX PROFILING %> | |
<% begin = Date.now() %> | |
<!-- ... --> | |
<% # XXX PROFILING %> | |
<% time = Date.now() - begin %> | |
<% console.log "partial for thing @#{@thing.id} rendered in #{time} ms" %> |