Skip to content

Instantly share code, notes, and snippets.

@kalorz
kalorz / float_test.go
Created July 29, 2021 21:30
Bun Float Bug
package float_test
import (
"database/sql"
"testing"
"github.com/go-pg/pg/v10"
_ "github.com/go-pg/pg/v10/orm"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/stdlib"
@kalorz
kalorz / ruby_gotchas_private_self_method_solution.rb
Created September 15, 2017 10:42
Ruby Gotchas: private self.method (solution)
class Foo
class << self
private
def bar
puts 'Class method called'
end
end
def self.baz
@kalorz
kalorz / ruby_gotchas_private_self_method.rb
Created September 15, 2017 10:40
Ruby Gotchas: private self.method
class Foo
private
def self.bar
puts 'Not-so-private class method called'
end
end
Foo.bar # => "Not-so-private class method called"
@kalorz
kalorz / ruby_gotchas_accessor_return.rb
Created September 15, 2017 10:39
Ruby Gotchas: accessor return value
class Foo
def self.bar=(value)
@foo = value
return 'OK'
end
end
Foo.bar = 3 # => 3
@kalorz
kalorz / ruby_gotchas_bang.rb
Created September 15, 2017 10:38
Ruby Gotchas: bang! methods return value
'foo'.upcase! # => "FOO"
'FOO'.upcase! # => nil
@kalorz
kalorz / ruby_gotchas_lexical_socpe_vs_inheritance.rb
Last active September 15, 2017 10:34
Ruby Gotchas: Lexical Scope vs Inheritance
MY_SCOPE = 'Global'
module Foo
MY_SCOPE = 'Foo Module'
class Bar
def scope1
puts MY_SCOPE
end
end
@kalorz
kalorz / ruby_gotchas_exception.rb
Created September 15, 2017 10:13
Ruby Gotchas: Exception
class BangBang < Exception
end
begin
raise BangBang
rescue
puts 'Caught it!'
end
@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
@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_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