Skip to content

Instantly share code, notes, and snippets.

View oliyoung's full-sized avatar

Oli Young oliyoung

View GitHub Profile
<select name="" id="">
<optgroup label="SA">
<option value="">Foo</option>
<option value="">Bar </option>
</optgroup>
<optgroup label="NSW">
<option value="">Foo</option>
<option value="">Bar </option>
</optgroup>
</select>
_.collect($('td[data-amount]'), function(cell) { return isNaN($(cell).data('amount')) ? 0 : $(cell).data('amount') }).reduce(function(a,b){return a+b;});
@oliyoung
oliyoung / gist:2146697
Created March 21, 2012 12:52
Cannot find Chef::Resource::EnablePackage for enable_package (NameError)
/usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/chef-0.6.0.2/lib/chef/recipe.rb:196:in `method_missing': Cannot find Chef::Resource::EnablePackage for enable_package (NameError)
Original: (eval):1:in `method_missing': uninitialized constant Chef::Resource::EnablePackage
from /data/vinomofo_admin/releases/20120321123702/deploy/cookbooks/redis/recipes/install.rb:9:in `from_file'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/chef-0.6.0.2/lib/chef/cookbook.rb:139:in `load_recipe'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/chef-0.6.0.2/lib/chef/recipe.rb:73:in `include_recipe'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/chef-0.6.0.2/lib/chef/recipe.rb:63:in `each'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/chef-0.6.0.2/lib/chef/recipe.rb:63:in `include_recipe'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/chef-0.6.0.2/lib/chef/recipe.rb:82:in `require_recipe'
from /data/vinomofo_admin/releases/20120321123702/deploy/cookbooks/redis/recipes/default.rb:6:in `from_file
serialize_table = (table) ->
_.map $('tbody tr', table), (tr) ->
$(tr).data("_id")
@oliyoung
oliyoung / gist:1420891
Created December 2, 2011 00:12
Competition selection query
select concat(users.first_name, ' ', users.last_name) as 'name', users.postcode, convert_tz(entries.created_at, '-08:00', '+10:30') as 'entered at'
from entries
left join users on users.id = entries.user_id
where convert_tz(entries.created_at, '-08:00', '+10:30') > '2011-08-14'
and convert_tz(entries.created_at, '-08:00', '+10:30') < '2011-12-01'
and users.is_admin = 0
and users.email not like '%qwoff%'
and users.email not like '%winecru%'
and users.email not like '%vinomofo%'
order by rand()
NameError: uninitialized constant ActionMailer::Base
from /Users/oliyoung/Sites/Web/xxx/app/mailers/mail.rb:1:in `<top (required)>'
from /Users/oliyoung/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.0/lib/action_mailer/base.rb:1:in `<top (required)>'
from /Users/oliyoung/Sites/Web/xxx/app/mailers/mail.rb:1:in `<top (required)>'
from (irb):1
from /Users/oliyoung/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from /Users/oliyoung/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from /Users/oliyoung/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
ruby-1.9.2-p290:
system:
uname: "Darwin Olis-MacBook-Pro.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64"
bash: "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)"
zsh: "/bin/zsh => zsh 4.3.11 (i386-apple-darwin11.0)"
rvm:
version: "rvm 1.8.0 by Wayne E. Seguin ([email protected]) [https://rvm.beginrescueend.com/]"
@oliyoung
oliyoung / create_facebook_user
Created September 16, 2011 00:20
Create and return fake Facebook user (depends on HTTParty, Fabricator & Devise)
@user = Fabricate.build(:user)
@config = Devise.omniauth_configs[:facebook]
@app = { :id => @config.args[0], :secret => @config.args[1] }
@token_url = "https://graph.facebook.com/oauth/access_token?client_id=#{@app[:id]}&client_secret=#{@app[:secret]}&grant_type=client_credentials"
@response = HTTParty.get(@token_url)
@app[:token] = CGI::escape(@response.parsed_response.split("=").last)
@user_url = "https://graph.facebook.com/#{@app[:id]}/accounts/test-users?access_token=#{@app[:token]}&name=#{@user.first_name}+#{@user.last_name}&installed=true&permissions=email,offline_access,publish_stream,user_hometown,email,user_birthday,user_interests&method=post"
@response = HTTParty.get(@user_url)
describe "visit /signup/step2" do
it "has the correct fields" do
visit signup_path
fill_in 'user_email', :with=>Faker::Internet.email
click_on "submit"
page.should have_selector("input#user_email")
page.should have_selector("input#user_password")
page.should have_selector("input#user_password_confirmation")
page.should have_selector("input#user_first_name")
page.should have_selector("input#user_last_name")
@oliyoung
oliyoung / gist:1177550
Created August 29, 2011 01:29
ActiveRecord scope
extend ActiveSupport::Concern
included do
scope :last_n_days, lambda{|n|
where("created_at > ?", n.days.ago)
}
scope :last_n_weeks, lambda{|n|
where("created_at > ?", n.weeks.ago)
}
scope :last_n_months, lambda{|n|
where("created_at > ?", n.months.ago)