Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Holdaway stecman

View GitHub Profile
@stecman
stecman / AVR_README.md
Last active October 9, 2022 19:46
Detect audio signal with an AVR attiny13a and emulate a MS-6147-RC 443 MHz remote to turn speaker power on
View AVR_README.md

Automatic speaker power control from multiple audio sources

Switches mains power on for speakers while an audio signal is detected, and times out after a period of silence. Uses the AVR ATTiny13a and a couple of op-amps.

Mains switching is achieved by emulating a MS-6147-RC 433.92 MHz remote control with firmware and a simple simple on-off-keying (OOK) transmit module.

This solves two problems for me:

@stecman
stecman / hidetitlebar
Created June 9, 2022 23:14
X11 / Linux hide titlebar of a window
View hidetitlebar
#!/bin/bash
# Hide the decorations of a window.
# Defaults to hiding the focused window's decorations.
# Pass -m to use the mouse to select the target window.
# Get the focused window's ID
ID_OPTION="-id $(xdotool getwindowfocus)"
while getopts 'm' flag; do
@stecman
stecman / NewKittyWindow.scpt
Last active March 12, 2022 05:15
New Kitty terminal window global hotkey on Mac OSX
View NewKittyWindow.scpt
# 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 / ffmpeg_hls.md
Last active December 21, 2022 20:23
ffmpeg streaming examples
View ffmpeg_hls.md

FFmpeg streaming

These are some ffmpeg command lines used when developing VHS dubbing controller.

HLS Stream (on Linux)

#!/bin/bash

# Stream a PAL 50i capture, cropped and de-interlaced using ffmpeg
@stecman
stecman / SwitchOutput.ahk
Last active September 18, 2020 03:27
AutoHotKey script to toggle audio output device in Asus Xonar Essence STX control panel
View SwitchOutput.ahk
; Switch output between headphones and speakers in Asus Xonar STX Control Panel
; On Linux can be done through easily through the ALSA command line tools, but on Windows it's GUI all the way down
;
; This assumes the Xonar Essence STX Audio Center is already running
SetTitleMatchMode, 3 ; Exact match
DetectHiddenWindows, On
ControlWindowTitle := "Xonar Essence STX Audio Center"
@stecman
stecman / nz-whitelist.sh
Last active September 16, 2020 05:33
Linux iptables whitelist country for specific ports
View nz-whitelist.sh
#!/bin/bash
# Run this to update the country whitelist chain in iptables
#
# This is confingured for New Zealand. Other CIDR ranges can be found at:
#
# https://www.ipdeny.com/ipblocks/
#
# To use this chain, configure iptables to redirect some traffic to it. Eg:
#
@stecman
stecman / STM8S_programming_examples.md
Last active December 31, 2022 18:03
STM8S code examples
View STM8S_programming_examples.md

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

@stecman
stecman / _stm32f070-libopencm3-usb-clock.md
Last active February 23, 2020 22:21
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 September 14, 2021 18:39
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
Last active February 17, 2023 06:33
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 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);