Skip to content

Instantly share code, notes, and snippets.

View paneq's full-sized avatar
🏠
Working from home

Robert Pankowecki paneq

🏠
Working from home
View GitHub Profile
require 'invalid_length_error'
module ActiveModel
class Errors
def normalize_message(attribute, message, options)
custom_message = options[:message] || message || :invalid
if custom_meesage.respond_to?(:call)
custom_message.call(attribute, options)
elsif custom_message.is_a?(Symbol)
@paneq
paneq / interface.rb
Created January 10, 2012 18:06
Ruby interface
module Interface
def ===(obj)
self.instance_methods.all?{|m| obj.respond_to?(m)}
end
end
module IService
extend Interface
@paneq
paneq / ad.rb
Created January 21, 2012 21:00
class Ad
def self.last_unverified
self.unverified_ads.last
end
end
def glassy_link(txt, url)
link_to txt, url, :class => :glassy
end
def format_date(date)
date.to_formatted_s(:long)
end
@paneq
paneq / output.txt
Created January 25, 2012 14:18
EM exception
SomeFeature:
ERROR test_something (0.42s)
SystemStackError: stack level too deep
/home/rupert/.rvm/rubies/ruby-1.9.2-p180-fastrequire/lib/ruby/1.9.1/prettyprint.rb:206
@paneq
paneq / output.txt
Created February 6, 2012 13:39
fibers and ||= behaviour
ruby-1.9.2-p180-fastrequire :001 > f = Fiber.new do
ruby-1.9.2-p180-fastrequire :002 > @something ||= begin
ruby-1.9.2-p180-fastrequire :003 > Fiber.yield # external query
ruby-1.9.2-p180-fastrequire :004?> 2
ruby-1.9.2-p180-fastrequire :005?> end
ruby-1.9.2-p180-fastrequire :006?> end
=> #<Fiber:0x000000028d45a8>
ruby-1.9.2-p180-fastrequire :007 > f.resume
=> nil
ruby-1.9.2-p180-fastrequire :008 > puts @something.inspect
@paneq
paneq / gelf.rb
Created February 7, 2012 12:20
GELF performance test
require 'rubygems'
require 'gelf'
n = GELF::Notifier.new("localhost", 12201)
index = 0
t = Time.now
File.open("production.log") do |f|
f.each_line do |line|
n.info(line)
@paneq
paneq / bbq_java.rb
Created February 7, 2012 23:47
bbq factories
class SessionFactory
def next(options)
Capybara::Session.new(options[:driver], Bbq.app)
end
end
class PooledSessionFactory
attr_accessor :idle, :taken
def initialize(session_factory)
@paneq
paneq / me_gusta.rb
Created February 13, 2012 11:07
Challenge
(bob & cindy).is_ok?
(bob & cindy).receive_message do |user, message|
end
TestUser === bob.class
TestUserGroup === (bob & cindy).class