Skip to content

Instantly share code, notes, and snippets.

@bycoffe
bycoffe / gist:1817709
Created February 13, 2012 15:45
Create an XLS spreadsheet from an electronic FEC filing, using Fech
require 'fech'
require 'spreadsheet'
module Fech
class Filing
# Create an XLS spreadsheet from a filing.
def as_xls(filename=nil)
spreadsheet = Spreadsheet::Workbook.new
bold = Spreadsheet::Format.new :weight => :bold
@bycoffe
bycoffe / gist:1817556
Created February 13, 2012 15:20
Create a Google Spreadsheet from an electronic FEC filing, using Fech
require 'fech'
require 'google_spreadsheet'
module Fech
class Filing
# Create a Google Spreadsheet from a filing.
# Note that for large filings, this will fail because of the limit
# Google Spreadsheets places on the number of cells.
def upload_to_google_spreadsheet(email, password, title=nil)
aaronbycoffe@us150633:~$ curl -I newtgingrich.com
HTTP/1.1 200 OK
Content-Length: 1037
Content-Type: text/html
Content-Location: http://newtgingrich.com/redirect.htm
Last-Modified: Wed, 21 Dec 2011 19:35:56 GMT
Accept-Ranges: bytes
ETag: W/"c819afc217c0cc1:31c"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
aaronbycoffe@us150633:~$ curl -I newtgingrich.com
HTTP/1.1 200 OK
Content-Length: 873
Content-Type: text/html
Content-Location: http://newtgingrich.com/redirect.htm
Last-Modified: Wed, 21 Dec 2011 02:02:42 GMT
Accept-Ranges: bytes
ETag: "c6f3b09f84bfcc1:314"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
@bycoffe
bycoffe / template-loader.coffee
Created September 28, 2011 18:20
Load JS template from external file
loadTemplate = (filename) ->
jQuery.ajax({
url: filename,
async: false,
}).responseText
@bycoffe
bycoffe / smooth.js
Created September 9, 2011 20:09
Gaussian smoothing function in JavaScript
// Adapted from http://www.swharden.com/blog/2008-11-17-linear-data-smoothing-in-python/
var smooth = function (list, degree) {
var win = degree*2-1;
weight = _.range(0, win).map(function (x) { return 1.0; });
weightGauss = [];
for (i in _.range(0, win)) {
i = i-degree+1;
frac = i/win;
gauss = 1 / Math.exp((4*(frac))*(4*(frac)));
weightGauss.push(gauss);
@bycoffe
bycoffe / google-charts.coffee
Created September 9, 2011 16:23
Basic Google Charts API wrapper in CoffeeScript
class window.GoogleChart
constructor: ->
@width = 0
@height = 0
@encoded = []
@data = []
simpleEncoding: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
extendedMap: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.',
@bycoffe
bycoffe / fapiis_scraper.py
Created April 20, 2011 13:33
First pass at scraping the FAPIIS site, just to see if it's possible.
"""
First pass at scraping the FAPIIS site, just to see if it's possible.
This seems to work, but it's impossible to know whether the data it's
returning will be accurate since FAPIIS doesn't currently contain any
data.
This method requires knowing the company's DUNS number, though it's
likely possible to back this up a step to allow for searching by name.
"""
import urllib
#!/usr/bin/python
'''
Python-based gift exchange randomizer.
Step through a list of people and, for each member of that list,
select someone else to be a recipient of their gift. That recipient:
A) Must not be themselves (no self-gifting)
B) Must not already have been assigned as a recipient
class FixedWidthParser(object):
"""A parser for fixed-width data files. Pass in a data file and
a list of field names and lengths, and get back a dictionary
for each row.
Useful for converting a fixed-width file to a CSV.
See tests.py for a usage example.
"""