Skip to content

Instantly share code, notes, and snippets.

View willbailey's full-sized avatar

Will Bailey willbailey

  • Facebook
  • San Francisco, CA
View GitHub Profile
@willbailey
willbailey / index.js
Created December 14, 2011 19:16
making property observation intrinsic to classes
'use strict';
var B = typeof exports !== 'undefined' ? exports : {};
// prefix for internal property state
var __PROP__ = '__PROP__';
// default constructor used in setting up prototype chain
var ctor = function() {};
B.extend = function(__super__, proto) {
@willbailey
willbailey / gist:1302885
Created October 21, 2011 01:31
connections
// ### Events
// Event mixin copied from Backbone
var Events = {
bind: function(evt, callback) {
var events = this._events = this._events || {};
var callbacks = events[evt] = events[evt] || [];
callbacks.push(callback);
},
unbind: function(evt, callback) {
@willbailey
willbailey / WBVector.h
Created October 6, 2011 07:51
WBVector
@interface WBVector : NSObject <NSCopying> {
CGFloat _x;
CGFloat _y;
CGFloat _z;
}
@property (nonatomic) CGFloat x;
@property (nonatomic) CGFloat y;
@property (nonatomic) CGFloat z;
@willbailey
willbailey / gist:1210437
Created September 12, 2011 01:54
springy
var extend = function(dest) {
var sources = Array.prototype.slice.call(arguments, 1), source, key;
for (var i = 0, l = sources.length; i < l; i++) {
source = sources[i];
for (key in source) {
if (source.hasOwnProperty(key)) {
dest[key] = source[key];
}
}
}
@willbailey
willbailey / gist:981352
Created May 19, 2011 18:04
BoltJS TableView
// ### TableView
// TableView provides an efficient mechanism for progressively
// rendering from a data source provided by the owner object.
// Cells are queued for reuse when they go offscreen and then
// translated back into position with updated content as they
// are reused.
var TableView = exports.TableView = core.createClass({
name: 'TableView',
extend: View,
// implement the table delegate protocol
var tableDelegate = (function() {
return {
sectionHeaderAtIndex: function() {
return null;
},
heightForSectionHeader: function(section) {
return 0;
// we have a thing model with a property of name
Model.install('ThingModel', {
properties: {
name: 'a'
}
});
// we have a thing collection that maintains our things
Collection.install('ThingCollection', {
extend: 'Collection',
// declare a model with some properties
Model.install('Thing', {
properties: {
color:'#000000',
background:'#00FFFF'
}
});
// declare a view with some properties
// and create appropriate setters that respond to changes
#!/usr/bin/env node
var fs = require('fs');
var exec = require('child_process').exec;
// handle args
var continuous = process.argv.indexOf('--watch') !== -1 ? true : false;
var minify = process.argv.indexOf('--minify') !== -1 ? true : false;
var releaseTarget = __dirname + '/release/';
var jsTarget = releaseTarget + 'bolt.js';
var cssTarget = releaseTarget + 'bolt.css';
@willbailey
willbailey / node match sync
Created March 2, 2011 19:20
node list files matching a regex recursively
var fs = require('fs');
var listFiles = function(path, match) {
var files = [];
var paths = fs.readdirSync(path);
paths.forEach(function(file) {
var stats = fs.statSync(path + '/' + file);
if (stats.isDirectory()) {
files = files.concat(listFiles(path + '/' + file, match));
} else {