Skip to content

Instantly share code, notes, and snippets.

View panzi's full-sized avatar

Mathias Panzenböck panzi

View GitHub Profile
@panzi
panzi / diff_table.py
Last active November 17, 2026 21:51
Very simple table diffing in Python. NOTE: It compares cell contents a little bit fuzzy per default.
#!/usr/bin/env python3
from typing import Sequence, NamedTuple, Callable, Literal, Match
from enum import Enum
from html import escape as h
from io import StringIO
from os.path import splitext
from unicodedata import normalize
import re
@panzi
panzi / get_html_tables.py
Last active November 18, 2026 00:24
Parse tables from HTML.
#!/usr/bin/env python3
import re
from typing import NamedTuple, Literal, TextIO
from html.parser import HTMLParser
from html import escape as h
_SPACES = re.compile(r'\s+')
@panzi
panzi / get_tables.py
Last active November 12, 2026 15:42
A very simple function to parse CSV or TSV data from Markdown fenced code blocks while ignoring everything else.
#!/usr/bin/env python3
import csv
import sys
from io import StringIO
from typing import Iterable, Literal
__all__ = 'get_tables', 'get_code_blocks',
@panzi
panzi / display_table.py
Last active November 12, 2026 15:41
A very simple function to display a table in a Jupyther notebook.
#!/usr/bin/env python3
from html import escape as h
from typing import Sequence, Literal
from itertools import chain, repeat
try:
from IPython.display import display, HTML # type: ignore
except ImportError:
def HTML(html):
@panzi
panzi / image_grid.py
Last active November 13, 2026 00:04
Very simple function to display a grid of images in Jupyter notebooks (HTML only).
#!/usr/bin/env python3
import json
from PIL.Image import Image, open as open_image
from html import escape as h
from pathlib import Path
from uuid import uuid4
from io import BytesIO
from base64 import b64encode
@panzi
panzi / create_shortcut.py
Last active September 24, 2026 20:37
Create a .lnk file in Python without any extra dependencies (like PyWin32). Useful in environments where you can't have more dependencies (like Blender add-ons). Not sure if this is correct. Using it in a Blender add-on crashes Blender every now and then for me, but only after the shortcut was created.
# License: LGPLv2-or-later
# Author: Mathias Panzenböck
import ctypes
import errno
import struct
from typing import Callable, Any, Sequence
from ctypes import c_void_p, CFUNCTYPE, POINTER, c_int, c_ulong, c_ushort, c_ubyte, Structure, _Pointer, cast
from ctypes.wintypes import LPVOID, WORD, DWORD, ULONG, LPWSTR, BOOL, LPCVOID, HLOCAL, LPCOLESTR, LPOLESTR, LPCWSTR
@panzi
panzi / downloadCSV.ts
Last active April 16, 2026 21:11
Minimal function to save a CSV from memory in browser JavaScript. Consider this code as public domain, since it's trivial.
export function escapeCSV(value: string): string {
if (/^[-+._=\/a-z0-9]*$/i.test(value)) {
return value;
}
return `"${value.replace(/"/g, '""')}"`;
}
export function buildCSV(data: string[][]): string {
const buf: string[] = ['\ufeff']; // BOM
@panzi
panzi / README.md
Created March 21, 2025 15:30
Testing check marks in GitHub markdown tables
Source Display
[x] [x]
[x] text [x] text
- [x] - [x]
<ul><li>[x]</li></ul>
  • [x]
:heavy_check_mark: ✔️
:ballot_box_with_check: ☑️
:white_check_mark: ✅
☑ ☑
@panzi
panzi / msgid.py
Last active October 2, 2024 22:22
Python script to list and compare Message-IDs of MBOX files.
#!/usr/bin/env python3
from typing import Generator
import sys
import mailbox
import argparse
import hashlib
def hash_body(hasher, msg: mailbox.Message) -> None:
@panzi
panzi / .env
Last active June 2, 2024 00:08
NodeJS now supports --load-env=.env, so you don't need the dotenv package anymore. However, the two ways of reading .env files disagree on parsing. (I remember docker-compose parses .env files different to dotenv, too, but haven't re-tested it now.)
VAR1
VAR2 =
VAR3 = "EGG BACON" "AND SPAM"
"VAR4"="BLUBB"
"VAR 4"=BLUBB
VAR5= "FOO BAR" # COMMENT
VAR6= FOO BAR # COMMNET
#VAR7=...