Skip to content

Instantly share code, notes, and snippets.

@kalorz
kalorz / gist:3267549
Created August 5, 2012 22:34
ActiveModel::Errors patch for storing "raw" error messages/symbols in Errors object, before they are translated into human readable messages
# This patch is for storing "raw" error messages/symbols in Errors object, before they are translated into human
# readable messages.
#
# u = User.create
# u.errors.messages # => {:login => ["cannot be blank"], :year_of_birth => ["must be greater than 1900"]}
# u.errors.raw # => {:login => [{:blank => {}], :year_of_birth => [{:greater_than => {:value => 1618, :count => 1900}}]}
module ActiveModel
class Errors
@kalorz
kalorz / author.rb
Created September 17, 2012 18:07
Typus + HABTM
class Author < ActiveRecord::Base
has_and_belongs_to_many :books
attr_accessible :name, :book_ids, as: [:default, :admin]
end
1) Failure:
test_should_get_daily_offers(Api::OffersControllerTest) [test/functional/api/offers_controller_test.rb:134]:
<{"status"=>"ok",
"offers"=>
[{"id"=>2,
"partner_id"=>2,
"icon_url"=>"/system/offers/icons/original/100x100.png",
"name"=>"50% off second item",
"summary"=>"Buy any product at our store, get second 50% cheaper!",
"expires_at"=>1351437987,
@kalorz
kalorz / ObfuscatedStrings.java
Last active December 12, 2015 02:09
Obfuscated Strings
class ObfuscatedStrings {
static
{
String[] arrayOfString = new String[9];
char[] arrayOfChar1 = "$\037@1h+\b\f-d+\037\f=r+\032J,p\006\016F:x+\bJ?q6".toCharArray();
int i = arrayOfChar1.length;
int j = 0;
char[] arrayOfChar2;
int i1;
### Keybase proof
I hereby claim:
* I am karolsarnacki on github.
* I am karol (https://keybase.io/karol) on keybase.
* I have a public key whose fingerprint is 257E 8A80 9785 FB05 97C8 164E B636 26C5 C820 383A
To claim this, I am signing this object:
@kalorz
kalorz / and_or_1.rb
Last active February 3, 2017 14:23
Ruby Gotchas
surprise = true and false # => surprise is true
surprise = true && false # => surprise is false
@kalorz
kalorz / ruby_gotchas_and_or_ampersand.rb
Created September 15, 2017 09:57
Ruby Gotchas: and / &&
surprise = true and false # => surprise is true
surprise = true && false # => surprise is false
@kalorz
kalorz / ruby_gotchas_and_or_ampersand_explanation.rb
Created September 15, 2017 09:59
Ruby Gotchas: and / && (explanation)
(surprise = true) and false # => surprise is true
surprise = (true && false) # => surprise is false
@kalorz
kalorz / ruby_gotchas_equality.rb
Created September 15, 2017 10:05
Ruby Gotchas: eql? and ==
1 == 1.0 # => true
1.eql? 1.0 # => false
@kalorz
kalorz / ruby_gotchas_super.rb
Last active September 15, 2017 10:10
Ruby Gotchas: super
class Foo
def show
puts 'Foo#show'
end
end
class Bar < Foo
def show(text)
super