Skip to content

Instantly share code, notes, and snippets.

biblicabeebli /
Created February 17, 2021 01:49
The proper way to get a list of timezones
from collections import defaultdict
from datetime import timedelta
import pytz
from dateutil import tz
def timedelta_to_label(td: timedelta) -> str:
""" returns a string like +1:00 """
label = "-" + str(abs(td)) if td.total_seconds() < 0 else "+" + str(abs(td))
return label[:-3]
biblicabeebli /
Created February 17, 2021 01:44
An elegant little timeout cache decorator for python
from functools import wraps
from time import perf_counter # perf_counter is a highly quality timestamp
# Keys are the functions themselves, values are a tuple containing the timeout expiry
# of the cache entry, and the cached return value.
function_cache = {}
def timeout_cache(seconds: int or float):
def check_timeout_cache(wrapped_func):