Skip to content

Instantly share code, notes, and snippets.


Joseph L. Sheedy jsheedy

View GitHub Profile
noxdafox /
Created Apr 15, 2018
This code snippet shows how to wrap a concurrent.futures.Executor class to provide a limited queue size.
from threading import BoundedSemaphore
from concurrent.futures import ProcessPoolExecutor
class MaxQueuePool:
"""This Class wraps a concurrent.futures.Executor
limiting the size of its task queue.
If `max_queue_size` tasks are submitted, the next call to submit will block
until a previously submitted one is completed.
fitzk /
Last active Feb 8, 2017
Generates a JSON object of Donald Trump's tweets and their associated meta-data.
import tweepy
import json
CONSUMER_KEY = # your consumer key
CONSUMER_SECRET = # your consumer secret
ACCESS_KEY = # your access key
ACCESS_SECRET = # your access secret
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
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)
EvilScott /
Last active Aug 1, 2016
Install OpenCV for MacOS with Python 3.4 + VirtulEnv
#!/usr/bin/env bash
# this script will download, configure, compile, and install opencv for macos with python 3.4 using a virtualenv
# instructions are from
# you need git, homebrew, and a virtualenv with python 3.4
# grab prereqs
brew install cmake pkg-config jpeg libpng libtiff openexr eigen tbb ffmpeg
# grab opencv source
jsheedy /
Last active Aug 31, 2020
Sometimes you need a file-like object when all you have is an iterator, for instance when using psycopg2's cursor.copy_from. This class will handle the impedance mismatch.
import io
import sys
class IteratorFile(io.TextIOBase):
""" given an iterator which yields strings,
return a file like object for reading those strings """
def __init__(self, it):
self._it = it
self._f = io.StringIO()
messa /
Created Jun 26, 2015
Python asyncio + SSL TCP client/server example
#!/usr/bin/env python3
import asyncio
import multiprocessing
import os
import ssl
from time import sleep
port = 9000
rfunduk / setup-WxH.applescript
Created Aug 22, 2013
Example AppleScript for re-arranging commonly used windows for a screen resolution. Eg. switching between laptop at 1440x900 and external monitor at 2560x1440 is a big pain, requiring a lot of moving around and resizing of windows. So instead you adapt this script, make a setup-1440x900.applescript and a setup-2560x1440.applescript, and run them…
View setup-WxH.applescript
tell application "Flint" to activate -- needs to be in front
tell application "System Events" to tell application process "Flint"
get properties of window 1
set size of window 1 to {700, 800}
set position of window 1 to {1700, 300}
end try
end tell
tell application "Adium" to activate -- needs to be in front
JeffPaine /
Created Jul 10, 2012
A python list of all US state abbreviations.
states = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA",
"HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD",
"MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ",
"NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC",
"SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
You can’t perform that action at this time.