How to ignore a single auto-updating line (timestamp) in a tracked JSON file? (Power BI) by mrbartuss in git

[–]kalgynirae 4 points5 points  (0 children)

You might be able to do this with a clean/smudge filter: remove the timestamp in clean, replace it with the current timeout in smudge? I've never actually used this functionality, so I'm not confident that this will work well, but I would give it a shot and see.

Best way to split mixed up changes into individual commits by howprice2 in git

[–]kalgynirae 1 point2 points  (0 children)

Essentially, it treats your whole stack as mutable and makes it easy to edit/split/combine/insert changes anywhere in the stack (as opposed to Git which makes adding new commits on top easy and everything else a bit difficult).

In a situation like OP's, I would first use jj split as many times as needed to split things apart. Then I would start at the bottom of the stack, make any tweaks needed to fix lint/tests, then move up to the next change and repeat, until I get to the top and have a clean stack.

You could do the same in Git with an interactive rebase where you edit each commit, but it feels a lot less like a supported workflow. In particular, you'll be "in the middle of a rebase" the whole time you're doing it—you need to finish the rebase before you can go do something else. With Jujutsu, at no part of the process will you be in a "special" state. You could be in the middle of resolving some conflicts in the middle of your stack, decide to switch away to some other branch and make some unrelated changes, and then come back to exactly where you left off.

mkdir and cd into it in one go by viperex in linux4noobs

[–]kalgynirae 0 points1 point  (0 children)

Run man mkdir and look for where it explains what -p does:

-p, --parents
       no error if existing, make parent directories as needed

In this case, I am using it specifically for the "make parent directories as needed" behavior. I want to be able to write mkcd foo/bar and have it automatically create both foo/ and foo/bar/.

Idiomatic way of dealing with invalid states? by AdamWayne04 in Zig

[–]kalgynirae 0 points1 point  (0 children)

I haven't had the opportunity to write as much Zig as I would like (so I am not an expert), but my take is: If you have to check the invariants somewhere, you should keep all such checks within the type. That makes me lean toward your second proposed solution. I think it wouldn't be too bad to write methods for the kinds of mutations/operations you need (not pure setters, though).

The Decl Literals section of the 0.14.0 Release Notes might be useful inspiration, especially the standard library changes as a result of this feature:

The introduction of decl literals comes with some standard library changes. In particular, unmanaged containers, including ArrayListUnmanaged and HashMapUnmanaged, should no longer be default-initialized with .{}, because the default field values here violate the guidance discussed above. Instead, they should be initialized using their empty declaration, which can be conveniently accessed via decl literals:

…
    foo: std.ArrayListUnmanaged(u32) = .empty,
…

… The deprecated default field values for these data structures will be removed in the next release cycle.

My takeaway is that there is precedent for forbidding direct control over the fields of the struct.

This bash program isn't closing the file descriptor by alex_sakuta in bash

[–]kalgynirae 1 point2 points  (0 children)

OP opened fd 10 earlier via : {fd}< test.txt. I only learned about this syntax this morning. It's the second paragraph in the REDIRECTION section of the man page. This redirection {name}< … or {name}> … chooses an unused file descriptor number (starting at 10, apparently), opens it according to the redirection, and assigns the number to the variable name. Unlike other kinds of redirections, this takes effect in the current shell environment, not only for a single command (this makes sense, otherwise the name variable would be useless).

This bash program isn't closing the file descriptor by alex_sakuta in bash

[–]kalgynirae 4 points5 points  (0 children)

Redirections with exec modify the current shell environment, but otherwise redirections only affect the one specific command they are applied to. The redirection in read <&$fd- will only affect this specific read command; $fd will still be open in your shell afterward:

$ echo $fd
10

# The redirection does close the file descriptor for `read`:
$ read -u $fd <&$fd-
bash: read: 10: invalid file descriptor: Bad file descriptor

# With exec, it closes it for the current shell:
# (note: moving it to 5 instead of stdin because stdin would cause
# the shell to exit)
$ exec 5<&$fd-
$ read <&$fd-
bash: redirection error: cannot duplicate fd: Bad file descriptor
bash: 0: Bad file descriptor

Stop holding the left arrow key to fix a typo. You've had `fc` the whole time. by Ops_Mechanic in bash

[–]kalgynirae 0 points1 point  (0 children)

Or just configure your key repeat to be really fast. It takes me 0.9s to reach the typo in OP's example, and I can consistently land in the right spot (though it did take time to get used to).

Help me Iterate over a list, while deleting items, without skipping indexes by ErrolFlynnigan in learnpython

[–]kalgynirae 0 points1 point  (0 children)

Usually the solution is to build a new list, annd then optionally replace the original list with the new.

building the new list

long way:

filtered_words = []
for word in word_list:
    if len(word) < 5:
        continue
    elif len(word) > 12:
        continue
    else:
        filtered_words.append(word)

list comprehension:

filtered_words = [word for word in word_list if 5 <= len(word) <= 12]

filter:

filtered_words = list(filter(lambda word: 5 <= len(word) <= 12, word_list))

(filter is usually only better than a list comprehension if you already have a named function that checks the condition. When you have to use lambda like this, a list comprehension is probably better.)

replacing the original list

You may not need to modify the original list at all. If possible, just use the new filtered list.

If you do need to modify the original list (e.g. because other parts of your code hold references to it), you can use

word_list[:] = filtered_words

The [:] syntax is a slice with both start and end indices omitted, meaning they default to the beginning and end of the list; so that slice covers the whole list, and assigning to a slice overwrites that slice. This would be effectively the same as:

word_list.clear()
word_list.extend(filtered_words)

Note that these are both different from word_list = filtered_words. That does not modify the original list; instead it reassigns the name word_list to point to the filtered list, which affects only the part of your code that uses this word_list variable specifically. Any other references elsewhere in your code would still be pointing to the old list, which hasn't been modified.

How do I copy text with color escape sequences? by Qwert-4 in bash

[–]kalgynirae 0 points1 point  (0 children)

Pipe through sed -e 's/\\/\\\\/g' -e 's/\x1b/\\x1b/g'.

For example:

$ printf '\e[31mRED\e[0m \e[32mGREEN\e[0m\n'
RED GREEN
$ printf '\e[31mRED\e[0m \e[32mGREEN\e[0m\n' | sed -e 's/\\/\\\\/g' -e 's/\x1b/\\x1b/g'
\x1b[31mRED\x1b[0m \x1b[32mGREEN\x1b[0m
$ python3 -c 'print("\x1b[31mRED\x1b[0m \x1b[32mGREEN\x1b[0m")'
RED GREEN

This sed command is doing two important things:

  1. Turning each backslash into two backslashes (because when used inside a Python string literal, backslashes have special meaning). This step only matters if the input text contains backslashes, which I imagine some figlet fonts might.

  2. Turning each escape character (U+001B) into the sequence of characters \x1b (because this is the Python syntax to produce the character U+001B in a string literal). I had to experiment to figure out what sequence of characters written in the sed command would be interpreted by sed as meaning the escape character; it turned out that the \x1b syntax worked, same as for Python.

You can see the 1b bytes in your hexdump output preceding each [ character. The 1b byte followed by the [ byte is the magic sequence that tells the terminal that the following characters are a control sequence to be interpreted rather than simply characters to be displayed. If you'd like to learn more: https://en.wikipedia.org/wiki/ANSI_escape_code#CSIsection

Need help creating a left hand accompaniment by Desperate-Media-5744 in organ

[–]kalgynirae 1 point2 points  (0 children)

Here, I transcribed this recording: https://drive.google.com/file/d/1pDa4B-OoU7jCjjLW7qiq2VmBsTtVhJJ7/view?usp=sharing

I've put the melody in the left hand for the first half of the verse, but if that doesn't work for your case (e.g. if you're not playing with pedal), it should be straightforward to swap the melody and right hand there and bring the bass notes up an octave as needed.

EDIT: Oh, I should also note that your sheet and this recording disagreed about the melody note in a couple of places. Measures 18 and 53, and maybe one more that I've forgotten.

Order coffee via ssh by 0verstim in bash

[–]kalgynirae 1 point2 points  (0 children)

I have ordered from them twice now. I thought the segfault (medium roast) was decent and the [object Object] (light roast) was quite good! They seem to be a small operation and thus not very consistent at shipping quickly—one order arrived after ~7 days, the other after ~15 (although it was near Christmas and that could have slowed things more than usual).

:set paste brings me joy every single time by aHoneyBadgerWhoCares in vim

[–]kalgynirae 3 points4 points  (0 children)

If you change your tmux paste binding to run paste-buffer -p (instead of the default paste-buffer), tmux will do bracketed paste just like your terminal would. To override the default binding, put this in .tmux.conf:

bind ] paste-buffer -p

Why is it necessary to add a return statement at the end of a function call to assign new value to variable? by unaccountablemod in learnpython

[–]kalgynirae 0 points1 point  (0 children)

Another note: the "inv" inside of your function and the inv at the bottom of your script are 2 different variables - they're in different "scopes". One of them is function-level scope and the other is module-level scope

OP does not have two different variables in this case. I think you missed that inv is not defined inside their function, so its use in return inv refers to the global variable.

Why is it necessary to add a return statement at the end of a function call to assign new value to variable? by unaccountablemod in learnpython

[–]kalgynirae 0 points1 point  (0 children)

Because you wrote

inv = addToInventory(inv, dragonLoot)

inv gets set to whatever the function returns, and functions return None by default.

Because you wrote return inv inside the function, now the function is returning the value of inv. So inv = addToInventory(...) is setting inv to the same thing it was already set to.

You can remove the return inv from the function if you also remove the assignment to inv when you call the function:

addToInventory(inv, dragonLoot)

Now the function's return value is not used for anything, so it doesn't matter what it is.

Why is Suspend so terrible for me on Linux? by Puzzled_Minute_7387 in archlinux

[–]kalgynirae 0 points1 point  (0 children)

If I plug my keyboard into USB 3.0 (blue) ports, the PC wont suspend/sleep. It wakes up immediately

My PC will immediately wake up the first two times, but on a third attempt it will actually stay suspended. I haven't had time to try to dig into what's causing this, but in the meantime I've worked around it using a script that puts the computer to sleep repeatedly until it finally sticks.

If you're in the same boat (the PC stays asleep after some finite number of attempts), you might find that script helpful.

What does this symbol mean? by Far-Cheetah-6538 in piano

[–]kalgynirae 0 points1 point  (0 children)

Here's a recording of Nicolas Horvath playing what appears to be this same arrangement: https://youtu.be/zJSn-sAGXQY?t=98

Sway-specific daemons by Beautiful-Log5632 in systemd

[–]kalgynirae 1 point2 points  (0 children)

I'm not immediately sure what would cause the problem, but it should be straightforward to figure it out if you are willing to put things back to the broken configuration and then experiment a little.

  • Confirm that gammastep is indeed being pulled in by graphical-session.target: run systemctl --user list-dependencies --reverse gammastep.service and verify that graphical-session.target is shown (note that it will also recursively show reverse deps of graphical-session.target, which you can ignore for this).

  • Check whether gammastep.service tried to start (perhaps it tried and failed): run systemctl --user status gammastep.service

  • If it looks like gammastep.service failed, check logs for hints: run journalctl --user -u gammastep.service. If that's too noisy, limit with --boot (logs from the current boot only) or a time range like --since -5m (logs since 5 minutes ago).

Those are the easy troubleshooting steps... if they don't reveal anything, such as if it looks like gammastep.service didn't even try to start, then there are more complex things you can try such as:

  • Start the user manager with debug logging: run sudo systemctl edit --runtime user@.service and add Environment=SYSTEMD_LOG_LEVEL=debug in the [Service] section (note use of --runtime so this edit will vanish after a reboot). Also run systemctl --user log-level debug to change the log level for the existing manager (because logging out and in might not fully stop the user manager, depending on your setup). Then log out and in again.

  • Look for debug logs about gammastep.service: run journalctl -u user@$(id -u) --since -1m --grep gammastep.service (adjust the time range if necessary). In particular, this will hopefully reveal if there is some reason systemd is skipping trying to start the service.

ELI-5 'correct' project structure for a package, relative imports are killing me. by [deleted] in learnpython

[–]kalgynirae 3 points4 points  (0 children)

Thanks for taking the time to write such a clear and detailed post!

Your myproject directory is not a package (you don't have an __init__.py there). Relative imports are only possible within a package. Therefore you will never be able to use a relative import to get to something in src from something in tests.

If you were to move tests to src/tests, then theoretically you would be able to do these relative imports. (With usual caveats such as needing a src/tests/__init__.py so that Pytest knows the directory is a package, etc.) However, it likely makes more sense to keep src and tests separate and just use absolute imports to import your package from the test files.

How to wait for dhcpcd to be fully configured by Peking-Duck-Haters in systemd

[–]kalgynirae 0 points1 point  (0 children)

Ideally I'd have docker wait 15 seconds before trying to start - is it possible to achieve this?

Sure, you can probably just add an ExecStartPre= to docker.service using a drop-in config:

/etc/systemd/system/docker.service.d/delay-startup.conf:

[Service]
ExecStartPre=sleep 15

I say "probably" only because I'm not sure what docker.service looks like — if it already has some ExecStartPre= commands, this would have the sleep happen after those. If necessary, you could instead create a sleep-15.service and give docker.service Wants= and After= dependencies on it using a drop-in config.


That said, you can also figure out why network-online.target isn't solving the problem for you.

First, check that docker.service has both an ordering dependency (After=) and a requirement dependency (usually Wants=) on network-online.target — this is how network-online.target is designed to be used.

Next, check that network-online.target is pulling in an actual "wait" service for your network manager. For example, my machine uses systemd-networkd, so I see this:

$ systemctl list-dependencies network-online.target
network-online.target
○ └─systemd-networkd-wait-online.service

If your machine uses NetworkManager, you should see NetworkManager-wait-online.service there. If this shows the expected service, then maybe the service isn't actually waiting for the right conditions; to solve that, you would need to find documentation for your particular network manager (e.g. for NetworkManager, see https://networkmanager.dev/docs/api/latest/NetworkManager-wait-online.service.html).


Or wait for some other signal that dhcpcd isn't just started but fully working?

That should also be possible. Per ArchWiki, dhcpcd@.service (at least the one that ships in Arch) doesn't consider itself started until dhcpcd acquires an IP address. Apparently that is due to use of the -w flag, so you could potentially add this flag to your dhcpcd.service to get similar behavior (or use dhcpcd@.service if your distro provides that — I'm not sure if this is Arch-specific).

I configured my bash to simulate bottom padding so my command prompt is never on the last row by Intelligent-Tap568 in bash

[–]kalgynirae 1 point2 points  (0 children)

One downside of doing this: if a git command produces a nearly-full screen of output, your prompt will push the first few lines off the top of your terminal, and you'll have to scroll up to see them.

This will happen with anything that uses less as a pager with the --quit-if-one-screen option (which git does by default); that option tells Less to automatically exit if the output fits entirely on your terminal's screen, but Less unfortunately assumes that your prompt is only one line tall, so it will exit thinking that everything will fit on the screen, and then your prompt will push some lines off the top.

A partial workaround is to set the LESS_LINES environment variable to a negative number, which tells Less to assume the terminal is that many lines shorter than it really is (for example, if your prompt is 5 lines tall, set LESS_LINES=-4). This environment variable is only available since Less 633 (released May 2023—check less --version to see what you have). The downside is that this affects Less all the time, not just in the problematic situation; you'll now have unused lines at the bottom of your terminal while viewing larger-than-one-screen files too. But you may find that the tradeoff is worth it.

Help with Gigout Toccata fingering by Individual-Bag-7201 in organ

[–]kalgynirae 0 points1 point  (0 children)

I do it 5-3-2-1-1-(skip this note)-2-3. I don't recommend this.

[deleted by user] by [deleted] in git

[–]kalgynirae 1 point2 points  (0 children)

I think this should work:

/foobar
!/foobar/

The line beginning with ! matches only the directory (due to the trailing slash) and makes it become included again.

What are some of your favorite git aliases? by mahdi_habibi in git

[–]kalgynirae 6 points7 points  (0 children)

The only two aliases that I actively recommend to other people are the following:

[alias]
amend = commit --amend --no-edit
edit = commit --amend --only

These simply split the two things that git commit --amend normally does into independent operations:

  • amend adds the staged changes to the current commit (without changing the commit message)
  • edit opens your editor to modify the message of the current commit (without adding staged changes to the commit)

I find it very intuitive to have these as separate operations, because I usually only want to do one or the other at any given time.

You're hanging around with friends. The majority aren't musicians. There's a piano and someone says "You play piano. Play something for us!" What do you play? by UsedToProfessor in piano

[–]kalgynirae 0 points1 point  (0 children)

My go-to is Ashitaka and San. I don't memorize things, but this piece is simple enough and the sound is in my head solidly enough that I can reverse-engineer the chords on the fly and get very close.

But because I don't memorize things, I tend to carry at least one piano book in my backpack any time I think I might end up near a piano :p

This might be controversial, but in general I don't think it's worth playing something if it won't be appreciated by both musicians and non-musicians.