Skip to content

Instantly share code, notes, and snippets.

Avatar

Luca Guidi jodosha

View GitHub Profile
@jodosha
jodosha / 1.json
Created Nov 18, 2022
Rack upload exception
View 1.json
{"foo": "100% bar"}
@jodosha
jodosha / ivar_vs_accessor.rb
Last active Jun 27, 2022
Ruby Benchmark: ivar vs accessor
View ivar_vs_accessor.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require "benchmark/ips"
class Ivar
def initialize
@ivar = 23
end
@jodosha
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|
x.report("assign") do
@jodosha
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 = {}
end
end
def __pn_methods
@jodosha
jodosha / output.log
Created Aug 11, 2021
dry-configurable test suite output at f44ea91
View output.log
Failures:
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/
Diff:
@@ -1,2 +1,3 @@
-/\/Users\/jodosha\/Code\/dry-rb\/dry-configurable.*default value as positional argument to settings is deprecated/
View rake.sh
⚡ 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
TypeError:
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
jodosha / config.ru
Created May 7, 2021
Code spike for hanami-api + dry-container + dry_auto-inject (see https://github.com/hanami/api/pull/26)
View config.ru
# frozen_string_literal: true
require "bundler/setup"
require "hanami/api"
require "hanami/api/container"
class Routes
def url(name)
"/#{name}"
end
@jodosha
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}"
end
end
@jodosha
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]}"
Thread.new do
puts "inner thread: #{Thread.current[:request_id]}"
end.join
@jodosha
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!(*)
end
end