# frozen_string_literal: true
require 'bundler/setup'
Bundler.setup :system
require 'pry-byebug'
require 'benchmark'
require 'benchmark/ips'
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
# frozen_string_literal: true | |
require 'bundler/setup' | |
Bundler.setup :system | |
require 'pry-byebug' | |
require 'benchmark' | |
require 'benchmark/ips' | |
require 'benchmark/memory' |
# frozen_string_literal: true
# require 'pry-byebug'
require 'benchmark'
require 'benchmark/ips'
require 'benchmark/memory'
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
# frozen_string_literal: true | |
def db_migrations | |
return @db_migrations if defined?(@db_migrations) | |
puts "Request to DB from #{self.class} (#{object_id})" | |
@db_migrations = [3, 5] | |
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
> ruby test.rb | |
I, [2018-09-14T05:14:28.929558 #30046] INFO -- : true | |
Warming up -------------------------------------- | |
native 1.000 i/100ms | |
baseline 2.000 i/100ms | |
lazy 1.000 i/100ms | |
via_transduce 1.000 i/100ms | |
Calculating ------------------------------------- | |
native 11.293 (± 0.0%) i/s - 57.000 in 5.054247s | |
baseline 21.711 (± 4.6%) i/s - 110.000 in 5.077083s |
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
# frozen_string_literal: true | |
def fibonacci(n) | |
return n if n <= 1 | |
fibonacci(n - 1) + fibonacci(n - 2) | |
end | |
def calculate(id: 1, n: 40) | |
start = Time.now | |
puts "Start ##{id}: #{start}" |
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
class MyObject | |
attr_accessor :foo, :bar | |
def initialize(foo = nil, bar = nil) | |
self.foo = foo | |
self.bar = bar | |
end | |
def empty? | |
foo.nil? || foo.empty? |
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
# Including neccessary modules from ./base/modules | |
Dir.glob(File.join 'base', 'modules', '*.rb').each do |mod| | |
require mod | |
basename = File.basename mod, '.*' | |
include const_get basename.split('_').map(&:capitalize).join | |
# With helpers: | |
# include basename.camelize.constantize | |
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
def alias_task(name, old_name) | |
t = Rake::Task[old_name] | |
desc t.full_comment if t.full_comment | |
task name, *t.arg_names do |_, args| | |
# values_at is broken on Rake::TaskArguments | |
args = t.arg_names.map { |a| args[a] } | |
t.invoke(*args) | |
end | |
end |