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
Rails::Application.routes.draw do | |
... | |
get '/shop/facebook' => 'facebook_shop#index' | |
get '/shop/paypal' => 'paypal_shop#index' | |
rewrite_shop_path = proc do |env| | |
if env['HTTP_HOST'] =~ /facebook/ | |
env['PATH_INFO'] = "/shop/facebook" | |
else |
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 'dry-validation' | |
require 'active_model' | |
require 'benchmark' | |
schema = Class.new(Dry::Validation::Schema) do | |
key(:name, &:filled?) | |
key(:age) { |v| v.int? & v.gt?(18) } | |
end.new | |
class User |
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 ThreadSafe | |
class NonConcurrentCacheBackend | |
def self.method(key, value) | |
end | |
end | |
class MriCacheBackend < NonConcurrentCacheBackend | |
WRITE_LOCK = Mutex.new | |
def self.method(key, value) |
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
Calculating ------------------------------------- | |
type-safe users 273.000 i/100ms | |
ar user models 257.000 i/100ms | |
------------------------------------------------- | |
type-safe users 2.813k (± 1.7%) i/s - 14.196k | |
ar user models 2.574k (±10.7%) i/s - 12.850k | |
Comparison: | |
type-safe users: 2812.7 i/s | |
ar user models: 2574.2 i/s - 1.09x slower |
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 "benchmark/ips" | |
HASH = { :foo => 1, :bar => 2 } | |
def hc | |
{ | |
:foo => HASH.fetch(:foo), | |
:bar => HASH.fetch(:bar), | |
} | |
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
# apt-get install crystal | |
Reading package lists... Done | |
Building dependency tree | |
Reading state information... Done | |
E: Unable to locate package crystal |
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 'minitest/spec' | |
require 'minitest/autorun' | |
require 'ostruct' | |
describe "Failure" do | |
it "fails with value" do | |
data = OpenStruct.new(:value => "bar") | |
assert_equal "bar", data.value | |
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 'allocation_tracer' | |
ObjectSpace::AllocationTracer.setup(%i{path line type}) | |
ObjectSpace::AllocationTracer.trace | |
at_exit{ | |
results = ObjectSpace::AllocationTracer.stop | |
sum = Hash.new { |hash, key| hash[key] = [0] * 6 } | |
puts ObjectSpace::AllocationTracer.header.join("\t") | |
results.sort_by{|k, v| v[0]}.each{|k, v| | |
path, line, type = k |
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 'set' | |
require 'benchmark/ips' | |
KEYS = (:a .. :z).to_a | |
SET = Set.new(KEYS) | |
HASH = Hash[KEYS.product([true])] | |
Benchmark.ips do |x| | |
x.report "set.include" do | |
SET.include?(:z) | |
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
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require_relative 'setup' | |
run "Loading ONE user object" do |x| | |
x.expect { |user| user.name == 'name 1' } | |
x.report("AR") { ARUser.by_name('name 1').first } | |
x.report("ROM") { users.by_name('name 1').first } | |
end |