Skip to content

Instantly share code, notes, and snippets.

View wakingyeung's full-sized avatar
:octocat:
code code code

Waking wakingyeung

:octocat:
code code code
View GitHub Profile
"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------
@wakingyeung
wakingyeung / lock.py
Last active September 5, 2021 03:55
Distributed locks with Redis for Python.
#!/usr/bin/env python
# -*- coding=utf-8 -*-
import math
import time
import uuid
import redis
@wakingyeung
wakingyeung / snowflake.py
Last active March 12, 2023 11:47
Twitter snowflake id generator for Python.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import multiprocessing
import re
import threading
import time
LAST_TIMESTAMP = -1
SEQUENCE = 0