Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Drinking tea

Matt Walker walkermatt

💭
Drinking tea
View GitHub Profile
View simple-https-server.py
# 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 / mario.clj
Created Oct 17, 2015
Mario style pyramids!
View mario.clj
; 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]
@walkermatt
walkermatt / fizzbuzz.clj
Last active Jul 12, 2017
fizzbuzz without conditionals in Clojure
View fizzbuzz.clj
;; 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 / bbox-to-wkt-polygon.js
Created Aug 16, 2015
Create WKT POLYGON from a bounding box in JavaScript
View bbox-to-wkt-polygon.js
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];});
View gist:7594cf5e82a70f2c3fd7
function hexToRgb(hex) {
return 'rgb(' + hex.slice(1).match(/../g).map(c => parseInt(c, 16)) +')'
}
@walkermatt
walkermatt / spatialtype.md
Created Jun 22, 2015
mapinfo.mapinfo_mapcatalog spatialtype values for PostGIS
View spatialtype.md

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
View create_index.sql
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');
View map2.js
// 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");
@walkermatt
walkermatt / ObjectifyJSONEncoder.py
Last active Dec 20, 2016 — forked from aisipos/objectifiedJson.py
JSON encoder that can handle simple lxml objectify types, based on the original: https://gist.github.com/aisipos/345559, extended to accommodate encoding child nodes with the same tag name as a list.
View ObjectifyJSONEncoder.py
import json
import lxml
from lxml import objectify
class ObjectifyJSONEncoder(json.JSONEncoder):
""" JSON encoder that can handle simple lxml objectify types,
based on the original: https://gist.github.com/aisipos/345559, extended
to accommodate encoding child nodes with the same tag name as a list.
Usage:
@walkermatt
walkermatt / osgeolive.sh
Last active Aug 29, 2015
Set up OSGeo Live Xubuntu instance for OL3 & Leaflet workshop
View osgeolive.sh
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/ &
You can’t perform that action at this time.