Skip to content

Instantly share code, notes, and snippets.

View whalec's full-sized avatar

Cameron Barrie whalec

View GitHub Profile
class EmailForm
EMAIL_REGEX = /\A[\w\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)\z/i
class Errors < Array
def on(method)
unless blank?
error = find{|error| error[0].to_sym == method.to_sym}
return error[1] unless error.blank?
end
module WardenStub
def warden
@_warden ||= mock
end
def user
@_user ||= mock(User)
end
APPLICATION[:version] == '1.0.1'
APPLICATION[:language] == 'en-uk'
class CreateMedia < ActiveRecord::Migration
def self.up
create_table :media do |t|
t.string :name, :null => false
t.text :description
t.references :asset, :null => false
t.timestamps
end
class Node
addToStage: ->
console.log "Add node to stage"
# AViewController.h
@interface AViewController : UIViewController
{
}
@property(readwrite, retain) NSString *aString;
@property(readwrite, assign, getter=isReady) BOOL ready;
# AViewController.m
@implementation AViewController
[[NSArray arrayWithObjects:...];
is actually just
[[[NSArray alloc] initWithObjects:...] autorelease];
It's a convenience method that means you don't need to release it since it's in the autorelease pool.
@whalec
whalec / phone_feature_spec.rb
Created November 24, 2010 02:38
These specs are failing in certain orders.
require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
describe "Finding a phone" do
before do
5.times { make_phone! }
5.times { Plan.make }
@phones = Phone.find(:all)
@plan = Plan.find(:all)
@whalec
whalec / gist:803505
Created January 31, 2011 01:15
how bag's might work in migrations
class SetupDatabase < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.bag_for :category
t.references :sector
t.timestamps
end
add_bag_indexes_for(:categories)
end
end
bag do
field :title, :hint => {:size => 40}, :search => {
:sortable => true,
:as => :name
# Thinking Sphinx options in here
}
end