Skip to content

Instantly share code, notes, and snippets.

@alexprengere
alexprengere / check_missing_cities.py
Last active April 30, 2020 06:43
Check airports not connected to a big city
from neobase import NeoBase
N = NeoBase()
for key in N:
N.set(key, city_codes=set(N.get(key, "city_code_list")))
for key in sorted(N):
if "A" not in N.get(key, "location_type"):
continue
@alexprengere
alexprengere / main.py
Created April 26, 2017 08:59
Genetic algorithm example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Code from https://lethain.com/genetic-algorithms-cool-name-damn-simple
"""
from random import randint, random
from operator import add
@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:
@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 / 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_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 / 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 / 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 / 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 / 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)