Skip to content

Instantly share code, notes, and snippets.


Joseph L. Sheedy jsheedy

View GitHub Profile
jsheedy /
Created Sep 15, 2020
bash run() - exit script if subprocess fails
function run() {
# usage: run "command string --with-args"
cmd_output=$(eval $1)
if [ $return_value != 0 ]; then
echo "Command $1 failed"
exit -1
echo "output: $cmd_output"
echo "Command succeeded."
""" quick hack to press the buttons on the Spotify desktop app based on nanoKONTROL transport buttons using cliclick.
The volume control on slider 1 is especially janky """
import subprocess
import rtmidi
midiin = rtmidi.RtMidiIn()
def print_message(midi):
jsheedy / Dockerfile
Created Jul 2, 2018
dockerfile-compose for a celery worker with autoreload on code change
View Dockerfile
FROM python:3.6
RUN mkdir /app
ADD requirements.txt /app/
RUN pip install -r requirements.txt
CMD [ \
"watchmedo", \
"auto-restart", \
jsheedy / Makefile
Created Mar 28, 2017
boring old cube GL
View Makefile
gcc boring_old_cube.cpp -framework OpenGL -framework GLUT -o boring_old_cube -w
jsheedy /
Created Dec 2, 2016
asyncio + uvloop echo server benchmark

asyncio + uvloop echo server benchmark

This is an attempt at a bare minimum client/server benchmark of asyncio with optional use of uvloop. On my 2015 macbook pro, I get almost 2.5X improvement using uvloop in the server.

The client runs PARALLEL tasks at once. Running only a single task results in about 1/8 the throughput of 100 simultaneous tasks.

# with uvloop
$ python
satisfied 100000 requests in 1.41021 seconds (70911.42 reqs/s)
jsheedy /
Last active Feb 16, 2021
benchmark for postgres inserts using copy_from and IteratorFile from
import time
import psycopg2
from iter_file import IteratorFile
conn = psycopg2.connect(host="localhost", database="test")
# args = [(1,2), (3,4), (5,6)]
args = [(i,i+1) for i in range(1,1*10**4,2)]
jsheedy /
Created Jun 10, 2016
OpenCV-Python skeletonize function
def skeletonize(img):
""" OpenCV function to return a skeletonized version of img, a Mat object"""
# hat tip to
img = img.copy() # don't clobber original
skel = img.copy()
skel[:,:] = 0
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,3))
jsheedy /
Created May 25, 2016
floyd-steinberg dithering of a single channel uint8 image
def floyd_steinberg_dither(data):
result = data.astype(np.float64)
fs_matrix = np.array( (
( np.nan, np.nan, 7/16 ),
( 3/16, 5/16, 1/16),
), dtype=np.float64 );
fs_mask = np.array( (
jsheedy /
Last active Mar 18, 2016
JSON stream extractor
#!/usr/bin/env python
""" parses a JSON document on stdin, and prints to stdout the portion of the document
referenced by the Python getter substring given as the first argument.
This implementation uses eval(), so use with care! No warranty implied.
For example
$ curl '' 2> /dev/null | ~/bin/ '["RelatedTopics"][0]["Text"]'
jsheedy /
Created Feb 20, 2016
latest weather observations from UW ATG building rooftop
""" provides latest_uw_data(), a generator which yields dictionary records of current
weather obs from UW ATG """
from datetime import datetime,timedelta
from urllib import request
def latest_uw_data():
url = ""
with request.urlopen(url) as f: