Skip to content

Instantly share code, notes, and snippets.

View nateberkopec's full-sized avatar

Nate Berkopec nateberkopec

View GitHub Profile
@nateberkopec
nateberkopec / PLAN-yabeda-adapter.md
Created March 15, 2026 22:20
Plan: Yabeda monitoring system adapter for speedshop-cloudwatch

Plan: Yabeda Monitoring System Adapter

Goal

Add an optional Yabeda adapter so that users who define metrics via Yabeda's DSL can have those metrics sent to CloudWatch through the existing Reporter infrastructure (async batching, StatisticSet aggregation, queue overflow protection, high-resolution support).

This gem does not collect metrics via Yabeda. The existing Puma/Sidekiq/Rack/ActiveJob

@nateberkopec
nateberkopec / rename_png_refs.sh
Last active March 10, 2026 23:18
Update all .png references to .jpg across a codebase using git status pairs
#!/bin/bash
# After converting PNGs to JPEGs, update all references in the codebase.
# Parses git status for deleted .png / new .jpg pairs and does a global find-and-replace.
# Usage: ./rename_png_refs.sh [directory]
set -euo pipefail
DIR="${1:-.}"
DRY_RUN="${DRY_RUN:-false}"
@nateberkopec
nateberkopec / rename_png_refs.sh
Created March 10, 2026 23:14
Update all .png references to .jpg across a codebase using git status pairs
#!/bin/bash
# After converting PNGs to JPEGs, update all references in the codebase.
# Parses git status for deleted .png / new .jpg pairs and does a global find-and-replace.
# Usage: ./rename_png_refs.sh [directory]
set -euo pipefail
DIR="${1:-.}"
DRY_RUN="${DRY_RUN:-false}"
@nateberkopec
nateberkopec / png_to_jpeg.sh
Created March 10, 2026 23:03
Convert PNGs > 100KB to optimized JPEGs for Cloudflare Polish
#!/bin/bash
# Convert PNGs > 100KB to optimized JPEGs for Cloudflare Polish webp conversion
# Usage: ./png_to_jpeg.sh [directory]
# Requires: ImageMagick (convert), jpegoptim
set -euo pipefail
DIR="${1:-.}"
QUALITY=85
MIN_SIZE_KB=100
@nateberkopec
nateberkopec / heroku-inventory
Created March 4, 2026 21:37
heroku-inventory: Catalog all Heroku resources (formation, dynos, addons, buildpacks, config, metrics) for a team or app as JSON
#!/usr/bin/env bash
set -uo pipefail
usage() {
echo "heroku-inventory: Catalog Heroku resources" >&2
echo "" >&2
echo "Usage:" >&2
echo " heroku-inventory --team <team-name>" >&2
echo " heroku-inventory --app <app-name>" >&2
echo "" >&2
@nateberkopec
nateberkopec / README.md
Created March 3, 2026 00:38
Puma worker TERM/restart benchmark (Docker + k6): app, scripts, final artifacts, and results summary

Worker TERM/restart benchmark (Docker + k6)

This benchmark reproduces the scenario discussed in chat:

  • 4 Puma workers
  • open-model traffic at 12 req/s (k6 constant-arrival-rate)
  • synthetic Rack app with ~250ms service time
  • service alternates CPU and IO slices randomly every ~10ms
  • compare threads=5 vs threads=25
  • during traffic: kill one worker, wait for restart, let it serve ~5s, then kill a different worker (round-robin)
@nateberkopec
nateberkopec / agent-rm-rf-hooks.md
Last active February 25, 2026 18:26
Protecting Against Autonomous Agent rm -rf Commands

Protecting Against Autonomous Agent rm -rf Commands

Protecting Against Agent rm -rf Commands

AI coding agents can run shell commands. Sometimes they run rm -rf by mistake. This deletes files forever. While of course I always read and approve all tool calls manually, by hand, and never let my agents work except under direct supervision 100% of the time, sometimes I miss things.

How It Works

  1. Hooks catch rm -rf before it runs
  2. Refuse the command with a clear error telling you to use trash
@nateberkopec
nateberkopec / gcstat.md
Created March 8, 2017 18:25
A Guide to GC.stat

Most Ruby programmers don't have any idea how garbage collection works in their runtime - what triggers it, how often it runs, and what is garbage collected and what isn't. That's not entirely a bad thing - garbage collection in dynamic languages like Ruby is usually pretty complex, and Ruby programmers are better off just focusing on writing code that matters for their users.

But, occasionally, you get bitten by GC - either it's running too often or not enough, or your process is using tons of memory but you don't know why. Or maybe you're just curious about how GC works!

One way we can learn a bit about garbage collection in CRuby (that is, the standard Ruby runtime, written in C) is to look at the built-in GC module. If you haven't read the docs of this module, check it out. There's a lot of interesting methods in there. But for right now, we're just going to look at one: GC.stat.

GC.stat outputs a hash with a bunch of different numbers, but none of th

@nateberkopec
nateberkopec / n_plus_one_where.rb
Created January 4, 2026 22:14
Rails N+1 query that cannot be fixed with includes() - using where() in instance method
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails", "~> 8.0"
gem "sqlite3"
end

Unslopper local run notes

This repo is just a scratchpad for running the Unslopper model locally with llama.cpp.

What worked

  • Install llama.cpp via Homebrew.
  • Use the GGUF Q8_0 quant (the bf16 repo is too large for typical Mac memory).
  • Use llama-completion with a Qwen-style chat template prompt file and --no-conversation so it does a single completion and exits.
  • Redirect logs away from stdout so the output file is clean.