Skip to content

Instantly share code, notes, and snippets.

@bycoffe
bycoffe / index.html
Created January 28, 2014 17:25
Force layout with collision detection, sorting and variable-radius circles
<!doctype html>
<meta charset="utf-8">
<html>
<head>
<style type="text/css">
#canvas {
width: 900px;
height: 500px;
}
@bycoffe
bycoffe / paper_chase.rb
Created September 18, 2013 21:48
A Ruby module for searching for FEC images
# encoding: utf-8
require 'net/http'
require 'nokogiri'
require 'uri'
module PaperChase
class Report
attr_accessor :type, :amended, :filed_on, :from_date, :end_date, :pages, :page_by_page, :pdf_url
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bycoffe
bycoffe / README.md
Created June 26, 2013 20:19
Town/county map using d3 and TopoJSON

This is a demonstration of how to create a combination town/county map from a shapefile using TopoJSON and d3.js.

It includes a simplified version of the code used for the Massachusetts special Senate election results on The Huffington Post.

Get the data

Download a shapefile of Massachusetts towns from the state's GIS site:

wget http://wsgw.mass.gov/data/gispub/shape/census2000/towns/census2000towns_poly.exe
@bycoffe
bycoffe / README.md
Created June 26, 2013 20:17
Highlighting with point-in-polygon

This code demonstrates how to draw circles on multiple SVGs using d3.js and highlight them by dragging the mouse to draw an enclosing shape.

This is a simplified version of the code used for the Massachusetts special Senate election results on The Huffington Post.

$ ogr2ogr -f 'ESRI Shapefile' -t_srs 'EPSG:4326' drought.shp usdm130521.shp
$ topojson --cartesian --width=800 --height=800 -p -o drought.json drought=drought.shp
wget -mkr -nH --no-parent http://www.nytimes.com/projects/2012/snow-fall/
vertices = [];
for (i=0; i<turnoutData.length; i++) {
vertices.push([x(turnoutData[i].date), y(turnoutData[i].registered_voters_percent)])
}
svg.selectAll("path.cell")
.data(d3.geom.voronoi(vertices))
.enter().append("path")
.attr({
"class": "cell",
d: function(d, i) {
@bycoffe
bycoffe / index.html
Created May 14, 2013 13:35
Point-in-polygon
<!doctype html>
<meta charset="utf-8">
<html>
<head>
<style type="text/css">
#canvas {
width: 800px;
height: 400px;
border: 1px solid #666;
}
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 9 columns, instead of 46 in line 1.
votes (amendments 715,725,713,719,711,720,714,717,730)|count|senators
Nay,Yea,Nay,Yea,Nay,Yea,Nay,Yea,Yea|38|Alexander (R),Ayotte (R),Barrasso (R),Blunt (R),Boozman (R),Burr (R),Chambliss (R),Coats (R),Coburn (R),Cochran (R),Corker (R),Cornyn (R),Crapo (R),Cruz (R),Enzi (R),Fischer (R),Flake (R),Graham (R),Grassley (R),Hatch (R),Heller (R),Hoeven (R),Inhofe (R),Isakson (R),Johanns (R),Johnson (R),McConnell (R),Moran (R),Portman (R),Risch (R),Roberts (R),Rubio (R),Scott (R),Sessions (R),Shelby (R),Thune (R),Vitter (R),Wicker (R)
Yea,Nay,Yea,Nay,Yea,Nay,Yea,Nay,Yea|26|Baldwin (D),Blumenthal (D),Boxer (D),Brown (D),Cantwell (D),Cardin (D),Carper (D),Durbin (D),Feinstein (D),Franken (D),Gillibrand (D),Harkin (D),Hirono (D),Leahy (D),Levin (D),Menendez (D),Mikulski (D),Murphy (D),Murray (D),Nelson (D),Reed (D),Rockefeller (D),Schatz (D),Schumer (D),Stabenow (D),Whitehouse (D)
Yea,Nay,Yea,Nay,Yea,Nay,Yea,Yea,Yea|7|Casey (D),Coons (D),Kaine (D),Klobuchar (D),Merkley (D),Shaheen (D),Wyden (D)
Yea,Yea,Yea,Yea,Nay,Yea,