Skip to content

Instantly share code, notes, and snippets.

zed

Block or report user

Report or block zed

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View __main__.py
#!/usr/bin/env python3
"""
- read subprocess output without threads using a socket pair
- show the output in a tkinter GUI (while the process is still running)
- stop subprocess on a button press
"""
import logging
import os
import socket
import sys
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):
@zed
zed / Performance - generate n random digits.ipynb
Last active Feb 6, 2018
Performance - generate n random digits.ipynb
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()
@zed
zed / ytcallback-server.py
Last active Sep 12, 2018
Send telegrams about new videos on subscribed YouTube channels.
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
You can’t perform that action at this time.