Skip to content

Instantly share code, notes, and snippets.

View davidcelis's full-sized avatar
Verified account

David Celis davidcelis

Verified account
View GitHub Profile
Processing SystemsController#delegate_data_key (for 173.12.191.149 at 2011-09-20 16:11:27) [POST]
Parameters: {"delegate_to"=>"5934", "id"=>"5481"}
Deadlock detected on retry 1, restarting transaction
Deadlock detected on retry 2, restarting transaction
Deadlock detected on retry 3, restarting transaction
Deadlock detected on retry 4, restarting transaction
Deadlock detected on retry 5, restarting transaction
Deadlock detected on retry 6, restarting transaction
Deadlock detected on retry 7, restarting transaction
Deadlock detected on retry 8, restarting transaction
@davidcelis
davidcelis / not_right.rb
Created September 29, 2011 17:59
why is this wrong
require "nokogiri"
xml = Nokogiri::XML(File.open("some_shit.xml"))
xml.at_css("xmldata")
# => nil
xml.xpath("//soap12:Envelope")
# => works, returns element and children
Given /^I have entered a valid drink order$/
When I fill in the following:
| field1 | value1 |
| field2 | value2 |
| etc | etc |
@davidcelis
davidcelis / routes.rb
Created November 29, 2011 20:06
Example permalink matching
# Permalink matching
match "/users/:username" => "users#show", as: "user"
# 1
(1...1000).select {|i| i % 3 == 0 || i % 5 == 0 }.inject(:+)
# 2
fib1,fib2,sum = 1,1,0
until fib2 > 4000000
fib1,fib2 = fib2,(fib1 + fib2)
sum += fib2 if fib2 % 2 == 0
end
module Engine
mattr_accessor :user_class, :redis, :redis_host, :redis_port
class << self
def user_class
@@user_class.constantize
end
def redis
@@redis ||= Redis.new(@@redis_host, @@redis_port)
★ Hated it
★★ Didn't like it
★★★ Liked it
★★★★ Really liked it!
★★★★★ Loved it!
@davidcelis
davidcelis / beers_controller.rb
Created February 13, 2012 07:08
Example recommendable controller implementation
class BeersController < ApplicationController
def like
@beer = Beer.find(params[:id])
respond_to do |format|
if current_user.like @beer
# respond to HTML with a redirect, render ajax js, etc.
else
# flash[:error], if you wish
end
@davidcelis
davidcelis / post.rb
Created February 20, 2012 20:35
Polymorphism 101
class Post < ActiveRecord::Base
has_many :tag_links
has_many :tags, :through => :tag_links
# ...
end
@davidcelis
davidcelis / spec.rb
Created February 24, 2012 20:28
a spec, yo
describe Model do
describe "#method" do
it "should return the expected value" do
obj = Factory(:model)
obj.method.should == __
end
end
describe "#some_other_method" do
it "should not raise an exception" do