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 / 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 {
commit 2111cdc41fbd683e43b33a38a7f4b60670b3013b
Author: wbailey <wi11.bai1ey@facebook.com>
Date: Fri Feb 25 09:50:40 2011 -0800
model change event is now just "changed"
diff --git a/src/binding.js b/src/binding.js
index 668c9a9..dafbee1 100644
--- a/src/binding.js
+++ b/src/binding.js
@willbailey
willbailey / gist:735813
Created December 10, 2010 05:05
lucky 13
require "open-uri"
def bet(bet)
win = false; winnings = 0
until win
win = open("http://roulette.engineyard.com").read.match(/13/)
winnings += (win ? bet * 35 : -bet)
end
winnings
end
- (UIImage*)tintedImageWithColor:(UIColor*)tint {
CGSize size = self.size;
CGRect imageBounds;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] &&
[[UIScreen mainScreen] scale] == 2) {
imageBounds = CGRectMake(0, 0, size.width * 2, size.height * 2);
} else {
imageBounds = CGRectMake(0, 0, size.width, size.height);
}
var jsonToXMLString = function(data){
var carrier = DOM.create('carrier');
var convert = function(data, currentNode) {
keys(data).each(function(k) {
var v = data[k];
if (is_scalar(v)) {
currentNode.setAttribute(k, v);
} else if (hasArrayNature(v)) {
v.each(function(vv){
var node = DOM.create(k);