Skip to content

Instantly share code, notes, and snippets.

require 'benchmark/ips'
require 'active_support/hash_with_indifferent_access'
require 'active_support/core_ext/hash'
begin
@attributes = [{ 'id' => 1, 'name' => 'Julia', 'created_at' => Time.now }] * 1000
@mapping = { 'id' => 'user_id' }
def sleep
super 0.00000001 # typecasting simulation
@dmeremyanin
dmeremyanin / sorted_insert.rb
Created August 16, 2012 14:22
Insert a number into a sorted array
class Array
def sorted_insert!(value)
min, max = 0, size
while max > min
middle = (min + max) / 2
if self[ middle ] > value
max = middle
else
def re(f = false)
begin
yield
rescue => e
p e.__id__
f ? raise(e) : raise
end
end
e = StandardError.new
@dmeremyanin
dmeremyanin / pathfinder.rb
Created December 6, 2011 11:33
pathfinder
#!/usr/bin/env ruby
class Input
def initialize(name = 'input.txt', lines = rand(10..20))
File.open(name, 'w+') do |file|
lines.times do |i|
file.puts (0..i).map { rand(-50..50) }.join(' ')
end
end
end