Skip to content

Instantly share code, notes, and snippets.

@perliedman
perliedman / secondsToTime.js
Created October 27, 2016 12:20
Convert a number of seconds as integer to a string of hours, minutes and seconds (HH:MM:SS)
var secondsToTime = function(s) {
var pad = function(v) {
return v < 10 ? '0' + v : v.toString();
}
var result = '';
for (var i = 0; i < 3; i++) {
result = pad(s % 60) + (i ? ':' : '') + result;
s = Math.floor(s / 60);
}
#!/bin/bash
LL="31 70"
P0=`echo $LL | cs2cs +proj=longlat +datum=WGS84 +no_defs +to +proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs`
for I in `seq 1 10`;
do
P=`echo $LL | cs2cs +proj=longlat +datum=WGS84 +no_defs +to +proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs`
LL=`echo $P | cs2cs -I +proj=longlat +datum=WGS84 +no_defs +to +proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs`
done
@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.
@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 / 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 / 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 / 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 / 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