Skip to content

Instantly share code, notes, and snippets.

View anpr's full-sized avatar

Andreas Profous anpr

View GitHub Profile
@anpr
anpr / hmac_expiry_signer.py
Last active June 28, 2018 15:58
Thumbor: Url Signer with Expiration
# -*- coding: utf-8 -*-
# thumbor-side code, added to url signers of thumbor
from datetime import datetime
import base64
import hashlib
import hmac
from thumbor.url_signers import BaseUrlSigner
try:
@anpr
anpr / toys.py
Created December 4, 2019 20:34
Toy Combinations
toys = [
("Yoyo", 122),
("Doll", 275),
("Duckie", 185),
("Tractor", 597),
("Airplane", 647),
("Ball", 216),
("Racecar", 713),
("Dog", 457),
("Jump Rope", 146),
@anpr
anpr / fromisoformat.py
Created March 7, 2021 10:34
Does fromisoformat product timezone-aware datetimes?
from django.utils import timezone
from datetime import datetime
def is_timezone_aware(dt):
# See https://docs.python.org/3/library/datetime.html#determining-if-an-object-is-aware-or-naive
return dt.tzinfo is not None and dt.tzinfo.utcoffset(d) is not None
now = timezone.now()
is_timezone_aware(now)
# >>> True
# Start with `python magisches_dreieck.py`
import itertools
for p in itertools.permutations(range(1, 14)):
sum = p[0] + p[1] + p[5] + p[9]
if (
p[1] + p[2] + p[3] + p[4] == sum
and p[5] + p[6] + p[7] + p[8] == sum
and p[9] + p[10] + p[11] + p[12] == sum
and p[0] + p[2] + p[6] + p[10] == sum