Skip to content

Instantly share code, notes, and snippets.

View danchen6's full-sized avatar
⛰️

Dan Chen danchen6

⛰️
View GitHub Profile
@danchen6
danchen6 / random_int64.py
Created January 16, 2025 14:36
Generate a random 64-bit signed integer, with timestamp embedded in the higher 42 bits.
import random
import time
def random_int64():
'''Generate a random 64-bit signed integer, with timestamp embedded in the higher 42 bits.'''
CUSTOM_EPOCH = 1735689600 # 2025/01/01 00:00:00 UTC
HIGH_42BIT_MASK = 0x7FFFFFFFFFC00000 # hex((2 ** 41 - 1) << 22)
LOW_22BIT_MASK = 0x3FFFFF # hex(2 ** 22 - 1)
@danchen6
danchen6 / libpython_py-enum-objects.py
Last active December 26, 2024 06:21
Additional command `py-enum-objects` for the GDB script `libpython.py` with Python 3.9+
# USAGE:
# 1) Append this snippet to https://github.com/python/cpython/blob/v3.9.21/Tools/gdb/libpython.py
# 2) In GDB run `source /path/to/libpython.py`
# 3) In GDB run `py-enum-objects /path/to/output.txt`
#
class PyEnumObjects(gdb.Command):
'Enumerate all objects tracked by the garbage collector (Python 3.9+)'
def __init__(self):
super(PyEnumObjects, self).__init__(
'py-enum-objects',