Skip to content

Instantly share code, notes, and snippets.

View pjambet's full-sized avatar

Pierre Jambet pjambet

View GitHub Profile
@pjambet
pjambet / exception.rb
Created November 22, 2023 23:23
Explicitly set a cause
def foo(exception)
raise StandardError, "I'm an error thrown by the method caused by #{exception.class}", cause: exception
end
def always_raise(message)
raise message
end
def rescue_exception
yield
@pjambet
pjambet / repro.rb
Created July 20, 2023 02:02
Example for bugsnag PR
# frozen_string_literal: true
require "bundler/inline"
require "active_support/concern"
require_relative "./repro_helper"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
@pjambet
pjambet / scope_repro.rb
Last active February 10, 2023 17:33
Scoping issues with default scopes and explicit scopes
# frozen_string_literal: true
require "bundler/inline"
require "debug"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
@pjambet
pjambet / unscope_repro.rb
Last active February 9, 2023 23:54
Rails 7.0 unscope & all_queries: true for update/destroy issue
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
@pjambet
pjambet / update_counter_repro.rb
Created February 9, 2023 19:10
Rails 7.0 update_counter & scope issue
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
# Thanks to https://twitter.com/elijahmanor/status/1557003773272133632
alias fv="fd --type f --hidden --exclude .git | fzf-tmux -p --reverse | xargs nvim"
alias fkill="ps | fzf | cut -d\" \" -f1 | xargs kill -9"
@pjambet
pjambet / kilo.rb
Last active August 24, 2022 12:55
A very basic text editor in ruby, copied from Kilo and adapted in Ruby
require 'termios'
s = [0, 0, 0, 0].pack("S_S_S_S_")
STDOUT.ioctl(Termios::TIOCGWINSZ, s)
HEIGHT, WIDTH, _, _ = s.unpack("S_S_S_S_")
# Raw mode
current = Termios.tcgetattr(STDIN)
t = current.dup
@pjambet
pjambet / repro.rb
Last active June 30, 2022 14:31
Active Record association scopes causing issues with `association.create` on has_many
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "7-0-stable"
package main
import (
"fmt"
"math/rand"
// "sync/atomic"
"bufio"
"net"
// "strconv"
require 'benchmark/ips'
require 'set'
def bench(size)
Benchmark.ips do |x|
set = Set.new
array = []
hash = {}
size.times do |i|