Skip to content

Instantly share code, notes, and snippets.

Michael Ashbridge mashbridge

Block or report user

Report or block mashbridge

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mashbridge /
Created Nov 22, 2013
Create cubic polygons in KML
// This program accepts a center point (lat, lng, alt) and a distance (in m)
// and generates a cube of side distance around that point.
// e.g. ./cubegen 37.0 -122.0 1000 200
#include <iostream>
#include <string>
#include <vector>
#include "kml/base/math_util.h"
#include "kml/dom.h"
mashbridge / Makefile
Created Nov 22, 2013
Poisson surface reconstruction Example
View Makefile
# Assumes headers and libs in /usr/local/. You'll need eigen3 or another
# solver library. On OS X you can maybe do:
# brew install eigen
# brew install cgal --imaging --with-eigen3 --with-lapack
IDIRS = /usr/local/include /usr/local/include/eigen3
LDIRS = /usr/local/lib
INCS = $(foreach d, $(IDIRS), -I$d)
mashbridge / gmap-circle.js
Last active Dec 27, 2015
Using the Google Maps API v3 to draw a circle of given radius around a point.
View gmap-circle.js
// Given c as google.maps.LatLng, r in meters.
function drawCircle(c, r) {
var cLat = * Math.PI / 180;
var cLng = c.lng() * Math.PI / 180;
var d = r / 6378137.0;
var paths = [];
// Using 64 segments.
for (var tc = 0; tc < 2 * Math.PI; tc += (Math.PI / 32)) {
var lat = Math.asin(Math.sin(cLat) * Math.cos(d)

The size of Wales.

To build wales.json:

curl -O "" && unzip && ogr2ogr -f GeoJSON -where "SUBUNIT IN ('Wales')" wales.subunit.json ne_10m_admin_0_map_subunits.shp && topojson --id-property su_a3 -p name=NAME -p name -o wales.json wales.subunit.json


David Friedman wondered aloud about a <spoiler> element. The Web Components proposal will allow custom HTML elements. This is an example of an <x-spoiler> element (the spec requires a hypen in the name) implemented using Google's Polymer library.

Click on the obscured text to reveal the spoiler.

mashbridge /
Created Apr 26, 2013
A basic point-in-polygon test using libkml.
// Implements a basic point-in-polygon test using libkml.
#include <assert.h>
#include <iostream>
#include <string>
#include "kml/base/vec3.h"
#include "kml/dom.h"
using kmlbase::Vec3;
mashbridge / arraydepth.go
Created Dec 24, 2012
How to calculate the dimensionality of an array in Go
View arraydepth.go
func ArrayDepth(i interface{}) int {
return arrayDepth(i, 0)
func arrayDepth(i interface{}, n int) int {
kind := reflect.ValueOf(i).Kind()
if kind == reflect.Array || kind == reflect.Slice {
n += 1
j := i.([]interface{})
return arrayDepth(j[0], n)
mashbridge / iotest.go
Created Dec 23, 2012
Reading data from stdin or a file in Go
View iotest.go
If no filename given as argument, read from stdin. Allows use as piped tool.
mashbridge@hex iotest$ go build iotest.go
mashbridge@hex iotest$ ./iotest x.txt
file data: foo bar
mashbridge@hex iotest$ ./iotest < x.txt
stdin data: foo bar
View gist:4256541
// For large numbers of math.Pow(x,y) calls, it's worth special-casing y=2
// and squaring it yourself.
package main
import (
You can’t perform that action at this time.