The thing with a lot of these tricks is that you have to get into the habit of using them. I knew `Ctrl+r` for history since I learned about the command line. I even have a nice shell integration with fzf. But I still used the up/down arrow keys for years or scrolled up when I was looking for a previous command, because I never remembered the shortcut and just took the path of least resistance to find something. Usua…
It's quite true. Years ago, after `git switch` was released, I wanted to try to switch from `git checkout` to `git switch`. Ultimately I had to set up some bash nastiness to error and "scold" me when I typed `git checkout` from memory, while still allowing shell scripts to call `git checkout` just fine. It was a fun exercise, and at least now I know how I could do it again: https://github.com/lelandbatey/dotfiles/blo…
Small programming tricks
171–180 of 187 posts
Re: Small programming tricks
#172The thing with a lot of these tricks is that you have to get into the habit of using them. I knew `Ctrl+r` for history since I learned about the command line. I even have a nice shell integration with fzf. But I still used the up/down arrow keys for years or scrolled up when I was looking for a previous command, because I never remembered the shortcut and just took the path of least resistance to find something. Usua…
I was my most effective when I had a bunch of cheat sheets taped up in my workspace.
Re: Small programming tricks
#173Earlier quoted context omitted.
atuin kind of fixes this habit, when you click up you get a list of the latest commands, and you can just start typing to search. It's extremely natural.
I found atuin way too hard/slow to use, I think I went two days before I nuked it and went back to pure omzsh. Has it gotten any better in the past 2ish years?
Re: Small programming tricks
#174A lot more tricks can be learned from just watching AI work. Instead of allowing AI to work autonomously, go back to the old days where you manually approve every command the AI runs. Just recently while doing performance optimization work, I found Opus using the `perf` command in ways I didn’t know possible. Just give AI a real task and carefully read what commands are used by the AI to solve the problem; most likel…
There are several keyboard shortcuts that you would never find out from watching an agent, but are mindblowing to new Linux users. I suck at remembering vim keybindings, but I have ingrained ctrl+a ctrl+e for jumping to the start/end of a string (which also works all over OS X). I had been a developer for an embarassing amount of time before I discovered those. There are other terminal specific shortcuts for removing…
Re: Small programming tricks
#175Earlier quoted context omitted.
Another one, not quite as handy but still awesome: ctrl s / ctrl-q. This freezes/unfreezes the terminal output so you can read it, without interrupting your program. Useful for very fast walls of text.
Oh so that is what this is for. I thought ctrl-q / ctrl-s are there as a nasty way to screw with users, who every now and then accidentally press one of these, and find their terminal frozen and no longer visibly reacting to input, for no apparent reason.
Re: Small programming tricks
#176Simple trick I use almost daily for navigating backwards to an exact directory: https://gist.github.com/GNOMES/6bf65926648e260d8023aebb9ede9... I use this often instead of chaining together multiple '../..'. Also nice for when I use Zoxide to CD into a deep nested directory. I quickly found out unless you manually CD each hop, the different parent directories aren't added to your Zoxide DB. (I have come across snippi…
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
Just keep typing period and hitting enter until you get where you want according to your prompt. I haven't found much use for more than four periods. One period would be well-defined but useless.Re: Small programming tricks
#177Earlier quoted context omitted.
Yeah, I don't buy the premise that branchless code is intrinsically easier to understand. Maybe OP's point is that adding unnecessary branches makes code harder to read? But that's generally the case for any unnecessary code.
I see stuff along the lines of: if (x == 0) { return y; } y += 25*x; return y; and skipping the if just makes the function shorter and simpler, while also not involving the CPU branch prediction. Another one that doesn't necessarily skip all branching but at least drops one - and more importantly makes the code simpler and easy to verify, is removing the if statement in code like if (count == 0) { return; } for (int…
In the first case, the compiler removes the first if/return
In the second case, if you don't have the first if/return the compiler will add it. That's because it will actually convert your loop into a do/while, with the test in the end, because it is more efficient. But it has to handle the count == 0 special case first, so it will do that early return even if it is not explicitly there.
That's the kind of optimization modern compilers are good at.
Re: Small programming tricks
#178> In NodeJS, you can keep a connection open to an external resource by creating an https.Agent and then providing it to your http requests: fetch(url, {method, agent}). This can have a dramatic impact on latency. Is it true that you can pass a nodejs agent to fetch ? I don't think so
Re: Small programming tricks
#179Earlier quoted context omitted.
I’m lazy so With fish, I just type a part of the command and press up few times to get to where I want. There’s also fish-fzf.
I've relied on this so much that I copy my entire history between machines...