Skip to content

Instantly share code, notes, and snippets.

View psobot's full-sized avatar

Peter Sobot psobot

View GitHub Profile
@psobot
psobot / multiprocesscallback.py
Created May 13, 2012 20:28
Cross-process Python Callbacks
"""
multiprocesscallback.py, by Peter Sobot (psobot.com), May 13, 2012
Handles callback functions in classes that have member functions that
are executed in a different process. A crazy experiment in Python
magic that breaks a lot of rules.
Do not use in production, for any reason. (Although I do.)
If your class takes in a callback, like so:
@psobot
psobot / autoclip.py
Created October 22, 2023 13:51
AutoClip™ - Split up Music Rehearsal Videos
"""
1. Record an Off-Beat Jazz rehearsal session with an Sony A7C camera
2. Plug in an SD card to your Mac
3. Run this script, which will automatically segment the rehearsal session and render
to lower-quality, shareable, Google Drive-able H265-encoded video files
4. Upload to Google Drive
5. Get better at playing Jazz
Requirements:
python3 -m pip install tqdm ffmpeg-python numpy ffmpeg matplotlib
@psobot
psobot / kos_file_dumper.py
Last active June 13, 2023 16:27
Kurzweil KOS File Packer/Unpacker
"""
Kurzweil K2500/K2600 KOS operating system update file packer/repacker
by Peter Sobot, Nov 6, 2021
@psobot / github@petersobot.com
Requirements: none! Pure Python. Just use Python 3.2+.
"""
import os
import math
@psobot
psobot / bouncer.py
Last active June 8, 2023 02:42
Logic Pro X Project Bounce script
import os
import sys
import time
import atomac
import subprocess
if len(sys.argv) < 2:
print "Usage: bouncer.py <path_to_logic_project> (<path_to_logic_project>)"
os.exit(1)
@psobot
psobot / lame.py
Created April 14, 2012 19:34
Asynchronous MP3 encoding in Python
from Queue import Queue
import subprocess
import threading
import traceback
import logging
import time
log = logging.getLogger(__name__)
"""
@psobot
psobot / format_stacktrace_from_strace.py
Last active October 31, 2022 12:58
Dump a stack trace of a Go process without stderr attached. This is a super dirty hack, but it uses strace, pgrep and python to send QUIT to a Golang process, intercept its system calls to stderr, and format them nicely for humans. Tested on Ubuntu with Go 1.1.
import sys
import re
output = sys.stdin.readlines()
r = re.compile(r'write\(2, "(.+?)", \d+\)\s+= \d+')
print "".join([x.replace(r'\n', "\n").replace(r'\t', "\t") for x in sum([r.findall(o) for o in output], [])])
@psobot
psobot / stacksearch.py
Created September 27, 2022 17:03
Search a Python stack for a variable with a given name
import inspect
from typing import Tuple, Any
def search_stack_for_variable(variable_name: str, frame=None) -> Tuple[str, Any]:
if frame is None:
frame = inspect.currentframe()
if variable_name not in frame.f_locals:
if frame.f_back is None:
raise ValueError(f"No variable named \"{variable_name}\" found in callstack.")
@psobot
psobot / terminatablethread.py
Created September 13, 2013 15:47
A terminatable thread class that automatically joins all threads with the main thread on exit. Based on work by Tomer Filiba (http://tomerfiliba.com/recipes/Thread2/) but updated and tested on Python 2.7.1.
import atexit
import ctypes
import inspect
import threading
"""
Any instances of TerminatableThread that are running when the program exits
(due to normal interpreter shutdown, KeyboardInterrupt, SystemExit, etc.)
will have SystemExit raised within their next 100 Python bytecode executions,
allowing them to possibly catch the SystemExit and clean up as necessary.
@psobot
psobot / protodump.py
Created March 13, 2022 21:58
Protobuf Definition Dumper
"""
Super hacky script to parse compiled Protobuf definitions out of one or more binary files.
Very useful if, say, you want to pull the internal data structures out of a compiled App Store app.
Requires `pip install 'protobuf>=3.20.0rc1'`.
Example usage:
python3 protodump.py /Applications/SomeAppBundle.app ./proto_files_go_here/
(c) Peter Sobot (@psobot), March 13, 2022
@psobot
psobot / phone_prefixes.json
Last active February 2, 2022 11:02
Mapping of phone number prefixes to geographic coordinates, countries and regions.
{
"+1": [[63.004759, -99.392855], "Canada"],
"+1242": [[26.215829, -98.187851], "Bahamas"],
"+1246": [[13.186666, -59.55727], "Barbados"],
"+1264": [[18.217056, -63.050923], "Anguilla"],
"+1268": [[17.08682, -61.796431], "Antigua and Barbuda"],
"+1284": [[18.719042, -64.326495], "British Virgin Islands"],
"+1340": [[33.282206, -117.185162], "US Virgin Islands"],
"+1345": [[19.323764, -81.195721], "Cayman Islands"],
"+1441": [[32.301277, -64.77506], "Bermuda"],