Skip to content

Instantly share code, notes, and snippets.

@bycoffe
bycoffe / README.md
Last active June 25, 2024 14:57
Split an SVG path into pieces
@bycoffe
bycoffe / index.html
Created August 7, 2012 16:29 — forked from enjalot/index.html
Simple Pie Chart example with D3.js
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Testing Pie Chart</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.1.3"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
@bycoffe
bycoffe / LICENSE
Last active March 13, 2022 18:37
D3.js world map with force layout
Copyright (c) 2016 Aaron Bycoffe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
@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 / 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 / index.html
Created February 9, 2016 14:54
Town/county switch with topojson
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#map path {
fill: #fff;
stroke: #999;
stroke-width; 1;
}
#map path.state.border {
fill: none;
@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;
}
@bycoffe
bycoffe / chicago_elections_scraper.rb
Created April 8, 2015 01:45
Scraper for Chicago runoff election results
require 'json'
require 'nokogiri'
require 'open-uri'
results = []
open("http://www.chicagoelections.com/ap/results.htm") do |req|
doc = Nokogiri::HTML(req.read)
race = {:updated => doc.css("#ResultsContainer")[0].text.sub(/Last Updated: /, '')}
#!/usr/bin/python
import csv
import datetime
import re
from urllib.parse import unquote
from utils import load_data, save_data
from SPARQLWrapper import SPARQLWrapper, JSON
def run():
@bycoffe
bycoffe / public_file_crawler.rb
Created August 3, 2012 19:30
A script for scraping the FCC's website and finding political file submissions
require 'open-uri'
require 'nokogiri'
class PublicFileCrawler
def initialize(params={})
@call_sign = params[:call_sign]
@url = "https://stations.fcc.gov/station-profile/#{@call_sign}/political-files/browse-%3e2012"
@checked = {}
@found = {}