Skip to content

Instantly share code, notes, and snippets.

@jmealo
jmealo / gist:3602657
Created September 2, 2012 18:27
Zipcode to State
var state_abbr = [ 'AA','AE','AK','AL','AP','AR','AZ','CA','CO','CT','DC','DE','FL','GA','GU','HI',
'IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC',
'ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','PR','RI','SC','SD','TN',
'TX','UT','VA','VT','WA','WI','WV','WY' ];
var prefix_matrix = { 100:38, 101:38, 102:38, 103:38, 104:38, 105:38, 106:38, 107:38, 108:38,
109:38, 110:38, 111:38, 112:38, 113:38, 114:38, 115:38, 116:38, 117:38,
118:38, 119:38, 120:38, 121:38, 122:38, 123:38, 124:38, 125:38, 126:38,
127:38, 128:38, 129:38, 130:38, 131:38, 132:38, 133:38, 134:38, 135:38,
136:38, 137:38, 138:38, 139:38, 140:38, 141:38, 142:38, 143:38, 144:38,
@jmealo
jmealo / String to APA (English) Abbreviation
Created January 30, 2013 14:46
This function returns the capitalized abbreviation of the passed string according to APA rules for title case (http://blog.apastyle.org/apastyle/2012/03/title-case-and-sentence-case-capitalization-in-apa-style.html). It omits the following minor words: and, or, nor, but, a, an, the, as, at, by, for, in, of, on, per and to.
function strToAbbr(str) {
str = str.toUpperCase();
str = str.replace(/\b(AND|OR|NOR|BUT|A|AN|THE|AS|AT|BY|FOR|IN|OF|ON|PER|TO)\b/g, '');
var words = str.split(/\s+/), abbr = '';
for(var x = 0; x < words.length; x++) abbr += words[x].substr(0,1);
return abbr;
}
@jmealo
jmealo / gist:5022473
Last active December 14, 2015 03:39 — forked from djq/gist:2846196
#!/bin/bash
#
# Install Postgres 9.1, PostGIS 2.0 and pgRouting on a clean Ubuntu 12.04 install (64 bit)
# updated to PostGIS 2.0.1
# add the ubuntu gis ppa
sudo apt-get -y install python-software-properties
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
{
"brand": "joyent",
"image_uuid,": "7abad50e-b865-11e0-8462-730bcfdde020d",
"alias": "pgbench",
"hostname": "pgbench",
"max_physical_memory": 16384,
"nics": [
{
"nic_tag": "admin",
"ip": "76.8.51.210",
@jmealo
jmealo / gist:5417527
Created April 19, 2013 01:40
MongoError: Can't extract geo keys from object, malformed geometry?:
{
"type": "LineString",
"coordinates": [
[
-75.43241,
40.122597
],
[
-75.432447,
40.122651
@jmealo
jmealo / philadelphia.poly
Created April 20, 2013 23:47
Poly file for the city of Philadelphia
city_limits_0
1
-7.501497E+01 4.013793E+01
-7.501456E+01 4.013768E+01
-7.501401E+01 4.013735E+01
-7.501387E+01 4.013726E+01
-7.501223E+01 4.013626E+01
-7.501146E+01 4.013578E+01
-7.501062E+01 4.013527E+01
-7.501043E+01 4.013515E+01
sw=# EXPLAIN ANALYZE SELECT ST_Distance(ST_Transform(ST_GeomFromText('POINT(-75.211457 39.956314)', 4326), 900913), planet_osm_line.way) AS planar_degrees, name FROM planet_osm_line ORDER BY planar_degrees ASC LIMIT 2;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------
Limit (cost=4719.15..4719.15 rows=2 width=600) (actual time=39.156..39.157 rows=2 loops=1)
-> Sort (cost=4719.15..4758.76 rows=15845 width=600) (actual time=39.154..39.154 rows=2 loops=1)
Sort Key: (st_distance('010100002031BF0D005777154645F05FC15B189DFEB2895241'::geometry, way))
Sort Method: top-N heapsort Memory: 25kB
-> Seq Scan on planet_osm_line (cost=0.00..4560.70 rows=15845 width=600) (actual time=0.028..33.340 rows=15845 loops=1)
Total runtime: 39.186 ms
(6 rows)
crime_enum = {
'Aggravated Assault Firearm': 0,
'Aggravated Assault No Firearm': 1,
'Burglary Non-Residential': 2,
'Burglary Residential': 3,
'Homicide - Criminal ': 4,
'Homicide - Criminal': 4,
'Homicide - Gross Negligence': 5,
'Homicide - Justifiable ': 6,
'Motor Vehicle Theft': 7,
@jmealo
jmealo / prep-env.sh
Last active December 21, 2015 01:59
Script to prepare environment in SmartOS Zone or Ubuntu VM before installing software
#!/bin/bash
# To run:
# source <(curl -s https://gist.github.com/jmealo/6231713/raw)
# note: running it this way renders the network configuration tests superfluous
if [[ "$(uname)" = "SunOS" ]] ; then
OS="SMARTOS"
elif [[ -f /etc/debian_version ]]; then
OS="DEBIAN"
@jmealo
jmealo / extract-progress.py
Last active December 21, 2015 06:28
Extracts .tar, .tar.gz, .tar.bz2 and .zip files with an optional progress bar. Raises ExtractException when it encounters an error.
import os, re, commands, subprocess
def streamCommand(cmd):
# runs a shell command and returns stdout as a stream you can loop over
stdout = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT).stdout
return stdout
def getFileExtension(filename):