Skip to content

Instantly share code, notes, and snippets.

Stephen Holdaway stecman

Block or report user

Report or block stecman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stecman
stecman / _NMEA GPS datetime for AVR.md
Last active Oct 16, 2019
NMEA GPRMC sentence parsing for low memory microcontrollers: read GPS date and time from UART
View _NMEA GPS datetime for AVR.md

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
stecman / _readme.md
Last active Oct 8, 2019
Brother P-Touch PT-P300BT bluetooth driver python
View _readme.md

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 / AutoCrop.lua
Last active Oct 1, 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
stecman / README.md
Last active Sep 28, 2019
Pushover notification CLI script
View README.md

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

Installation

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

@stecman
stecman / silverstripe-remove-empty-tabs.php
Last active Aug 13, 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
stecman / index.htm
Last active Aug 9, 2019
CSS3 playing cards with flexbox
View index.htm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cards</title>
<link href="http://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
@stecman
stecman / dump-pyc-with-gdb.md
Created Jun 30, 2019
Dumping all bytecode from a packaged Python application
View dump-pyc-with-gdb.md

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 performed on 64-bit Linux with a Python 3.6 target.

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 / Makefile
Last active Jun 5, 2019
AVR basics
View Makefile
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 / monday-for-week.php
Last active Jun 5, 2019
Reliable PHP function to return Monday for week
View monday-for-week.php
<?php
/**
* Find the starting Monday for the given week (or for the current week if no date is passed)
*
* This is required as 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
@stecman
stecman / hackaday-to-md.py
Last active Jun 5, 2019
Hackaday.io article to markdown converter for migrating or backing up projects/posts
View hackaday-to-md.py
#!/usr/bin/env python3
# Convert hackaday posts to markdown with images stored nearby
#
# This needs the following modules to run:
#
# - https://github.com/matthewwithanm/python-markdownify
# - https://2.python-requests.org/en/master/
# - https://www.crummy.com/software/BeautifulSoup/
You can’t perform that action at this time.