Live data from Hacker News

Ask HN: Small scripts, hacks and automations you're proud of?

news.ycombinator.com

141–150 of 340 posts

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#141
Here are two scripts I now can't imagine living without:

[1] is the reason I no longer need a taskbar/dock. It's a sort of framework you can use to build a muscle-memory-friendly window switcher in Linux, similar to pinning windows to the taskbar in Windows -- map Win+1 to terminal, Win+2 to vs code, etc. If the app isn't running then it launches it; else, switch to it. (I wrote this because couldn't find a consistent and foolproof way to do this in Linux, and if you switch window managers you have to start from scratch)

(For better ergonomics, if the keyboard I'm using doesn't have a win/meta key on the right, I rebind right control to win/meta)

[2] is a timestamped log file for you, a human. Set up a cron job to launch it every hour to note what you were working on, or append lines from the terminal whenever you're chewing on a hard problem. Then, use the data to build an accurate picture of what you worked on during the last week, or grep last quarter's log to find out why you decided to use library A instead of library B. I have used this since 2018 and frequently go back to gain insight into the reasons for old decisions.

1: https://gist.github.com/cbd32/cbec9a32b32bd9e93b0d2696c71b5f...

2: https://gist.github.com/cbd32/f1ee2967ec0181b934639c30f4e68f...

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#142
> a bot to automatically answer apartment ads

Isn’t that spamming? The bot answers ads that you haven’t even seen and that you might reject based on description/photos. There could be other people genuinely interested in these ads who will have a harder time contacting the landlord.

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#143
post #26

This little script in my i3 keybindings opens a new terminal with the same working directory as the currently focused terminal, pretty useful for my workflow: bindsym ctrl+$alt+t exec xdotool getactivewindow getwindowpid | xargs ps | grep "alacritty" && (xdotool getactivewindow getwindowpid | xargs pgrep -P | xargs pwdx | cut -d":" -f 2 | xargs alacritty --working-directory ) || WINIT_X11_SCALE_FACTOR=1 alacritty htt…

Alacritty has this function built-in, just define `SpawnNewInstance` in the config file:

    key_bindings:
        - { key: T,   mods: Control|Shift, action: SpawnNewInstance }

https://wiki.archlinux.org/title/Alacritty#Spawn_new_instanc...

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#144
This tiny script keeps my gmail inbox clean and manageable.

It auto-archives any emails older than 2 days (you can change this obviously) unless they're starred - this changes my email experience in two ways:

1) My email inbox ONLY has emails that are either new or that I decided were relevant. I have two days to notice this.

2) When I'm scanning my email, if I see something important that I don't have time to deal with, I can star it and keep moving and know that it'll still be visible and in a manageable-size queue later.

When I travel off-grid it is a bit of a pain since I have to go through a lot of archives, but that can be addressed by just turning it off.

I also ruthlessly unsubscribe to things I've stopped reading to keep everything manageable.

https://github.com/AlexMakiJokela/Gmaid

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#145
post #23

Earlier quoted context omitted.

"going through the iterative process of getting it functioning and fixing bugs was pretty invigorating." Damn right it is! Writing scrapers is definitely the gateway drug of programming. It's such an exciting feeling to step across the boundaries from "passive user at the mercy of the UI" to "I can do anything if I can conceptualise it (and break it up into steps)".

You summed up what dragged me from "Sure I'll learn to program a notepad or todo app so I can learn, but I won't" to "I can do anything if I think about what I want first, then how to get it!"

+1. Writing scrapers and even API calls were the step for me that went from "I'm making my computer do something" to "I'm making my computer do something that's interacting with the outside world on terms that I programmed it to. Whoa! I can do a lot of different variations of this!"

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#146

Honestly, the script/hack/automation I'm still most proud of is from around 1983, when I was 12 years old, for my Commodore 64. Back then, all computer communications were over the phone line, and in my house, we only had one line, so I spent a lot of late nights, dialing into BBSs, often not going to sleep until the sun came up. Then, I would get in trouble at school for falling asleep in class. So I came up with a…

that sounds sweet haha

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#147

Most useful script I've ever written, and legitimately how I keep track of everything important in my life: #! /bin/bash function todo { if [ $# -eq 0 ] then vim ~/Dropbox/todo/todo_list.txt else vim "$HOME/Dropbox/todo/todo_list_$1.txt" fi } Sourcing this in my shell means I just have to type... todo To automatically get into my default todo list which is synced to dropbox (and thus accessible everywhere on mobile a…

here's my pull request

$ cat ~/.bash_profile

> alias lstd='ls ~/Dropbox/todo'

> EOF

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#148

This is more in the "hack" category, but here is a solution for bookmarking directories[1] that I am quite fond of: mkdir ~/.marks/ export CDPATH=.:~/.marks/ function mark { ln -sr "$(pwd)" ~/.marks/"$1"; } Then: mark @name # add bookmark called @name for the current directory cd @name # jump to the bookmarked location cd @ # list all available bookmarks It can list bookmarks, auto-complete, jump to sub-directories w…

You might be interested in hash in zsh.

https://til.hashrocket.com/posts/xsavbhlrz4-shortcuts-with-h...

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#149
post #122

A useful hack I've implemented in several projects is to accept the stored password hash as a valid password. It is generally possible to impersonate a user but there are always subtle differences in the way those sessions work. Accepting the hash lets people with database access perform a real login if needed.

> Accepting the hash lets people with database access perform a real login if needed.

... and if anyone managed to say do an SQL injection and retrieve said hashes, then that then would give them access to your users accounts, right?

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#150
I have a Python script, called t.py and a bash alias "t" that calls it. I use it for quick navigation in the terminal instead of "cd" and "pushd/popd".

The basic format is: "t So, "t 1" goes to parent directory, faster than "cd .." Then, "t 4" goes to "cd ../../../.." And of course "t" will print out all the options.

"t a" goes to my main development git worktree, while "t b" goes to place I build from.

But the real star is the history. I embedded "`save_t_history`" into my bash prompt. That's another scropt that saves the current directory to a history file, then removes duplicates so staying in the same directory doesn't accumulate. Typing "t h" shows the history back to about 25 unique directories. Typing "t h1" goes to the last directory you were in. "t h5" goes five ago. I be working in tmux in one pane, and then jump to another and type "t h0" to bring it to the same directory.

This is basically my bread and butter for getting around.

I would post the code, but a.) it's on a work computer so technically property of my company and b.) it's a mess so I'd recommend others just build their own version.

A hint to get started is that the "t" alias is an alias for "cd `python3 /opt/t.py`"

Post reply on HN