Skip to content

Instantly share code, notes, and snippets.

@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 / bin-grep.py
Created April 16, 2013 12:30
Simple utility to grep/find a byte pattern in a file. I can only assume you can use grep or some other utility to do this as well.
#!/usr/bin/python
from sys import argv
path = argv[1]
hex_pattern = argv[2]
str_pattern = "".join([chr(int(hex_pattern[x:x+2], 16)) for x in range(0,len(hex_pattern), 2)])
with open(path, 'r') as f:
@perliedman
perliedman / map-design-cc.md
Created June 18, 2013 10:30
Map Design Crash Course

Map Design Crash Course

Overview

  • Spatial "raw" data is usually in vector form.
  • Nodes (sometimes called coordinates or vertices), sometimes connected to form lines, linestrings or polygons.

Some concepts in spatial geometry

@perliedman
perliedman / geometrycollection.wkt
Created October 29, 2013 15:28
Problematic WKT
GEOMETRYCOLLECTION (LINESTRING (6308869.40378 356821.22669, 6308867.893 356822.41744, 6308852.75314 356830.22159, 6308869.92754 356844.26638), LINESTRING (6308755.07971 356674.51686, 6308784.81355 356719.16757, 6308815.20022 356765.46178, 6308829.63774 356763.22832, 6308852.87023 356759.82402, 6308867.19982 356771.06823, 6308875.40631 356796.20162, 6308872.51907 356815.17242), LINESTRING (6308874.12086 356813.73392, 6308876.83028 356795.77697, 6308868.23871 356770.06254, 6308853.09618 356758.29456, 6308815.86529 356763.89689, 6308799.76731 356739.37835, 6308747.77971 356662.11613, 6308746.55411 356661.61702, 6308744.06545 356657.72563, 6308731.77184 356668.45076, 6308699.45221 356683.15463, 6308682.44689 356684.63193, 6308654.96629 356683.66846, 6308636.13879 356680.0482, 6308618.19888 356671.76352, 6308608.41685 356661.79428, 6308578.7973 356592.35062, 6308545.33908 356542.14886, 6308517.52088 356509.38474, 6308505.40266 356506.84141, 6308493.59689 356506.98067, 6308375.07918 356520.46209), LINESTRING (63088
@perliedman
perliedman / number_tiles.py
Last active December 30, 2015 08:28
Calculate number of tiles in a tile set
from sys import argv
from math import ceil, floor
res = float(argv[1])
number_zoom_levels = int(argv[2])
tile_size = int(argv[3])
bbox = [float(v) for v in argv[4].split(',')]
total_tiles = 0
for z in xrange(0, number_zoom_levels + 1):
@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;
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 / 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
@perliedman
perliedman / leaflet_1_0.svg
Last active April 18, 2016 14:22
Leaflet-1.0-verified
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.