Skip to content

Instantly share code, notes, and snippets.

View jsheedy's full-sized avatar

Joseph L. Sheedy jsheedy

  • San Francisco Bay Area
View GitHub Profile
@jsheedy
jsheedy / ansi_grafx.py
Last active March 30, 2022 19:47
ansi grafx demo
import io
import itertools
import shutil
import sys
BLOCK = chr(9608)
ESC = "\x1b["
RST = ESC + "0m"
@jsheedy
jsheedy / run.sh
Created September 15, 2020 16:31
bash run() - exit script if subprocess fails
function run() {
# usage: run "command string --with-args"
cmd_output=$(eval $1)
return_value=$?
if [ $return_value != 0 ]; then
echo "Command $1 failed"
exit -1
else
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
jsheedy / Dockerfile
Created July 2, 2018 19:17
dockerfile-compose for a celery worker with autoreload on code change
FROM python:3.6
RUN mkdir /app
ADD requirements.txt /app/
WORKDIR /app/
RUN pip install -r requirements.txt
CMD [ \
"watchmedo", \
"auto-restart", \
@jsheedy
jsheedy / Makefile
Created March 28, 2017 00:43
boring old cube GL
cube:
gcc boring_old_cube.cpp -framework OpenGL -framework GLUT -o boring_old_cube -w
@jsheedy
jsheedy / README.md
Created December 2, 2016 20:47
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 client.py
satisfied 100000 requests in 1.41021 seconds (70911.42 reqs/s)
@jsheedy
jsheedy / pg_copy_from.py
Last active January 23, 2023 17:52
benchmark for postgres inserts using copy_from and IteratorFile from https://gist.github.com/jsheedy/ed81cdf18190183b3b7d
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
jsheedy / skeletonize.py
Created June 10, 2016 23:56
OpenCV-Python skeletonize function
def skeletonize(img):
""" OpenCV function to return a skeletonized version of img, a Mat object"""
# hat tip to http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/
img = img.copy() # don't clobber original
skel = img.copy()
skel[:,:] = 0
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,3))
@jsheedy
jsheedy / floyd_steinberg.py
Created May 25, 2016 23:46
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
jsheedy / extract_data.py
Last active March 18, 2016 18:26
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 'http://api.duckduckgo.com/?q=ramen&format=json' 2> /dev/null | ~/bin/extract_data.py '["RelatedTopics"][0]["Text"]'