Skip to content

Instantly share code, notes, and snippets.

View romilly's full-sized avatar

Romilly Cocking romilly

View GitHub Profile
@romilly
romilly / progress.py
Created November 4, 2021 16:48
Track writing progress for pandoc or LeanPub book
#!/usr/bin/env bash
# capture wordcounts in dayfile
# invoke with project root as argument; default is (currently) start-apl
# assumes book contents are markdown files in the `manuscript` directory
# creates a `progress` direectory if necessary
# writes wordcounts (using wc) for each markdown file and totals in a file whose name is based on today's date
_project=${1:-start-apl}
cd ~/git/active/$_project/
_now=$(date +"%Y%m%d")
mkdir -p progress
@romilly
romilly / _nuke.py
Created July 17, 2022 12:23
Delete all files and directories from a micropython file-system (including .py files)
# ***WARNING***
# Running this file will delete all files and directories from the micropython device it's running on
# If you run keep_this=False it will delete this file as well.
# see https://docs.micropython.org/en/latest/library/os.html for os function list
import os
def _delete_all(directory='.', keep_this=True):
@romilly
romilly / chromatic.py
Created October 12, 2023 09:32
Convert a note pitch like A#4 to its frequency.
# -*- coding: utf-8 -*-
"""
Convert a note pitch like A#4 to its frequency.
"""
# Generate a unique pitch for a note based on its pitch class and octave.
def name(pitch_class: str, octave: int) -> str:
return f"{pitch_class}{octave}"
@romilly
romilly / peeky_reader.py
Created November 14, 2025 08:17
A TextIO reader that allows one-line lookahead
"""
PeekyReader - A TextIO wrapper that allows peeking at the next line.
"""
from typing import TextIO
class PeekyReader:
"""A TextIO wrapper that allows clients to peek at the next line before reading it."""
def __init__(self, text_io: TextIO):
@romilly
romilly / five-whys.md
Last active January 3, 2026 06:54
A Claude code command that seeks the root cause of a problem when using Claude code, and suggests corrective action

Five Whys Root Cause Analysis

After a defect or problem has been fixed, use this command to find the root cause and prevent recurrence.

Process

  1. Ask me to describe the defect or problem that occurred
  2. Ask "Why did this happen?" and wait for my response
  3. Based on my answer, ask "Why?" again, probing deeper
  4. Continue until we reach a root cause (typically 3-6 iterations) - stop when we hit something systemic rather than symptomatic