Skip to content

Instantly share code, notes, and snippets.

@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 / _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 / 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
import xml.etree.ElementTree as ET
import html2text
def convert(enex_file_name: str, markdown_file_name: str) -> None:
enex = ET.parse(enex_file_name)
root = enex.getroot()
note = root.find('note')
html = note.find('content').text
text = html2text.html2text(html)
@romilly
romilly / pico-uart.py
Created February 23, 2021 07:23
Drive UART1 on a Raspberry Pi Pico
"""
MicroPython code to read and write from UART1 on the Pico
UART0 is not available as it is used for the REPL.
To test, you can use a 3V3 FTDI cable or similar device that connects a host computer with the Pico.
NB: Make sure it's a 3V3 cable, not a 5V cable, or you could kill your PIco!!
Connect FTDI black to Pico GND.
@romilly
romilly / fungen.md
Last active February 5, 2021 09:31

Testing a Pico-based function generator

I've moved the journal and code for fungen to the Pico Code Project on GitHub.

@romilly
romilly / scope.md
Last active February 5, 2021 09:24

Pico AF oscilloscope

I've moved the journal and code for the 'scope to the Pico Code Project on GitHub.

"""
Example for remote control from host via Serial link.
This is the code to run on the Pico.
It sets up the onboard LED and allows you to turn it on or off.
"""
from machine import Pin
# use onboard LED which is controlled by Pin 25
# on a Pico W the onboad lLED is accessed differently,
import serial
class Talker:
TERMINATOR = '\r'.encode('UTF8')
def __init__(self, timeout=1):
self.serial = serial.Serial('/dev/ttyACM0', 115200, timeout=timeout)
def send(self, text: str):
@romilly
romilly / blog.md
Last active January 26, 2021 09:58

Why I use APL every day

I first met APL (A Programming Language) in 1968.

I've always used it a lot, and now I use it every day.

Many developers will never have heard of the language. Many of those that have, either love it (as I do) or hate it.

I think now is the time to explain what APL is, why I use it so often, and why I think that developers should take a look at it.