Skip to content

Instantly share code, notes, and snippets.

View aconz2's full-sized avatar

Andrew Consroe aconz2

View GitHub Profile
@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)
@aconz2
aconz2 / fifoleak.py
Created May 28, 2018 04:59
FIFO leak when using many processes under pypy
import multiprocessing
from subprocess import run, PIPE
import os
import gc
def worker(x):
return x * x
def n_files_open():
return len(files_open())
@aconz2
aconz2 / slack-redirect.js
Created May 7, 2018 15:49
slack redirect rewrite (tampermonkey)
// ==UserScript==
// @name Avoid Slack Redirect
// @namespace slackrediravoid
// @include https://*.slack.com/*
// @version 1
// @grant none
// ==/UserScript==
let si = window.setInterval(clearanchors, 2000);
function clearanchors(){
let anchors = document.querySelectorAll('a[href^="https://slack-redir"]');
@aconz2
aconz2 / s3-streaming-fileobj.py
Last active December 18, 2019 21:25
monkey patch s3 streamingbody to be streamable for csv for example
import boto3
import io
import csv
from functools import partial
s3c = boto3.client('s3')
def logging_read(read, amt):
print('READ {}'.format(amt))
return read(amt)
@aconz2
aconz2 / csv-to-xlsx.ps1
Created January 3, 2018 22:56
convert csv to xlsx with excel
param(
[parameter(mandatory=$true)]
[string]$infile,
[parameter(mandatory=$true)]
[string]$outfile
)
# https://msdn.microsoft.com/en-us/vba/excel-vba/articles/workbook-saveas-method-excel