Skip to content

Instantly share code, notes, and snippets.

@rshorey
rshorey / voterfiles.md
Last active October 30, 2022 02:49
So you want to report using voterfiles

So you want to report using voterfiles

History

In 2002, the Help America Vote Act required (among other things) that states must maintain a "computerized statewide voter registration list". These lists (henceforth "voterfiles") contain information about every registered voter and their voting history.

But what about the secret ballot?

When people who have not worked with voterfile data before hear about voterfiles, their first response is almost always "But in my 8th grade civics class, I learned that a critical component of American democracy is the secret ballot! How can states have a list of how you vote?" Voterfiles do NOT include information about how an individual voted. They report whether an individual voted in a specific election.

What information do voterfiles contain?

The exact format and contents of a publicly available voterfile differ from state to state. At a minimum, a file will contain:

@palewire
palewire / README.md
Last active August 6, 2018 12:58
Simple COPY examples

Simple COPY examples

Two simple examples of quickly loading data into PostgreSQL with the COPY command.

  • First, loading data to a database on your own computer in localhost.sh
  • Second, loading data to a database hosted on the Internet in cloud.sh

Much more sophisticated stuff is possible. Refer to the official docs and consider adopting a wrapper like django-postgres-copy for more complicated tasks.

@dannguyen
dannguyen / SQL-subqueries-aggregates-crimes.md
Last active November 3, 2016 00:27
An example of how to explore and filter a non-normalized SQL database table using subqueries and joins using cross-platform syntax (e.g no DISTINCT or WINDOW)

A SQL tutorial on using subqueries to filter a table against itself

This is a short SQL tutorial on how to do multiple transformation/aggregates of a table in order to perform analyses of the kind:

Given a list of grocery stores that includes how much fruit they've sold, per type of fruit, e.g.:

| store | fruit | price | sold |
@dannguyen
dannguyen / generic-mapzen-city-geocoder.py
Last active November 16, 2016 21:10
more generic version of mapzen-geocoder in python, used to get city locations in the U.S. https://mapzen.com/documentation/search/
from csv import DictReader, DictWriter
from os import environ
from time import sleep
import requests
FNAME = 'mx-syria.csv'
ONAME = FNAME + 'geocoded.csv'
API_KEY = environ['MAPZEN_SEARCH_KEY']
BASE_URL = 'https://search.mapzen.com/v1/search'
@dannguyen
dannguyen / _README.md
Last active January 20, 2016 07:16
Scripts to autodownload and organize the California kindergarten immunization data files

Fetching and collating the California Kindergarten immunization data in Python and Bash

by Dan Nguyen @dancow

tl;dr: a quick example of practicing reproducible data journalism, and somewhat timely given the recent school vaccination law signed by California Gov. Jerry Brown

These are scripts that are part of the mundaneprogramming.github.io repo for SRCCON 2015 and will soon have their own entry/explanation on that site. They aren't meant to be best/canonical practices (e.g. I felt like using csv.DictWriter so there it is), nor do I guarantee that they work. But you're free to run them to see what happens. All they currently do is download the relevant spreadsheets and compile them into a file, which ends up being one of the most tedious parts of the entire investigation due to how the [files are organized on the home

@geobabbler
geobabbler / d3_squares_example.js
Last active May 25, 2016 14:55
D3 squares example for blog post
d3.json(
"data/statistics.geojson",
function (json) {
//dimensions
var w = 980;
var h = 480;
//get the center of the data
var center = d3.geo.centroid(json);
var svg = d3.select("body").append("svg")
.attr("width", w)
@chris-creditdesign
chris-creditdesign / README.md
Last active August 29, 2015 14:19
Impact of terror groups 1970 to 2013
@knowtheory
knowtheory / google_docs_scraper.js
Created January 13, 2015 14:53
Google Drive has an in document javascript API which allows you to do powerful and crazy things like build a web scraper that runs on a timer. When in a google spreadsheet, go to the tools menu and select "script editor".
// Fetch and append the current temperature
function fetchAndAppendWeather() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
// All the actual work is done in the top row.
// We get the link stored in cell A1 (say http://www.wunderground.com/cgi-bin/findweather/getForecast?query=02217 )
var weatherLink = sheet.getRange("A1").getValue();
// we set a formula importing a targeted portion of the web page
@thomaswilburn
thomaswilburn / Code.gs
Created August 29, 2014 19:20
Apps Script example for handling custom forms
var sheetID = "xxx-id-goes-here-xxx";
var rowConfig = "timestamp name location favorite note lifespan season contact lat lng zone approve feature".split(" ");
/***
Requests may come in with the following parameters:
name
favorite - player name (number?)
note
@sjenkinsdc
sjenkinsdc / phpexamples.php5
Created January 14, 2014 15:01
PHP Examples for the Saxotech Online object (Now Newscycle Digital). The official documentation is lacking php examples, so we put together a script showing each SOSE Property, Method and ENV variables in PHP format. See script results at http://www.tamberra.com/section/phpexamples
// ==========================================================================================
// File: /samples/phpexamples.php5
// Desc: To give users PHP examples of using the SOSE object
// https://docs.newscyclesolutions.com/display/Onl/The+SAXOTECH+Online+object
// Author: Stacey Jenkins
// Date: 1/13/2013
//
// ==========================================================================================