Skip to content

Instantly share code, notes, and snippets.

@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);
@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: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: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:4134486
Created November 23, 2012 08:14
compound tasks
k.task('a', function(done){ done(); });
k.task('b', function(done){ done(); });
k.task('c', function(done){
this.D.a().b().then(done);
});
k().D.c().then(function(){
console.log('done!');
@threepointone
threepointone / project.js
Last active March 22, 2016 10:20
project: Facebook's reconcilliation algorithm in regular js, applied to dom nodes License: MIT
"use strict";
var _ = require('underscore'),
slice = [].slice;
var mutations = {
append: append,
remove: remove,
replace: replace,
setAttr: setAttr
var _ = require('underscore');
var domready = require('domready'),
bean = require('bean'), // events
bonzo = require('bonzo'), // DOM wrapper/manipulation
qwery = require('qwery'), // css selectors
morpheus = require('morpheus'),
slice = Array.prototype.slice;
// Attach events API to the prototype of DOM wrapper:
@threepointone
threepointone / store.js
Created July 21, 2014 06:00
simple stores for flux
var util = require('util'),
_ = require('underscore'),
EventEmitter = require('events').EventEmitter
function Store(ctx, initial) {
this.state = initial || {};
EventEmitter.call(this);
this.initialize.apply(this, arguments);
}
@threepointone
threepointone / oia_csp.js
Last active March 22, 2016 10:19
an implementation of rob pike's parallel search slide in oia
oia(lets [go chan put take timeout alts] (require 'js-csp/lib/csp') (do
(fn fake [kind]
(fn [c query]
(go (gen []
(yield (take (timeout (js Math.random()*200))))
(yield (put c [kind query]))))))
(def web1 (fake :web1))
(def web2 (fake :web2))
@threepointone
threepointone / gist:26dffd540c9e438c466f
Created January 14, 2015 21:46
jade -> json trees
var _ = require('underscore'),
Parser = require('jade/lib/parser');
module.exports = {
toJSON: toJSON,
fromJSON: fromJSON
}
function toJSON(src, options) {
var parser = new Parser(src),