Skip to content

Instantly share code, notes, and snippets.

View lukasmartinelli's full-sized avatar

Lukas Martinelli lukasmartinelli

View GitHub Profile
@lukasmartinelli
lukasmartinelli / designy_by_contract.md
Last active August 29, 2015 14:17
SE2 Testat - Design by Contract

Aufgabe 1

Interface Spezifikation

/**
Invariance:
    assert isEmpty() != isFull()
*/
public interface PrimitiveIntStack {
@lukasmartinelli
lukasmartinelli / fix_quotes.py
Last active August 29, 2015 14:17
Fix missing quotes in csv
import fileinput
import re
import sys
if __name__ == "__main__":
for line in fileinput.input():
m = re.match(r"(.*/.*) (.*) (\d*)", line)
if m:
print('"{0}","{1}",{2}'.format(m.group(1),
DELETE FROM import.filepaths_1
WHERE data->>'repo' IN
(SELECT data->>'repo'
FROM (SELECT data->>'repo', ROW_NUMBER() OVER (partition BY data->>'repo' ORDER BY data->>'repo') AS rnum
FROM import.filepaths_1) t
WHERE t.rnum > 1
);
@lukasmartinelli
lukasmartinelli / handle_img.py
Last active October 21, 2015 13:27
Handle user uploaded images in Python
from img_rotate import fix_orientation
from PIL import Image
def fix_img(img):
proper_img = fix_orientation(img)
proper_img.thumbnail(1500, 1500), Image.ANTIALIAS)
return proper_img
@lukasmartinelli
lukasmartinelli / find_missing_mbtiles.md
Created December 11, 2015 18:22
Find out missing MBTiles at certain zoom level from list of files

Find the real tiles that should exist.

mercantile children "[0,0,0]" --depth 8 > correct_tiles.txt

Find the list of MBTiles from S3

@lukasmartinelli
lukasmartinelli / missing_tiles.csv
Created December 11, 2015 18:26
Missing Tiles
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
128/100/8
128/101/8
128/102/8
128/103/8
128/104/8
128/105/8
128/106/8
128/107/8
128/108/8
@lukasmartinelli
lukasmartinelli / places.tsv
Created March 4, 2016 14:19
OSMNames Places Export
osm_id name type lon lat
240037787 Hämikon village 8.280409935521845 47.24071495001383
240125902 Müswangen village 8.291551999410387 47.238828937980735
240053323 Beinwil (Freiamt) village 8.342289670976442 47.2302282671344
1808444632 Winterschwil hamlet 8.339991017850139 47.24019191925577
1102444816 Guggibad hamlet 8.297054467386715 47.273120225872944
1102444811 Brandholz hamlet 8.292870556598615 47.2803594241868
240106365 Geltwil village 8.322386674252868 47.249199028587
1808444611 Isenbergschwil hamlet 8.33719154600922 47.246563422953116
240053497 Buttwil village 8.311204880143265 47.2675939532916
@lukasmartinelli
lukasmartinelli / function.sql
Created March 8, 2016 18:57
Try optimize PostgreSQL function
CREATE OR REPLACE FUNCTION point_to_tiles(
_point geometry
) RETURNS SETOF tile
AS $$
DECLARE
d2r CONSTANT DOUBLE PRECISION := pi() / 180;
lon CONSTANT DOUBLE PRECISION := st_x(ST_Transform(_point, 4326));
lat CONSTANT DOUBLE PRECISION := st_y(ST_Transform(_point, 4326));
_sin CONSTANT DOUBLE PRECISION := sin(lat * d2r);
CREATE VIEW poi_label_zoom_level_changes AS (
SELECT osm_id, timestamp FROM poi_label_z14
);
CREATE VIEW road_zoom_level_changes AS (
SELECT osm_id, timestamp FROM road_z14
UNION ALL
SELECT osm_id, timestamp FROM road_z13
UNION ALL
@lukasmartinelli
lukasmartinelli / extract_cities.py
Created April 26, 2016 14:20
Extract city bounding box CSV from Mapzen
import json
doc = json.load(open('cities.json'))
for region, region_obj in doc['regions'].items():
for city_name, city_obj in region_obj['cities'].items():
bbox = city_obj['bbox']
parts = city_name.split('_')
if len(parts) != 2:
continue