Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am twneale on github.
  • I am twneale (https://keybase.io/twneale) on keybase.
  • I have a public key ASBHERV361ILHrWj9WnVa_X7mI5u8FrXDmrlwqhOswPRsgo

To claim this, I am signing this object:

@twneale
twneale / gist:ef11712e43991d671747
Created June 11, 2014 01:55
All hyperlinked citations in the Boston municipal code
Any person violating any provision of subsection
1-2.6
shall be punished by a fine not exceeding twenty ($20.00) dollars for each offense, and not only the
The provisions of subsection
2-12.3
to the contrary notwithstanding, this ordinance shall be published by the action of the City Council
@twneale
twneale / gist:86ac56607f48ab375e60
Created June 5, 2014 17:24
Duped US Code identifiers
[('/us/usc/t21/s812/b/1', 4),
('/us/usc/t21/s812/b/4', 4),
('/us/usc/t21/s812/b/5', 4),
('/us/usc/t21/s812/b/2', 4),
('/us/usc/t21/s812/a', 4),
('/us/usc/t21/s812/b', 4),
('/us/usc/t21/s812/b/3', 4),
('/us/usc/t21/s812/c', 4),
('/us/usc/t42/s14214/d/10', 3),
('/us/usc/t21/s812/a/1', 3),
usc25.xml:
- The xml for /us/usc/t25/s450l (Contract or grant specifications) contains a model agreement with its own internal
Thom Neale <[email protected]>
Apr 13
to Katherine
Hi Katherine, please forgive the earlier email fragment; I accidentally sent if before I was done typing.
@twneale
twneale / pypscl-example.py
Last active December 16, 2016 19:15
Calculating legislator ideal points with Python
from sunlight import openstates, response_cache
from pscl.ext.openstates import RollcallBuilder
response_cache.enable('mongo')
response_cache.logger.setLevel(10)
spec = dict(state='al', chamber='lower', search_window='term:2011-2014')
valid_ids = [leg['id'] for leg in openstates.legislators(spec)]
@twneale
twneale / getcitations.py
Last active August 29, 2015 13:56
Basic uscode citation-to-neoid function.
import re
def citations(text):
rgx = u'(\\d+)\\s+U\\.?S\\.?C\\.?\\s*\xa7*\\s\\s*([\\d\\w\\-\\\u2013\\.\u2013]+)(\\([\\d\\w\\-\\\u2013\\.\u2013()]+\\))*'
matches = []
for match in re.finditer(rgx, text):
title, section, path = match.groups()
section = section.strip(u'\u2013.- ')
start, end = match.span()
@twneale
twneale / gist:8363605
Created January 10, 2014 22:05
Get a set of all paragraph numbers used in the Code of Federal Regulations
import re
import os
import sys
import json
import contextlib
import lxml.etree
@contextlib.contextmanager
@twneale
twneale / gist:7826458
Created December 6, 2013 15:26
How to compare two strings with difflib
>>> import difflib
>>> for opcode in difflib.SequenceMatcher(None, "This is a test.", "That is a tent").get_opcodes():
... print opcode
...
('equal', 0, 2, 0, 2)
('replace', 2, 4, 2, 4)
('equal', 4, 12, 4, 12)
('replace', 12, 13, 12, 13)
('equal', 13, 14, 13, 14)
('delete', 14, 15, 14, 14)
@twneale
twneale / gist:6855493
Last active March 25, 2018 12:43
fab context manager to activate virtualenv before running command
'''See http://stackoverflow.com/a/5359988/120991
'''
from fabric.api import *
from contextlib import contextmanager
env.update(
use_ssh_config=True,
directory='/home/ubuntu/projects/thingy',
@twneale
twneale / gist:6443253
Created September 4, 2013 21:42
Salty bet search script
from operator import methodcaller
import lxml.html
from whoosh.index import create_in
from whoosh.fields import *
from whoosh.qparser import QueryParser
class Stats(object):