Skip to content

Instantly share code, notes, and snippets.

@stokarenko
stokarenko / Several GitHub accounts
Last active November 10, 2015 08:48
Several GitHub accounts
$ ssh-add ~/.ssh/id_rsa_some_other_github_account_name
$ git clone git@some_other_github_account_name.github.com:community/repo.git
# Add to repo/.git/config the `name` section like this
# [user]
# name = some_other_github_account_name
# email = some_other_github_account_name@users.noreply.github.com
require 'benchmark'
require 'benchmark/ips'
seed = 1239012
Benchmark.ips do |x|
x.report('bitwise multiplication by 2') { seed << 1 }
x.report('arithmetic multiplication by 2') { seed * 2 }
x.report('bitwise division by 2') { seed >> 1 }
@stokarenko
stokarenko / _while_true_vs_loop.rb
Created December 7, 2015 16:41
while(true) vs loop
require 'benchmark'
MAX = 10**8
puts Benchmark.measure{
a = MAX
while(true)
a -= 1
break if a == 0
@stokarenko
stokarenko / lazy_chaining.rb
Last active December 10, 2015 06:11
Lazy chining
require 'benchmark'
require 'benchmark/ips'
NORMAL_ITERATIONS = 100
LONG_ITERATIONS = 2000
def map_to_self(array, iterations)
iterations.times do
array = array.map{ |i| i }
end
@stokarenko
stokarenko / capybara_chrome.rb
Created August 29, 2017 11:12
Headless Chrome within RSpec & Capybara
# spec/support/capybara_chrome.rb
require 'selenium/webdriver'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
RSpec.configure do
Capybara.server = :puma
Capybara.server_port = 5000
require 'benchmark'
require 'benchmark/ips'
seed = [1,2,3]
map_proc = ->(i){ [i,i] }
Benchmark.ips do |x|
x.report('inject') { seed.inject({}){ |mem, i| mem[i]=i; mem } }
x.report('to_h') { seed.map(&map_proc).to_h }
x.report('Hash[map]') { Hash[seed.map(&map_proc)] }
module A
def func
p 'A'
super
end
end
class B
def func
p 'B'