Skip to content

Instantly share code, notes, and snippets.

View rich's full-sized avatar

Rich Cavanaugh rich

  • Datalot, Inc.
  • Port Saint Lucie, FL
View GitHub Profile
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');
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
require 'rubygems'
require 'nokogiri'
require 'activesupport'
class NokoHash
def self.from_s(str)
self.new(Nokogiri::XML(str))
end
def initialize(doc)
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
def self.included(receiver)
receiver.named_scope :latest_before, lambda {|time| {:conditions => ['created_at < ?', time]}}
end
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
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
~/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'
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