Skip to content

Instantly share code, notes, and snippets.

tidy -i -xml -asxml input.xml
#!/bin/bash
## Jonah Duckles - jonahd@gmail.com
## BASH & R Code to download census participation rates and make a map of census progress.
## Can be run daily to see how the census is progressing
## Requires library(maptools) library(RColorBrewer) and library(classInt) to be installed in R
## Requires gdal/ogr (www.gdal.org) and spatialite (http://www.gaia-gis.it/spatialite/) tools in your path
##
## Example output: http://jduck.net/files/participation2010.png
#!/bin/bash
# Streamlined workflow for capturing screen shots and uploading them to my website.
# Assumption: you have keypairs set up for ssh with the target HOST
read -p"Enter filename (no extension): " NAME
HOST=jduck.net
DIRECTORY=www/files
REMOTE=${HOST}:${DIRECTORY}/${NAME}
TMPFILE=/tmp/${RANDOM}.scap
#!/bin/bash
# Requires, gdal, wget, spatialite, R with (maptools, RColorBrewer, classInt)
# You should be able to put any state/county combination in here and get a map made
# Replace spaces with an underscore ie:
#state=New_York
#county=New_York
#
#state=ILLINOIS
#county=Cook
#
library(lattice) # ?xyplot for more info on the myriad of ways to use lattice
library(reshape) # need melt() and rename() to reshape data frame for easy plotting
# Lets plot "WorldPhones" from package datasets
wp <- rename(melt(WorldPhones), c(X1 = 'year', X2 = 'country', value = 'numphone'))
xyplot( numphone ~ year | country, data=wp, type="b", scales="free")
# To print multiple pages set layout=c(1,1) to plot 1 plot per page (or more if it makes sense)
pdf('~/path/to/mydoc.pdf', width=11, height=8.5)
xyplot( numphone ~ year | country, data=wp, type="b", scales="free", layout=c(1,1) )
dev.off()
#!/bin/env python
import csv
import re
from urllib2 import urlopen
from BeautifulSoup import BeautifulStoneSoup
WEATHERBUG_API_KEY = 'A6464697672'
WEATHERBUG_SEARCH_URL = 'http://api.wxbug.net/getStationsXML.aspx?ACode=' + WEATHERBUG_API_KEY + '&zipCode=60601&unittype=0'
# TODO support Binary and Code
import calendar
import datetime
import re
try:
import uuid
_use_uuid = True
except ImportError:
_use_uuid = False
@jduckles
jduckles / csv2psql
Created June 6, 2011 23:26
simple csv importer to psql
#!/bin/sh
DBHOST=mydbhost
DBNAME=mydbname
files=$1
target=$2
for file in ${files}; do
psql -h ${DBHOST} ${DBNAME} -c "\copy ${target} FROM '${file}' delimiters ','"
@jduckles
jduckles / gist:1086542
Created July 16, 2011 17:01
gdalinfo output
Driver: NITF/National Imagery Transmission Format
Files: 002AA013.TF3
Size is 1536, 1536
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
TOWGS84[0,0,0,0,0,0,0],
AUTHORITY["EPSG","6326"]],
@jduckles
jduckles / mahout
Created July 28, 2011 00:10
Commands from Mahout workshop Pt 1 at OSCON2011
# See http://www.oscon.com/oscon2011/public/schedule/detail/18836 for getting Mahout setup
# Get Reuters Data
wget http://goo.gl/qv6Ad
mkdir reuters-out
mv reuters21578.tar.gz reuters-out
cd reuters-out
tar -xzvf reuters21578.tar.gz
cd ..
# Mahout steps
# slip out text from SGM files