Skip to content

Instantly share code, notes, and snippets.

@lemon24
lemon24 / wikibooks2html.py
Created September 15, 2026 17:31
Script for turning a Wikibooks book into a single HTML file that can be converted to other formats by Calibre.
"""
Script for turning a Wikibooks book into a single HTML file
that can be converted to other formats by Calibre.
Currently hardcoded for https://en.wikibooks.org/wiki/Professionalism,
"Cases and Ideas in Professional Ethics".
"""
import re
import time
@lemon24
lemon24 / ufw.py
Created August 31, 2026 10:23
Minimal UFW pyinfra operation.
"""
Minimal UFW pyinfra operation.
ufw.ufw(
name="firewall",
enabled=True,
rules=[
"allow 22/tcp",
"allow 80/tcp",
"allow 443/tcp",
@lemon24
lemon24 / pyinfra_local_certbot_poc.py
Created January 27, 2026 12:44
local certbot + remote challenge (+ pyinfra) proof of concept
"""
local certbot + remote challenge proof of concept, using --manual-auth-hook[1]
a pyinfra operation using this may do something like:
if cert not on server:
if cert not locally:
get_certificate(domain)
yield "copy cert to server" command
"""
entry_dedupe prototype that supports multiple heuristics for finding potential duplicates.
see https://github.com/lemon24/reader/issues/371 for details.
"""
import itertools, re
from math import *
from urllib.parse import urlparse
from reader import make_reader
@lemon24
lemon24 / attachlock.py
Created February 22, 2024 16:49
Does an attached SQLite database block the main database? No! For https://github.com/lemon24/reader/issues/323
"""
Say you have a SQLite connection to database `main`
with attached database `attached`.
Does a long insert on the `attached` database in a similar connection
lock the `main` database in this connection?
No, it only locks `attached`.
Output:
@lemon24
lemon24 / test_323_search_sync_model.py
Last active February 5, 2024 21:48
Using model-based testing on a search sync implementation for https://github.com/lemon24/reader/issues/323
"""
...in which we use property-based / model-based testing to find
an eventually consistent way of synchronizing entries
from the main reader storage to an (unrelated) search index,
without coupling the storage and search with transactions / triggers.
A real model checker like TLA+ or Alloy may have been a better tool for this,
but I don't know how to use them.
This is the first step in https://github.com/lemon24/reader/issues/323.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lemon24
lemon24 / dkv.py
Last active October 22, 2023 09:59
Distributed key-value store prototype, with no kind of consistency.
"""
Distributed key-value store prototype, with no kind of consistency.
---
A demo (from before we had bootstapping): https://asciinema.org/a/616231
On one machine:
>>> d = dkv.DKV()
@lemon24
lemon24 / requests_localhost.py
Last active September 22, 2023 22:14
measure how much time it takes for requests to make many localhost requests
"""
measure how much time it takes for requests to make many localhost requests
try do so some optimizations
initial results on on an old mac:
$ python req.py http 100
itrg 0.3003
"""
stricter typing
for https://github.com/lemon24/reader/blob/master/src/reader/_parser.py
for https://github.com/lemon24/reader/issues/271
"""
from typing import *
import io
from dataclasses import dataclass
from random import choice