View echo-via-server.py
#!/usr/bin/env python3
"""Entry -> queue -> (client request) -> (server response) -> Label"""
import os
import socket
from threading import Thread
from tkinter import BOTH, Tk, ttk
from queue import Queue, Full
def echo_server(host, port):
View Performance - generate n random digits.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View __main__.py
#!/usr/bin/python3
"""Demonstrate that without `sys.exit()` exit status is zero after `app.exit(1)`."""
import sys
from PyQt5.Qt import QApplication, QPushButton
app = QApplication(sys.argv)
w = QPushButton("Exit 1")
w.clicked.connect(lambda: app.exit(1))
w.show()
View disable-button.py
#!/usr/bin/env python3
"""Disable button on pressing it."""
import tkinter.ttk
root = tkinter.Tk()
button = tkinter.ttk.Button(text='Press Me Once',
command=lambda: button.state(['disabled']))
button.pack()
root.mainloop()
View highlight.py
#!/usr/bin/env python
"""Emulate: grep -Ff <letters> [<words>]"""
import curses
import os
import sys
import re
if hasattr(sys.stdout, 'fileno') and os.isatty(sys.stdout.fileno()):
curses.setupterm()
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()