Skip to content

Instantly share code, notes, and snippets.

View jaantollander's full-sized avatar

Jaan Tollander de Balsch jaantollander

View GitHub Profile
@jaantollander
jaantollander / sphinx-quickstart.sh
Last active March 8, 2017 15:52
Script quick-starting Sphinx
sphinx-quickstart "docs" -p "project" -a "Jaan Tollander de Balsch" -v "0.1" -l "en" --makefile --batchfile --quiet
@jaantollander
jaantollander / quadtree.py
Created March 6, 2017 15:51
Quadtree implementation with Python and Numba
import numpy as np
import numba
from numba import deferred_type, optional, f8
node_type = deferred_type()
spec = (
("value", optional(f8[:, :])),
("center", f8[:]),
("length", f8),
@jaantollander
jaantollander / format_time.py
Last active February 14, 2017 13:25
IPython notebook's timeit time_format function
import math
import sys
def format_time(timespan, precision=3):
"""Formats the timespan in a human readable form
Args:
timespan (float):
Time in seconds.
@jaantollander
jaantollander / public.py
Last active February 13, 2017 16:06
Python decorator to add objects to __all__
def public(f):
"""Use a decorator to avoid retyping function/class names. [#]_
* Based on an idea by Duncan Booth:
http://groups.google.com/group/comp.lang.python/msg/11cbb03e09611b8a
* Improved via a suggestion by Dave Angel:
http://groups.google.com/group/comp.lang.python/msg/3d400fb22d8a42e1
References:
.. [#] https://stackoverflow.com/questions/6206089/is-it-a-good-practice-to-add-names-to-all-using-a-decorator
@jaantollander
jaantollander / decorator.py
Last active December 30, 2023 21:50
Template for Python decorator function and class
import functools
def decorator(function):
"""A general decorator function"""
@functools.wraps(function)
def wrapper(*args, **kwargs):
# Write decorator function logic here
# Before function call