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 / 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 / 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
"""
Prototype showing how a Twitter reader plugin could work, based on
https://github.com/lemon24/reader/issues/271#issuecomment-1111789547
FooRetriever and FakeParser are simplified versions of the actual thing.
Typing left as an exercise for the reader (won't be straightforward).
UpdaterWrapper is needed because we can't choose updaters
(like we do with parsers and mime types); we'd likely use feed.version.
"""
Working of off feedparser 6.0.8.
To do:
* [x] don't read entire file in memory
* [x] allow fallback to reading entire file in memory
* allow using alternative (defusedxml, lxml) sax handlers
* [x] fix content order bug
"""
API proposals for Reader.add_entry().
"""
### 1a: one-shot add entry
reader.add_entry(
feed_url='https://explainxkcd.com/rss.xml',
"""
(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