Skip to content

Instantly share code, notes, and snippets.

View skrungly's full-sized avatar

kingsley skrungly

View GitHub Profile
@skrungly
skrungly / generate.py
Last active May 9, 2025 02:19
code to generate a simple tic-tac-toe script :)
INTRO_SEGMENT = """\
print('| welcome to my simple tic-tac-toe game!')
print('| take your turn by choosing a tile [1-9].')\n
"""
GRID_SEGMENT = """\
print('\\n| {0} | {1} | {2} |')
print('| {3} | {4} | {5} |')
print('| {6} | {7} | {8} |\\n')
"""
@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