Skip to content

Instantly share code, notes, and snippets.

View prschmid's full-sized avatar

Patrick Schmid prschmid

  • Sharpen
View GitHub Profile
@prschmid
prschmid / moviepagemaker.py
Created November 11, 2012 17:51
Create a 'pretty' webpage for all of the moives in a directory by getting the movie poster from IMDB.
#!/usr/bin/python
"""
Create a 'pretty' webpage for all of the moives in a directory by getting the
movie poster from IMDB.
Since it depends on the OMDB API, not all posters that are returned are correct.
That being said, it's good enough for a start. =)
"""
@prschmid
prschmid / bytes_to_bitstring.py
Created January 3, 2013 05:51
A simple helper function that takes some input data (bytes) and converts it to a string of "bits" for debugging purposes.
def bytes_to_bitstring(bytes, size=32):
"""A simple helper function that takes some input data (bytes) and converts
it to a string of "bits" for debugging purposes.
Args:
bytes: The data to convert to a string of bits
size: The size (in bits) of the input data.
Returns:
A str of length `size` with the bytes converted into a string of bits.
"""
@prschmid
prschmid / idsentence.py
Last active January 17, 2023 00:02
Implement a memorable ID string. The original idea for this comes from Asana where it is documented on their blog: http://blog.asana.com/2011/09/6-sad-squid-snuggle-softly/
"""Implement a memorable ID string.
The original idea for this comes from Asana where it is documented on their
blog:
http://blog.asana.com/2011/09/6-sad-squid-snuggle-softly/
There are other partial implementations of this and can be found here:
Node.js: https://github.com/linus/greg
Java: https://github.com/PerWiklander/IdentifierSentence
@prschmid
prschmid / webservicethreadingtestcase.py
Last active March 31, 2022 13:21
An example of how to perform a multi-threaded unit test of a web service. The particulars of this example make use of some conventions used when developing a web service when using the Flask microframework, but can be modified to fit most needs.
"""An example of how to perform a multi-threaded unit test of a web service.
The particulars of this example make use of some conventions used when
developing a web service when using the Flask microframework, but can be
modified to fit most needs.
"""
import json
import threading
import time
@prschmid
prschmid / flask_route_status_code_test.py
Created May 17, 2013 15:07
An example test harness for testing the response status codes from routes in your flask application for different kinds of users (e.g. user, admin, super_user, etc.)
import unittest
# Import your Flask app from your module
from myapp import app
# A fitcitious database object that has get/put methods for getting/adding
# data. In your code you will want to use whatever database you are using
# (E.g. SQLAlchemy, MongoDB, CouchDB, etc.)
from database import database
@prschmid
prschmid / xl2wiki.py
Created February 18, 2015 21:19
Simple script to convert an Excel file to MediaWiki format
import sys
import xlrd
if __name__ == '__main__':
if not len(sys.argv) > 1:
sys.exit("Usage: xl2wiki infile.xls [outfile]")
# Read it in and build up a string in the mediawiki format
book = xlrd.open_workbook(sys.argv[1])
@prschmid
prschmid / ma_rmv_wait_times.py
Last active August 29, 2015 14:19
Quick script to query the MA RMVs for their wait times every 60 seconds. I ended up using this to find the optimum time to go visit the RMV since I didn't want to wait long...
# -----------------------------------------------------------------------------
# Modifiable parameters
# -----------------------------------------------------------------------------
# Where to save the results to
save_file = "times.txt"
# The branch locations you care about
locations = ["Boston", "Watertown", "Natick", "Roslindale"]
#! /usr/bin/python
"""Script to check users in healthcare exclusion lists
This checks the following sources:
* SAM exclusion list
* OIG Exclusion list
* OFAC list of Specially Designated Nationals and Blocked Persons (SDN)
* FDA Clinical Investigations Disqualification Proceedings
* FDA Debarment List (Drug Product Applications)
* TRICARE Sanctioned Providers
@prschmid
prschmid / ensure.py
Created January 14, 2016 18:16
Decorator to validate HTTP parameters and submitted JSON for Flask routes
from marshmallow import (
fields,
Schema)
def marshmallow_schema_to_dict(schema):
"""Convert a :class:`marshmallow.Schema` to a dict definition
:param schema: The :class:`marshmallow.Schema` to convert
:returns: A dict containing the details of the schema
@prschmid
prschmid / open_sftp.py
Last active January 27, 2023 08:35
python open_sftp() context manager for sftp read and writing of files with similar behavior to open()
from contextlib import contextmanager
from urlparse import urlparse
from paramiko import AuthenticationException
import pysftp
@contextmanager
def open_sftp(url, mode='r', n_retries=5, retry_sleep_time=5):
"""Context manager to read/write a file via SFTP