Skip to content

Instantly share code, notes, and snippets.

@xflr6
xflr6 / shasum_chunked.py
Last active October 25, 2025 13:55
Compare while-loop with break to for-loop with two-argument iter() for iterating over a large file in chunks
"""Compare four ways to iterate over a large binary file in chunks."""
import functools
import hashlib
import mmap
import os
import pathlib
import shutil
import time
import types
@xflr6
xflr6 / walk_subdirs.py
Last active October 12, 2025 09:23
Compare subdirectory generator using os.walk() with one using scandir.scandir()
"""Compare two ways to iterate over subdirectories of a tree."""
from collections.abc import Iterator
import os
import platform
import time
START_DIR = 'c:\\Users' if platform.system() == 'Windows' else '/usr'
@xflr6
xflr6 / fca_variants.py
Last active June 4, 2022 14:16
Compare different methods to brute-force FCA concept generation (sets, longs, gmpy2, NumPy bools, Numpy uint64)
"""Compare different brute-force FCA concept generation methods."""
from collections.abc import Iterator, Sequence
from itertools import combinations, compress
import time
import gmpy2
import numpy as np
OBJECTS = ('1s', '1de', '1pe', '1di', '1pi',
"""Benchmark FCA concepts lattice generation with bob_ross.csv."""
from collections.abc import Iterable, Iterator, Sequence
import csv
import os
import pathlib
import time
from typing import NamedTuple
import urllib.request
@xflr6
xflr6 / Wikidata.ipynb
Last active October 25, 2025 12:44
Check Glottolog -> Wikidata mapping
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xflr6
xflr6 / ControlCharacters.ipynb
Last active October 25, 2025 12:41
Drop Glottolog bibfiles for control characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xflr6
xflr6 / Pandas_read_sparql_query.ipynb
Last active October 25, 2025 12:38
Read pandas.DataFrame from SPARQL query
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xflr6
xflr6 / MakeElanSentences.ipynb
Last active October 25, 2025 12:33
Make a skeleton ELAN document from (text, translation) pairs
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xflr6
xflr6 / read_text.py
Created November 1, 2025 10:48
Compare different Python Standard Library methods to read an UTF-8 encoded text file.
"""Compare different stdlib methods to read an UTF-8 encoded text file."""
import codecs
import io
import os
import pathlib
import time
TEST_FILE = pathlib.Path('read_text.txt')