There is of course Benchmark, but its just not simple enough…
Code
class Time
def self.benchmark
t = Time.now.to_f
yield
Time.now.to_f - t
end
end
Usage
Time.benchmark{sleep 0.1}.between?(0.1, 0.2) # true
There is of course Benchmark, but its just not simple enough…
Code
class Time
def self.benchmark
t = Time.now.to_f
yield
Time.now.to_f - t
end
end
Usage
Time.benchmark{sleep 0.1}.between?(0.1, 0.2) # true
Got a huge string and just want to shift the first line ?
Usage
a = "xxx\nyyy" first_line = a.remove_first_line! a == "yyy" first_line == "xxx"
Code
class String
def remove_first_line!
first_newline = (index("\n") || size - 1) + 1
slice!(0, first_newline).sub("\n",'')
end
end
Usage
"aa aaaa aa".indexes('a') # [0, 1, 3, 4, 5, 6, 11, 12]
Code
class String
def indexes(needle)
found = []
current_index = -1
while current_index = index(needle, current_index+1)
found << current_index
end
found
end
end
When there is no uniqueness in mysql, things can go wrong….so we fix em…
Just built this little sh script, that can be used when rake is not installed (we use it to setup a new/clean system)
def sh(cmd)
puts cmd
IO.popen(cmd) do |pipe|
while str = pipe.gets
puts str
end
end
$?.success?
end