Skip to content

Instantly share code, notes, and snippets.

@mojodna
mojodna / binary-splitter.js
Last active June 19, 2018 04:17
Some random Node.js stream classes.
"use strict";
var stream = require("stream"),
util = require("util");
var buffertools = require("buffertools");
var BinarySplitter = function(delimiter) {
stream.Transform.call(this);
@mojodna
mojodna / gist:7728530
Created December 1, 2013 04:36
Enable Space Monkey Time Machine use
defaults write com.spacemonkey.SpaceMonkey SMEnableTimeMachine 1
@mojodna
mojodna / gist:7671241
Created November 27, 2013 05:52
Make GDAL (and proj) available on Joyent Manta
gdal-1.10.1 and proj-4.8.0 were built according to the directions here: https://github.com/mojodna/heroku-buildpack-gdal
Due to differences in the available base packages, different features are available (e.g. no PostgreSQL).
```bash
mlogin -s /stamen/public/gdal-1.10.1-1.sh --init="/assets/stamen/public/gdal-1.10.1-1.sh"
```
@mojodna
mojodna / default.vcl
Created November 12, 2013 20:12
Resolve ELB IPs and create a dynamic Varnish backend list (intended to run out of cron).
# ...
include "dynamic_backends.vcl";
# ...
@mojodna
mojodna / gist:6208289
Created August 12, 2013 04:42
Convert Mapnik !scale_denominator! into zooms.
CREATE OR REPLACE FUNCTION zoom(scaleDenominator numeric) RETURNS int AS $$
BEGIN
CASE
WHEN scaleDenominator > 1000000000 THEN RETURN 0;
WHEN scaleDenominator <= 1000000000 AND scaleDenominator > 500000000 THEN RETURN 1;
WHEN scaleDenominator <= 500000000 AND scaleDenominator > 200000000 THEN RETURN 2;
WHEN scaleDenominator <= 200000000 AND scaleDenominator > 100000000 THEN RETURN 3;
WHEN scaleDenominator <= 100000000 AND scaleDenominator > 50000000 THEN RETURN 3;
WHEN scaleDenominator <= 50000000 AND scaleDenominator > 25000000 THEN RETURN 4;
WHEN scaleDenominator <= 25000000 AND scaleDenominator > 12500000 THEN RETURN 5;
@mojodna
mojodna / gist:6205513
Created August 11, 2013 16:11
Break a LINESTRING or MULTILINESTRING into its constituent points with PostGIS.
SELECT ST_AsText(
ST_PointN(
way,
generate_series(1, ST_NPoints(way))
)
)
FROM (
SELECT (ST_Dump(way)).geom AS way
FROM planet_osm_line WHERE osm_id=25813470) AS dumped;
@mojodna
mojodna / gist:5609010
Created May 19, 2013 21:05
Importing Natural Earth into PostGIS w/ ogr2ogr
P900913="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
EXTENT="-180 -85.05112878 180 85.05112878"
ogr2ogr --config PG_USE_COPY YES --config OGR_ENABLE_PARTIAL_REPROJECTION TRUE --config SHAPE_ENCODING WINDOWS-1252 -t_srs "$P900913" -lco ENCODING=UTF-8 -lco SRID=900913 -clipsrc $EXTENT -segmentize 1 -skipfailures -f PGDump /vsistdout/ ne_10m_populated_places.shp | pv | psql -d natural_earth -q
@mojodna
mojodna / gist:5561521
Created May 11, 2013 21:42
PGRaster misc.
raster2pgsql -s 900913 -l 2,4,8 -d -I -Y -t 4096x4096 n43w125-900913.tiff ned | pv | psql -d scratch
gdalinfo "PG:host=localhost port=5432 dbname=scratch user=seth table=ned mode=2"
@mojodna
mojodna / 404.cfg
Last active December 16, 2015 12:59
Additional TileStache caches
{
"cache":
{
"class": "SparseCache",
"kwargs": {
"path": "/tmp/stache",
"umask": "0000",
"empty_size": 334
}
},
@mojodna
mojodna / gist:5283296
Last active December 15, 2015 15:39
Upgrading FileGDBs with Python and ArcGIS.
import arcpy
arcpy.UpgradeGDB_management("z:/data/workspace/huc02/nhdh0202.gdb", "PREREQUISITE_CHECK", "UPGRADE")