Skip to content

Instantly share code, notes, and snippets.

def unhash(h):
s = ''
letters = 'acdegilmnoprstuw'
while h > 7:
v = h % 37
s = letters[v] + s
h /= 37
return s
@perliedman
perliedman / index.js
Created August 8, 2014 13:39
requirebin sketch
var fs = require('fs');
var svg = require('svg-sketch')();
var size = [400, 400];
var concat = require('concat-stream');
var Pdf = require('svg-sketch-pdf');
var controls = require('svg-sketch-controls');
controls.control.setPaperSize(size);
var iframe = document.createElement('iframe');
iframe.setAttribute('style', 'width: 400px; height: 400px; border: solid 2px #888; border-radius: 5px; position: fixed; top: 0; left: 0');
@perliedman
perliedman / log-object.js
Created October 6, 2014 13:34
Explode an object to the console
function logObject(o, indent) {
var keys;
indent = indent || '';
try {
keys = Object.keys(o);
} catch (e) {
console.log(indent + '=' + o.toString());
return;
@perliedman
perliedman / OsrmTransportCostsMatrix.java
Last active March 26, 2019 12:39
OSRM Transport Costs for use with jsprit
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jsprit.core.problem.Location;
@perliedman
perliedman / distance-matrix.js
Created September 4, 2015 14:40
OSRM Distance Matrix
var request = require('simple-get'),
extend = require('extend');
function DistanceMatrix(features, options) {
this.options = extend({}, { serviceUrl: 'http://router.project-osrm.org/table'}, options);
this._features = features.features.reduce(function(fs, f, i) {
if (f.geometry.type !== 'Point') {
throw 'Feature geometries must be Points.';
}
@perliedman
perliedman / osm-test.js
Created October 28, 2015 21:59
node-osmium area test
var osmium = require('osmium');
var bboxPolygon = require('turf-bbox-polygon');
var path = process.argv[2];
var reader = new osmium.BasicReader(path);
var handler = new osmium.Handler();
var locHandler = new osmium.LocationHandler();
var header = reader.header();
var bound = header.bounds[0],
extent = [bound.left(),bound.bottom(),bound.right(),bound.top()],
extentPolygon = bboxPolygon(extent);
@perliedman
perliedman / GravatarUrlHelper.cs
Created November 5, 2015 07:52
Gravatar UrlHelper
public static class GravatarUrlHelper
{
public static string GravatarUrl(this UrlHelper urlHelper, string emailAddress, int size = 38, string defaultAvatar = "identicon")
{
var md5 = MD5.Create();
var hash = md5.ComputeHash(Encoding.ASCII.GetBytes(emailAddress.Trim().ToLowerInvariant()));
return string.Format("https://www.gravatar.com/avatar/{0}?s={1}&d={2}", hash, size, defaultAvatar);
}
}
@perliedman
perliedman / index.html
Created March 5, 2016 21:52
Fern fractal
<html>
<head>
<title></title>
<style type="text/css">
body {
background-color: black;
padding: 0;
margin: 0;
}
@perliedman
perliedman / direction-arrow.js
Created March 11, 2016 09:18
Leaflet direction arrow
var L = require('leaflet');
module.exports = L.CircleMarker.extend({
initialize: function(latLng, heading, options) {
this._heading = heading;
L.CircleMarker.prototype.initialize.call(this, latLng, options);
},
setHeading: function(heading) {
this._heading = heading;
@perliedman
perliedman / leaflet-reveal.css
Last active December 2, 2019 19:07
Embed Leaflet.js maps in Reveal.js presentations
.map {
width: 960px;
height: 480px;
}
.reveal .leaflet-container .leaflet-fade-anim .leaflet-tile, .reveal .leaflet-container .leaflet-fade-anim .leaflet-popup {
-webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear;
-o-transition: opacity 0.2s linear;
transition: opacity 0.2s linear;