Live data from Hacker News

Small programming tricks

will-keleher.com

221–230 of 239 posts

Re: Small programming tricks

#222
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!

Re: Small programming tricks

#223

Earlier quoted context omitted.

The OS-wide Emacs bindings are one of the main things still keeping me on macOS; in editors like Helix (or Zed with Helix mode) I invoke these really cursed combinations of the Helix(vim-like) shortcuts in the editor with the Emacs ones from the OS and it feels really natural as a means of moving around text. I haven't put in enough effort to replicate the experience on GNOME but once I jump ship from Apple I'll have…

I think gnome just had this as an option somewhere. Asking chatgpt says that this was removed in GTK4, so maybe it's no longer a thing?

I can still do everything in gnome with a shortcut, but not in vim style.

Re: Small programming tricks

#225

Earlier quoted context omitted.

I’ve read that if you’re trying to overturn a habit with a new habit, it’s best to undo whatever it is you did the old way, then redo it the new way. So if you want to use ctrl-r, but you’re using the up key, use the down key to navigate back to a clear line, then use ctrl-r. Do it enough times and your brain will work overtime to find a shortcut (aka just doing it the new way).

Temporarily binding the up arrow in the shell to echo "Use Ctrl-R" is probably the quickest way to un-/re-learn

I learned to type `ls` properly the first time, every time, shortly after installing `sl`.

Re: Small programming tricks

#226

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.

Re: Small programming tricks

#227

Earlier 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.

That's actually XON/XOFF - in the old days when computers could send serial data to your VT100 or whatever faster than it could handle it (and we're talking 9600 baud here), the terminal would send XOFF (ctrl-S) telling the computer to stop sending - then, when the terminal caught up, it would send XON (ctrl-Q) to let the system know it could resume sending.

The advantage of doing it this way ('software flow control') is it worked with just TX and RX lines, rather than having to connect up additional wires to indicate when the terminal was busy ('hardware flow control').

Re: Small programming tricks

#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"

Re: Small programming tricks

#229
post #134

Earlier quoted context omitted.

Hot-desking killed this practice. I now get desk anxiety on my in-office days

I am young enough that my entire career has been markdown files, screenshots, and photos on my phone. I (a)sync everywhere by pushing git lfs commits to my home server. Seems like overkill until it saves my ass. It continues to do so almost half a decade into all the LLM hype. It hits the sweet spot between simplicity, convenience, reliability, and precision. People strongly underestimate how good the git life can be…

> I (a)sync everywhere by pushing git lfs commits to my home server.

Don't let IT hear that unless you work on FOSS.

Re: Small programming tricks

#230

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 !

  #if 0
    // Normal path
  #else
    // Debug path
  #endif
Only works with C and C++, though.
Post reply on HN