Skip to content

Instantly share code, notes, and snippets.

@tkardi
tkardi / batch_create_prj.py
Last active March 22, 2017 09:42
Batch create *.prj files for files on a path
import glob
import os
import requests
def get_prj_wkt(srid):
url = 'http://epsg.io/%s.wkt' % srid
r = requests.get(url)
r.raise_for_status()
return r.text
@tkardi
tkardi / gist:e36ded3f718630ad932767283091e032
Created August 22, 2016 16:07
OSGeo mailing list statistics random data generator
with
numbers as
(select 10 as _top, 50 as num_of_subscriptions, 28404 as unique_subscribers, 290 as number_of_lists),
people as
(select st_point(random() * 99 + 1, random() * 99 + 1) as g, 'special subscribers'::text as ty
from numbers n, generate_series(1,n._top)),
unique_people as
(select st_point(random() * 99 + 1, random() * 99 + 1) as g, 'unique subscribers'::text as ty
from numbers n, generate_series(1,n.unique_subscribers-n._top)),
subs as
@tkardi
tkardi / group_by_months.py
Last active July 30, 2018 11:23
Group a datetime-range over months
from datetime import datetime, timedelta
def group_by_months(since, until):
"""Group a datetime range into month-based ranges with breaks at midnight.
>>> a = datetime(2015,11,5,3,12,5)
>>> b = datetime(2016,3,7,4,32,10)
>>> for i, (since, until) in enumerate(group_by_months(a, b)):
... print i,
... print since.strftime('%Y.%m.%d %H:%M:%S'),