Skip to content

Instantly share code, notes, and snippets.

@internetimagery
internetimagery / cell.py
Last active July 17, 2026 10:34
Cell - Representing Future/Result/Signal in one.
from __future__ import annotations
from dataclasses import dataclass, field
from concurrent.futures import Future
from threading import Lock, Event
from collections import deque
from weakref import WeakSet
from typing import Generic, Type, TypeVar, Optional, Any, Dict, Callable, Union, List, Tuple, overload, final, Final, cast, Set
T_co = TypeVar("T_co", covariant=True)
T = TypeVar("T")
@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
@internetimagery
internetimagery / range_expression.py
Last active April 24, 2023 11:20
Simple range expression parsing.
import re
def parse_compact_range(expression):
numbers = set()
for match_ in re.finditer(r"(?:(\d+)\s*\-\s*(\d+)|(\d+))\s*(?:,|$)", expression):
start, stop, exact = match_.group(1,2,3)
if exact is not None:
numbers.add(int(exact))
else:
begin, end = sorted(map(int, (start, stop)))
@internetimagery
internetimagery / git_annex_notes.md
Last active June 4, 2025 21:59
Git Annex Notes