Live data from Hacker News

Small programming tricks

will-keleher.com

231–240 of 247 posts

Re: Small programming tricks

#231
post #125

Simple 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…

For fish shell users, you get chronological directory traversal with Alt-Left Arrow and Alt-Right Arrow.

Re: Small programming tricks

#232
A lot of these tricks come down to knowing there is a better alternative program somewhere out there in the universe, and then installing it. I happen to keep a shell script handy for these situations, which automatically installs most of the options listed here:

https://github.com/hiAndrewQuinn/shell-bling-ubuntu

More readable presentation: https://hiandrewquinn.github.io/shell-bling-ubuntu/

Among other things, fzf gets installed with all the proper key bindings, ripgrep, fdfind... basically every papercut I could find between going from a vanilla Ubuntu or Debian box to a configured one is handled in this shell script.

Re: Small programming tricks

#233

A few tidbits I wish I had known about sooner: bash: Ctrl-L to clear the screen VSCodium: Shift+Alt+[arrows|mouse click] to select a rectangular block scp for moving files (instead of ftp)

Ctrl-lpj is ingrained in my fingers.

Ctrl-l to clear the screen, Ctrl-p to select previous command, Ctrl-j to enter it again. I don't even use Enter key when in terminal anymore.

When you want to pause entering a command for a moment do Ctrl-a to go to the start of the line, and type # to comment out. Then Ctrl-j. You can return to that later with Ctrl-p, then Ctrl-a again and Ctrl-d to remove that comment.

To edit complex commands you might want to use Alt-e to enter $EDITOR.

Re: Small programming tricks

#234

I remember when I was using JetBrains IDE they had this feature that would list all shortcuts and IDE features and how frequently I use them. This was excellent for feature discovery. I would regularly check it out and scroll to the list of features I never used and try them. I always wanted the same for Vim, zsh, etc.

Do they still do this? I'm using PyCharm daily but have never seen it. Would indeed be pretty cool!

Ha! I just checked it out (had to install IntelliJ for this!) and it is still there!!! "Help" -> "My productivity".

Re: Small programming tricks

#235

One of the things I frequently use with Emacs is writing/recording macros on the fly with F3 and running them. I am sure this is present in the other editors as well, but this has helped me a lot at times https://www.gnu.org/software/emacs/manual/html_node/emacs/Ba...

I do this all the time with Vim. To the point that it astonishes me that this isn't like the third or fourth thing people learn about Vim.

You can just record and play back your exact keystrokes like a _Super Smash Melee_ game plays back your inputs to replay matches. If you can figure out how to do any mildly complex action once you can literally replay it a thousand times. Just like AutoHotKey! To my that's the essence of citizen programming!

Re: Small programming tricks

#236

My main trick is to use fish and enable vi key bindings. Especially on mac where there is no Home And End functionality.

Can't say enough good things about fish from a UI/UX experience. There's a reason Shell Bling Ubuntu [0] swaps out your underlying shell to fish. Unless you need a terminal up ASAP for scripting purposes or shelling out (in which case dash is still much faster than bash) it's just such a better experience.

[0]: https://hiandrewquinn.github.io/shell-bling-ubuntu/

Re: Small programming tricks

#237

You might not need find due to advanced globs, but it's too easy to run into expansion limits when you match hundreds or thousands of files, so you're back to find for that.

Something about the find syntax never sat well with me, and I don't search often enough that I feel I need to learn it.

My "find" is almost always

    tree -if | grep "$" | head -1
head, of course, being optional

The tradeoff is needing to learn regex, which is not any easier to learn than find arguments.

Re: Small programming tricks

#238

I am so proud of this (I'm sure others came up with it way before me, but I still came up with it all by myself!) //* normal path /*/ debug path //*/ take away the the first slash to toggle the debug zone ON !

It's awesome in both senses! How readable has it become for you over time? Because on first glance and without syntax highlighting it's a head-scratcher.

With syntax highlighting I instantly know what it is :) But to be honest it's just for when I find myself toggling something a lot during development.. but still am too lazy to make a variable.

Re: Small programming tricks

#239
post #2

This reminded me to ask: To what extent are people still coding by hand these days? In my profession (academia), literally no one codes anymore. On one hand, it sucks because the joy and fun of programming has been replaced by constant agent orchestration tasks, but on the other hand, it's hard to go back to the way things were before because the productivity gain is so good. I remember learning a lot of these progra…

People in academia generally doesn't code much. So I am not surprised. LLM's have not affected us in the slightest when it comes to coding. Maybe we write a snippet, post it for llm to scrutinize, and usually LLMs spout bullshit and wrong suggestions and after enough verbal abuse it points to some issues with the code. But I don't get this delegation to LLM's for your entire coding. I hope everyone delegates to LLM :…

so are you a time traveller from like, 2023 or something?

Re: Small programming tricks

#240
post #228
post #125

Simple 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…

Somewhat along the same lines, as I regularly SSH to other hosts with the same network filesystem mounts, 'scd' starts an SSH session on a remote host in the same directory. #!/bin/bash # SSH to remote system and change into same (current) directory DIR=$(pwd) ssh -t $1 "cd $DIR; bash -l -i"

i made `rr` (remote run) for a use-case very similar to this.

it expects the remote fs is mounted under .../ssh/HOSTNAME/ and runs any command in that dir on the remote host. if it is not the root which is mounted, looks up mtab for the remote base directory.

https://codeberg.org/hband/hband-tools/src/branch/master/use...

Post reply on HN