Skip to content

Instantly share code, notes, and snippets.

Aquarium::Aspects::Aspect.new :around, :calls_to => /^metody_admina/, :in_type => User::AdminType do |jp, obj, *args|
jp.proceed
end
class Proc
alias :original_call :call
def call
puts "custom call from proc"
original_call
super if defined? super
end
end
require 'benchmark'
class InfoDesk
def flights
puts "flights"
end
def trains
puts "trains"
end
array = [:one, :two, :three]
array.[] 0 #=> :one
array.[] 1 #=> :two
# why?;-)
# array[:hello] #=> array[:hello]
# [:world] #=> [:world] :'((((
#
# array[:hello][:world] #=> array[:hello][:world]
class Event < ActiveRecord::Base
before_save :set_event_creator
def set_event_creator
self.creator = Event.creator
end
end
# Somewhere in controller ;-)
lite@lite-ubuntu:~/RubymineProjects/tweetfunnel$ dpkg -l | grep libqt4 | grep dev
lite@lite-ubuntu:~/RubymineProjects/tweetfunnel$ sudo apt-get install libqt4-dev
Czytanie list pakietów... Gotowe
Budowanie drzewa zależności
Odczyt informacji o stanie... Gotowe
Zostaną zainstalowane następujące dodatkowe pakiety:
libqt4-declarative libqt4-opengl-dev qt4-qmake
Sugerowane pakiety:
qt4-dev-tools qt4-doc libsqlite0-dev unixodbc-dev
Zostaną zainstalowane następujące NOWE pakiety:
class Array
def initialize(*args)
self.replace args
end
puts Array.new 1,2,3 #=> [1, 2, 3]
require 'benchmark'
require 'strscan'
n = 100000
u = "hello_world/whatever"
class String
# From rails
def camelize
def number_in_words(n)
return '' if n == 0
sc = [''] + %w{jeden dwa trzy cztery pięć sześć siedem osiem dziewięć}
sn = %w{dziesięć jedenaście dwanaście trzynaście czternaście piętnaście szesnaście siedemnaście osiemnaście dziewiętnaście}
sd = ['',''] + %w{dwadzieścia trzydzieści czterdzieści pięćdziesiąt sześćdziesiąt siedemdziesiąt osiemdziesiąt dziewiędziesiąt sto}
ss = [''] + %w{sto dwieście trzysta czterysta pięćset sześćset siedemset osiemset dziewięćset}
b = ['','',''],%w{tysiąc tysiące tysięcy},%w{milion miliony milionów},%w{miliard miliardy miliardów}
p = n.to_s.size
return 'bardzo dużo' if p > 11
d,dn = n.to_s[0,(p%3 == 0 ? 3 : p%3)], n.to_s[(p%3 == 0 ? 3 : p%3)..-1]
ruby-1.9.2-p0 > @var = "sth"
=> "sth"
ruby-1.9.2-p0 > "#@var/another"
=> "sth/another"