Skip to content

Instantly share code, notes, and snippets.

import asyncio
import os
async def task_inner():
with open("/dev/urandom", "rb") as urandom:
feed = await asyncio.to_thread(urandom.read, 128)
print(feed[:16].hex(), "\r", end="")
async def task():
async with asyncio.TaskGroup() as tg:
@johnslavik
johnslavik / settings.json
Created February 15, 2026 01:33
cpython vscode settings
{
"python.analysis.extraPaths": ["Lib/"],
"C_Cpp.files.exclude": { "PC/pyconfig.h": true, "Apple/iOS/Resources/pyconfig.h": true },
"C_Cpp.exclusionPolicy": "checkFilesAndFolders",
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {"source.fixAll": "never", "source.unusedImports": "never", "source.organizeImports.ruff": "never"}
}
# from bulmenisaurus on Python Discord
# this prints hello
print(
""
.encode("utf_8_sig")
.decode("mac_croatian")
.encode("037")
.decode("maclatin2")
@johnslavik
johnslavik / native-units.md
Last active August 16, 2025 20:03
CPython with native units

Native units for Python

Python introduces two new builtins:

  • intu — a unit-aware integer (a subclass of int)
  • floatu — a unit-aware float (a subclass of float)

Together, these are called u-numbers.
They behave like normal numbers but carry units, and arithmetic automatically respects those units.

@johnslavik
johnslavik / DRAMA.md
Last active December 17, 2025 16:16

🎭 ECHO'S LAST BREATH

A Syscall Tragedy in One Line and Thirteen Bytes


PERSONS

  • PROCESS, a voice yearning to be heard
  • KERNEL, the inexorable arbiter of fate
@johnslavik
johnslavik / breakpoints.sh
Last active February 16, 2025 15:22
Breakpoints from regex
#!/usr/bin/env bash
set -Eeuxo pipefail
rg $1 -no --no-heading -r '' | sed 's/:$//' | xargs -l echo break > $2.gdb
from collections.abc import Iterator, Sequence
from datetime import date, timedelta
from functools import partial
from itertools import batched
work_time = timedelta(hours=7, minutes=15)
year = 2025
(
@johnslavik
johnslavik / make-http-constants.py
Last active December 16, 2024 21:42
HTTP constant literals for typeshed
import ast
import sys
import textwrap
from pathlib import Path
from typing import NamedTuple
from typeshed_client import get_search_context, get_stub_ast
try:
typeshed_root = Path(sys.argv[1])
@johnslavik
johnslavik / story.md
Last active August 3, 2024 09:11
A fun story about a recruitment

from twisted import story 🚀


Note

This story was generated with the help of AI and mine (in the Python parts). I just think it is a must to mention it.

Prologue: The Recruitment Gauntlet

Narrator: Before Alex could even sit across from Sam in this final interview, there was a journey—a gauntlet of recruitment stages that would test the mettle of even the most seasoned developer. Let’s take a quick look back.

import pandas as pd
x = pd.DataFrame()