Skip to content

Instantly share code, notes, and snippets.

View caius's full-sized avatar
👻

Caius Durling caius

👻
View GitHub Profile
@caius
caius / after_create_commit_twice.rb
Last active June 21, 2024 15:53
`after_create_commit` can be invoked twice
gem "sqlite3", "~> 1"
require 'sqlite3'
gem "activerecord", "~> 7.1"
require 'active_record'
# Set up a database that resides in RAM
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: ':memory:'
)
require "rspec/autorun"
RSpec.describe "exceptional tekin" do
after(:each) do |example|
p example, example.exception
end
it "passes" do
expect(1).to eq(1) # duh
end
# .. snip ..
# Lifted from https://grafana.com/docs/grafana-cloud/quickstart/docker-compose-linux/#step-1-create-the-compose-file on 2022-10-07
grafana-node-exporter = {
# https://github.com/prometheus/node_exporter/releases
image = "prom/node-exporter:v1.7.0";
autoStart = true;
extraOptions = [
"--cpus=1"
"--memory=512m"
];
@caius
caius / my-jobs.rb
Last active January 16, 2024 18:43
ActiveJob::Base.queue_adapter = :delayed
$stdout.sync = true
$stdout.flush
class MyBaseJob < ActiveJob::Base
# Stop delayed retrying at all
def max_attempts
0
end
Error = Class.new(StandardError)
class Client
Error = Class.new(StandardError)
def call
raise "ZOMG"
rescue => e
raise Error.new("Uh oh #{e.inspect}")
end
@caius
caius / our_inflector.rb
Created October 16, 2023 20:18
Zeitwerk Inflector for full path -> Constant
# frozen_string_literal: true
# Custom inflector for Zeitwerk
#
# The default inflector at ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector only
# lets us override by `basename`, but we have both `Thing` and `THING` defined as constants
# in the app so that doesn't work for us. Rather than rename everything just now, work around it
# by letting us define overrides by _filepath_ (`abspath`) as well as `basename`.
#
# NB: Normally we'd subclass the default implementation, but it's a Module so can't do that.
@caius
caius / settings.json
Created October 2, 2023 10:17
Zed Config 2023-10-02
{
"auto_update": true,
"base_keymap": "TextMate",
"default_dock_anchor": "bottom",
"projects_online_by_default": false,
"theme": "Ayu Light",
"buffer_font_family": "FiraCode Nerd Font Mono",
"buffer_font_size": 14,
"tab_size": 2,
"hard_tabs": false,
require "benchmark/ips"
Benchmark.ips do |b|
b.report("Array.new block") do
Array.new(100) { 10 }
end
b.report("Array.new argument") do
Array.new(100, 10)
end
{
auto_https off
}
:8080 {
root * .
file_server
templates
}
// something
{
"one": true,
"bar": "Something",
}