Skip to content

Instantly share code, notes, and snippets.

View tanelsuurhans's full-sized avatar

Tanel Suurhans tanelsuurhans

  • ID.me
  • United States
View GitHub Profile
foo.inject({}) do |hash, bar|
hash.store(a, b)
hash
end
def self.stuff
scope = scoped
scope = scope.order("foo") if stuff
scope = scope.joins(:user) if user
scope = scope.where(:foo => "bar")
scope
end
def quoted_date(value) #:nodoc:
result = super
if value.acts_like?(:time) && value.respond_to?(:usec)
result = "#{result}.#{sprintf("%06d", value.usec)}"
end
if value.year < 0
result = result.sub(/^-/, "") + " BC"
end
result
class MyModel < ActiveRecord::Base
attr_accessible :my_attribute
def my_attribute=(value)
# do something else here...
write_attribute(:my_attribute, value)
end
end
package ee.suurhans.algorithms;
import com.sun.org.apache.xpath.internal.functions.FuncFalse;
import java.util.*;
/**
* User: Tanel Suurhans
* Date: 17.02.13
*/
describe "database" do
it "should have an unique index on confirmation_token" do
must have_db_index(:confirmation_token).unique(true)
end
it "should have an unique index on email" do
must have_db_index(:email).unique(true)
end
User::mass assigment
PASS (0:00:01.141) 0007 anonymous
PASS (0:00:01.158) 0011 anonymous
PASS (0:00:01.175) 0015 anonymous
PASS (0:00:01.193) 0003 anonymous
PASS (0:00:01.211) 0013 anonymous
PASS (0:00:01.230) 0005 anonymous
PASS (0:00:01.248) 0017 anonymous
PASS (0:00:01.265) 0002 anonymous
describe "validations" do
it { must validate_presence_of(:email) }
it { must ensure_length_of(:email).is_at_most(255) }
end
it "validate email" do
subject.must validate_presence_of(:email)
subject.must ensure_length_of(:email).is_at_most(255)
SELECT id,
sum(hours) AS totalhours
FROM mytable
GROUP BY id
HAVING sum(hours) > 50;
If you really can't be bothered to write sum() twice, you could consider
a two-level SELECT:
SELECT * FROM
Bundler could not find compatible versions for gem "devise":
In Gemfile:
locomotive_cms (= 2.0.0.rc12) ruby depends on
devise (~> 2.1.2) ruby
locomotive_cms (= 2.0.0.rc12) ruby depends on
devise (2.2.3)