This file contains hidden or 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 'thor' | |
module Hanami | |
module Auth | |
def Auth.included(thor) | |
thor.class_eval do | |
desc 'custom_command', 'Desc' | |
long_desc <<-EOS | |
EOS | |
def auth |
This file contains hidden or 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' | |
FRIZED_HASH = { | |
a: 'a', | |
b: 'b', | |
c: 'c', | |
d: 'd', | |
e: 'e' | |
}.freeze |
This file contains hidden or 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' | |
array = (1..10_000).to_a | |
Benchmark.ips do |x| | |
x.report('each_with_object') { array.each_with_object([]) { |i,a| a << (i * 2) } } | |
x.report('map') { array.map { |i| i * 2 } } | |
x.report('map!') { array.map! { |i| i * 2 } } | |
x.report('reduse') { array.reduce([]) { |a,i| a << i * 2 } } | |
x.compare! |
This file contains hidden or 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' | |
require 'shallow_attributes' | |
require 'virtus' | |
hash = { | |
addresses: [ | |
{ | |
street: 'Street 1/2', | |
city: { | |
name: 'NYC' |
This file contains hidden or 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 = {a: 1, b: 2, c: 3, d: 4} | |
Benchmark.ips do |x| | |
x.report('first') { hash.first } | |
x.report('to_a.first') { hash.to_a.first } | |
x.report('keys.first') do | |
key = hash.keys.first | |
[key, hash[key]] |
This file contains hidden or 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' | |
numbers = (1..25).to_a | |
Benchmark.ips do |x| | |
x.report('each') do | |
sum = 0 | |
numbers.each do |number| | |
sum += number | |
end |
This file contains hidden or 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' | |
array = [1, 2] | |
Benchmark.ips do |x| | |
x.report('multiple assignments'){ a, _ = array } | |
x.report(' #first method call'){ a = array.first } | |
x.report(' #[] method call'){ a = array[0] } | |
x.compare! | |
end |
This file contains hidden or 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' | |
str = 'hello_world_this_is_bench_for_slice_and_split' | |
Benchmark.ips do |x| | |
x.report('split'){ str.split('_').first } | |
x.report('slice'){ str.slice(/[^_]+/, 0) } | |
x.compare! | |
end |
This file contains hidden or 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 'lotus-controller' | |
require 'benchmark/ips' | |
class MyCustomError < StandardError; end | |
class MySecondCustomError < MyCustomError; end | |
def first_method(exception) | |
@handled_exceptions.merge!(exception) | |
@handled_exceptions = Hash[ | |
@handled_exceptions.sort{|(ex1,_),(ex2,_)| ex1.ancestors.include?(ex2) ? -1 : 1 } |
This file contains hidden or 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' | |
foo = 'foo' | |
bar = 'bar' | |
Benchmark.ips do |x| | |
x.report('+ and #to_s') { foo.to_s + bar.to_s } | |
x.report('+') { foo + bar } | |
x.report('#{}') { "#{foo}#{bar}" } | |
x.compare! | |
end |