Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
@jodosha
jodosha / each_benchmark.rb
Created November 9, 2009 13:49
Ruby benchmark: Array#each vs for x in array
#!/usr/bin/env ruby -w
require "benchmark"
TIMES = 100_000
ARRAY = (1..1_000).to_a
Benchmark.bm(30) do |b|
b.report "each" do
TIMES.times do |i|
ARRAY.each do |element|
@jodosha
jodosha / README.md
Created October 6, 2023 08:03
Hanami DEV Memory Footprint

Assessment

This is a memory footprint assessment of all the possibilities to start the Rack server and the assets watch. I know this isn't a scientific approach, but it gives us the order of magnitude of the differences between the options.

Conclusions

  • Using Ruby and NPM as middlemen to execute other commands wastes memory.
    • bundle exec hanami server and assets, npm exec
  • Foreman executes 3 Ruby processes.
⚡ git log -1
1961f9e [3 hours ago] (Luca Guidi) Refactoring: ensure proper level of abstraction in GitHub REST client
⚡ npm start -- --remote=mattzcarey/code-review-gpt#96 --debug=true
> code-review-gpt@0.1.0 start
> ts-node ./src/index.ts review --remote=mattzcarey/code-review-gpt#96 --debug=true
DEBUG Review started.
DEBUG Model used: gpt-4
@jodosha
jodosha / .gitignore
Last active August 6, 2023 08:17
How To Test Go HTTPS services
/*.pem
@jodosha
jodosha / install_nix_in_an_lxd_container.md
Created February 12, 2023 17:40 — forked from derekmahar/install_nix_in_an_lxd_container.md
How to Install Nix in an LXD Container

How to Install Nix in an LXD Container

Steps to install the Nix package manager inside an Ubuntu 20.04 LXD container using the images:ubuntu/focal image:

  1. On the LXD host, create an Ubuntu 20.04 container:
    lxc init images:ubuntu/focal container1
    
  2. On the LXD host, enable nested security on the container:
@jodosha
jodosha / 1.json
Created November 18, 2022 14:03
Rack upload exception
{"foo": "100% bar"}
@jodosha
jodosha / bench.rb
Last active October 13, 2022 05:15
Ruby benchmark: Array#uniq vs Set#to_a
#!/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 }
@jodosha
jodosha / ivar_vs_accessor.rb
Last active June 27, 2022 08:31
Ruby Benchmark: ivar vs accessor
#!/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 April 12, 2022 12:55
Ruby: Compare Hash direct assignment vs merge
#!/usr/bin/env ruby
# frozen_string_literal: true
require "benchmark/ips"
hash1 = {}
hash2 = {}
Benchmark.ips do |x|
x.report("assign") do
@jodosha
jodosha / request_id.rb
Created December 4, 2017 20:17
Ruby benchmark `SecureRandom.hex(16)` vs `SecureRandom.uuid`
#!/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!