Skip to content

Instantly share code, notes, and snippets.

Stephen Holdaway stecman

View GitHub Profile
stecman / AutoCrop.lua
Last active Apr 9, 2019
Lightroom plugin to calculate image crops using OpenCV
View AutoCrop.lua
-- 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 /
Last active Apr 6, 2019
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.


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.




Allowing control without root privileges

# Create rule so the device can be controlled by any user
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="f055", ATTR{idProduct}=="05df", MODE="0666"' \
  | tee /etc/udev/rules.d/99-status-light.rules
View How to

Note: this is an extract from Heyday's internal docs, written by me. Published as a Gist to share the love.

Authoring commits

We like sensible commit messages. There're a lot of good articles about writing great, useful commit messages, but here's the gist of what we like:

  • The single most important thing is: commit messages should explain why you are making the change.
  • Think, "what would future me want to know about this change?"
  • Avoid committing multiple sets of ideas/changes in the same commit: split them up.
  • Don't assume the reader understands what the original problem was.
stecman / RestController.php
Last active Mar 7, 2019
Generic REST controller for use in the Phalcon PHP framework
View RestController.php
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\DispatcherInterface;
use Phalcon\Mvc\Model\CriteriaInterface;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Mvc\View;
abstract class RestController extends Controller
stecman /
Last active Feb 23, 2019
DS18B20 1-Wire implementation for Atmel AVR

AVR C 1-Wire + DS18B20 temperature sensor

This implements Maxim's One Wire / 1-Wire protocol for AVR microcontrollers from the DS18B20 datasheet and Maxim's other application notes.


Single DS18B20 device on bus

With just one DS18B20 on the 1-Wire bus, you can ignore slave addresses:

stecman / _NMEA GPS datetime for
Last active Feb 16, 2019
NMEA GPRMC sentence parsing for low memory microcontrollers: read GPS date and time from UART
View _NMEA GPS datetime for

Date/time from GPS without storing NMEA string

This is a first pass at reading the date and time from a serial GPS device on a tiny microcontroller. The target device is an ATTiny13A with only 64 bytes of RAM, which isn't enough to store the full 79 characters of a NMEA sentence, so something like minmea wouldn't work (their API passes around full sentence strings).

When compiled with avr-gcc -Os, this is around 500 bytes of program space. The size can be reduced by 100 bytes if the handling of checksums is removed.

stecman / monday-for-week.php
Last active Feb 3, 2019
Reliable PHP function to return Monday for week
View monday-for-week.php
* Find the starting Monday for the given week (or for the current week if no date is passed)
* This is required as by default in PHP, strtotime considers Sunday the first day of a week,
* making strtotime('Monday this week') on a Sunday return the adjacent Monday instead of the
* previous one.
* @param string|\DateTime|null $date
* @return \DateTime
stecman / silverstripe-remove-empty-tabs.php
Last active Jan 2, 2019
Remove empty tabs in the SilverStripe CMS
View silverstripe-remove-empty-tabs.php
* Recurse through tabs and remove any with no child fields
* The way SilverStripe's field scaffolding works can leave empty tabs around after
* fields are moved or removed by the slices module.
* @param FieldList $fields
* @return FieldList
protected function removeEmptyTabs(FieldList $fields)
stecman /
Last active Dec 20, 2018
Pushover notification CLI script

Send Pushover notifications from the command line

Notify is a utility for sending push notifications via Pushover from the command line. It can be run manually, but is most useful for sending notifications from shell scripts, cron jobs, and long running tasks.

Pushover screenshot


To install, copy the contents of notify.php to somewhere on your computer, and make it executable:

You can’t perform that action at this time.