Skip to content

Instantly share code, notes, and snippets.

@internetimagery
internetimagery / bfs.py
Created July 23, 2026 09:02
More efficient BFS
# OLD
from collections import deque
queue = deque(starting_values)
while queue:
item = queue.popleft()
queue.extend(item.children)
# ... do things with item ...
# Less alloc
@internetimagery
internetimagery / relationship.py
Last active July 20, 2026 08:39
Weak Relationship Management
import gc
from operator import call
from weakref import ref, ReferenceType, WeakKeyDictionary
from typing import TypeVar, Generic, Set, List, Dict
T = TypeVar("T")
class WeakChildRelationship(Generic[T]):
__slots__ = ("_dict",)
@internetimagery
internetimagery / cell.py
Last active July 30, 2026 11:56
Cell - Representing Future/Result/Signal in one.
from __future__ import annotations
from collections import deque
from dataclasses import dataclass
from contextlib import contextmanager
from concurrent.futures import Future
from threading import Lock, Event, local
from weakref import ref, ReferenceType
from enum import Enum
import gc
@internetimagery
internetimagery / mapn_codegen.py
Last active June 28, 2026 11:01
Messing around with mapn codegen
from functools import partial, reduce
class M:
def __init__(self, val):
self.val=val
def map(self, func):
return M(func(self.val))
def bind(self, func):
return M(func(self.val).val)
def __repr__(self):
@internetimagery
internetimagery / example.py
Last active June 27, 2026 11:49
Simple inline codegen. Generate things like typing overloads in-file by running the file.
from typing import overload, Any
# <gen_get_overloads codegen>
# Anything in here is replaced with the result of gen_get_overloads()
# </gen_get_overloads>
def get(val: Any) -> Any:
return val
if __name__ == "__main__":
@internetimagery
internetimagery / collector.py
Last active October 14, 2025 08:58
Collect tokens for the backs of exported creature cards
# Make cards out of exported lists
# https://5e.tools/makecards.html
# Export then pass to tool to add background images
import json
import argparse
import unicodedata
import urllib.parse
import urllib.request
@internetimagery
internetimagery / pew.py
Last active July 21, 2025 09:49
loading animation
import time
import sys
anim = (
"\r| |",
"\r| |",
"\r| |",
"\r| |",
"\r| |",
"\r} |",
@internetimagery
internetimagery / factory.py
Last active July 12, 2025 21:34
Separate factory from class
import dataclasses
class DataFactory(type):
def from_number(cls, num: int) -> "Data":
return cls(str(num))
@dataclasses.dataclass
class Data(metaclass=DataFactory):
value: str
@internetimagery
internetimagery / .vimrc
Last active September 4, 2025 06:29
Current vimrc base
" Install vim-plug with following command
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" Then ':PlugInstall' to install them
" Set leader to space. This is set up before plugins are loaded.
let mapleader = " " " map leader to Space
" Declare plugins
call plug#begin()
@internetimagery
internetimagery / emoji.py
Last active October 27, 2024 08:35
Apply functions happily
from functools import partial
import builtins
class Emoji:
""" Execute functions with style """
__empty = object()
def __init__(self, left=__empty, right=__empty):
self.__left = left
self.__right = right