Skip to content

Instantly share code, notes, and snippets.

View modsognir's full-sized avatar

Jared Fraser modsognir

View GitHub Profile
class Test
%w{one two three}.each do |p|
define_method("#{p}?") { self.wat == p }
end
def wat
"two"
end
# Allows you to do (1) instead of (2)
# 1
Given /^I sign up as a staff member with login "([^\"]*)"$/ do |login|
Cucumber(%Q{
When I go to the sign up page
And I fill in "Username" with "#{login}"
And I fill in "Password" with "password"
And I fill in "Password again" with "password"
And I fill in "Email" with "#{login}@domain.com"
products = Product.where("price = 100").limit(5) # No query executed yet
products = products.order("created_at DESC") # Adding to the query, still no execution
products.each { |product| puts product.price } # That's when the SQL query is actually fired
class Product < ActiveRecord::Base
named_scope :pricey, where("price > 100")
named_scope :latest, order("created_at DESC").limit(10)
end
config.encryptor = :modsognir
h = ActiveSupport::OrderedHash.new
h['one'] = '1'
h['two'] = '1'
h['three'] = '1'
h.find_all { true }
=> [["one", "1"], ["two", "1"], ["three", "1"]]
class Model < ParentModel
include Foo::Bar
extend Bar::Baz
module InternalModule
...
end
default_scope :order => 'id ASC'
module ActiveSupport
module CoreExtensions
module Array
module Conversions
def to_sentence
self.join(' and ')
end
end
end
end
@modsognir
modsognir / gist:907039
Created April 7, 2011 04:29
quick git log parser
features = `git log | grep Feature:`
bugs = `git log | grep Bugfix:`
refactors = `git log | grep Refactor:`
out = ""
out += "Features:\n"
out += features.gsub('Feature:', "")
out += "Bugfixes:\n"
out += bugs.gsub('Bugfix:', "")
out += "Refactors:\n"
out += refactors.gsub('Refactor:', "")
2011-05-03 14:06:47.659 mate[24716:903] An uncaught exception was raised
2011-05-03 14:06:47.663 mate[24716:903] connection went invalid while waiting for a reply
2011-05-03 14:06:47.664 mate[24716:903] *** Terminating app due to uncaught exception 'NSInvalidReceivePortException', reason: 'connection went invalid while waiting for a reply'
*** Call stack at first throw:
(
0 CoreFoundation 0x941356ba __raiseError + 410
1 libobjc.A.dylib 0x9348f509 objc_exception_throw + 56
2 CoreFoundation 0x941353e8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x9413535a +[NSException raise:format:] + 58
4 Foundation 0x998bb0f4 -[NSConnection sendInvocation:internal:] + 4205
module Resque
class Task
attr_accessor :parent, :args
attr_accessor :queue, :failed_at, :payload, :exception, :error, :backtrace, :worker
def initialize(options={})
options['parent'] = options.delete('class')
options.each do |opt, val|
self.send("#{opt}=", val)
end