Skip to content

Instantly share code, notes, and snippets.

View eyeseast's full-sized avatar

Chris Amico eyeseast

View GitHub Profile
@eyeseast
eyeseast / gist:723741
Created December 1, 2010 16:32
Overriding sync to make this a read-only jsonp app
// Overriding sync to make this a read-only jsonp app
Backbone.sync = function(method, model, success, error) {
$.ajax({
url: getUrl(model),
type: 'GET',
// jsonp is read-only
//contentType: 'application/json',
data: null,
// nothing to send
#!/usr/bin/env python
# encoding: utf-8
"""
santa.py
Created by Chris Amico on 2010-12-10.
Use at your own risk.
"""
import csv
def rm_pyc():
"Clear all .pyc files that might be lingering"
local("find . -name '*.pyc' -print0|xargs -0 rm", capture=False)
@eyeseast
eyeseast / documentcloud.py
Created December 15, 2010 03:00
A simple python wrapper for the DocumentCloud API
import httplib2
import urllib
try:
import json
except ImportError:
import simplejson as json
# create a global Http object so we can reuse connections
http = httplib2.Http('.cache')
@eyeseast
eyeseast / doc_dump.py
Created December 31, 2010 15:12
Download a search result full of documents as their original PDFs
#!/usr/bin/env python
# encoding: utf-8
"""
Download a search result full of documents as their original PDFs
"""
import sys
import os
import httplib2
import urllib
@eyeseast
eyeseast / nom_votes.py
Created January 4, 2011 20:02
Get every nomination vote since the 107th Congress
#!/usr/bin/env python
# encoding: utf-8
"""
Get every nomination vote since the 107th Congress
"""
import csv
import sys
import os
from nytcongress import NytCongress
@eyeseast
eyeseast / nominees.py
Created January 4, 2011 20:05
Aggregate the number of nominees by outcome for each congress since the 107th
#!/usr/bin/env python
# encoding: utf-8
"""
Aggregate the number of nominees by outcome for each congress since the 107th
"""
import csv
import sys
import os
def get_app_data(project_path=None, app=None):
"Run dumpdata in a remote project and download the resulting JSON"
if not project_path:
project_path = prompt("Where do we find your project?")
if not app:
app = prompt("What app do you want data from?")
with cd(project_path):
run('python manage.py dumpdata %s --format=json --indent=4 > %s.json' % (app, app))
get('~/%s/%s.json' % (project_path, app), '%s.json' % app)
@eyeseast
eyeseast / greenparser.py
Created February 7, 2011 04:51
Download the last 10 entries from my blog, with or without gevent
#!/usr/bin/env python
# encoding: utf-8
"""
greenparser.py
A simple test script to measure the difference between
regular urllib2 downloads and gevent-based downloads.
"""
from gevent import monkey
monkey.patch_socket()
from lxml.html import parse
def get_feed(url):
"""
Find the first link to an XML feed (rss or atom) and return the URL
"""
page = parse(url).getroot()
page.make_links_absolute()
for link in page.head.findall('links'):
if link.get('type', '').lower() in ('application/rss+xml', 'application/atom+xml'):