Skip to content

Instantly share code, notes, and snippets.

function toArray(args) {
return [].slice.call(args);
}
function autocurry(fn) {
var len = fn.length;
var args = [];
return function next() {
args = args.concat(toArray(arguments));
return (args.length >= len) ?
var Promise = require("bluebird");
var fs = require("fs");
Promise.promisifyAll(fs);
// fs.readFileAsync("file.js", "utf8").then(...)
var readFileTree = function ( root ) {
var results = [];
class Bill extends Backbone.Model
initialize: ( id ) ->
@id = id;
@_when = $.when( @getAmendments(), @getVotes() )
then: ( callback ) ->
@_when.then( callback )
@
var createObservedObject = function(callback) {
var obj = {};
var args = [].slice.call(arguments, 1);
for(var i in args) {
var thisPropertyName = args[i];
(function(thisPropertyName) {
obj['_' + thisPropertyName] = undefined;
Object.defineProperty(obj, thisPropertyName, {
get: function() {
@bttmly
bttmly / extends-jquery.coffee
Last active August 29, 2015 14:03
extending the jQuery class
class JQueryInheritor extends jQuery
constructor: ( arg ) ->
jQuery.fn.init.call( this, arg );
myMethod = ->
# do something
@bttmly
bttmly / tiny-bling.js
Created June 29, 2014 19:59
Miniscule DOM selection function that returns arrays
function $( selector, context ) {
return [].slice.call( ( context || document ).querySelectorAll( selector ) );
}
(function(root, factory) {
// Set up Module appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
define(['underscore', 'exports'], function(_, exports) {
// Export global even in AMD case in case this script is loaded with others that may still expect a global "Module".
root.Module = factory(root, exports, $);
});
@bttmly
bttmly / makeORMClass.coffee
Last active August 29, 2015 14:03
HR ORM Example
pairs = ( obj ) ->
arr = []
for own key, val of obj when key isnt "id"
arr.push "#{ key }=#{ val}"
arr.join ","
makeORMClass = ( table ) ->
# CoffeeScript syntactic sugar for class creation.
class Model
@bttmly
bttmly / README.md
Last active August 29, 2015 14:03
workers-execution-contex

Download the files, run them on a local server (python -m SimpleHTTPServer works fine), and open up index.html.

var first = (function() {
var chainNames = ["then", "andThen", "next"];
var endChainNames = ["finally", "andFinally", "last"];
var chain = function(fn) {
var f1 = function(g) {
var func = function() {return g.call(this, fn.apply(this, arguments));};
chain(func);
return func;
};
var f2 = function(g) {