Skip to content

Instantly share code, notes, and snippets.

View BertrandBordage's full-sized avatar

Bertrand Bordage BertrandBordage

View GitHub Profile
#!/usr/bin/env python
from argparse import ArgumentParser
from io import BytesIO
import re
from xml.etree import ElementTree
NAMESPACED_RE = re.compile(r'^\{(.+)\}.+$')
SVG_NAMESPACE = 'http://www.w3.org/2000/svg'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BertrandBordage
BertrandBordage / lzw.py
Last active May 11, 2023 12:18
Lempel-Ziv-Welch algorithm in Python
from math import floor, ceil
from typing import AnyStr
ASCII_TO_INT: dict = {i.to_bytes(1, 'big'): i for i in range(256)}
INT_TO_ASCII: dict = {i: b for b, i in ASCII_TO_INT.items()}
def compress(data: AnyStr) -> bytes:
if isinstance(data, str):