Skip to content

Instantly share code, notes, and snippets.

View kekscom's full-sized avatar

Jan Marsch kekscom

View GitHub Profile
@kekscom
kekscom / gist:ac499df64c8d861776a61031d577d8bf
Created August 12, 2016 09:13
Split huge GeoJSON files into tiles
var tileSize = 256;
var zoom = 15;
var srcFile = 'huge.geojson';
var dstPath = 'tiles/';
var minX = Number.MAX_VALUE;
var maxX = 0;
var minY = Number.MAX_VALUE;
var maxY = 0;
'hallo_ballo:bla'.replace(/([^a-z0-9][a-z0-9])/ig, function($0, $1) {
return $1[1].toUpperCase();
});
@kekscom
kekscom / JS parse query string
Last active October 5, 2021 14:32
parse query string
const q = location.search.replace('?', '');
const params = {};
q.replace(/([^&=]+)=([^&]*)/g, ($0, $1, $2) => {
params[$1] = $2;
});
@kekscom
kekscom / gist:bd4e3d4e356f90050c77
Created November 9, 2015 13:16
Date() toISOString() incl. TZ offset
function formatLocalDate() {
var now = new Date(),
tzo = -now.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
pad = function(num) {
var norm = Math.abs(Math.floor(num));
return (norm < 10 ? '0' : '') + norm;
};
return now.getFullYear()
+ '-' + pad(now.getMonth()+1)
function relax(callback, startIndex, dataLength, chunkSize, delay) {
chunkSize = chunkSize || 1000;
delay = delay || 1;
var endIndex = startIndex + Math.min((dataLength-startIndex), chunkSize);
if (startIndex === endIndex) {
return;
}
@kekscom
kekscom / anaglyph.js
Last active August 29, 2015 14:05
Anaglyph canvas
renderLeft();
var canvasData1 = context.getImageData(0, 0, WIDTH, HEIGHT);
renderRight();
var canvasData2 = context.getImageData(0, 0, WIDTH, HEIGHT);
var
dataRed = canvasData1.data,
dataCyan = canvasData2.data,
R, G, B;
@kekscom
kekscom / ID.js
Last active December 6, 2018 13:32
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `ID`
@kekscom
kekscom / bookmarklet
Last active July 20, 2017 00:37
Switch to OSM
javascript:(function(m,k){
if(m=location.href.match(/@([+\d,.-]+)/)) {
k=m[1].split(',');
location.href='http://www.openstreetmap.org/#map=Z/Y/X'.replace('X',k[1]).replace('Y',k[0]).replace('Z',k[2]);
}
}())
@kekscom
kekscom / FixJson.js
Last active January 4, 2019 19:46
Fix truncated JSON data.
var json = '...'; // your truncated json data here
var chunk = json;
var m, q = false;
var stack = [];
while (m = chunk.match(/[^\{\[\]\}"]*([\{\[\]\}"])/)) {
switch (m[1]) {
case '{':
@kekscom
kekscom / gist:8998221
Created February 14, 2014 09:26
replace tags in a string by matching (primitive) object properties
function pattern(str, param, callback) {
return str.replace(/\{([\w_]+)\}/g, function(tag, key) {
return param[key] || tag;
});
}