I hereby claim:
- I am mawillcockson on github.
- I am mawillcockson (https://keybase.io/mawillcockson) on keybase.
- I have a public key ASDtn4sIGl7SslZu-ioUZwJ0JWd_6HC49F14VxV4YDP7kAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
#!/bin/env python | |
""" | |
https://twitter.com/dave_universetf/status/1342688553264762880 | |
""" | |
import sys | |
from typing import List | |
def split_by_dots(dotted_quad: str) -> List[int]: | |
"turns '1.2.3.4' into [1,2,3,4]" |
# https://twitter.com/IsntTrivial/status/1344185584013742086 | |
echo "sum(map(abs, map(operator.sub, p, q)))" | |
python -m timeit \ | |
-s "import operator;p=q=range(-10_000, 10_000, 1);" \ | |
-s "def manhattan_distance(p, q): return sum(map(abs, map(operator.sub, p, q)))" \ | |
"manhattan_distance(p, q)" | |
echo "" | |
echo "sum(abs(x - y) for x, y in zip(p, q))" | |
python -m timeit \ |
#!/bin/sh | |
# This is a very dumb script: run it more than once, and it will mess things up. | |
# | |
# This is meant to be run from as a regular user. | |
# | |
# At the end, when the command virt-manager is run from bash, virt-manager will | |
# be launched with access to virt-bootstrap. | |
# | |
# To uninstall, remove the following directories and files: | |
# ~/.local/lib/virt-bootstrap |
""" | |
example of subclassing pathlib.Path | |
the current downside is repr() shows a PosixPath or WindowsPath | |
mypy --strict is satisfied by the call to cast(), and as long as the __new__() | |
method returns an object of type pathlib.Path, everything else should work, | |
since the created object will be the same as if it were created with pathlib.Path | |
mypy will complain, as it does not like the Path type on the last line |
""" | |
NOTE: This sort of "subclassing" only allows modifying how the object is instantiated. | |
Other methods added to deriving classes aren't present on the instance. | |
For example, the following fails with an AttributeError: | |
class Example(StrictPath, Path): | |
"example subclass with a method" | |
def method(self) -> None: |
""" | |
neither pylint nor mypy catch this error, even with the most stringent checks | |
""" | |
def func() -> int: | |
"raises an exception" | |
raise RuntimeError("i can't do it :(") | |
""" | |
black --version | |
black, version 20.8b1 | |
comments indicate how black reformats the above line | |
all of these are treated as valid in Python 3.6+ | |
""" | |
from typing import List, Tuple | |
name: List[Tuple[float]] = [] |
# mypy: allow-any-expr | |
""" | |
usage: add_number_phrase [[start] stop] | |
finds binary operations of addition, subtraction, division, or multiplication | |
that result in a value that's equal to the number of letters of all of the | |
names of the numbers used in the calculation | |
start: number to start at (1 if not specified) | |
stop: number to stop at |
""" | |
tells the time difference between input events | |
""" | |
import math | |
from datetime import datetime, timedelta | |
from typing import List | |
def now() -> datetime: | |
"returns a timezone-aware object for the time when it's called" |