Skip to content

Instantly share code, notes, and snippets.

View marcandre's full-sized avatar

Marc-André Lafortune marcandre

View GitHub Profile
@marcandre
marcandre / timeout.rb
Created December 10, 2020 11:57
Timeout::wake
def Timeout.wake(secs)
Thread.handle_interrupt(Timeout::Error => :on_blocking) do
Timeout.timeout(secs) do
yield
end
end
end
N = 100
SECS = 0.1
@marcandre
marcandre / ractor_test.rb
Last active December 31, 2020 21:36
Ractor benchmark
#!/usr/bin/env ruby
if ENV['B']
BuiltinRactor = Ractor
Object.send :remove_const, :Ractor
require 'backports/3.0.0/ractor'
puts "Using pure Ruby implementation"
end
# usage `ruby ractor_test.rb <work_length> <num_workers> <num_requests>
@marcandre
marcandre / ex_vcr_process.ex
Created April 17, 2023 20:23
Allows calling ExVCR's `start_cassette` / `stop_cassette` from any process
defmodule Bobby.ExVcrProcess do
@moduledoc """
This GenServer allows calling `start_cassette` / `stop_cassette` from any process
# Instead of
use_cassette("x") do
do_something
end
# can be written as (each line from any process):