Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
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');
// 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 December 20, 2016 17:29 — 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.
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 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/ &
@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 / web.config
Created August 15, 2014 10:28
Enable CORS IIS7
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Accept,Content-Type,X-Requested-With" />
</customHeaders>
</httpProtocol>
</system.webServer>