Skip to content

Instantly share code, notes, and snippets.

@skrungly
skrungly / flags.py
Created November 3, 2018 20:18
flag enums
from numbers import Integral
class Flag(int):
def __new__(cls, value: int, parent_cls: type = None):
flag = super().__new__(cls, value)
if parent_cls is None:
parent_cls = cls
@skrungly
skrungly / mem_utils.py
Last active October 23, 2018 22:51
Memory Manipulation Utilities
import ctypes
def size_of(obj):
cls = type(obj)
return cls.__sizeof__(obj)
def mem_replace(target, source):
target_size = size_of(target)
@skrungly
skrungly / cpp_stdio.py
Created July 16, 2018 02:45
C++ style I/O implementation in Python. Oh dear.
import dis
from types import CodeType
def _patch_code(code: CodeType, **kwargs):
"""Create a new CodeType object with modified attributes."""
code_attrs = {}
# Collect the original CodeType attributes