Skip to content

Instantly share code, notes, and snippets.

@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)
// 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 / 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')
.block-centered {
margin-left: auto;
margin-right: auto;
}
.center, .centered {
text-align: center;
}
@pehrlich
pehrlich / site_controller.rb
Created September 11, 2012 23:15
Implementing Google's hashbang/Ajax crawl with Jruby on Rails
class SiteController < ApplicationController
def index
# who the f*!@ knows how to make a rails route for a get parameter?
if frag = params[:'_escaped_fragment_']
# good read: (Akephalos)
# http://robots.thoughtbot.com/post/1658763359/thoughtbot-and-the-holy-grail
# http://robots.thoughtbot.com/post/4583605733/capybara-webkit
# todo: phantomjs (webkit based)
@pehrlich
pehrlich / test.mirah
Created October 16, 2012 01:59
verbose mirah copmlication of bike.mirag (LeJos)
~/Projects/LeJos/bike mirahc --verbose --java --classpath /Users/peter/Downloads/leJOS_NXJ_0.9.1beta-3/lib/nxt/classes.jar test.mirah
Parsing...
test.mirah
Inferring types...
* [AST] [Import] Import(* = lejos.nxt.*) resolved!
* [AST] [Import] Import(GyroSensor = lejos.nxt.addon.GyroSensor) resolved!
* [AST] [Import] Import(GyroDirectionFinder = lejos.nxt.addon.GyroDirectionFinder) resolved!
* [Mirah::Typer] New type defined: 'MyButtonListener' < ''
* [AST] [Implements] Implements resolved!
* [Mirah::Typer] Learned local type under #<Mirah::AST::StaticScope:0x171ccb0> : b = Type(lejos.nxt.Button)
@pehrlich
pehrlich / brawl.md
Created October 24, 2012 04:58
Helicopter Event

Equipment

  • helicopters (todo, calculate charge time, flgiht time, find helicopters per person)
  • remote controls (todo: know why they bug out, how to repair)
  • AirZookas (make our own?)
  • spare helicpter parts (blades, gyros)

Charge time: 56 minutes 59 minutes

@pehrlich
pehrlich / support_controller.rb
Created October 25, 2012 01:52
Ruby code to turn Twilio text messages in to zendesk tickets
# this uses the official zendesk rubygem: https://github.com/zendesk/zendesk_api_client_rb
class SupportController < ApplicationController
skip_before_filter :verify_authenticity_token
def twilio_inbound
raise "Invalid Twilio Account Id" unless params[:AccountSid] == $twilio_account_id
raise "Invalid :from number" unless from_number = params[:From]
raise "Invalid message :body" unless body = params[:Body]
@pehrlich
pehrlich / boolean.rb
Created February 15, 2013 21:25
Rails Boolean to string yes no
class TrueClass
def to_s(style = :boolean)
case style
when :word then 'yes'
when :Word then 'Yes'
when :number then '1'
else 'true'
end
end
end
def expression_backtrace(backtrace)
new_trace = []
backtrace.each do |line|
match = /(.*):([0-9]+):in/.match line
file, linenum = match[1], match[2].to_i
new_trace << line
if File.exist?(file)
expr = File.readlines(file)[linenum - 1]