Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
ruby-install -M https://cache.ruby-lang.org/pub/ruby ruby 2.5.0-preview1 --sha512 2d39ef64aaf7a52014905f4ad59b53e83b71433e50a9227f9f50cbb7a2c9a5db9cd69fa7dbe01234819f7edd2216b3d915f21676f07d12bb5f0f3276358bce7f
@jodosha
jodosha / README.md
Created September 7, 2017 14:34
Mount Hanami inside Rails

1. Setup

rails new blog
cd blog
hanami new bookshelf
vim Gemfile # add `hanami`
bundle
vim bookshelf/config/environment.rb # See Note 1
@jodosha
jodosha / bench.rb
Created August 9, 2017 10:57
Bench: Hanami::Utils::String.transform w/ and w/o caching
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'hanami/utils/string'
INPUT = "Hanami::Utils::String".freeze
Benchmark.ips do |x|
x.report('uncached base') { Hanami::Utils::String.transform(INPUT, :underscore, :classify) }
x.report('uncached args') { Hanami::Utils::String.transform(INPUT, [:rsub, %r{/}, "#"]) }
x.report('uncached from string') { Hanami::Utils::String.transform(INPUT, :demodulize, :downcase) }
@jodosha
jodosha / .gitignore
Last active August 6, 2023 08:17
How To Test Go HTTPS services
/*.pem

Keybase proof

I hereby claim:

  • I am jodosha on github.
  • I am jodosha (https://keybase.io/jodosha) on keybase.
  • I have a public key ASBVaXTnG7VLDxcJwtfoIccTZAN50JtFGXEkIGtJCD9hAgo

To claim this, I am signing this object:

@jodosha
jodosha / bench.rb
Last active August 10, 2016 08:12
Hanami::Action::Params#error_messages: each_with_object vs flat_map benchmark
#!/usr/bin/env ruby
require 'bundler/setup'
require 'benchmark/ips'
require 'hanami/controller'
class Hanami::Action::Params
def flat_map_error_messages(error_set = errors)
error_set.flat_map do |key, messages|
k = Hanami::Utils::String.new(key).titleize
@jodosha
jodosha / freshness.rb
Created July 14, 2016 07:33
Compare MD5 digest vs last modified time (mtime) for file tracking
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'digest'
PATH = 'jquery.js'.freeze
FILE = File.new(PATH)
Benchmark.ips do |x|
x.report('mtime') { FILE.mtime.utc.to_i }
x.report('digest') { Digest::MD5.file(PATH).hexdigest }
@jodosha
jodosha / numeric_bench.rb
Created April 15, 2016 13:12
Benchmark for Hanami::Utils::Kernel.numeric?
#!/usr/bin/env ruby
require 'benchmark/ips'
module Hanami
module Utils
module Kernel
NUMERIC_MATCHER = /\A([\d\/\.\+iE]+|NaN|Infinity)\z/
def self.numeric?(arg)
arg.to_s.match(NUMERIC_MATCHER)
@jodosha
jodosha / Gemfile
Created April 1, 2016 07:21
Hanami::Validations with DRY-V
source 'https://rubygems.org'
gem 'dry-validation'
@jodosha
jodosha / bench.rb
Created January 29, 2016 09:36
Ruby: String#chars.each vs String#each_char
#!/usr/bin/env ruby
require 'benchmark/ips'
GC.disable
STRING = ("a" * 100).freeze
Benchmark.ips do |x|
x.report('chars.each') { STRING.chars.each {|c| c.upcase} }
x.report('each_char') { STRING.each_char {|c| c.upcase} }
x.compare!