Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Liedman perliedman

View GitHub Profile
@perliedman
perliedman / extract_plugin_data.py
Last active Apr 18, 2016
Extract data about Leaflet Plugins
View extract_plugin_data.py
#!/usr/bin/python
import re
from bs4 import BeautifulSoup
import urllib2
import csv
from datetime import datetime
from agithub import Github
View leaflet-reveal-unzoom.js
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 Dec 2, 2019
Embed Leaflet.js maps in Reveal.js presentations
View leaflet-reveal.css
.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 Mar 11, 2016
Leaflet direction arrow
View direction-arrow.js
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;
View index.html
<html>
<head>
<title></title>
<style type="text/css">
body {
background-color: black;
padding: 0;
margin: 0;
}
View GravatarUrlHelper.cs
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 Oct 28, 2015
node-osmium area test
View osm-test.js
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);
View distance-matrix.js
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 Mar 26, 2019
OSRM Transport Costs for use with jsprit
View OsrmTransportCostsMatrix.java
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 Oct 6, 2014
Explode an object to the console
View log-object.js
function logObject(o, indent) {
var keys;
indent = indent || '';
try {
keys = Object.keys(o);
} catch (e) {
console.log(indent + '=' + o.toString());
return;