Skip to content

Instantly share code, notes, and snippets.

@alexprengere
alexprengere / run_times_from_pace.py
Last active August 29, 2015 13:57
Simple converter from pace to reference times for runners.
#!/usr/bin/env python
"""
Simple converter from pace to reference times
for runners.
$ ./run_times_from_pace.py 4:15 -d 1.0
1.00km in 0:04:15 gives you:
1km: 0:04:15 ( 1.00km)
@alexprengere
alexprengere / stat_functions.py
Created October 30, 2014 10:21
Some basic stat functions
#!/usr/bin/python
"""
Some stats functions::
>>> mean([1, 2, 6])
3.0
>>> variance([1, 2, 6], bias=True)
4.666666...
@alexprengere
alexprengere / prettify.py
Last active August 29, 2015 14:08
Some prettification functions.
#!/usr/bin/python
"""
Some prettification functions.
>>> humanize(1024, is_bytes=True)
'1.0 kB'
>>> humanize(1000*12342)
'12.3 M'
>>> pretty_num(1255000)
@alexprengere
alexprengere / fix_tz.py
Last active August 29, 2015 14:21
Fix ori_por timezones
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from GeoBases import GeoBase
import pytz
def pors_with_unk_tz(db_oripor):
for p in db_oripor:
p_tz = db_oripor.get(p, 'timezone')
@alexprengere
alexprengere / generate_optd_por_tz.py
Last active August 29, 2015 14:21
Generate timezone file from optd_por_best_known_so_far.csv
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from GeoBases import GeoBase
import pytz
def load_best_known(filename):
with open(filename) as f:
@alexprengere
alexprengere / check_names.py
Last active August 29, 2015 14:22
Check names consistency in optd_public
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from GeoBases import GeoBase
def main():
g = GeoBase('ori_por', verbose=False)
for p in g:
@alexprengere
alexprengere / geobases_cities_to_por.py
Last active December 12, 2015 00:18
Map cities to points of reference using GeoBases ori_por data source
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Map cities to points of reference sorted
by pageranks.
"""
from GeoBases import GeoBase
@alexprengere
alexprengere / flask_over_geobases.py
Last active December 12, 2015 01:28
Webservices over GeoBases with Flask
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Webservice over GeoBases using Flask.
"""
# Flask is a microframework web
from flask import Flask, request, jsonify
@alexprengere
alexprengere / geobases_custom_map.py
Last active December 12, 2015 01:28
GeoBases visualize method used to display custom markers and lines on a map, *development version*.
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Drawing some lines between airports on a map.
"""
from GeoBases import GeoBase
def main():
@alexprengere
alexprengere / log_exceptions.py
Created September 6, 2016 09:07
A decorator to force the logging of uncatched exceptions, useful for workers with multiprocessing
import traceback
from functools import wraps
def log_exceptions(fd):
def _wrapped(func):
@wraps(func)
def _func(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception: