Skip to content

Instantly share code, notes, and snippets.

@Zeturic
Zeturic / classify.py
Created July 25, 2022 07:49
generator -> iterable container
def classify(fn):
class Wrapper:
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
def __iter__(self):
yield from fn(*self.args, **self.kwargs)
return Wrapper
@Zeturic
Zeturic / evaluate.py
Created July 19, 2022 23:39
Evaluate math expressions in Python using whitelisted AST nodes and eval
import ast
import math
from types import MappingProxyType
_empty_map = MappingProxyType({})
math_locals = MappingProxyType(
{name: value for (name, value) in vars(math).items() if not name.startswith('_')} |
{"abs": abs, "complex": complex, "min": min, "max": max, "pow": pow, "round": round}
parentheses in `struct` format strings for substructures
`pathlib.Path.read_lines` and `pathlib.Path.write_lines`
lazy version of str.splitlines
easier way to manage range objects
method that returns (start, stop, step) as a tuple
methods that take return modified copies
ChainSet
OrderedSet
read-only proxies for lists and sets
collections.abc classes should have useful reprs
; small AHK script to copy a filename to the clipboard
; defaults to ctrl + shift + c
^+c::
clipboard := Explorer_GetSelection_Basename()
return
Explorer_GetSelection_Basename(hwnd="") {
fullname := Explorer_GetSelection(hwnd)
SplitPath fullname, ToReturn