This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Shows how the with statement / context managers are semantically equivalent | |
with a try-except-finally block. | |
https://docs.python.org/3/reference/compound_stmts.html#the-try-statement | |
https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement | |
https://docs.python.org/3/reference/compound_stmts.html#the-with-statement | |
https://docs.python.org/3/reference/datamodel.html#with-statement-context-managers | |
https://docs.python.org/3.7/library/sys.html#sys.exc_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Scoping for https://github.com/lemon24/reader/issues/67 "Tumblr feeds not working". | |
Output looks like: | |
$ python3 tumblr.py | |
initial None | |
have tumblr redirect | |
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python bench.py time | |
entries runs get_entries /?show=all ratio | |
32 8 0.01 0.20 32.7 | |
64 8 0.01 0.30 28.4 | |
128 8 0.02 0.51 25.2 | |
256 8 0.04 0.94 23.1 | |
512 8 0.08 1.78 22.0 | |
1024 4 0.09 1.77 20.1 | |
2048 2 0.11 1.85 17.4 | |
4096 1 0.13 1.84 13.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### render() | |
$ python3 bench.py time | |
entries runs get_entries /?show=all ratio /?show=all#100kb | |
32 8 0.02 0.33 17.5 0.33 | |
64 8 0.03 0.51 19.4 0.51 | |
128 8 0.04 0.87 20.0 0.86 | |
256 8 0.08 1.57 20.7 1.57 | |
512 8 0.15 2.99 19.6 2.97 | |
1024 4 0.17 3.00 17.9 2.98 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def example(): | |
print('Example!') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Run an HTTP(S) server with various customizations using only stuff from stdlib. | |
See make_httpd() and run_httpd() for details. | |
""" | |
import http.server | |
import contextlib | |
import threading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Read commands from stdin, run them in parallel, and send the output to stdout. | |
Command output looks like: | |
<command_id> <pid> (stdout|stderr) <original_line> | |
When a command exits, a single line containing the status is output: | |
<command_id> <pid> exited <status_code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE entries ( | |
id TEXT NOT NULL, | |
feed TEXT NOT NULL, | |
title TEXT, | |
summary TEXT, | |
content TEXT, | |
PRIMARY KEY (id, feed) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import textwrap | |
import collections | |
class BaseQuery: | |
indent = ' ' | |
separators = collections.defaultdict( | |
lambda: ',', | |
WHERE=' AND', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- fts5 | |
CREATE VIRTUAL TABLE entries USING fts5( | |
id UNINDEXED, | |
content | |
); | |
INSERT INTO entries | |
VALUES | |
('one', 'one'), |
OlderNewer