Skip to content

Instantly share code, notes, and snippets.

View JoeGermuska's full-sized avatar

Joe Germuska JoeGermuska

View GitHub Profile
#!/usr/bin/env python
import json
import os, os.path
DEFAULT_PROFILE_NAME = "default.2m2"
SESSION_PATH = "Library/Application Support/Firefox/Profiles/%s/sessionstore.js"
# TODO consider generalizing the session store to open (different users, different profiles)
def session_path():
return os.path.join(os.environ['HOME'],SESSION_PATH % DEFAULT_PROFILE_NAME)
@JoeGermuska
JoeGermuska / csvcut
Created September 14, 2009 17:56
Like cut, but smart about CSV quoting
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Change row[1] to the row index to be printed. row[1] will print the second
item in the row.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Leveraged from/motivated by an example from @bycoffe
@JoeGermuska
JoeGermuska / csvcut
Created September 14, 2009 21:01 — forked from bycoffe/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Leveraged from/motivated by an example from @bycoffe
Should use something better than getopt, but this works...
strfix <- function(s) {
s = gsub("(^ +)|( +$)", "", s)
s = sub("^(.*)$","\\U\\1",s, perl=TRUE)
return (s)
}
@JoeGermuska
JoeGermuska / csvcut
Created June 11, 2010 15:21 — forked from bycoffe/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Should use something better than getopt, but this works...
Usage:
csvcut foobar.csv
@JoeGermuska
JoeGermuska / csvcut
Created September 1, 2010 20:51 — forked from bycoffe/csvcut
#!/usr/bin/env python
"""
Like cut, but for CSVs. To be used from a shell command line.
Note that fields are zero-based, as opposed to 'cut' where they are 1-based.
Should use something better than getopt, but this works...
Usage:
csvcut foobar.csv
@JoeGermuska
JoeGermuska / schema_maker.py
Created March 7, 2012 22:59
Example of script to make a csvkit fixed width schema from IL Board of Ed School Report Card file layouts
#!/usr/bin/env python
import sys
import csv
input_file = sys.argv[1]
r = csv.reader(open(input_file))
w = csv.writer(sys.stdout)
w.writerow(['column','start','length'])
for row in r:
try:
@JoeGermuska
JoeGermuska / ranker.py
Created April 18, 2012 15:20
Example of how to convert a csv file to a table of ranked headers for each row
#!/usr/bin/env python
import csv, json
from collections import defaultdict
r = csv.reader(open("data.csv"))
headers = r.next()
countries = headers[1:]
out_rows = []
for row in r:
area = row[0]
out_row = [area]
@JoeGermuska
JoeGermuska / gist:2514658
Created April 28, 2012 00:34
The Chicago Tribune is seeking a CAR journalist…
The Chicago Tribune is seeking a CAR journalist who can serve a 2-year
residency for the newsroom. The candidate for this Computer Assisted
Reporting position should have proven watchdog skills and experience
with every facet of story development, from filing FOIA requests to
finishing a polished draft of a newspaper story and its digital
package. Clips should show proven results of this kind of work.
A key part of the job is to work with suburban reporters assigned to
specific towns to tell stories that can be told only by those with
command of hard data. This journalist also will be looking
@JoeGermuska
JoeGermuska / millennium_park_2013.py
Last active December 16, 2015 21:29
A pair of simple python scripts to produce ICS files of free music in Chicago for the Summer of 2013, and the ICS files they produced. You should be able to "subscribe" to these calendars in MacOS Calendar or Google Calendar using the "raw" URL for the ICS files below, or more simply http://j.mp/millpark2013 and http://j.mp/summerdance2013 The M…
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from icalendar import Calendar, Event
from datetime import timedelta
from dateutil.parser import parse
from dateutil.tz import tzlocal
from pyquery import PyQuery as pq
from urlparse import urljoin
urls = {