Skip to content

Instantly share code, notes, and snippets.

View cluesque's full-sized avatar

Bill Kirtley cluesque

View GitHub Profile
@cluesque
cluesque / Gemfile
Created January 14, 2021 21:00
For rails console pry is a much better REPL than IRB, so why not use it in production?
# This goes at global scope (remove it from your other groups)
gem 'pry-rails', require: false
gem 'pry-byebug', require: false
@cluesque
cluesque / progress_regressor.rb
Created December 1, 2022 19:13
ProgressRegressor class
# Useful for tracking the progress of a large batch job
# Pass in 'counter', a lambda that returns an integer
# This will periodically call the counter,
# track the rate counted things are consumed (or produced)
# and make a prediction about when it completes
# options:
# - divisor: how many times per minute to sample, default 6 (every ten seconds)
# - rolling_window: how many rate samples to average when making predictions (default 10)
# - target: what value are we aiming for, default 0 (consuming a queue)
@cluesque
cluesque / checker.rb
Created August 3, 2023 16:44
Liveness monitor for ruby programs
# Have your health checker execute this
require './liveness_monitor'
puts LivenessMonitor.new.status
@cluesque
cluesque / tables_approaching_limit.sql
Created February 14, 2024 23:36
Postgres: Report how close each table primary key is to its limit
WITH column_info AS (
SELECT t.relname AS table_name, c.attname AS column_name, c.atttypid, c.attlen AS length, y.typname AS type
, pg_get_expr(adbin, adrelid) AS default
, (regexp_matches(pg_get_expr(adbin, adrelid), 'nextval..(.*).::regclass'))[1] AS sequencename
FROM pg_class t
LEFT OUTER JOIN pg_attribute c ON c.attrelid = t.oid
LEFT OUTER JOIN pg_type y ON y.oid = c.atttypid
LEFT OUTER JOIN pg_attrdef d ON t.oid = d.adrelid AND d.adnum = c.attnum
WHERE pg_get_expr(adbin, adrelid) LIKE '%nextval%'
),