Skip to content

Instantly share code, notes, and snippets.

View aconz2's full-sized avatar

Andrew Consroe aconz2

View GitHub Profile
@aconz2
aconz2 / lldbtest.py
Created August 8, 2021 17:20
Example using the lldb Python bindings to create breakpoints, run a program, and step through programatically
import lldb
import os
import sys
symbol_types = {}
for x in dir(lldb):
if x.startswith('eSymbolType'):
symbol_types[getattr(lldb, x)] = x[len('eSymbolType'):]
dbg = lldb.SBDebugger.Create()
@aconz2
aconz2 / inkscapeautosmoothnodes.py
Last active November 25, 2022 07:40
Implements the auto-smooth node type from Inkscape in Python with svgpathtools. Keywords: fitting cubic bezier curve spline points smooth
import svgpathtools as svg
from typing import List, Tuple
def points(path: svg.Path):
for seg in path:
yield seg.start
yield path.end
def normalized(x: complex) -> complex:
return x / abs(x)
@aconz2
aconz2 / cookie-cutter-cutter.scad
Created February 21, 2021 04:55
Easy way to make cookie cutters from an SVG or DXF using openscad for 3d printing
@aconz2
aconz2 / serve-serial.sh
Created February 12, 2021 22:55
proxy serial port from laptop to virtual machine running on a server
# on server that has virtual machine, IP is 192.168.1.207
# in virt-manager, add a serial port, it will show up as /dev/pts/something
sudo socat -d -d file:/dev/pts/1 TCP-LISTEN:9090
# on laptop that is plugged into device, -x will log communication as hex
sudo socat -x -d -d /dev/ttyUSB0,b9600,raw TCP:192.168.1.207:9090
# then remote into virtual machine and use the serial port!
@aconz2
aconz2 / blenderlivereload.py
Last active April 20, 2020 00:08
Blender plugin to rerun a Python script on change. Still buggy properly shutting down
from threading import Event, Thread
import bpy
from inotify_simple import INotify, flags
import traceback
# this is still buggy on properly cleaning things up on exit
def run(exit: Event, changed: Event, filename):
inotify = INotify()
inotify.add_watch(filename, flags.MODIFY)
@aconz2
aconz2 / live-reload.sh
Last active November 3, 2022 13:12
simple way to get live reloading browser. Pipe list of filenames that will trigger a refresh (see entr)
#!/usr/bin/env bash
trap 'kill $(jobs -pr) 2>/dev/null' SIGINT SIGTERM EXIT
browser=chromium-browser
python3 -m http.server &
$browser "http://localhost:8000/$1" 2>/dev/null &
browserpid=$!
@aconz2
aconz2 / libavformat_example.c
Created April 13, 2020 18:55
Example using lib{avformat,codec} to demux and decode frames of a container file
// clang -g -O2 -I/usr/include/ffmpeg -lavformat -lavutil -lavcodec avformat_example.c -o avformat_example
#include <assert.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/file.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
@aconz2
aconz2 / enumeratewalks.py
Created February 7, 2019 15:25
Enumerate paths on a pixel grid of varying path lengths
import itertools
import numpy as np
from PIL import Image
from operator import itemgetter
from collections import defaultdict
import base64
import io
dirs_map = {
(1, 0) : 'R',
@aconz2
aconz2 / catmull_rom_to_bezier.py
Last active July 20, 2022 10:11
python smooth interpolation of points using cubic bezier, computed from catmull_rom
"""
python reimplementation of http://schepers.cc/getting-to-the-point (source http://schepers.cc/svg/path/catmullrom2bezier.js)
Pretty much the coolest thing ever
"""
from collections import namedtuple
import numpy as np
Point = namedtuple('Point', ('x', 'y'))
def catmull_rom_to_bezier(points):
@aconz2
aconz2 / migrate.py
Created July 5, 2018 19:31
peewee migrator
# generic migration template
from playhouse.migrate import *
from models import *
migrator = SchemaMigrator.from_database(database)
def add_column(field):
return migrator.add_column(field.model._meta.table_name, field.column_name, field)