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 / README.md
Last active Jun 15, 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 / _readme.md
Last active Jun 9, 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 / 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/
View README.md

Requirements

Install https://pypi.python.org/pypi/libusb1

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
@stecman
stecman / AutoCrop.lua
Last active May 7, 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")
View How to Git.md

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
stecman / RestController.php
Last active Mar 7, 2019
Generic REST controller for use in the Phalcon PHP framework
View RestController.php
<?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
stecman / _DS18B20-AVR-OneWire.md
Last active Feb 23, 2019
DS18B20 1-Wire implementation for Atmel AVR
View _DS18B20-AVR-OneWire.md

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.

Usage

Single DS18B20 device on bus

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

You can’t perform that action at this time.