Skip to content

Instantly share code, notes, and snippets.

@walkermatt
walkermatt / map_reduce.js
Last active August 29, 2015 14:01
Toy map / reduce functions in JavaScript
// Define reduce, fn and list are required, init is an optional initial value
// which will be passed to fn with the first item in list
function reduce(fn, list, init) {
var val = init,
start = 0;
if (val === undefined) {
if (list.length > 1) {
val = list[0];
start = 1;
} else {
@walkermatt
walkermatt / loader_parallel.sh
Last active August 29, 2015 14:04
GNU Parallel all the things!
find /var/data/osmm/ -type f -print0 | \
parallel -0 python loader.py loader.config "src_dir={}"
@walkermatt
walkermatt / osgis.geojson
Last active August 29, 2015 14:05
Location map for OSGIS 2014
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@walkermatt
walkermatt / osgeolive.sh
Last active August 29, 2015 14:05
Set up OSGeo Live Xubuntu instance for OL3 & Leaflet workshop
setxkbmap gb && sudo apt-get install git-core gedit && cd && git clone https://github.com/AstunTechnology/osgis-ol3-leaflet.git ; cd osgis-ol3-leaflet ; gedit ol3/ol3.js & firefox http://astuntechnology.github.io/osgis-ol3-leaflet/ &
// Extent of the map in units of the projection (these match our base map)
var extent = [-3276800, -3276800, 3276800, 3276800];
// Fixed resolutions to display the map at (pixels per ground unit (meters when
// the projection is British National Grid))
var resolutions = [1600,800,400,200,100,50,25,10,5,2.5,1,0.5,0.25,0.125,0.0625];
// Define WGS84 projection (copied from http://epsg.io/3857.js)
proj4.defs("EPSG:3857","+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 +wktext +no_defs");
SELECT 'CREATE INDEX ' || quote_ident(f_table_name || '_geom_idx') || ' ON ' || quote_ident(f_table_schema) || '.' || quote_ident(f_table_name) || ' USING GIST (' || quote_ident(f_geometry_column) || ');' AS SQL
FROM geometry_columns
WHERE f_table_name IN ('topographicarea',
'topographicline');
@walkermatt
walkermatt / gist:7594cf5e82a70f2c3fd7
Created July 26, 2015 12:47
Hexidecimal colour to RGB
function hexToRgb(hex) {
return 'rgb(' + hex.slice(1).match(/../g).map(c => parseInt(c, 16)) +')'
}
@walkermatt
walkermatt / gist:1383021
Created November 21, 2011 15:50 — forked from eriwen/gist:187610
Pythonic site monitor
#!/usr/bin/env python
# sample usage: checksites.py eriwen.com nixtutor.com yoursite.org
import pickle, os, sys, logging
from httplib import HTTPConnection, socket
from smtplib import SMTP
def email_alert(message, status):
fromaddr = 'you@gmail.com'
@walkermatt
walkermatt / disaggregate_postgis_complex_contents.sql
Created November 25, 2011 09:19
Disaggregate MultiLineStrings using ST_Dump PostGIS
SELECT *, ST_GeometryType(geom) as geom_type, ST_AsEWKT(geom) as geom_wkt from complex;
@walkermatt
walkermatt / loader.config
Created June 4, 2012 13:30
Loader config for AddressBase Plus on Windows into PostgreSQL
src_dir=C:\GML_Loader\data\import
out_dir=C:\loader_data\export
tmp_dir=C:\loader_data\temp
ogr_cmd=ogr2ogr -append -skipfailures -f PostgreSQL PG:'dbname=test active_schema=public host=localhost port=5432 user=postgres password=******' $file_path
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_addressbase