Skip to content

Instantly share code, notes, and snippets.

View steveherrin's full-sized avatar

Steve Herrin steveherrin

  • Mountain View, CA
View GitHub Profile
@steveherrin
steveherrin / main_aiocache.py
Created January 11, 2024 19:38
Minimal demo of using aiocache with FastAPI
"""
caching test/demo
first:
pip install fastapi aiocache "uvicorn[standard]"
"""
import asyncio
import contextlib
import json
import logging
@steveherrin
steveherrin / encode_music.py
Last active August 9, 2023 20:34
Reencode a music library from FLAC to Opus
import pathlib
import subprocess
import sys
REENCODE_EXTENSIONS = {'.flac', '.m4a', '.alac'}
COPY_EXTENSIONS = {'.jpg', '.jpeg', '.png', '.mp3', '.opus', '.ogg'}
IGNORE_EXTENSIONS = {'.log', '.cue', '.txt'}
@steveherrin
steveherrin / bayer_matrix.py
Last active January 17, 2021 01:43
Bayer Matrix Generator
"""
Bayer Matrix
Generate a PNG Bayer Matrix
Usage:
bayer_matrix <order> [--output=<file>]
Options:
-h --help Show this screen
@steveherrin
steveherrin / blender_snippets.py
Last active August 10, 2020 06:08
useful Blender snippets
def stereographic_project(obj):
"""
Given a 2D xy plane, project it onto a 1 m sphere centered at the origin
A point source of light placed at the top of this sphere (z = 1 m)
will then cast a shadow that looks the same as the original plane
"""
for vert in obj.data.vertices:
x = vert.co.x
y = vert.co.y
@steveherrin
steveherrin / maidenhead.py
Created July 9, 2019 02:05
Raspberry Pi GPS Utility Scripts
#!/usr/bin/env python2
from __future__ import print_function, unicode_literals
import gps
import gps.clienthelpers
def get_lat_lon(client):
while client.read() == 0:
@steveherrin
steveherrin / Makefile
Last active April 25, 2019 15:49
Mermaid Makefile
SOURCES := $(shell find . -name '*.mmd' -not -path "node_modules")
SVGS := $(SOURCES:%.mmd=%.svg)
DATEFILE := .last_build.$(shell date +%Y-%m-%d).date
MERMAID_CLI := node_modules/.bin/mmdc
all: $(MERMAID_CLI) $(SVGS)
$(MERMAID_CLI): node_modules
node_modules: package.json
@steveherrin
steveherrin / sudoku_solver.rs
Created December 27, 2018 17:23
Sudoku Solver using Z3
extern crate z3;
fn main() {
let mut initial_s: Vec<&str> = vec![
" 9 4 ",
" 7 6 1 ",
"4 58 ",
"9 6 85 ",
"8 3",
" 51 2 9",
@steveherrin
steveherrin / scope.py
Last active August 9, 2017 20:30 — forked from rfmerrill/scope.py
#!/usr/bin/env python
import numpy as np
import cv2
import sys
import scipy.io.wavfile
import scipy.signal
MIDDLE_RANGE = 2**15
ARBITRARY_MAX_RANGE = 65600 # we use 65600 instead of 65536 so we don't go off the edge