Skip to content

Instantly share code, notes, and snippets.

@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 / template-loader.coffee
Created September 28, 2011 18:20
Load JS template from external file
loadTemplate = (filename) ->
jQuery.ajax({
url: filename,
async: false,
}).responseText
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
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
@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)
@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 / fechexample
Created February 25, 2012 18:11
FECh example
filing = Fech::Filing.new(766953)
filing.download
fields = [:contributor_first_name,
:contributor_last_name,
:contributor_organization_name,
:contribution_amount]
rows = filing.rows_like(/sa/, :include => fields)
original = Fech::Filing.new(764200)
original.download
amendment = Fech::Filing.new(764828)
amendment.download
comparison = Fech::Comparison.new(amendment, original)
p comparison.summary
# {:date_signed=>"20120207"}
["TEXT", "SA11ai", nil, "Regarding negative receipts listed on line 11(a)(i) with the description of 'ACH Return', these are interbank clearing of electronic payments processed by the Automated Clearing House (ACH) network of participating banks and the Federal Reserve. These are returns of contributions by individuals which have been deducted from our credit card merchant account or bank account by the credit card company or bank."]
["TEXT", "SA15", nil, "\"Regarding 'Asset Sales' reported on Schedule A supporting Line 15 of our report", " occasionally the RNC has used office equipment that we need to dispose of. This equipment may be sold in bulk to a commercial liquidation business or piece by piece to individuals. When this is done", " these items are reported as 'asset sale' and the price charged is such that they in no way constitute a political contribution. The used assets liquidated by sale to individuals or business are reported as 'Asset Sale' and are priced at fair market value. These items s
{:rec_type=>"TEXT", :filer_committee_id_number=>"SA11ai", :back_reference_tran_id_number=>nil, :text=>"Regarding negative receipts listed on line 11(a)(i) with the description of 'ACH Return', these are interbank clearing of electronic payments processed by the Automated Clearing House (ACH) network of participating banks and the Federal Reserve. These are returns of contributions by individuals which have been deducted from our credit card merchant account or bank account by the credit card company or bank."}