Skip to content

Instantly share code, notes, and snippets.

@ghing
ghing / client.py
Created January 20, 2015 22:27
Test python-elections from filesystem
"""AP client that reads data from file instead of from the AP FTP server"""
import os
from elections import AP
class MockFTP(object):
def quit(self):
pass
@ghing
ghing / csv2md.py
Created November 8, 2014 00:37
Output GitHub Flavored Markdown tables for a CSV file
#!/usr/bin/env python
import csv
import sys
import click
def underlines(fieldnames):
underlines = []
for fieldname in fieldnames:
@ghing
ghing / pick_xls_row.py
Created October 5, 2014 15:41
Grab a row from an Excel spreadsheet and output it. Useful for extracting test cases for OpenElections loaders from source results.
#!/usr/bin/env python
import argparse
import xlrd
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Extract rows from an Excel '
'file.')
parser.add_argument('filename', nargs=1,
@ghing
ghing / index.html
Last active August 29, 2015 14:07
Playing with rainfall data
<!doctype html>
<html>
<head></head>
<body>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var ENDPOINT_ROOT = 'http://chicagorains.com/api/hourlyPrecip/';
function getURL(date, location) {
@ghing
ghing / loader_process_notes.md
Last active August 29, 2015 13:57
Openelections loader implementation notes

Loader process

Starting with the most recent election look at the data files.

Document fields

  • names
  • types
  • formatting conventions.
@ghing
ghing / temperature_sensor.ino
Created January 31, 2014 22:01
Read temperature from a TMP102 sensor and push to Xively
//
// Read temperature from a TMP102 sensor and push to Xively
//
#include <SPI.h>
#include <WiFly.h>
#include <Wire.h>
const char ssid[] = "BigBabyBoy";
@ghing
ghing / piezo_shock_sensor.ino
Created November 29, 2013 15:36
Arduino sketch to read piezoelectric sensor for Florence's science project.
// Use a Radio Shack 273-059 piezo buzzer as a shock sensor
// Based on recipe from http://www.eng.utah.edu/~cs5789/handouts/piezo.pdf
// and the Knock example (http://arduino.cc/en/Tutorial/Knock)
const int ledPin = 13; // Built in LED is pin 13
const int piezoPin = 0; // Piezoelectric element is attached to analog pin 0
const int threshold = 7; // Ignore readings below this value;
const int delayTime = 500; // HTime to pause during each loop
int val, t;
@ghing
ghing / avg_text_asset_length.py
Created August 21, 2013 13:48
Get the average length (in characters) of published text assets
from django.utils.html import strip_tags
from storybase_asset.models import HtmlAsset
assets = HtmlAsset.objects.filter(stories__status='published')
total_length = 0
for asset in assets:
# Strip HTML from the body to more accurately reflect visible length
total_length += len(strip_tags(asset.body))
avg_length = total_length / assets.count()
@ghing
ghing / index.html
Last active December 18, 2015 11:29 — forked from jwirfs-brock/index.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="app">
</div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="tabletop.js"></script>
@ghing
ghing / dump_script_assets.py
Created May 23, 2013 20:25
Create a fixture of all HtmlAsset models that include 'script' in the body
#!/usr/bin/env python
# Create a fixture of all HtmlAsset models that include 'script' in the
# body
# Usage: dump_script_assets.py | python -mjson.tool > script_assets.json
from django.core.management import setup_environ
# Edit this to use a particular settings module
import settings.dev
setup_environ(settings.dev)