Skip to content

Instantly share code, notes, and snippets.

@pehrlich
pehrlich / spine_attr_tracking.js.coffee
Created April 7, 2012 16:15
Dirty attribtue tracking for spine like AR
InstanceMethods =
snapshot_attributes: ->
attrCopy = {}
for k, v of @attributes()
attrCopy[k] = v
@_attributes_snapshot = attrCopy
console.log 'snapshotted', this, attrCopy, @_attributes_snapshot, @was('type')
// number to string, pluginized from http://stackoverflow.com/questions/5529934/javascript-numbers-to-words
window.num2str = function (num) {
return window.num2str.convert(num);
}
window.num2str.ones = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
window.num2str.tens = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
window.num2str.teens = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
@pehrlich
pehrlich / model.js.coffee
Created March 9, 2012 22:46
monkey patch dynamic spine model configuration
Spine.Model.include
# this is a monkey patch to allow dynamic loading of attributes.
load_without_updating_config: Spine.Model.prototype.load
load: (atts)->
for key, value of atts
if @constructor.attributes.indexOf(key) == -1
@constructor.attributes.push key
@load_without_updating_config(atts)
@pehrlich
pehrlich / active_controller.js.coffee
Created February 6, 2012 03:22
Spine.js get active controller from stack
Spine.Stack.include
active_controller: ()->
@manager.active_controller
window.app = new App
app.manager.bind 'change', (controller)->
console.log 'stack change', this, arguments
@active_controller = controller
@pehrlich
pehrlich / backbone_extensions.js.coffee
Created January 27, 2012 01:11
Getting rid of some cruft in backbone
# the current setup, for conveience, removes all capital letters from class names, which is not the best.
# this could be fixed, but carefully.
# remove the default ensure element, we handle this in Base
Backbone.View.prototype._ensureElement = () ->
class ZenBucket.Views.Base extends Backbone.View
initialize: (render) ->
# set up sensible defaults
@pehrlich
pehrlich / neo4j-AcceptsHashFor.rb
Created January 25, 2012 05:55
Allows a neo4j to be given a hash and build a related model
module Neo4j
module Rails
class Model
class << self
# This allows anything to be thrown at a relationship and understood.
# usage:
#
# has_one(:location).to(Location)
# accepts_hash_for :location
@pehrlich
pehrlich / SerializeConverter.rb
Created January 25, 2012 03:30
Serialize to property for neo4j
module Neo4j
module TypeConverters
class SerializeConverter
# serializes to sting
class << self
def convert?(type)
type == :serialize
end
@pehrlich
pehrlich / application_controller.rb
Created December 24, 2011 16:15
handle json with query mobile
# someday: move to json response module?
def json_response(options)
logger.warn "JSON response: #{options}"
render json: options
end
def json_callback(method, args = [])
json_response({status: :window_callback, method: method, args: args})
end
@pehrlich
pehrlich / nxt.css
Created December 20, 2011 20:36
borked jquery themeroller theme
/*!
* jQuery Mobile v1.0rc2
* http://jquerymobile.com/
*
* Copyright 2010, jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
/*!
* jQuery Mobile Framework
@pehrlich
pehrlich / sparkle.js.coffee
Created December 17, 2011 21:11
jq extension to create 'chaser lights' circling around a button
$.fn.sparkle = (arg_options) ->
options = {
width: 3
gap: 3
comets: 2
}
$.extend(options, arg_options) if arg_options
span = options.width + options.gap