Skip to content

Instantly share code, notes, and snippets.

Joseph L. Sheedy jsheedy

Block or report user

Report or block jsheedy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View spotify_kontrol.py
""" 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 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/
WORKDIR /app/
RUN pip install -r requirements.txt
CMD [ \
"watchmedo", \
"auto-restart", \
@jsheedy
jsheedy / Makefile
Created Mar 28, 2017
boring old cube GL
View Makefile
cube:
gcc boring_old_cube.cpp -framework OpenGL -framework GLUT -o boring_old_cube -w
@jsheedy
jsheedy / README.md
Created Dec 2, 2016
asyncio + uvloop echo server benchmark
View README.md

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 Apr 20, 2018
benchmark for postgres inserts using copy_from and IteratorFile from https://gist.github.com/jsheedy/ed81cdf18190183b3b7d
View pg_copy_from.py
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 Jun 10, 2016
OpenCV-Python skeletonize function
View skeletonize.py
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
floyd-steinberg dithering of a single channel uint8 image
View floyd_steinberg.py
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 Mar 18, 2016
JSON stream extractor
View extract_data.py
#!/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"]'
@jsheedy
jsheedy / uw_rooftop.py
Created Feb 20, 2016
latest weather observations from UW ATG building rooftop
View uw_rooftop.py
""" 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 = "http://www.atmos.washington.edu/cgi-bin/latest_uw.cgi?data"
with request.urlopen(url) as f:
@jsheedy
jsheedy / context_manager_iterator.py
Created Jan 29, 2016
a context manager / iterator which remembers the final value
View context_manager_iterator.py
import random
class Foo():
data = (random.randint(0, 1000) for x in range(10))
last = None
def __iter__(self):
return self
You can’t perform that action at this time.