This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table categories ( | |
id serial, | |
parent_id int4 references categories (id), | |
name varchar(100), | |
primary key (id) | |
); | |
insert into categories (name) values ('one'), ('two'), ('three'); | |
insert into categories (parent_id, name) values (1, 'cat'), (1, 'dog'), (1, 'bird'), (3, 'no'), (3, 'yes'), (3, 'maybe'), (8, 'good'), (8, 'bad'), (8, 'evil'), (4, 'diabetes'), (4, 'wilford brimley'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fp = '/Users/rich/stocks.test.xml' | |
n = 5 | |
Benchmark.bm(7) do |x| | |
x.report("Hash.from_xml") do | |
n.times do | |
h = Hash.from_xml(open(fp).read)['stock_feed'] | |
h['sector'].map{|s| s['stock'].map {|i| i['name']}.first}.flatten | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'activesupport' | |
class NokoHash | |
def self.from_s(str) | |
self.new(Nokogiri::XML(str)) | |
end | |
def initialize(doc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
d.id, | |
coalesce(f.cnt, 0) as cnt | |
from | |
departments as d left join | |
(select department_primary, count(1) as cnt from faculty group by department_primary) as f | |
on f.department_primary = d.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.included(receiver) | |
receiver.named_scope :latest_before, lambda {|time| {:conditions => ['created_at < ?', time]}} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Link < ActiveRecord::Base | |
acts_as_revisable | |
belongs_to :post | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Author < ActiveRecord::Base | |
acts_as_revisable :on_delete => :revise | |
end | |
class AuthorRevision < ActiveRecord::Base | |
acts_as_revision | |
end | |
@author = Author.create(:name => 'Rich') | |
@author.destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error during failsafe response: closed stream | |
[ pid=20176 file=Hooks.cpp:508 time=2009-04-03 10:00:56.78 ]: | |
Backend process 9361 did not return a valid HTTP response. It returned: [Status] | |
*** Exception NoMethodError in application (undefined method `[]=' for nil:NilClass) (process 9361): | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/passenger-2.1.0/lib/phusion_passenger/rack/request_handler.rb:68:in `process_request' | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/passenger-2.1.0/lib/phusion_passenger/abstract_request_handler.rb:197:in `main_loop' | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/passenger-2.1.0/lib/phusion_passenger/railz/application_spawner.rb:340:in `start_request_handler' | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/passenger-2.1.0/lib/phusion_passenger/railz/application_spawner.rb:298:in `handle_spawn_application' | |
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/pa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/Projects/oss/serviceproxy (git::master) $ github pull --merge jeremydurham | |
/opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/bin/../lib/github/command.rb:57:in `exec': Operation not supported - git pull jeremydurham master (Errno::E045) | |
from /opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/bin/../lib/github/command.rb:57:in `send' | |
from /opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/bin/../lib/github/command.rb:57:in `run' | |
from /opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/bin/../lib/github/command.rb:45:in `git_exec' | |
from /opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/lib/commands/commands.rb:109:in `command' | |
from /opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/bin/../lib/github/command.rb:25:in `send' | |
from /opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/bin/../lib/github/command.rb:25:in `call' | |
from /opt/local/lib/ruby/gems/1.8/gems/defunkt-github-0.3.4/bin/../lib/github.rb:74:in `invoke' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Author < ActiveRecord::Base | |
has_many :books do | |
def correct | |
map {|b| b.name} | |
end | |
def broken | |
proxy_target.map {|b| b.name} | |
end | |
end |