Skip to content

Instantly share code, notes, and snippets.

@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}"