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 pathlib import Path | |
from orjson import loads | |
import re | |
TRIM = 50 | |
plover_dir = Path("~/.config/plover/").expanduser() | |
dictionary = {} | |
for path in plover_dir.glob("*.json"): |
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
#!/bin/sh | |
set -eu | |
setup() { | |
GITHUB_WORKSPACE="$(mktemp -d)" | |
DOWNLOADS="$(mktemp -d)" | |
export GITHUB_WORKSPACE | |
export DOWNLOADS | |
eval "$(curl -fsSL 'https://api.github.com/repos/gohugoio/hugo/releases/latest' \ | |
| jq --compact-output --raw-output '.assets | |
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
""" | |
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" |
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
# 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 |
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
""" | |
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]] = [] |
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
""" | |
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 :(") | |
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
""" | |
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: |
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
""" | |
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 |
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
#!/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 |
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://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 \ |