Skip to content

Instantly share code, notes, and snippets.

View class_ancestors.rb
module A
def func
p 'A'
super
end
end
class B
def func
p 'B'
View array_to_hash.rb
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)] }
@stokarenko
stokarenko / capybara_chrome.rb
Created Aug 29, 2017
Headless Chrome within RSpec & Capybara
View capybara_chrome.rb
# 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
View lazy_chaining.rb
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
View _while_true_vs_loop.rb
require 'benchmark'
MAX = 10**8
puts Benchmark.measure{
a = MAX
while(true)
a -= 1
break if a == 0
View bitwise_operators_in_ruby.rb
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 / Several GitHub accounts
Last active Nov 10, 2015
Several GitHub accounts
View 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
You can’t perform that action at this time.