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
mashbridge / cubegen.cc
Created Nov 22, 2013
Create cubic polygons in KML
View cubegen.cc
// 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
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
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 = c.lat() * Math.PI / 180;
var cLng = c.lng() * Math.PI / 180;
var d = r / 6378137.0;
var paths = [];
// http://williams.best.vwh.net/avform.htm#LL
// 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)
View README.md

The size of Wales.

To build wales.json:

curl -O "http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_map_subunits.zip" && unzip ne_10m_admin_0_map_subunits.zip && 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

View README.md

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
mashbridge / pointinpolygon.cc
Created Apr 26, 2013
A basic point-in-polygon test using libkml.
View pointinpolygon.cc
// 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
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
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 (
"flag"
"fmt"
"math"
)
You can’t perform that action at this time.