Skip to content

Instantly share code, notes, and snippets.

View x42005e1f's full-sized avatar

Ilya Egorov x42005e1f

View GitHub Profile
@x42005e1f
x42005e1f / lognint.py
Last active August 12, 2026 07:20
Integer logarithm in O(1) (especially for the C preprocessor)
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: ISC
from __future__ import annotations
import sys
from math import ceil, log
@x42005e1f
x42005e1f / _testatomic.pyx
Created April 4, 2026 04:53
A proof of concept: atomics over shared memory
#!/usr/bin/env cython
# SPDX-FileCopyrightText: 2026 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: 0BSD
# cython: freethreading_compatible = True
# cython: subinterpreters_compatible = own_gil
# distutils: extra_compile_args = -DCYTHON_USE_MODULE_STATE=1
@x42005e1f
x42005e1f / fasture.py
Last active June 12, 2026 14:49
A fast future implementation (thread-safe, signal-safe, non-blocking)
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: ISC
# requires-python = ">=3.8"
# dependencies = [
# "exceptiongroup>=1.3.0; python_version<'3.11'",
# "typing-extensions>=4.5.0; python_version<'3.12'",
# ]
@x42005e1f
x42005e1f / asyncio_guest.py
Last active March 7, 2026 00:38
An experimental guest mode for asyncio (inspired by Trio)
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: ISC
# requires-python = ">=3.8"
# dependencies = [
# "outcome>=1.0.0",
# "sniffio>=1.3.0",
# "wrapt>=2.0.0",
@x42005e1f
x42005e1f / clocktime.py
Last active March 22, 2026 00:00
Yet another microbenchmarking module (draft)
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: ISC
# requires-python = ">=3.8"
# dependencies = [
# "aiologic>=0.15.0",
# "more-itertools>=2.1.0; implementation_name=='cpython'",
# "typing-extensions>=3.10.0; python_version<'3.10'",
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2025 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: 0BSD
from __future__ import annotations
import sys
from contextvars import ContextVar
@x42005e1f
x42005e1f / patcher.py
Last active August 23, 2025 21:32
Some patches for thread-safety (threading & eventlet)
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: ISC
# mypy: disable-error-code="attr-defined, import-untyped, no-untyped-def"
# pyright: reportAttributeAccessIssue=false, reportOptionalMemberAccess=false
from __future__ import annotations
@x42005e1f
x42005e1f / glock.py
Last active June 7, 2026 12:13
A group-level lock (async-aware & thread-aware)
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2025 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: ISC
from __future__ import annotations
from collections import OrderedDict
from typing import TYPE_CHECKING
@x42005e1f
x42005e1f / rps.py
Last active November 10, 2025 01:36
A rate limiter (async-aware only)
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: 0BSD
__all__ = (
"RPSLock",
)
from functools import wraps
@x42005e1f
x42005e1f / aiologic_fibonacci_bench.py
Last active April 4, 2025 12:27
One of aiologic's most impressive benchmarks
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2024 Ilya Egorov <0x42005e1f@gmail.com>
# SPDX-License-Identifier: 0BSD
import sys
import time
import threading
from concurrent.futures import ThreadPoolExecutor, wait