Skip to content

Instantly share code, notes, and snippets.

@myersjustinc
myersjustinc / countyFIPS.js
Created September 21, 2011 21:55
Mappings between five-digit county FIPS codes and their corresponding counties
// Source: http://www.census.gov/geo/www/ansi/countylookup.html
var countyToFIPS = {
'Alabama': {
'Autauga County': '01001',
'Baldwin County': '01003',
'Barbour County': '01005',
'Bibb County': '01007',
'Blount County': '01009',
'Bullock County': '01011',
@myersjustinc
myersjustinc / README.md
Created November 4, 2011 22:00
Parse saved FactFinder2 queries using web.py and ep.io (updates now at https://github.com/myersjustinc/american_linkfinder)

AFF saved query converter

(NOTE: This Gist is no longer being maintained. See https://github.com/myersjustinc/american_linkfinder for further updates.)

This converter takes a saved query file from American FactFinder and generates a deep link URL corresponding to that query.

There are two versions of the converter:

@myersjustinc
myersjustinc / parseTags.js
Created November 8, 2011 16:52
JS port of django-tagging's tagging.utils.parse_tag_input(), licensed MIT. See http://code.google.com/p/django-tagging/source/browse/trunk/tagging/utils.py for original Python.
// Output should pass all tests in tagging.tests.tests.TestParseTagInput except '"one two'
// and '"one two three'. Not sure why those fail, but I figured I should go ahead and
// post what I've got, anyway.
function parseTagInput(tagText) {
function eliminateDuplicates(arr) {
// From Rhett Anderson (@nosredna):
// http://dreaminginjavascript.wordpress.com/2008/08/22/eliminating-duplicates/
// Modified to fit my coding style, but that should be about it.
var out = [];
@myersjustinc
myersjustinc / inequality.js
Created November 8, 2011 23:10
Using maphilight for a U.S. state choropleth map
// Naming everything under a main "choro" namespace isn't necessary, but it's a bit cleaner.
var choro = {};
choro.ctrl = {};
// One thing to keep in mind: In this data object, state names which normally have spaces
// continue to do so. In the image map (see map.html), they have underscores instead of
// spaces. (This is because the HTML class attribute treats spaces as separators so an
// element can have multiple classes.) This is why there are different .replace() calls
// throughout this script to add or remove the underscores as necessary.
choro.data = {
@myersjustinc
myersjustinc / mercator.html
Created November 14, 2011 19:12
Mercator scale factors by latitude
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mercator craziness</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">//<![CDATA[
var map;
var circles = [];
function degToRad(degrees) {return degrees * Math.PI / 180;}
@myersjustinc
myersjustinc / formatNumber.js
Last active September 29, 2015 11:47
JS number formatting (thousands and uniform decimal places)
var formatNumber = function( value, decimalPlaces, alwaysDecimalize ) {
// Set default decimal formatting values if undefined
// decimalPlaces defaults to 0
// Sets the number of places after the decimal point, if necessary
// alwaysDecimalize defaults to false
// If true, always shows a decimal and the set number of decimal
// places, even for integral values (useful with currency values)
decimalPlaces = typeof decimalPlaces === 'undefined' ? 0 : decimalPlaces;
alwaysDecimalize = (typeof alwaysDecimalize === 'undefined' ? false :
alwaysDecimalize);
@myersjustinc
myersjustinc / larson_scanner.brd
Created March 18, 2012 01:10
Intro to Electronics (HacDC) Week 6
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE eagle SYSTEM "eagle.dtd">
<eagle version="6.1">
<drawing>
<settings>
<setting alwaysvectorfont="no"/>
<setting verticaltext="up"/>
</settings>
<grid distance="0.05" unitdist="inch" unit="inch" style="lines" multiple="1" display="no" altdistance="0.025" altunitdist="inch" altunit="inch"/>
<layers>
@myersjustinc
myersjustinc / get_data.py
Created April 24, 2012 17:22
Get Local Area Unemployment Statistics for both counties and states, defaulting to latest month available for both
#!/usr/bin/env python
from collections import defaultdict, namedtuple
from ftplib import FTP
import logging
import re
import sys
try:
import json
except ImportError:
import simplejson as json
@myersjustinc
myersjustinc / README.md
Created May 25, 2012 19:48
ISO 3166 country codes

Country codes

Just thought they might be handy to have around.

Methodology

The alpha-2 codes were copied from the ISO itself. The alpha-3 and numeric codes were copied from the UN Statistics Division, and any name discrepancies between the two organizations were resolved in favor of the UN version.

@myersjustinc
myersjustinc / README.md
Created May 25, 2012 20:54
Convert HTML image map to SVG

This takes an HTML document that contains a client-side image map ( and elements) and creates an SVG image based on the shapes described in the image map (since SVG's a more general-purpose format than the HTML image map).

The HTML document doesn't necessarily have to be well-formed XML (there's a fallback to the BeautifulSoup parser for documents with some weirdness in them), which might be useful.

Dependencies

  • lxml
  • Python (of course)