rails new blog
cd blog
hanami new bookshelf
vim Gemfile # add `hanami`
bundle
vim bookshelf/config/environment.rb # See Note 1
This file contains 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-install -M https://cache.ruby-lang.org/pub/ruby ruby 2.5.0-preview1 --sha512 2d39ef64aaf7a52014905f4ad59b53e83b71433e50a9227f9f50cbb7a2c9a5db9cd69fa7dbe01234819f7edd2216b3d915f21676f07d12bb5f0f3276358bce7f |
This file contains 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
#!/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) } |
This file contains 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
/*.pem |
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:
This file contains 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
#!/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 |
This file contains 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
#!/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 } |
This file contains 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
#!/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) |
This file contains 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
source 'https://rubygems.org' | |
gem 'dry-validation' |
This file contains 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
#!/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! |