Skip to content

Instantly share code, notes, and snippets.

View sxross's full-sized avatar

s.ross sxross

View GitHub Profile
@sxross
sxross / new_model_object.coffee
Created November 28, 2011 18:12
Creating a Single Backbone.js Model Object
aSingleBand = new Band(name: 'Foo Fighters')
@sxross
sxross / layout.haml
Created November 28, 2011 18:21
Layout Haml File
!!!5
%html
%head
%meta{:charset => "utf-8"}
// Always force latest IE rendering engine (even in intranet) & Chrome Frame
%meta{:content => "IE=edge,chrome=1"}
%meta{"http-equiv" => "X-UA-Compatible"}
= stylesheet_link_tag "site.css"
= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"
@sxross
sxross / index.html.haml
Created November 28, 2011 21:20
Index for Backbone Example
- content_for :head do
%title The Middleman!
%h1 The Middleman is watching.
#band-app
%table#band-list
%thead
%tr
%td
%a#sort-name{:href => '#'}
@sxross
sxross / backbone_render.coffee
Created December 8, 2011 22:05
Backbone render
SONG_TEMPLATE = '''
<table>
{{#if songs.length }}
{{#each songs}}
<tr><td>{{ this.name }}</td><td>{{ this.duration }}</td></tr>
{{/each}}
{{/if}}
</table>
'''
@sxross
sxross / save_cancel_toolbar.rb
Created August 12, 2012 17:15
UIToolbar Subclass to Include Save and Done Buttons
class SaveCancelToolbar < UIToolbar
attr_writer :delegate
def initWithFrame frame, andTitle: title
super
items = []
spacer = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemFlexibleSpace, target:nil, action:nil)
@cancel_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemCancel, target:self, action:'on_cancel:')
@sxross
sxross / mixin-template.rb
Created October 21, 2012 06:14
A Template for Building a Mixin
module MixinTemplate
def self.included(base)
base.extend(ClassMethods)
base.instance_variable_set('@my_data', [])
end
module ClassMethods
...
end
@sxross
sxross / core_helpers.rb
Created January 13, 2013 23:51
RubyMotion Extension I Can't Get To Work
class String
def add_formatted(str, format = '%s')
return self if str.nil?
self << format % str if str.length > 0
self
end
def to_us_phone
phone = self.dup.gsub(/[^\d]/, '')
last = phone[-4..-1]
@sxross
sxross / gist:4526913
Created January 13, 2013 23:54
Spec for core_extensions.rb
# See https://gist.github.com/4526905 for the code this tests
describe "core helpers" do
it "has a 'to_us_phone' method" do
'hello'.should.respond_to? :to_us_phone
end
describe "7-digit phone numbers" do
it "formats string" do
'1112222'.to_us_phone.should == '111-2222'
@sxross
sxross / gist:4711848
Created February 5, 2013 03:07
Super in module context
module MotionModel
module Model
def save(*)
puts "called MM#save"
end
end
end
module MotionModel
module Paranoid
module SugarCube
module DateParser
# Parse a date string: E.g.:
#
# SugarCube::DateParser.parse_date "There is a date in here tomorrow at 9:00 AM"
#
# => 2013-02-20 09:00:00 -0800
def self.parse_date(date_string)
detect(date_string).first.date
end