Skip to content

Instantly share code, notes, and snippets.

View kekscom's full-sized avatar

Jan Marsch kekscom

View GitHub Profile
@kekscom
kekscom / BulkInsert.js
Created July 9, 2012 19:54
MySQL bulk Insert
/**
This little helper creates bulk SQL insert queries like this:
INSERT INTO mytable (id, col1, col2) VALUES
(1, "col1value", "col2value"),
(2, "col1value", "col2value"),
(3, "col1value", "col2value"),
:
:
(4999, "col1value", "col2value"),
@kekscom
kekscom / Thick Line to Polygon JS
Created December 3, 2012 10:43
A JavaScript method to turn thick lines into polygons
/**
* @author Jan Marsch (@kekscom)
* @example see http://jsfiddle.net/osmbuildings/2e5KX/5/
* @example thickLineToPolygon([{x:50,y:155}, {x:75,y:150}, {x:100,y:100}, {x:50,y:100}], 20)
* @param polyline {array} a list of point objects in format {x:75,y:150}
* @param thickness {int} line thickness
*/
var thickLineToPolygon = (function () {
function getOffsets(a, b, thickness) {
@kekscom
kekscom / gist:5053306
Last active May 26, 2022 08:03
JavaScript toLocalISOString() function
function toLocalISOString(d) {
var off = d.getTimezoneOffset();
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes() - off, d.getSeconds(), d.getMilliseconds()).toISOString();
}
@kekscom
kekscom / gist:5367764
Created April 11, 2013 22:38
hatching test in canvas, see it in action: http://jsfiddle.net/S5aAY/
// <canvas>
var w = 600, h = 300;
var canvas = document.getElementsByTagName('CANVAS')[0];
canvas.width = w;
canvas.height = h;
var context = canvas.getContext('2d');
@kekscom
kekscom / gist:6829920
Created October 4, 2013 17:54
soldner to wgs84 for soldner coordinates 26197,19294
var proj = require("proj4");
proj.defs("EPSG:3068", "+proj=cass +lat_0=52.41864827777778 +lon_0=13.62720366666667 +x_0=40000 +y_0=10000 +ellps=bessel +datum=potsdam +units=m +no_defs");
console.log(proj("EPSG:3068", "WGS84", [26197,19294]));
@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;
});
}
@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 / 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 / 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 / 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;