Skip to content

Instantly share code, notes, and snippets.

@zed
zed / ping_pong.c
Last active January 30, 2023 07:05
Native messaging "ping_pong" example in C
View ping_pong.c
/*** Native messaging "ping_pong" example in C.
*
* It is reimplementation of the corresponding Python example from
* https://github.com/mdn/webextensions-examples/tree/master/native-messaging
*
* # Python 3.x version
* # Read a message from stdin and decode it.
* def getMessage():
* rawLength = sys.stdin.buffer.read(4)
* if len(rawLength) == 0:
View violations.py
#!/usr/bin/env python3
"""
https://www.youtube.com/watch?v=BleOgPhsdfc
"""
from dataclasses import dataclass
@dataclass
class RedLightViolation:
"""..."""
@zed
zed / external_ip.py
Created April 4, 2020 16:16
Get external/public ip using DNS, HTTP, STUN protocols
View external_ip.py
#!/usr/bin/env python3
"""Get external ip using DNS, HTTP, STUN protocols.
Print the first result (the fastest).
Usage:
$ python3 -m external_ip [--quiet]
Optional dependencies:
$ python3 -m pip install aidns pynat pystun3
View .gitignore
/*.json
/*.xml
@zed
zed / __main__.py
Last active January 4, 2021 11:46
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 July 30, 2022 00:10
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()