Skip to content

Instantly share code, notes, and snippets.

Luca Guidi jodosha

Block or report user

Report or block jodosha

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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
@jodosha
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 = 100.times.map { "my-test-string" }.freeze
Benchmark.ips do |x|
x.report("Array#uniq") { INPUT.uniq }
x.report("Set#to_a") { Set.new(INPUT).to_a }
View Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
gem "rack"
gem "puma"
gem "guard-puma"
@jodosha
jodosha / Gemfile
Created Jan 7, 2019
dry-view ERB capture syntax example
View Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
gem "dry-view", git: "https://github.com/dry-rb/dry-view.git", branch: "erb-support"
gem "erbse"
@jodosha
jodosha / discard.rb
Created Dec 13, 2018
Ruby parallel assignment benchmark
View discard.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require "benchmark/ips"
def validate
[false, "not valid"]
end
Benchmark.ips do |x|
View bench.rb
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'bundler/setup'
require 'dnsimple'
account_id = 1010
zone_id = 100
record_id = 999
Benchmark.ips do |x|
@jodosha
jodosha / request_id.rb
Created Dec 4, 2017
Ruby benchmark `SecureRandom.hex(16)` vs `SecureRandom.uuid`
View request_id.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require "benchmark/ips"
require "securerandom"
Benchmark.ips do |x|
x.report("hex(16)") { SecureRandom.hex(16) }
x.report("uuid") { SecureRandom.uuid }
x.compare!
@jodosha
jodosha / bench.rb
Created Nov 17, 2017
Ruby: Hash#key? vs Set#include?
View bench.rb
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'set'
SET = (4..16).to_set.freeze
HASH = SET.each_with_object({}) { |n, ret| ret[n] = true }.freeze
Benchmark.ips do |x|
x.report('set') { SET.include?(16) }
x.report('hash') { HASH.key?(16) }
View script.sh
ruby-install -M https://cache.ruby-lang.org/pub/ruby ruby 2.5.0-preview1 --sha512 2d39ef64aaf7a52014905f4ad59b53e83b71433e50a9227f9f50cbb7a2c9a5db9cd69fa7dbe01234819f7edd2216b3d915f21676f07d12bb5f0f3276358bce7f
@jodosha
jodosha / README.md
Created Sep 7, 2017
Mount Hanami inside Rails
View README.md

1. Setup

rails new blog
cd blog
hanami new bookshelf
vim Gemfile # add `hanami`
bundle
vim bookshelf/config/environment.rb # See Note 1
You can’t perform that action at this time.