Skip to content

Instantly share code, notes, and snippets.

@threepointone
threepointone / gist:3756209
Created September 20, 2012 14:16
Simple Queue/Parallel exec in js
var q = function() {
var args = _.flatten(arguments);
var ctr = args.length;
var complete;
function run(i) {
args[i](function() {
if (i + 1 === ctr) {
if (complete) {
complete();
@threepointone
threepointone / gist:3103649
Created July 13, 2012 08:27
attributes for objects (ala YUI)
match = require 'minimatch'
_ = require 'underscore'
class Events
on: (evt, handler = _.i, scope = @) ->
@_events or= []
spec =
evt: evt
handler: handler
scope: scope
@threepointone
threepointone / gist:3097182
Created July 12, 2012 10:11
simple namespaced events in coffeescript
match = require 'minimatch'
_ = require 'underscore'
class Events
constructor: ->
@_events = [];
on: (evt, handler = _.i, scope = @) ->
@_events.push {evt, handler, scope};@
fire: (evt, args...) ->
_.each @_events, (spec) =>
@threepointone
threepointone / gist:2382589
Created April 14, 2012 07:12
YUI-ey way to require node modules
// going to use _ for array flattening until this - http://yuilibrary.com/projects/yui3/ticket/2531371 is resolved.
var _ = require('underscore'),
YUI = require('yui3').YUI;
YUI.add('node-js', function (Y) {
Y.namespace('nodejs');
Y.nodejs.require = function () {
var requires = {},
modules = _.flatten(arguments);