Skip to content

Instantly share code, notes, and snippets.

@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 / 00-sqlite3-server.md
Last active February 14, 2024 14:28
Python sqlite3 server using multiprocessing.managers

This gist tracks the creation of an almost fully functional sqlite3 server in Python 3, using only the multiprocessing.managers standard library module.

But why?

  • To see if it can be done.
  • To learn about multiprocessing managers.
  • Aside from whole-database locking, SQLite (maybe, see below) supports table-level locking between multiple connections in the same process to the same database. A "SQLite server" makes it possible for users in different processes to use SQLite connections that live in the same process.

@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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lemon24
lemon24 / mutagen-mp4-tags.py
Last active November 18, 2023 12:53
using mutagen to update MP4 tags
import shutil
import mutagen
shutil.copy('original.mp4', 'new.mp4')
# mutagen.File knows how to open any file (works with both MP4 and MP4):
#
# https://mutagen.readthedocs.io/en/latest/user/gettingstarted.html
# https://mutagen.readthedocs.io/en/latest/api/base.html#mutagen.File
@lemon24
lemon24 / sqlite-fts5-highlight-group-by.sql
Last active November 8, 2023 04:34
SQLite FTS5: "unable to use function highlight in the requested context"; https://github.com/lemon24/reader/issues/122
-- fts5
CREATE VIRTUAL TABLE entries USING fts5(
id UNINDEXED,
content
);
INSERT INTO entries
VALUES
('one', 'one'),
@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
"""
(Broken?) MinHash implementation attempting to optimize Jaccard similarity
for https://github.com/lemon24/reader/issues/202 (reader.entry_dedupe plugin).
---
Current state:
It kinda works, but no matter how much I increase LOOPS,
the result doesn't seem to converge to the real similarity
"""
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