Skip to content

Instantly share code, notes, and snippets.

View pechorin's full-sized avatar
🌴
(do (code) (love lists))

andrey pechorin pechorin

🌴
(do (code) (love lists))
View GitHub Profile
# Drop this file in config/initializers to run your Rails project on Ruby 1.9.
# This is three separate monkey patches -- see comments in code below for the source of each.
# None of them are original to me, I just put them in one file for easily dropping into my Rails projects.
# Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes
# that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's
# true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9.
#
# Andre Lewis 1/2010
# encoding: utf-8
yes_no_conditions_creator = lambda {|yes_or_no,field_name|
if yes_or_no == 'yes'
{:conditions => "books.#{field_name.to_s} = true"}
elsif yes_or_no == 'no'
{:conditions => "books.#{field_name.to_s} = false or books.#{field_name.to_s} is null"}
else
{}
end
}

REE

3.0.5

development

order index

4.51s - firebug Completed 200 OK in 1677ms (Views: 749.7ms | ActiveRecord: 134.0ms)

order ajax update

# server at 8081
require 'rubygems'
require 'faye/websocket'
app = lambda do |env|
ws = Faye::WebSocket.new(env)
ws.onmessage = lambda do |event|
puts event.data
if event.data == 'started'
@pechorin
pechorin / gist:2480007
Created April 24, 2012 14:12
грубый черновик :D
# БЫЛО
# нужно создать такие коллбеки, которые могут быть скипнуты, если переменная skip_<имя_коллбека> возвращает true
class A
attr_accessor :skip_send_faye_notify
after_create :send_faye_notify
def send_faye_notify
unless @skip_senf_faye_notify
send
# Concern
module SkipSpecificCallback
extend ActiveSupport::Concern
module ClassMethods
def with_skip(callback_name, *args)
options = args.extract_options!
raise Exception, ":on not specified" if options[:on].blank?
attribute_name = "skip_#{callback_name}"
@pechorin
pechorin / gist:2499364
Created April 26, 2012 12:54
state miaso
class A
state_machine do
state :active
state :removed
event :remove do
transition :active => :removed
end
@pechorin
pechorin / gist:2509232
Created April 27, 2012 13:31
lolproxy
class Renderer
def render
puts "RENDERED"
end
end
# а теперь создадим прокси :))
class Image
def after_save
puts "after save image!"
end
end
img = Image.new
img.after_save # => "after save image!"
@pechorin
pechorin / gist:2700458
Created May 15, 2012 09:48
io call target/sender
kiriy := Object clone
kiriy name := "Kiriy"
kiriy kill := method(
("my name is " .. call target name) println
("and i was killed by " .. call sender name) println
)
killer := Object clone
killer name := "Dron"