Skip to content

Instantly share code, notes, and snippets.

View aparrish's full-sized avatar

Allison Parrish aparrish

View GitHub Profile
@aparrish
aparrish / add_param_to_url.py
Created March 21, 2013 18:29
add a parameter to the query string of a URL. is this really the easiest way to do this (without resorting to a non-standard library)?
import urlparse
import urllib
def add_param_to_url(url, param, val):
parsed = urlparse.urlsplit(url)._asdict()
query = urlparse.parse_qs(parsed['query'])
query[param] = [val]
parsed['query'] = urllib.urlencode(query, True)
return urlparse.urlunsplit(urlparse.SplitResult(**parsed))
@aparrish
aparrish / wrong_concordance.py
Last active December 15, 2015 12:09
making a "concordance" module—the wrong way to do it
concordance = dict()
def tokenize(line):
return line.split(" ")
def feed(line):
words = tokenize(line)
for word in words:
if word not in concordance:
concordance[word] = 0
@aparrish
aparrish / wrong_concordance2.py
Created March 27, 2013 22:13
making a "concordance" module—slightly better
def tokenize(line):
return line.split(" ")
def feed(concordance, line):
words = tokenize(line)
for word in words:
if word not in concordance:
concordance[word] = 0
concordance[word] += 1
@aparrish
aparrish / portnameteau.py
Created April 18, 2013 22:31
simple algorithm for mashing together two english words
import re
import random
def vtoc_idx(s):
match_obj = re.search(r'[aeiou][^aeiou]', s.lower())
if match_obj:
return match_obj.start() + 1
else:
return None
@aparrish
aparrish / word_of_the_troll.txt
Created December 7, 2013 14:27
Imaginary headlines intended to troll those individuals among us who are prone to lexical upset. This was going to be a twitter bot, but I couldn't get it to do what I wanted from a rhetorical perspective, so I generated 10k lines of output and put them here. The words are made from random urbandictionary.com entries that I mangled with portname…
Holyoake Glossary Of English to nominate "Jacquefe" for Word of the Month
Australian Nomenclature Institute to nominate "Automanlv" for Word of the Century
Ogilvie Lexicon Of North American English advances "Ol33T" as Word of the Year
Roget Glossary Of International English to nominate "San Dieydg" for Word of the Decade
Practical English Thesaurus selects "Buffet Mop" as Word of the Week
Royal British English Dictionary names "Doufml" Word of the Fortnight
Central Board Of Orthography to select "Toory Quinto" as Word of the Century
Heritage Association Of Vocabulary to advance "Hiking Irt" as Word of the Century
United States Global English Dictionary to declare "Concert Happie" Word of the Week
Coleridge English Lexicon to pick "Ignof Practice" as Word of the Year
@aparrish
aparrish / exercise.txt
Last active August 29, 2015 13:56
supplemental exercise for RWET
(1) create a program that prints every other line of input.
i.e., if you ran the program like so:
$ python every_other_line.py <sea_rose.txt
it would produce the output
Rose, harsh rose,
meagre flower, thin,
@aparrish
aparrish / two_cats.py
Created March 27, 2014 14:53
prints out two cats
# vim:fileencoding=utf8
print u"🐱"
print u"\U0001F431"
@aparrish
aparrish / lebron_james.csv
Created May 29, 2014 02:16
LeBron James' 2013-2014 regular season game log, in CSV format.
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 30 columns, instead of 29 in line 9.
Rk,G,Date,Age,Tm,,Opp,,GS,MP,FG,FGA,FG%,3P,3PA,3P%,FT,FTA,FT%,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS,GmSc,+/-
1,1,2013-10-29,28-303,MIA,,CHI,W (+12),1,38:01,5,11,.455,0,1,.000,7,9,.778,0,6,6,8,1,0,2,0,17,16.9,+8
2,2,2013-10-30,28-304,MIA,@,PHI,L (-4),1,36:38,9,17,.529,4,7,.571,3,4,.750,0,4,4,13,0,0,4,3,25,21.4,-8
3,3,2013-11-01,28-306,MIA,@,BRK,L (-1),1,42:14,11,19,.579,1,2,.500,3,5,.600,1,6,7,6,2,1,5,2,26,19.9,-3
4,4,2013-11-03,28-308,MIA,,WAS,W (+10),1,34:41,9,14,.643,3,5,.600,4,5,.800,0,3,3,5,1,0,6,2,25,17.0,+16
5,5,2013-11-05,28-310,MIA,@,TOR,W (+9),1,36:01,13,20,.650,1,3,.333,8,8,1.000,2,6,8,8,0,1,1,2,35,33.9,+3
6,6,2013-11-07,28-312,MIA,,LAC,W (+5),1,37:09,6,13,.462,1,3,.333,5,9,.556,0,5,5,6,1,0,4,4,18,10.8,-1
7,7,2013-11-09,28-314,MIA,,BOS,L (-1),1,36:32,9,13,.692,0,0,,7,9,.778,1,7,8,10,0,0,5,1,25,23.1,+5
8,8,2013-11-12,28-317,MIA,,MIL,W (+23),1,29:58,13,21,.619,4,7,.571,3,6,.500,0,3,3,2,0,0,3,0,33,21.6,+14
9,9,2013-11-15,28-320,MIA,,DAL,W (+6),1,36:58,14,18,.778,1,1,1.000,10,11,.909,0,6,6,4,1,0,6,0,39,31.
@aparrish
aparrish / scores.txt
Created May 29, 2014 02:18
bunch of numbers, woo
17,25,26,25,35,18,25,33,39,30,13,21,22,35,28,27,26,23,21,21,24,17,25,30,24,18,38,19,33,26,26,15,30,32,32,36,25,21,34,30,29,27,18,34,30,24,31,13,37,36,42,33,31,20,61,22,19,17,23,19,21,24,43,15,25,32,38,17,13,32,17,34,38,29,37,36,27
@aparrish
aparrish / botdraft.txt
Created June 7, 2014 21:30
I am not going to finish this bot today. but here's the gist! haha literally gist.
X is a cleric. Its university is Y (http://dbpedia.org/ontology/EducationalInstitution).
X is a ship. Its ship draft (μ) is Y (http://www.w3.org/2001/XMLSchema#double).
X is a legislature. Its region served is Y (http://dbpedia.org/ontology/Place).
X is a dog. Its foal date is Y (http://www.w3.org/2001/XMLSchema#date).
X is a lake. Its area total (m2) is Y (http://www.w3.org/2001/XMLSchema#double).
X is a automobile engine. Its piston stroke (μ) is Y (http://www.w3.org/2001/XMLSchema#double).
X is a Painting. Its original title is Y (http://www.w3.org/2001/XMLSchema#string).
X is a speedway league. Its location city is Y (http://dbpedia.org/ontology/City).
X is a governmental administrative region. Its iso code of a province is Y (http://www.w3.org/2001/XMLSchema#string).
X is a murderer. Its waist size (μ) is Y (http://www.w3.org/2001/XMLSchema#double).