Skip to content

Instantly share code, notes, and snippets.

View lukasmartinelli's full-sized avatar

Lukas Martinelli lukasmartinelli

View GitHub Profile
@lukasmartinelli
lukasmartinelli / semester_report
Created February 15, 2014 16:43
Calculate the total time based on the summary and time of iCalendar Events
from icalendar import Calendar
from datetime import timedelta
from itertools import groupby
from operator import itemgetter
def calculate_time(event):
start = event['DTSTART'].dt
end = event['DTEND'].dt
return end - start
@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 / create_extracts.sh
Last active August 9, 2021 16:28
Create coutnry extracts from world MBTiles
#!/bin/bash
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="60.403889,29.288333,74.989862,38.5899217" world.mbtiles afghanistan.mbtiles
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="19.0246095,39.5448625,21.1574335,42.7611669" world.mbtiles albania.mbtiles
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="-8.7689089,18.868147,12.097337,37.3962055" world.mbtiles algeria.mbtiles
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="1.3135781,42.3288238,1.8863837,42.7559357" world.mbtiles andorra.mbtiles
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="11.3609793,-18.1389449,24.18212,-4.2888889" world.mbtiles angola.mbtiles
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="-63.7391991,17.9609378,-62.6125448,18.8951194" world.mbtiles anguilla.mbtiles
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="-73.6603073,-55.285076,-53.5374514,-21.6811679" world.mbtiles argentina.mbtiles
tilelive-copy --minzoom=0 --maxzoom=14 --bounds="43.3471395,38.7404775,46.7333087,41.400712" world.mbtiles armenia.mbtiles
@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);