Skip to content

Instantly share code, notes, and snippets.

View avescodes's full-sized avatar

Avery Quinn avescodes

View GitHub Profile
@avescodes
avescodes / permit.rb
Created February 8, 2011 16:49
Read through this snippet for a few minutes then walk us through what you think it does
class Permit < ActiveRecord::Base
# ... snip*
# Assume "def model" exists elsewhere in the class.
def to_ability
modes = [:create, :read, :update, :destroy].select do |mode|
self.send(:"can_#{mode}?")
end
@avescodes
avescodes / gist:730470
Created December 6, 2010 15:53
RegistersRefactor => Master Merge
Removing app/controllers/activities_meta_data_controller.rb
Removing app/controllers/aspects_controller.rb
Removing app/controllers/impacts_controller.rb
Removing app/controllers/legislation_values_controller.rb
Removing app/models/activities_meta_data_store.rb
Removing app/models/activities_meta_datum.rb
Removing app/models/activities_meta_datum_methods/key_value_store.rb
Removing app/models/activity_observer.rb
Removing app/models/aspect.rb
Removing app/models/facility_register_observer.rb
rails-script () {
rfpath=$(find-rakefile .)
target=$1; shift
if [ -f $rfpath/script/rails ]; then
$rfpath/script/rails $target $argv
else
$rfpath/script/$target $argv
fi
}
@posts = (params[:title] ? Post.where("UPPER(posts.title) LIKE UPPER(%?%)", parmas[:title]) : Post).paginate(:page => 1, :order => "created_at DESC", :per_page => 20)
%p.intro
== Hello #{h(@user.email)},
%br/
%br/
== We've just launched MakeYourGirlfriendHappy.com! You had signed up on our mailing list and we took the liberty of creating your account for you so you don't have to enter your information twice. Click #{link_to('here',"http://makeyourgirlfriendhappy.com/profile/password/edit?reset_password_token=#{@user.reset_password_token}")} to create your password.
%br/
%br/
== Regards,
%br/
%br/
@avescodes
avescodes / Methods on Class Instances
Created October 26, 2010 15:26
Creating/calling instance methods defined on class instances that are defined on that classes instance meta-class instance *head-explode*
ruby-1.9.2-p0 > string = "ABC"
=> "ABC"
ruby-1.9.2-p0 > def string.thing
ruby-1.9.2-p0 > puts 'abc'
ruby-1.9.2-p0 > end
=> nil
ruby-1.9.2-p0 > string.thing
abc
=> nil
ruby-1.9.2-p0 > "abc".thing
Ryans-iPhone:~ root# sudo gem install rails
dyld: lazy symbol binding failed: Symbol not found: __OSSwapInt16
Referenced from: /usr/lib/ruby/1.9.1/arm-darwin9/socket.bundle
Expected in: flat namespace
dyld: Symbol not found: __OSSwapInt16
Referenced from: /usr/lib/ruby/1.9.1/arm-darwin9/socket.bundle
Expected in: flat namespace
Trace/BPT trap
candidates = [:burke, :kevin, :lisa, :mark, :afolabi, :brent, :tiffany, :cary, :peer, :brock, :john, :keith, :brad, :ryan]
# Let's let everyone make their own choice :P
occurrences = candidates.inject({}) {|h,candidate| h[candidate] = candidates.sample(3); h}
# Now tally them up
counts = occurrences.values.flatten.inject({}) {|h,person| h[person] ||= 0; h[person] += 1; h}
sorted = counts.sort {|a,b| b.last <=> a.last }
@avescodes
avescodes / variable-method_squash.rb
Created July 14, 2010 18:35
Apparently even if a local variable declaration isn't run it will still shadow a method with the same name
def thing
"ASDF"
end
puts thing #=> ASDF
if false
thing = "JKL:"
end
// ==UserScript==
// @name Panda Environment Reminder
// @namespace http://panda-build
// @description Color the user bar based on environment and remove annoying flash message
// @include http://localhost:3000/*
// @include http://panda-build/*
// @include https://panda-staging/*
// @include http://panda-*/*
// ==/UserScript==