View ytcallback-server.py
#!/usr/bin/env python3
"""Send telegrams about new videos on subscribed YouTube channels.
To try it, install dependencies:
$ python3 -mpip install aiohttp feedparser werkzeug
run the callback server:
$ env TELEBOT_TOKEN=<token> TELEBOT_CHAT_ID=<chat_id> python3 ytcallback-server.py
View test_josephus3.py
#!/usr/bin/env python3
"""Closed formula (safe_position3(n)) for Josephus3 problem for 1<=n<2**31"""
from decimal import Decimal, getcontext, localcontext
def safe_position3(n, *, precision=getcontext().prec):
# [jos]: http://user.math.uzh.ch/halbeisen/publications/pdf/jos.pdf
# j(n, k, n - l) = (n - c_m) * k + d_m;
# c_m <= n < c_m_plus_1
# return j(n, 3, n) + 1;
View .gitignore
/.cache/v/cache/lastfailed
View write-pdf-pyfpdf.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Write Unicode text to a pdf file embedding font."""
from fpdf import FPDF # $ pip install fpdf
output_filename = 'unicode.pdf'
# http://unifoundry.com/pub/unifont-10.0.05/font-builds/unifont-10.0.05.ttf
font_path = 'unifont-10.0.05.ttf'
# https://helloworldcollection.github.io/#Human
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