In the middle of the desert you can say anything you want
Seen first in 230228-1835 Python Callable Protocols for complex Callable typing.
pass
)If you need to add typing to a complex Callable, with, say, parameter names etc., there are Callback Protocols.
# NB "self" is included!
class Combiner(Protocol):
def __call__(self, *vals: bytes, maxlen: Optional[int] = None) -> list[bytes]: ...
def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes:
for item in data:
Python 3.7 needs typing_extensions
, 3.8+ support it natively.
See also: python typing signature (typing.Callable) for function with kwargs - Stack Overflow
git diff [--options] <commit> <commit> [--] [<path>...]
For example, for ‘between now and 2 commits back’:
$ git diff HEAD^^ HEAD main.c
$ git diff HEAD~2 HEAD -- main.c
Paths need to be relative to the root of the repo.
Another option (can do different files) is:
git diff <revision_1>:<file_1> <revision_2>:<file_2>
Source: git - How do I diff the same file between two different commits on the same branch? - Stack Overflow
(Bonus: the --
makes it work for files with weird names like -p
, good for scripts but rarely needed in practice).
Previously: 230221-1406 Gitlab has a git graph and comparisons
From How to use skip and xfail to deal with tests that cannot succeed — pytest documentation on dynamically skipping tests based on a condition:
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_function():
Better than my previous approach of if xxx: pytest.skip("...")
inside the tests themselves.
Adventures in cross-platform programming: I used fnmatch to basically simulate globs in a place where regexes were overkill, but not for filenames.
On windows, paths are case insensitive and therefore fnmatch is case insensitive too, leading to unexpected behaviour.
fnmatchcase() is case-sensitive regardless of OS.
TIL Gitlab has
tig
/ pycharm log /. .., located at “Repository -> Graph”. Really neatI should play more with the existing interfaces of things I use often
TIL you can’t.
How do I add an empty directory to a Git repository? - Stack Overflow suggests:
.gitkeep
.git-
prefix should be reserved for git-specific files.placeholder
- same as above, but less clear but no .git-
prefixREADME
explaining everything.gitignore
in the directoryAs usual, Real Pyhon has an excellent tutorial about the topic: Managing Multiple Python Versions With pyenv – Real Python
pyenv install 3.10.0 # install python version
pyenv global 3.10.0 # set it to be the global unqualified `python3` one
pyenv global system # reset back to whatever the previous system default was
EDIT God I’m stupid - this basically removes the Alt key from my keyboard. That I still need from time to time.
Wsll fix sometime later definitely.
I did a change to my keyboard layout that’s notable enough to actually merit its own small post: I added number keys on the right-hand default position through the addition of a level5.
The keyboard now looks like this: !assets/kl_cut_new.png
I stole the idea of having numbers there from TODO Reddit post.
These keys - given how nice they are right where my right hand is - were mostly already taken both at levels 2-3-4 (Shift, Mod, Shift+Mod), so I decided to look into adding level5. Instead of editing the source of the layout - which didn’t immediately work for me and I gave up quickly - I reused the approach from the Caps-lock-LED-as-keyboard-layout-indicator, and passed it as a setxkbmap
parameter.
I now activate the layout using the following line:
setxkbmap -option -option 'grp_led:caps' -option 'lv5:ralt_switch_lock' vv,ruua
lv5:ralt_switch_lock
is an option I found in the 230208-1643 List of all xkbmap configuration options, it activates level5 on the RALT/AltGr key.
So, now I can easily type 1-6 with my right hand, by pressing RALT with my right thumb (and without moving my fingers too far from their home row).
7-9 are special, as they are on the row immediately over the RALT key and the chord is very awkward, so I added them additionally as Mod+X
- that is, the LALT key, and can type them with “left thumb to press LALT and right hand to press mwv
/M,.
”.
There’s no 0
because I can press it with my right ring finger without any effort.
Installed and used Image Occlusion Enhanced - AnkiWeb for the first time, it’s neat!
I used it to mask out parts of slides instead of re-typing them, which goes against the good practices of creating-your-own-flashcards, but still - I feel its potential.
It supports neat stuff like grouping etc., more here: Advanced Use · glutanimate/image-occlusion-enhanced Wiki · GitHub