In the middle of the desert you can say anything you want
I have a pytest of a function that uses python @lru_cache
:
cacheinfo = gbif_get_taxonomy_id.cache_info()
assert cacheinfo.hits == 1
assert cacheinfo.misses == 2
LRU cache gets preserved among test runs, breaking independence and making such bits fail.
Enter pytest-antilru · PyPI which resets the LRU cache between test runs. Installing it as a python package is all there’s to ite.
Needed argparse to accept yes/no decisions, should have been used inside a dockerfile that doesn’t have if/else logic, and all solutions except getting a parameter that accepts string like true/false seemed ugly.
The standard linux --do-thing
and --no-do-thing
were also impossible to do within Docker, if I want to use an env. variable etc., unless I literally set them to --do-thing
which is a mess for many reasons.
I had 40 tabs open because apparently this is not a solved problem, and all ideas I had felt ugly.
How do I convert strings to bools in a good way? (bool
alone is not an option because bool('False')
etc.)
Basic if value=="true"
would work, but maybe let’s support other things as a bonus because why not.
My first thought was to see what YAML does, but then I found the deprecated in 3.12 distutils.util.strtobool
: 9. API Reference — Python 3.9.17 documentation
It converts y,yes,t,true,on,1 / n,no,f,false,off,0 into boolean True
/False
.
The code, the only reason it’s a separate function (and not a lambda inside the type=
parameter) was because I wanted a custom ValueError and to add the warning for deprecation, as if Python would let me forget. An one-liner was absolutely possible here as well.
def _str_to_bool(x: str):
"""Converts value to a boolean.
Currently uses (the rules from) distutils.util.strtobool:
(https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool)
True values are y, yes, t, true, on and 1
False values are n, no, f, false, off and 0
ValueError otherwise.
! distutils.util.strtobool is deprecated in python 3.12
TODO solve it differently by then
Args:
value (str): value
"""
try:
res = bool(strtobool(str(x).strip()))
except ValueError as e:
logger.error(
f"Invalid str-to-bool value '{x}'. Valid values are: y,yes,t,true,on,1 / n,no,f,false,off,0."
)
raise e
return res
# inside argparse
parser.add_argument(
"--skip-cert-check",
help="Whether to skip a cert check (%(default)s)",
type=_str_to_bool,
default=SKIP_CERT_CHECK,
)
This allows:
--no-do-thing
flagsdistutils
is deprecated in 3.12 though :(
YAML is known for it’s bool handling: Boolean Language-Independent Type for YAML™ Version 1.1.
Regexp:
y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF`
I don’t like it and think it creates more issues than it solves, e.g. the “Norway problem” (211020-1304 YAML Norway issues), but for CLI I think that’s okay enough.
Wanted to do coloring and remembered about Krita and the tutorial about flat coloring (Flat Coloring — Krita Manual 5.2.0 documentation) mentioned the Colorize Mask and it’s awesome!
Needed to actually understand it, and even had to watch a video tutorial (Tutorial: Coloring with “Colorize-mask” in Krita - YouTube) but it was so worth it!
It’s basically a bucket fill tool on steroids, and even might be reason enough to move away from Inkscape for some of these tasks!
Cleaned lineart:
Mask (red is transparent):
Result:
Result with random brushes moon texture below it:
Interesting bits:
Multiply
, but if there’s anything else below it it’ll be a mess - sometimes it should just be converted to a paint layer w/ the correct settings to see what it will look like in the endHeard the expression “roter Faden”, googled it, and it’s actually interesting and relevant.
In a scientific context, it’s the main topic / leitmotiv / … of the text. You ask a question, and all parts of the text should work together to answer it, relating to it in a clear way.
Excellent (PDF) link on this exact topic in scientific writing & an itemized list of ways to make it clear: https://www.uni-osnabrueck.de/fileadmin/documents/public/1_universitaet/1.3_organisation/sprachenzentrum/schreibwerkstatt/Roter_Faden_Endversion.pdf
TODO hypothetically save it from link rot somewhere
Also:
wolph/python-progressbar: Progressbar 2 - A progress bar for Python 2 and Python 3 - “pip install progressbar2” really cool flexible progressbar.
Also: progressbar.widgets — Progress Bar 4.3b.0 documentation:
Examples of markers:
- Smooth: ` ▏▎▍▌▋▊▉█` (default)
- Bar: ` ▁▂▃▄▅▆▇█`
- Snake: ` ▖▌▛█`
- Fade in: ` ░▒▓█`
- Dots: ` ⡀⡄⡆⡇⣇⣧⣷⣿`
- Growing circles: ` .oO`
You can export your own papers as single file and the entire Internet tells you how. But if you’re NOT the author, this is a workaround I found:
Github: simonw/llm: Access large language models from the command-line
The example from the tweet:
git log | head -n 200 | llm -s "Of the most recent 5 commits, which is probably the most important? I use 'Minor' and similar commit messages to mark unimportant commits."
llm
on pypy
I’ll restart https://serhii.net/links later, and this will be the first bit I’ll add there:
TL;DR comedians are associated with depression/anxiety:
Humour has been shown to develop from a young age, fostered by parental behaviour. A parent’s immature nature can lead to additional responsibilities forced onto children, which can evoke issues of self-worth and a need for acceptance. The constant search for approval may cause mental health issues such as anxiety or depression […] Laughter can evolve as a medium for self-preservation, detaching the individual from any adversity faced allowing for perceived control over uncomfortable situations.
Sad clown paradox is characterised by a cyclothymic temperament, which encourages the creation of light-hearted humour in a professional setting, despite inner turmoil.
So, this: https://chat.openai.com/share/764434d6-ceba-4b9d-8cfc-7899f73f9cd3
You can enter a dummy markdown file or whatever and ask it to generate some other similar files! Like lorem ipsum but way way cooler and more open to nuance
TIL wowchemy exists, and wowchemy/starter-hugo-research-group: 👥 轻松创建研究组或组织网站 Easily create a stunning Research Group, Team, or Business Website with no-code is one template there that I’ll use to start learning about it.
This will be much messier than the average post in the Diensttagebuch
Their documentation seems to be undergoing some overhaul and half of the links don’t work and half don’t open in qutebrowser, will do what I can
The main idea seems to be that blocks can live in different .md
files in a folder, and are shown in the page based on their “weight” argument.
Wowchemy has different block types, one is Page Collection | Wowchemy for a collection of pages. A la page list in vanilla Hugo.
Actually there’s 🧱 Build your pages with blocks: no-code required! | Wowchemy Docs that’s closer to that
https://university.wowchemy.com/reference/page-features/
type: widget_page
means it’ll parse the pages AND DIRECTORIES inside the dir it’s located in as widgets, example of this is the home page.
I see no way to include two different lists of pages inside the directory without having all these pages also appear as widgets - in other words, how to “include” pages in that subfolder from some of the widgets but not the widgets page itself.
But - now I see why the home page is inside ./content/home
…