Skip to content

Instantly share code, notes, and snippets.

View MNic's full-sized avatar

Marshall MNic

  • Duke University
  • Durham, NC
View GitHub Profile
from bisect import bisect_left
import pandas as pd
# Create Example Fixture
data = [['A', 1], ['B', 3], ['C', 5]]
df = pd.DataFrame(data=data, columns=('ID', 'Delta'))
## Example 1
# Build out a very large dict with a discrete value key for every
# possible value in the bin. Works with ints
@MNic
MNic / arcos_data.py
Last active October 15, 2019 20:30
WaPo ARCOS API Example
import requests
# See API documentation:
# https://arcos-api.ext.nile.works/__swagger__/
# base_url = 'https://arcos-api.ext.nile.works/'
def wapo_county_request(endpoint, state, county, key='WaPo', version='v1'):
"""Returns county data from Washington Post ARCOS API
@MNic
MNic / memoize_method.py
Created August 7, 2019 18:58
Memoization for class methods
# From http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/
class memoize(object):
"""cache the return value of a method
This class is meant to be used as a decorator of methods. The return value
from a given method invocation will be cached on the instance whose method
was invoked. All arguments passed to a method decorated with memoize must
be hashable.

Keybase proof

I hereby claim:

  • I am mnic on github.
  • I am mnic (https://keybase.io/mnic) on keybase.
  • I have a public key ASDvf1q3PMHt5bWuwHGF2vg1YnsAa9ep-PfclEKwCWPkBQo

To claim this, I am signing this object: