In the middle of the desert you can say anything you want
Python 3.8’s Walrus1 operator is neat for printing outputs:
logger.warning(f"result is false with {start_offset=} {end_offset=} in {doc.name=}. {a.is_online=}")
[https://docs.python.org/3/whatsnew/3.8.html What’s New In Python 3.8 — Python 3.10.2 documentation] ↩︎
Was looking for something similar for months, found it in an unexpected place: Implement –pdb in a python cli
Example from there:
if "--pdb" in sys.argv:
try:
bombs()
except:
extype, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
else:
bombs()
I changed the flow to this, so I don’t need to call bombs()
in two places:
try:
bombs()
except Exception as e:
if args.pdb:
extype, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
else:
raise e
After writing if x not in y: raise ValueError()...
for the Nth time, thought of using an assert
, and you can happily do something similar:
assert x in y, f"{x} should be inside {y}"
black
formats that into
assert (
x in y
), f"{x} should be inside {y}"
which looks nice too. That’s much faster to write than my usual ValueError
pattern.
UsingAssertionsEffectively - Python Wiki touches on that, quoting from it directly below without changes.
Places to consider putting assertions:
[…]
Assertions should not be used to test for failure cases that can occur because of bad user input or operating system/environment failures, such as a file not being found. Instead, you should raise an exception, or print an error message, or whatever is appropriate. One important reason why assertions should only be used for self-tests of the program is that assertions can be disabled at compile time.
I have a lot of rarely-used personal shell scripts, all aliases now, this would be a huge improvement: Sd: My Script Directory | Hacker News
This works to lengthen the last span until the present moment (=changing it’s end to “now”):
w mod end @1 now
A good candidate for my future 220210-2236 Personal script directory :)
pkill
autocompletes running processes, which is logical but still really neat.
If I write multiple posts per day, their order within that day looks wrong. This is because in their frontmatter each has a date but no time.
date: 2022-02-09
This is done so on obyde’s side, not something I want to change.
Solution?
Use the Zettelkasten-filenames of the actual .md files.1 I wanted them like this for better ordering visually on my local filesystem, why not take advantage of this.
Solution by SO2:
{{ range sort site.RegularPages "File.Path" }}
{{ . }}
{{ end }}
I’m now writing inside 220209-2209 Hugo sorting posts by filename
↩︎
templates - How to order content by FilePath in Hugo? - Stack Overflow ↩︎
rjekker/i3-battery-popup is a script that does things (message, notification, sound etc.) when the battery gets low.
I installed wish
1, added i3-battery-popup -L 30
to startup.
Was this really that easy this whole time?..
(TIL - it’s a tk-based dialog thing). Gets used by the script if available. ↩︎
CommandSet
creates a small menu with buttons; a lot of things that previously were CLI aliases fit there much better:
lazy.run_extension(
CommandSet(
commands={
"single small": "autorandr single_small",
"single": "autorandr single",
"home": "autorandr home",
"R night": redshift_night,
"R reset": redshift_reset,
"T disable": touchpad_disable,
"T enable": touchpad_enable,
"Screenshots": open_screenshots,
},
)
),
“Open directory with screenshots” made everything freze, qtile couldn’t be restarted, the usual.
The command I used was
open_screenshots = f"bash -c 'xdg-open {dirs.SCREENSHOT_R}''"
On a hunch, added the &
to detach the process.
open_screenshots = f"bash -c 'xdg-open {dirs.SCREENSHOT_R} &'"
Works like magic, the window appears, everything else keeps working.
I want to create a qtile widget to show the currently running taskwarrior task in my statusbar.
task rc.verbose=nothing rc.color=off a
The report in ~/.taskrc
is:
# Currently active name
report.a.description='Currently active task'
report.a.columns=id,description,project
report.a.labels=ID,D,P
report.a.filter=+ACTIVE
Found out about taskw, looks really nice. First draft implementation:
from taskw import TaskWarrior
def pretty_task(act):
return f"{act['id']}/{act['description']}"
def get_task():
w = TaskWarrior()
tasks = w.load_tasks()['pending']
act = [t for t in tasks if "start" in t]
# act = [t for t in tasks]
return '_'.join([pretty_task(a) for a in act])
Returns:
19:04:27 ~/.config/qtile/cfgs/ 130
> python3 get_task.py
98/Add Taskwarrior to qtile statusbar through python binding
Couldn’t find a way to access taskwarrior’s “virtual tags” (+ACTIVE
…), so I used the fact that "start"
exists in the dictionary only if the task started.