Skip to content

Instantly share code, notes, and snippets.

Patrick Schmid prschmid

View GitHub Profile
@prschmid
prschmid / auth0_login.rb
Last active Aug 17, 2017
Programmatically Logging in to a site with the Auth0 Lock Widget
View auth0_login.rb
# The site you want to log in to
SITE_URL = nil
# The username/password you want to log in with
USERNAME = nil
PASSWORD = nil
# All of these details are visible when you do a "login" and
# inspect the parameters POSTed when you click "login" on
# the Lock Widget. You'll want to do this in your favorite
@prschmid
prschmid / send_nested.rb
Created Jan 26, 2017
Ruby method to enable "sending" nested calls to an object
View send_nested.rb
class Object
# Retrieve the value of a deeply nested attribute
#
# Example usage
#
# attribute = "data.foo['bar'].id"
# value = obj.send_nested(attribute)
#
# Under the hood this will do something akin to
# obj.send(data).send(foo)['bar'].send(id)
@prschmid
prschmid / hl7_to_dict.py
Last active Jan 10, 2019
Convert an HL7 message to a dictionary.
View hl7_to_dict.py
"""Converting HL7 messages to dictionaries
Example Usage:
import pprint
from hl7apy.parser import parse_message
# Taken from http://hl7apy.org/tutorial/index.html#elements-manipulation
s = """MSH|^~\&|GHH_ADT||||20080115153000||ADT^A01^ADT_A01|0123456789|P|2.5||||AL
EVN||20080115153000||AAA|AAA|20080114003000
@prschmid
prschmid / open_sftp.py
Last active Apr 3, 2019
python open_sftp() context manager for sftp read and writing of files with similar behavior to open()
View open_sftp.py
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
@prschmid
prschmid / ensure.py
Created Jan 14, 2016
Decorator to validate HTTP parameters and submitted JSON for Flask routes
View ensure.py
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
View background_exclusion_check.py
#! /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 / ma_rmv_wait_times.py
Last active Aug 29, 2015
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...
View ma_rmv_wait_times.py
# -----------------------------------------------------------------------------
# Modifiable parameters
# -----------------------------------------------------------------------------
# Where to save the results to
save_file = "times.txt"
# The branch locations you care about
locations = ["Boston", "Watertown", "Natick", "Roslindale"]
@prschmid
prschmid / xl2wiki.py
Created Feb 18, 2015
Simple script to convert an Excel file to MediaWiki format
View xl2wiki.py
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 / flask_route_status_code_test.py
Created May 17, 2013
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.)
View flask_route_status_code_test.py
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 / webservicethreadingtestcase.py
Last active Jan 17, 2019
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.
View webservicethreadingtestcase.py
"""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
You can’t perform that action at this time.