This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
import select | |
import signal | |
import socket | |
try: | |
from resource import getpagesize | |
except ImportError: | |
import mmap | |
def getpagesize(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
import tkinter as tk # https://stackoverflow.com/questions/66734619/no-module-named-tkinter#66735147 | |
import tkinter.messagebox | |
# Two different approaches to handling mainloop errors in tkinter. | |
# 1. A context manager that will display errors in callbacks and initializers (RECOMMENDED) | |
# 2. A subclass of Tk that will only display errors in callbacks, not initializers | |
@contextmanager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# import _cachedir | |
# CACHEDIR = _cachedir.cachedir('my_application@company.com') | |
# CACHEDIR = _cachedir.cachedir('my_packagename@pypi.org') | |
# NOTE: | |
# This does not create a secure enclave of any kind. | |
# Obviously, malicious applications running on the same | |
# user account could read or modify the cache directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations, permutations | |
import re | |
MIN_LENGTH = 4 | |
ILLEGAL_PATTERN_RE = re.compile('(%s)' % '|'.join( | |
# Simulate negative lookbehind via negative lookahead | |
# h/t https://learnbyexample.github.io/py_regular_expressions/lookarounds.html#negated-groups | |
f'^(?!.*{b}.*{a}{c}).*{a}{c}' for a,b,c, in | |
['123', '159', '147', '258', '369', '357', '321', '456', '654', '789', '741', '753', '852', '987', '951', '963'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""https://github.com/python/cpython/issues/53464""" | |
def simultaneous_remove(l, indices): | |
##assert isinstance(l, Collection) and not isinstance(l, Mapping) | |
_len = len(l) | |
to_remove = sorted(((i if i >= 0 else _len + i) for i in indices), reverse=True) | |
for i in to_remove: | |
del l[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def peek1(collection): | |
"Get an arbitrary element from *collection*, non-destructively" | |
try: | |
return next(iter(collection)) | |
except StopIteration: | |
raise ValueError("axiom of choice on empty collection") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
; py -V:PyPy/3.10 | |
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PyPy\3.10] | |
"SupportUrl"="https://www.pypy.org/" | |
"DisplayName"="PyPy3.10" | |
"SysVersion"="3.10" | |
"SysArchitecture"="64bit" | |
"Version"="7.3.15" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Double-Zero 1.0 Universal | |
THE TEXT OF THIS DOCUMENT ("00") IS THAT OF THE CREATIVE COMMONS "CC0 | |
1.0 UNIVERSAL", EXCEPT WITH THE LIMITATION OF PATENT RIGHTS REMOVED. | |
IT HAS NOT BEEN REVIEWED BY, OR PRODUCED IN COLLABORATION WITH, THE | |
CREATIVE COMMONS ORGANIZATION. | |
THE AUTHOR(S) OF THIS DOCUMENT PROVIDE THIS INFORMATION ON AN "AS-IS" | |
BASIS. THE AUTHOR(S) MAKE NO WARRANTIES REGARDING THE USE OF THIS | |
DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM After creating a venv via py -m venv "%USERPROFILE%\.venvs\MYVENVNAMEHERE" | |
REM Save this as %USERPROFILE%\.venvs\MYVENVNAMEHERE\Scripts\shell.bat | |
REM This script is OK to call from another folder, such as %USERPROFILE% | |
@echo on | |
REM Try "%%ProgramFiles(x86)%%\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && start python -m "idlelib" | |
cmd /k "%~dp0\activate.bat" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import greenlet | |
def teeinto_lockstep(it, *consumer_callables): | |
"""tee iterator *it* into multiple non-`async`, non-Generator consumers, in constant memory, without `threading`. | |
The behavior of each passed iterable is UNDEFINED after its respective consumer exits. | |
If a consumer function raises an exception, that exception will bubble out of teeinto_lockstep. |