Skip to content

Instantly share code, notes, and snippets.

// 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 / spatialtype.md
Created June 22, 2015 11:02
mapinfo.mapinfo_mapcatalog spatialtype values for PostGIS

MapInfo requires a mapinfo.mapinfo_mapcatalog relation to be present in a PostGIS database in order to load relations. The spatialtype column is a float which indicates the geometry type of the relation:

19.0 = POINT, MULTIPOINT
19.1 = LINESTRING, MULTILINESTRING
19.2 = POLYGON, MULTIPOLYGON
19.3 = GEOMETRY
@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 / bbox-to-wkt-polygon.js
Created August 16, 2015 15:04
Create WKT POLYGON from a bounding box in JavaScript
var str = "POLYGON((left top,right top,right bottom,left bottom,left top))";
var bbox = {left: 10, top: 30, right: 20, bottom: 40};
str.replace(/[a-z]+/g, function(s) {return bbox[s];});
@walkermatt
walkermatt / fizzbuzz.clj
Last active July 12, 2017 14:08
fizzbuzz without conditionals in Clojure
;; fizzbuzz without conditionals in Clojure
; Simple patten matching using a single map lookup
(defn fizzbuzz [x]
(let [v [(= (mod x 3) 0) (= (mod x 5) 0)]]
({[true false] "fizz"
[false true] "buzz"
[true true] "fizzbuzz"
[false false] x} v)))
@walkermatt
walkermatt / mario.clj
Created October 17, 2015 19:08
Mario style pyramids!
; Inspired by
; http://entxtech.blogspot.co.uk/2015/10/how-to-write-more-functional-and.html
; "create a program where you can enter a height in blocks for a mario-like
; pyramid (like the one Mario runs up to reach the flag-pole). Once the height
; is specified, you then build the pyramid using hashes and spaces."
; ## [0,2]
; ## [1,2]
; ### [0,3]
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.pem with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# change to the directory you want to serve and run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
# to add the certificate to Chrome see:
# http://stackoverflow.com/a/15076602/526860
import BaseHTTPServer
@walkermatt
walkermatt / scratch.js
Last active January 16, 2018 09:07
Ramda stuff
var R = require('ramda');
var states = [
{symbol: 'CT', name: 'Connecticut', pop: 3574097},
{symbol: 'ME', name: 'Maine', pop: 1328361},
{symbol: 'MA', name: 'Massachusetts', pop: 6547629},
{symbol: 'NH', name: 'New Hampshire', pop: 1316470},
{symbol: 'RI', name: 'Rhode Island', pop: 1052567},
{symbol: 'VT', name: 'Vermont', pop: 623741},
];
@walkermatt
walkermatt / map.html
Created September 16, 2016 17:47
OpenLayers 3 LayerSwitcher and Popup together
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>OpenLayers 3 - LayerSwitcher &amp; Popup</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.17.1/ol.css" />
<link rel="stylesheet" href="https://rawgit.com/walkermatt/ol3-layerswitcher/master/src/ol3-layerswitcher.css" />
<link rel="stylesheet" href="https://rawgit.com/walkermatt/ol3-layerswitcher/master/examples/layerswitcher.css" />
<link rel="stylesheet" href="https://rawgit.com/walkermatt/ol3-popup/master/src/ol3-popup.css" />