Skip to content

Instantly share code, notes, and snippets.

Avatar

Per Liedman perliedman

View GitHub Profile
@perliedman
perliedman / gist:9528322
Created Mar 13, 2014
Console logging to page
View gist:9528322
var _log = console.log;
console.log = function() {
var e = document.getElementById('log'),
i;
for (i = 0; i < arguments.length; i++) {
e.innerHTML = e.innerHTML + arguments[i] + '\n';
}
View keybase.md

Keybase proof

I hereby claim:

  • I am perliedman on github.
  • I am liedman (https://keybase.io/liedman) on keybase.
  • I have a public key whose fingerprint is 555C 82CE 057A 1598 9580 BD5A 95EE 964B 2EA9 FB22

To claim this, I am signing this object:

View fogunhash.py
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 Aug 8, 2014
requirebin sketch
View index.js
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 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;
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 / README.markdown
Created Mar 26, 2012 — forked from jrust/README.markdown
Bootstrap's Typeahead plugin extended (AJAX functionality, comma-separated values, autowidth, and autoselect)
View README.markdown

This is a fork of a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

  • Support for delaying the lookup (good for preventing too many AJAX requests)
  • Some fixes regarding the data fed to the onselect callback

For the proper source, and other examples, please see the original gist and the extended version

Example showing off all the above features

@perliedman
perliedman / gist:3665685
Created Sep 7, 2012
Markers with Leaflet.iconlabel plugin (https://github.com/jacobtoye/Leaflet.iconlabel), which at least for me appear with an increasing offset. I believe this is a bug.
View gist:3665685
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gypsum</title>
<link rel="stylesheet" type="text/css" href="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.css"/>
<link rel="stylesheet" type="text/css" href='https://raw.github.com/jacobtoye/Leaflet.iconlabel/master/dist/leaflet.iconlabel.css'/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src='http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.js'></script>
@perliedman
perliedman / import_gsd.sh
Created Nov 22, 2012
Import Lantmäteriverket's GSD shape files into a PostGIS database
View import_gsd.sh
# Imports all GSD shape data to a database.
# NOTE: If the db exists, it is *dropped* before importing any data
DB=lmv
GSD_PATH=/media/local/MapData/lmv-shape
SQL_LOG=/dev/null
ERROR_LOG=gsd_import.log
# Create a clean slate
rm $SQL_LOG
@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);