Skip to content

Instantly share code, notes, and snippets.

@perliedman
perliedman / extract_plugin_data.py
Last active April 18, 2016 13:42
Extract data about Leaflet Plugins
#!/usr/bin/python
import re
from bs4 import BeautifulSoup
import urllib2
import csv
from datetime import datetime
from agithub import Github
L.Map.addInitHook(function() {
var slides = document.querySelector('.slides'),
zoom = Number(slides.style.zoom);
// Reveal.js sometimes use the zoom CSS property, but sometimes a scale
// transform instead. We handle both.
if (zoom) {
this._container.style.zoom = 1/zoom;
} else {
zoom = Number(slides.style.transform.replace(/.*scale\(([0-9\.]+)\).*/, '$1'));
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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;