Skip to content

Instantly share code, notes, and snippets.

View jasiek's full-sized avatar

Jan Szumiec jasiek

View GitHub Profile
@jasiek
jasiek / trace.log
Created March 11, 2012 23:58
Langusta 0.2.1 profile trace
/home/jps/.rvm/rubies/ruby-1.9.3-p0/bin/ruby -I"lib:test/quality:lib:." -I"/home/jps/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib" "/home/jps/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/quality/test_*.rb"
% cumulative self self total
time seconds seconds calls ms/call ms/call name
55.46 624.54 624.54 40716 15.34 24.98 Array#include?
34.85 1016.96 392.42 43450242 0.01 0.01 Fixnum#==
1.14 1029.76 12.80 393881 0.03 0.05 Range#include?
0.94 1040.34 10.59 11030 0.96 105.86 Integer#times
0.76 1048.85 8.51 348944 0.02 0.07 Range#===
0.70 1056.70 7.85 85317 0.09 0.48 Langusta::NGram#normalize
0.56 1063.02 6.31 86501 0.07 0.35 Langusta::UnicodeBlock.of
class Deferrable < SimpleDelegator
# Public: Create a side thread that wraps whatever you need to have available in the future.
def initialize(&blk)
super(Thread.new(&blk))
end
# Internal: We need the result of the computation of this thread NOW, so block on it and return
# the value.
def __getobj__
p = lambda { |x|
x * 2
}
p === 7 #=> 14
@jasiek
jasiek / gist:1711082
Created January 31, 2012 15:28 — forked from LTe/gist:1710563
module M
def method
puts "hello"
end
end
def execute(current_module, &block)
Object.new.tap do |o|
o.extend(current_module)
o.instance_eval &block
module M
def hello
1
end
end
module N
include M
ruby-1.9.3-p0 :001 > def f(x, y=1)
ruby-1.9.3-p0 :002?> method(__method__).parameters
ruby-1.9.3-p0 :003?> end
=> nil
ruby-1.9.3-p0 :004 > f(1, 2)
=> [[:req, :x], [:opt, :y]]
(?<ltr>[ABCEGHJKLMNPRSTVXYWZ]){0}
(?<num>[0-9]){0}
(?<fsa>\g<ltr>\g<num>\g<ltr>){0}
(?<ldu>\g<num>\g<ltr>\g<num>){0}
(?<cpc>\g<fsa> \g<ldu>){0}
^\d{5}|\g<cpc>$
\g<group-name>
(?<group-name>regular-expression){0}
@jasiek
jasiek / gist:1295394
Created October 18, 2011 13:19
Ruby pre-initialized struct
class Basket < Struct.new(:entries)
def self.new(*args)
b = super(*args)
b.entries ||= []
b
end
def total
entries.inject(0.0) do |sum, entry|