Skip to content

Instantly share code, notes, and snippets.

View spenthil's full-sized avatar

Sen Palanisami spenthil

View GitHub Profile

Keybase proof

I hereby claim:

  • I am spenthil on github.
  • I am sen (https://keybase.io/sen) on keybase.
  • I have a public key ASAI2klc6Ew6TiLddaLAGYVeJ1JU-il7zrOy_lU4hnDeZwo

To claim this, I am signing this object:

@spenthil
spenthil / gist:5912415
Created July 2, 2013 19:37
shirts.io GET /quote/ endpoint
import requests
api_key = "PRAGMATISMPLZ"
shirtsio_url = "https://www.shirts.io/api/v1"
def shirtsio_get(endpoint, params=None):
params = params or dict()
params["api_key"] = api_key
response = requests.get(shirtsio_url + endpoint, params=params)
if response.status_code != 200:
@spenthil
spenthil / gist:3211707
Created July 30, 2012 23:09
pyzmq: ioloop in separate thread
import zmq, zmq.eventloop.zmqstream,zmq.eventloop.ioloop
import threading
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()
zmq.eventloop.ioloop.install()
# run ioloop in separate thread
@spenthil
spenthil / gist:2714212
Created May 16, 2012 21:45
filtering on empty GenericRelation
In [24]: InsuranceClaim.objects.annotate(num_invoiceitems=Count('invoiceitems')).filter(num_invoiceitems__gt=0).count()
Out[24]: 29319
In [25]: InsuranceClaim.objects.annotate(num_invoiceitems=Count('invoiceitems')).filter(num_invoiceitems__eq=0).count()
Out[25]: 9826
@spenthil
spenthil / gist:2713766
Created May 16, 2012 20:41
claims in a state that have an email associated with it
from collections import Counter
state = 'bpi'
result = Counter(x.endswith("counsyl.com") for x in InsuranceClaim.objects.filter(status=state).values_list('orderkit__order__profile__user__email', flat=True))
total = sum(result.values()) / 100.0
percentages = {k:int(v/total) for k,v in result.iteritems()}
print percentages
@spenthil
spenthil / gist:2419577
Created April 19, 2012 08:15
claim submission "Blue Shield California" or "Blue Cross of California"
import requests
from datetime import datetime
import re
from counsyl.product.billing.models import InsurancePayer
def filing_blue_payer(payer_name, date=None):
try:
prefix = InsurancePayer.objects.get(name=payer_name).member_id_regexes.all()[0].regex
except IndexError:
return "no prefixes :("
@spenthil
spenthil / gist:2355602
Created April 10, 2012 23:30
ipython notebook startup
from django.core.management import setup_environ
from counsyl.product import settings
setup_environ(settings)
from django.db.models.loading import get_models
for m in get_models():
exec "from %s import %s" % (m.__module__, m.__name__)
from pandas import *
from collections import *
@spenthil
spenthil / gist:2354862
Created April 10, 2012 21:50
ipynb in the background
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.spenthil.osx.ipynb</string>
<key>Program</key>
<string>/usr/local/share/python/ipython</string>
<key>ProgramArguments</key>
<array>
@spenthil
spenthil / inspectdb.py
Created October 17, 2010 00:49
Does the same thing as `django-admin.py inspectdb` but doesn't require you to fully setup a django project first. From django's documentation: 'Introspects the database tables in the database pointed-to by the [database_name] [parameter] and outputs a Dja
#!/usr/bin/env python
__version__ = ['1', '0', '0']
from django.conf import settings
from django.core.management import ManagementUtility
def inspectdb(name, engine='mysql', user='root', password='', host='', port=''):
# setup django
tuple1 = ()
tuple2 = ()
dict1 = {}
dict2 = {}
list1 = []
list2 = []
# makes sense, tuples are immutable
assert(id(tuple1) == id(tuple2))
# also makes sense dicts are mutable
assert(id(dict1) != id(dict2))