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 / _stm32f070-libopencm3-usb-clock.md
Last active Feb 23, 2020
OpenCM3 USB clock configuration
View _stm32f070-libopencm3-usb-clock.md

USB with libopenCM3 on the STM32F070F6

This specific part doesn't work out of the box with the OpenCM3 STM32 F0 USB example/testcase for two reasons:

  • The USB pins (PA11/PA12) are hidden behind a mux on pins PA9/PA10 and need to be switched in. This physically connects the USB peripheral to the pins.
  • The STM32F070 must use an external oscillator to drive the 48MHz USB clock. My design used a 12MHz HSE, which libopencm3 didn't have a built-in clock configuration function for.
@stecman
stecman / config.txt
Last active Jan 17, 2020
Raspberry Pi 2 B+ 1440x2560 resolution config
View config.txt
# Enable 1440x2560 resolution (mobile phone screen that expects this orientation)
hdmi_group=2
hdmi_mode=87
hdmi_pixel_freq_limit=400000000
hvs_priority=0x32ff
max_framebuffer_width=1440
max_framebuffer_height=2560
framebuffer_width=1440
framebuffer_height=2560
@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 / hackaday-to-md.py
Last active Feb 20, 2020
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/
@stecman
stecman / AutoCrop.lua
Last active Mar 22, 2020
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 / _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 / BaseModel.php
Created Oct 14, 2018
Phalcon PHP modifiable array assignment of relationships on new objects
View BaseModel.php
<?php
use Phalcon\Mvc\Model;
/**
* Configuration and behaviours for all models
*/
abstract class BaseModel extends Model
{
/**
@stecman
stecman / avr_eprom_dump_over_serial.c
Last active Jul 19, 2018
Dump EPROM over serial with AVR
View avr_eprom_dump_over_serial.c
/**
* Thrown together program to dump 512 kbit EPROMs from an AVR ATMega64A/128A
* More specifically, a bunch of ST M27C512 from the early 90's
*
* Connections:
*
* Port A 0-7: low address byte (output)
* Port B 0-7: high address byte (output)
* Port D 0-7: data (input)
*
@stecman
stecman / avr_serial_pin_pulse.c
Last active Mar 24, 2018
Hacked together serial-controlled pin power pulser (AVR)
View avr_serial_pin_pulse.c
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <stdlib.h>
#include <string.h>
void init_usart(void)
{
cli();
@stecman
stecman / .bash_profile
Created Feb 27, 2018
Fuzzy find (fzf) to show file from history in Git
View .bash_profile
# Show file from Git tree at a certain point in the history
function hist() {
local ref=$1
local query=$2
if [ -z $ref ]; then
echo "Please specify a ref";
return;
fi
You can’t perform that action at this time.