Skip to content

Instantly share code, notes, and snippets.


Luca Guidi jodosha

View GitHub Profile
jodosha / hash_assign_vs_merge.rb
Created Apr 12, 2022
Ruby: Compare Hash direct assignment vs merge
View hash_assign_vs_merge.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require "benchmark/ips"
hash1 = {}
hash2 = {}
Benchmark.ips do |x|"assign") do
jodosha / fibonacci.rb
Created Sep 29, 2021
Give Ruby 3 an Elixir flavor: provide pattern matching for recursion
View fibonacci.rb
# frozen_string_literal: true
module PatternMatching
def self.extended(base)
base.class_eval do
@__pn_methods = {}
def __pn_methods
jodosha / output.log
Created Aug 11, 2021
dry-configurable test suite output at f44ea91
View output.log
1) Dry::Configurable::DSL compiles but deprecates giving a default as positional argument
Failure/Error: expect(logger.string).to match(/#{FileUtils.pwd}.*default value as positional argument to settings is deprecated/)
expected "/Users/jodosha/.gem/ruby/3.0.1/gems/rspec-core-3.10.1/lib/rspec/core/example.rb:262:in `block in run...ed and will be removed in the next major version\nProvide a `default:` keyword argument instead\n\n" to match /\/Users\/jodosha\/Code\/dry-rb\/dry-configurabl
e.*default value as positional argument to settings is deprecated/
@@ -1,2 +1,3 @@
-/\/Users\/jodosha\/Code\/dry-rb\/dry-configurable.*default value as positional argument to settings is deprecated/
⚡ bundle exec rake
/Users/jodosha/.rubies/ruby-3.0.1/bin/ruby -I/Users/jodosha/.gem/ruby/3.0.1/gems/rspec-core-3.10.1/lib:/Users/jodosha/.gem/ruby/3.0.1/gems/rspec-support-3.10.2/lib /Users/jodosha/.gem/ruby/3.0.1/gems/rspec-core-3.10.1/exe/rspec /Users/jodosha/Code/hanami/monolith-template/spec/suite --pattern **/*_spec.rb
An error occurred while loading ./spec/suite/main/features/home_spec.rb.
Failure/Error: class Action < Hanami::Action
no implicit conversion of nil into String
# /Users/jodosha/.gem/ruby/3.0.1/gems/hanami-controller-2.0.0.alpha2/lib/hanami/action/configuration.rb:410:in `public_directory'
# /Users/jodosha/.gem/ruby/3.0.1/gems/hanami-controller-2.0.0.alpha2/lib/hanami/action/application_configuration.rb:81:in `public_send'
jodosha /
Created May 7, 2021
Code spike for hanami-api + dry-container + dry_auto-inject (see
# frozen_string_literal: true
require "bundler/setup"
require "hanami/api"
require "hanami/api/container"
class Routes
def url(name)
jodosha / benchmark.rb
Created Jul 22, 2020
Ruby Method Overloading
View benchmark.rb
require "benchmark/ips"
require_relative "./method_overloading"
class Foo
include MethodOverloading
def call(number)
"foo #{number}"
jodosha / thread_current.rb
Created Jul 9, 2020
Limits of Ruby's Thread.current
View thread_current.rb
# frozen_string_literal: true
Thread.current[:request_id] = 'abc123'
puts "main thread: #{Thread.current[:request_id]}" do
puts "inner thread: #{Thread.current[:request_id]}"
jodosha / memory.rb
Created Sep 16, 2019
Ruby speed & memory bench: Array#compact vs nil check
View memory.rb
# frozen_string_literal: true
require "pathname"
require "memory_profiler"
class Env
def load!(*)
jodosha / bench.rb
Last active Aug 8, 2019
Ruby benchmark: Array#uniq vs Set#to_a
View bench.rb
#!/usr/bin/env ruby
require "benchmark/ips"
require "set"
INPUT = { "my-test-string" }.freeze
Benchmark.ips do |x|"Array#uniq") { INPUT.uniq }"Set#to_a") { }
View Gemfile
# frozen_string_literal: true
source ""
gem "rack"
gem "puma"
gem "guard-puma"