View pyqt5-draw-text-in-desktop-center.py
#!/usr/bin/env python3
"""Draw text in the center of the screen."""
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
w = QLabel()
View README.md

namedtuple vs. dict micro-benchmark

$ python -m perf timeit --rigorous --duplicate 10 --hist --stats -s 'import collections; Point = collections.namedtuple("Point", "x y")' 'Point(10.5, 11.5)'
$ python -m perf timeit --rigorous --duplicate 10 --hist --stats '{"x": 10.5, "y": 11}'

Point(10.5, 11.5) is 6 times slower than {'x': 10.5, 'y':11.5}. The absolute times are 635 ns +- 26 ns vs. 105 ns +- 4 ns. Don't create classes at the function level unless you know why you need it. If your API requires dict than use dict -- it has nothing to do with performance.

View README.md

To generate ssh keys for a passwordless login, type on the phone in StaSh launched in Pythonista for iOS:

$ mkdir $STASH_ROOT/.ssh
$ cd $STASH_ROOT/.ssh
$ ssh-keygen
$ mail -s 'public ssh key' -f id_rsa.pub your_email@example.com

Then on the server, add id_rsa.pub from the e-mail, to be able to ssh from the phone without a password:

View child.py
#!/usr/bin/env python3
"""Print a random number of lines in response to each input line.
Terminate each response with 'END'.
"""
import sys
import random
def log(msg):
View __main__.py
#!/usr/bin/env python
"""Play Youtube video on remote VLC.
Usage: play-youtube-video-on-remote-vlc <webpage-url>
Send media url to remote (desktop) VLC using (Lua) http interface
https://wiki.videolan.org/VLC_HTTP_requests/
"""
import base64
import os
View roman_numerals.rl
/** Convert Roman numerals given on the command line to decimals.
$ ragel -F0 -o roman_numerals.c roman_numerals.rl
$ gcc -finput-charset=utf-8 -fexec-charset=utf-8 -o roman_numerals roman_numerals.c
$ ./roman_numerals IX Ⅻ CCCC
9
12
400
$ ./roman_numerals IIX && exit 1 || echo invalid
invalid
View KV.ebnf
# $ grako -o kv_parser.py KV.ebnf
@@grammar :: KV
# whitespace inside a string excluding the start/end of the line
@@whitespace :: /((?!^)(?![\r\n])\s)+/
@@eol_comments :: /#[^\r\n]*/
@@left_recursion :: False
# input is zero or more assignments
View parse_space_separated_assignments.py
#!/usr/bin/env python3
r"""Parse space-separated key=value pairs.
Format from http://ru.stackoverflow.com/a/635295/23044
>>> from pprint import pprint
>>> pprint(parse(r'a=1 b="2" c=3.123 d=[1, 2, 3] e={"Ke\n":["h=4"],"Key2":{" ":1}}'))
{'a': 1,
'b': '2',
'c': 3.123,