Skip to content

Instantly share code, notes, and snippets.

@jmealo
jmealo / wackamole.xml
Created August 19, 2013 14:20
Wackamole SMF manifest for the pkgsrc distribution on SmartOS (based on everycity's manifest)
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
<service name='network/wackamole' type='service' version='0'>
<dependency name='filesystem_minimal' grouping='require_all' restart_on='none' type='service'>
<service_fmri value='svc:/system/filesystem/minimal'/>
</dependency>
<dependency name='loopback' grouping='require_any' restart_on='error' type='service'>
<service_fmri value='svc:/network/loopback'/>
</dependency>
@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):
@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"
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,
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)
@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
@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
{
"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: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
@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;
}