This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recur(n) | |
if n == 0 | |
bench | |
else | |
recur(n-1) | |
end | |
end | |
def bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'sqlite3' | |
GEMFILE | |
system 'bundle' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
An exception occurred running at_exit handlers | |
no block given (LocalJumpError) | |
Backtrace: | |
ERROR: the VM is exiting improperly running at_exit handlers | |
intended operation: :exception | |
associated value: nil | |
destination scope: unknown | |
An exception occurred |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
bignum = (2 ** (0.size * 8)) | |
start = 0 | |
class H < Hash | |
def [](key) | |
super if key.kind_of?(Symbol) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
bignum = (2 ** (0.size * 8)) | |
start = 0 | |
h = {:a => start} | |
h[:a] += bignum # get into the Bignum territory | |
iterations = 100_000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using accessors: | |
attr_volatile :table, :size_control | |
def check_for_resize | |
while (current_table = table) && MAX_CAP > (table_size = current_table.size) && RESIZING != (size_ctrl = size_control) && size_ctrl < @counter.sum | |
try_in_resize_lock(current_table, size_ctrl) do | |
self.table = rebuild(current_table) | |
(table_size << 1) - (table_size >> 1) # 75% load factor | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rehearsal ---------------------------------------------------------- | |
via_case(nil) 0.260000 0.000000 0.260000 ( 0.296114) | |
via_literal(nil) 0.530000 0.000000 0.530000 ( 0.552677) | |
via_case("null") 0.750000 0.000000 0.750000 ( 0.761376) | |
via_literal("null") 0.570000 0.000000 0.570000 ( 0.646138) | |
via_case("nomatch") 1.610000 0.000000 1.610000 ( 1.669481) | |
via_literal("nomatch") 0.390000 0.010000 0.400000 ( 0.430214) | |
------------------------------------------------- total: 4.120000sec | |
user system total real |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Trigo | |
[:sin, :cos, :tan].each do |trigo_fun| | |
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ | |
def #{trigo_fun}(angle) | |
_trigo(:#{trigo_fun}, angle) | |
end | |
RUBY_EVAL | |
end | |
private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Original | |
def reverse_sql_order(order_query) | |
order_query.join(', ').split(',').collect { |s| | |
if s.match(/\s(asc|ASC)$/) | |
s.gsub(/\s(asc|ASC)$/, ' DESC') | |
elsif s.match(/\s(desc|DESC)$/) | |
s.gsub(/\s(desc|DESC)$/, ' ASC') | |
else | |
s + ' DESC' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h = {} | |
v = 1 | |
threads = Array.new(my_cpu_count = 4) do | |
Thread.new do | |
2_000_000.times {|i| h[i] = v} | |
end | |
end | |
threads.map(&:join) |
NewerOlder