Skip to content

Instantly share code, notes, and snippets.

View thurloat's full-sized avatar

Adam Thurlow thurloat

View GitHub Profile
data = ServerResponses.initialData
# data.player.points = 10
# oh noes, we have ServerResponses.initialData infected
data = _.clone data
data.player = _.clone data.player
data.player.points = 10
server_mock.respondTo "GET /something", data
data = ServerResponses.initialData
data = merge data,
player:
points: 10
awarded_prize:
prize:
name: "Better prize"
@thurloat
thurloat / formview.coffee
Created January 18, 2012 02:59
Backbone Form -> Model sync View
# FormView Class
#
# Backbone View subclass that will allow you to bind input fields
# to model fields and keep the data in sync using the same
# declarative syntax you're used to for Backbone Views.
#
# blog post: http://thurloat.com/2012/01/17/backbone-sync-models-and-views
#
# class TestView extends FormView
#
@thurloat
thurloat / model_spec.coffee
Created January 13, 2012 14:50
Awesome function spying
it 'should fail if end date is after start date', ->
testTrip = new Trip
errorSpy = do sinon.spy
testTrip.set
end: '01/13/2012'
start: '02/14/2012',
error: errorSpy
expect(testTrip.get('start')).not.toEqual('02/14/2012')
expect(testTrip.get('end')).not.toEqual('01/13/2012')
@thurloat
thurloat / js-shootout-spine.md
Created January 9, 2012 13:50
Javascript Shootout

Javascript SHOOTOUT!

Spine JS

Spine.js is a simple and small MVC framework written in coffeescript and distributed as both Coffeescript and Javascript. It makes design decisions for you and implements a "full" ORM and Data Sync layer on top of the regular controller / view binding. It's based on Backbone's API, so many of it's features are similar

Spine is distributed with a command line utility to generate an application scaffolding for you, and to generate code for your Controllers and Models.

@thurloat
thurloat / install_nginx.sh
Created November 23, 2011 12:11
install nginx
#!/bin/sh
set -x
nginx_version=1.0.10
sudo apt-get install gcc
sudo apt-get install libpcre3-dev
sudo apt-get install libssl-dev
mkdir install_nginx && cd install_nginx
@thurloat
thurloat / foo.js
Created October 20, 2011 19:18
does this work
/**
* pre-existing HTML
* <div id="foo"></div>
*/
var foo = function(foobar){
var panel = $('#foo');
if (panel.is(":empty")){
this.button = new ButtonThing();
panel.append(this.button.asWidget());
@thurloat
thurloat / migration.sql
Created October 17, 2011 16:15
Automated Migrations? For fools!
ALTER TABLE `news_items` DROP COLUMN updated;
ALTER TABLE `news_items` ADD COLUMN updated datetime DEFAULT NULL;
ALTER TABLE `news_items` CHANGE `timestamp` `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;
UPDATE `news_items` as item SET `updated` = item.`timestamp`;
@thurloat
thurloat / lopper.php
Created October 14, 2011 18:14
Word Lopper
<?php
/**
* Ensures that line lengths fit within a chunk size, cares for HTML, HTML entities, and words.
*/
$scanning = true;
$inHtml = false;
$pieces = array();
$cursor = 0;
@thurloat
thurloat / cz
Created October 7, 2011 14:29
How I talk to honza
#!/usr/bin/env python
#coding=utf-8
import pytranslate
import getopt
import sys
from AppKit import NSPasteboard, NSArray
opts, params = getopt.getopt(sys.argv[1:], 'r')