Skip to content

Instantly share code, notes, and snippets.

View paultopia's full-sized avatar

Paul Gowder paultopia

View GitHub Profile
import sys, re, argparse, string, codecs
parser = argparse.ArgumentParser()
parser.add_argument("citearg", help="the file containing the citations from footnotes etc.")
parser.add_argument("refarg", help="the file containing reference list")
manuFiles = parser.parse_args()
def makeCorpoi(citefile, reffile):
citebox = open(citefile, 'r')
@paultopia
paultopia / uglystring
Created June 3, 2015 02:47
ugly string I'm trying to parse
b'Raaflaub, Kurt. 1FOREIGNAthens: Equalities, Inequalities.1FOREIGN In Demokratia: A Conversation on Democracies, Ancient and Modern, edited by Josiah Ober and Charles Hedrick, 139-74. Princeton: Princeton University Press, 1996.\n \n1FOREIGN1FOREIGN1FOREIGN. The Discovery of Freedom in Ancient Greece. Chicago: University of Chicago Press, 2004.\n\nRantanen, Jason. 1FOREIGNThe Malleability of Patent Rights.1FOREIGN forthcoming in Michigan State Law Review (2015).\n \nRawls, John. A Theory of Justice. Cambridge, MA: Harvard University Press, 1999a.\n\n1FOREIGN1FOREIGN1FOREIGN. 1FOREIGNThe Idea of Public Reason Revisited.1FOREIGN In The Law of Peoples: With, 1FOREIGNThe Idea of Public Reason Revisited1FOREIGN, by John Rawls, 129-80. Cambridge, MA: Harvard University Press, 1999b.\n\n1FOREIGN1FOREIGN1FOREIGN. Justice as Fairness: A Restatement. Cambridge, MA: Harvard University Press, 2001.\n\n1FOREIGN1FOREIGN1FOREIGN. Political Liberalism. New York: Columbia University Press, 2005.\n\nRaz, Joseph. 1FOREIGNThe R
@paultopia
paultopia / happystring
Created June 3, 2015 03:05
the string that gets correctly parsed
b'This truth, of course, is embedded deeply into our constitutional ideas. Thus, the Supreme Court applies rational basis review to every legislative act, even those not impinging on a fundamental right or protected class (e.g. Cleburne v. Cleburne Living Center, 473 U.S. 432 (1985)). But the idea goes deeper: positive law is purpose-driven activity (the legislature is trying to bring something about by its enactments), and purpose-driven activity is under a rational requirement to take the means necessary to achieve its ends (Kant 2002, 31-34). \n Davidson, 2001, chs. 9-10; Lewis 1974.\n The quote, along with the principles of coherence and charity, come from Davidson (2001).\n Ordinarily, these attitudes will be beliefs, however the expressive meaning of a law could comprise some other propositional attitude. Nothing in the argument turns on this. Beliefs might be about social, physical, or normative truths, or some combination of them1FOREIGNa law may require attributions of beliefs about, e.g., economi
'''FTP server for Pythonista (iOS)
You can use this to exchange files with a Mac/PC or a file management app on the same device (e.g. Transmit).
If you use a Mac, you can connect from the Finder, using the "Go -> Connect to Server..." menu item.
'''
import os
from socket import gethostname
@paultopia
paultopia / SSHClient.py
Last active August 29, 2015 14:23 — forked from omz/SSHClient.py
# Very simple SSH client for Pythonista
import paramiko
import console
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host = console.input_alert('Connect to')
user, passwd = console.login_alert('Login')
ssh.connect(host, username=user, password=passwd)
print 'Connected to %s. Type `exit` to disconnect.' % host
# with list comprehension
print '\n'.join(['Fizzbuzz' if x % 15 == 0 else 'Fizz' if x % 3 == 0 else 'Buzz' if x % 5 == 0 else str(x) for x in range(input('Start: '), input('End: ') + 1, input('Step: '))])
# with lambdas and map (two versions)
print '\n'.join(map(lambda x: 'Fizzbuzz' if x % 15 == 0 else (lambda x: 'Fizz' if x % 3 == 0 else (lambda x: 'Buzz' if x % 5 == 0 else str(x))(x))(x), range(input('Start: '), input('End: ') + 1, input('Step: '))))
print '\n'.join(map(lambda x: 'Fizzbuzz' if x % 15 == 0 else 'Fizz' if x % 3 == 0 else 'Buzz' if x % 5 == 0 else str(x), range(input('Start: '), input('End: ') + 1, input('Step: '))))
# these versions sometimes work, and sometimes throw an error about being unable to convert string to int, even before user is asked for input.
@paultopia
paultopia / weirdbroken.py
Created September 12, 2015 17:36
weirdbrokencode
samplerow = [1, u'Message-ID: <20625717.1075857797770.JavaMail.evans@thyme>\r\nDate: Wed, 13 Dec 2000 06:03:00 -0800 (PST)\r\nFrom: thane.twiggs@enron.com\r\nTo: jeffery.ader@enron.com, mark.bernstein@enron.com, scott.healy@enron.com, \r\n\tjanelle.scheuer@enron.com, tom.dutta@enron.com, dana.davis@enron.com, \r\n\tpaul.broderick@enron.com, chris.dorland@enron.com, \r\n\tgautam.gupta@enron.com, michael.brown@enron.com, \r\n\tjohn.llodra@enron.com, george.wood@enron.com, joe.gordon@enron.com, \r\n\tstephen.plauche@enron.com, jennifer.stewart@enron.com, \r\n\tdavid.guillaume@enron.com, tom.may@enron.com, \r\n\trobert.stalford@enron.com, jeffrey.miller@enron.com, \r\n\tnarsimha.misra@enron.com, joe.quenet@enron.com, \r\n\tpaul.thomas@enron.com, ricardo.perez@enron.com, \r\n\tkevin.presto@enron.com, sarah.novosel@enron.com, \r\n\tchristi.nicolay@enron.com\r\nSubject: ISO-NE failure to mitigate ICAP market -- Release of ISO NE\r\n confidential information\r\nMime-Version: 1.0\r\nContent-Type: text/plain; charset=u
@paultopia
paultopia / weirdbehavior.py
Last active September 12, 2015 19:41
code that behaves very oddly. not reproducible probably
# creating an example list item plus an example list:
samplerow = [1, u'Message-ID: <20625717.1075857797770.JavaMail.evans@thyme>\r\nDate: Wed, 13 Dec 2000 06:03:00 -0800 (PST)\r\nFrom: thane.twiggs@enron.com\r\nTo: jeffery.ader@enron.com, mark.bernstein@enron.com, scott.healy@enron.com, \r\n\tjanelle.scheuer@enron.com, tom.dutta@enron.com, dana.davis@enron.com, \r\n\tpaul.broderick@enron.com, chris.dorland@enron.com, \r\n\tgautam.gupta@enron.com, michael.brown@enron.com, \r\n\tjohn.llodra@enron.com, george.wood@enron.com, joe.gordon@enron.com, \r\n\tstephen.plauche@enron.com, jennifer.stewart@enron.com, \r\n\tdavid.guillaume@enron.com, tom.may@enron.com, \r\n\trobert.stalford@enron.com, jeffrey.miller@enron.com, \r\n\tnarsimha.misra@enron.com, joe.quenet@enron.com, \r\n\tpaul.thomas@enron.com, ricardo.perez@enron.com, \r\n\tkevin.presto@enron.com, sarah.novosel@enron.com, \r\n\tchristi.nicolay@enron.com\r\nSubject: ISO-NE failure to mitigate ICAP market -- Release of ISO NE\r\n confidential information\r\nM
# takes all HTML files in a directory, dumps it to evernote notebook.
# usage: designed for quick transfer of apple notes to evernote
# using the tool provided at https://github.com/pmatiello/notes-export
# first to get html files dumped in a notebook.
# then call from command line:
# python n2ev.py DEVTOKEN FULLPATHTODIR NOTEBOOKNAME
# DEVTOKEN is a developer token for your evernote acconut, which can
# be acquired from evernote: https://dev.evernote.com/#apikey
# FULLPATHTODIR is, obviously, the path to the directory in which your notes
# are stored, as html files. NOTEBOOKNAME is the new evernote notebook to
@paultopia
paultopia / addcss.py
Created October 8, 2015 22:00
Easy way to add CSS or whatever to header of a bunch of HTML files at once.
# USAGE:
#
# To add code to the end of every <head> tag (like a css link, a font link, etc.) to quick-format an entire website:
# 1. Start in the top-level-directory of the site. Put this file there.
# 2. Add your formtting for the <head> tag to the formatme variable.
# EXAMPLE: mine was '<link href="https://fonts.googleapis.com/css?family=Halant:300" rel="stylesheet" type="text/css"><link rel="stylesheet" href="http://paul-gowder.com/conlawII/prettify.css">'
# be sure to either escape quotes or use single quotes to demarcate the string and double-quotes in the html/vice versa
# 3. Run this script.
# 4. Bam. Every html page in in the top-level directory and all its subdirectories now has the formatting you want.