Skip to content

Instantly share code, notes, and snippets.

View stecman's full-sized avatar

Stephen Holdaway stecman

View GitHub Profile
@stecman
stecman / Makefile
Last active August 5, 2026 08:56
DS18B20 1-Wire implementation for Atmel AVR
DEVICE = atmega328p
CLOCK = 16000000
PROGRAMMER = -c arduino -P /dev/ttyUSB0 -b57600
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
SOURCES = $(shell find . -name '*.c')
OBJECTS = $(SOURCES:.c=.o)
# Automatic dependency resolution
@stecman
stecman / AutoCrop.lua
Last active July 8, 2026 17:13
Lightroom plugin to calculate image crops using OpenCV
-- LR imports
local LrApplication = import("LrApplication")
local LrApplicationView = import("LrApplicationView")
local LrBinding = import("LrBinding")
local LrDevelopController = import("LrDevelopController")
local LrDialogs = import("LrDialogs")
local LrExportSession = import("LrExportSession")
local LrFileUtils = import("LrFileUtils")
local LrFunctionContext = import("LrFunctionContext")
local LrLogger = import("LrLogger")
@stecman
stecman / _readme.md
Last active June 7, 2026 15:51
Brother P-Touch PT-P300BT bluetooth driver python

Controlling the Brother P-Touch Cube label maker from a computer

The Brother PTP300BT label maker is intended to be controlled using the official Brother P-Touch Design & Print iOS/Android app. The app has arbitrary limits on what you can print (1 text object and up to 3 preset icons), so I thought it would be a fun challenge to reverse engineer the protocol to print whatever I wanted.

Python code at the bottom if you want to skip the fine details.

Process

Intitially I had a quick peek at the Android APK to see if there was any useful information inside. The code that handles the communication with the printer in Print&Design turned out to be a native library, but the app clearly prepares a bitmap image and passes it to this native library for printing. Bitmaps are definitely something we can work with.

@stecman
stecman / _README_ssh_agent_sudo_auth.md
Last active May 29, 2026 06:51
SSH-key based sudo authentication with Ansible

SSH key-based sudo authentication

To run privileged tasks without resorting to passwordless-sudo (NOPASSWD), you can use the libpam ssh_agent_auth module to authenticate based on SSH public keys in a separate authorized keys file.

This module requires SSH connections to be made with the -A command line option, or the ForwardAgent yes config option. You also need a local SSH agent running with the required key added.

I've presented this as an Ansible playbook + variables as it's a useful application

@stecman
stecman / wayland-screen-recording.md
Last active April 15, 2026 06:22
Screen recording on Sway under Wayland Ubuntu 24.04

Screen recording in Sway (and other Wayland compositors)

Some notes on screen recording in Wayland / Sway on Ubuntu as I had issues getting a good result. This was using a machine with Intel Arc graphics.

Setup

Install wf-recorder:

sudo apt-get install wf-recorder 
@stecman
stecman / Bake_codepoints_rust.md
Last active April 6, 2026 20:04
Render glyphs to image with Rust

Bake glyphs from fonts to image files (Rust)

This is an appendix item for Unicode Input Terminal.

Find all of the Unicode codepoints a font can represent and renders them to invidiaul image files. Note the output directory is hard-coded to /tmp/rendered.

cargo run <font-file, ...>
@stecman
stecman / NewKittyWindow.scpt
Last active March 27, 2026 23:53
New Kitty terminal window global hotkey on Mac OSX
# Open a new kitty terminal window on MacOS
#
# 1. Copy this script into AppleScript Editor and save it somewhere
# 2. Use something like Apptivate to run the script on a global hotkey:
# http://www.apptivateapp.com/
#
# Note this script doesn't work well as a Service through Automator as the
# "click menu" functionality requires accessibility privileges granted.
# Services run as the focused app, so that setup would require every context
# the shortcut is run from to have accessibility granted.
@stecman
stecman / dump-pyc-with-gdb.md
Last active February 17, 2026 14:21
Dumping all bytecode from a packaged Python application

This is a technique for extracting all imported modules from a packaged Python application as .pyc files, then decompiling them. The target program needs to be run from scratch, but no debugging symbols are necessary (assuming an unmodified build of Python is being used).

This was originally performed on 64-bit Linux with a Python 3.6 target. The Python scripts have since been updated to handle pyc files for Python 2.7 - 3.9.

Theory

In Python we can leverage the fact that any module import involving a .py* file will eventually arrive as ready-to-execute Python code object at this function:

PyObject* PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals);
@stecman
stecman / write-to-tape.md
Last active February 15, 2026 04:35
Buffered write to LTO tape on linux

Writing to LTO tape with a text index and a memory buffer

This script is for writing to LTO tape on Linux with tar and producing a plain text index file. It uses a large memory buffer to keep the destination tape drive fed when the source drive can't consistently match the tape's write speed (eg. when there are a mix of small and large files).

This was written for a small, manually managed tape collection. It writes tape index information and tar listings as text to a file. This file can be stored separately, searched easily, and appended to the end of the tape if you want your tapes to be self-describing:

@stecman
stecman / STM8S_programming_examples.md
Last active February 14, 2026 03:18
STM8S code examples

This is a collection of code snippets for various features on the STM8S family microcontrollers (specifically the STM8S003F3). These are written against the STM8S/A SPL headers and compiled using SDCC.

Some of this controller's functions aren't particularly intuitive to program, so I'm dumping samples for future reference here. These are based on the STM8S documentation:

Run at 16MHz