Live data from Hacker News

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

news.ycombinator.com

21–30 of 340 posts

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

#21

In terms of shell aliases and helper functions, I actually go out of my way to not allow myself any. As a young person, I was on a trip to visit another ISP to learn how a VPN would work between our two companies. Their administrator, a wonderful person with 30 years of experience in the telco-turned-ISP world, had all these incredible aliases on her workstation for managing her fleet. But on the new vendor's system,…

I feel much the same way, and for much the same reason. I do, however, have a largish fleet of aliases that I've built up over the years.

The vast majority of them are simple short forms. For example `tf` for `terraform` and `tfp` for `terraform plan`. My brain just naturally thknks of the full command when using the short form and, because of this, I'm not at a loss if I'm logged in somewhere without my aliases.

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

#22

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…

I've just spent the last few minutes playing with the bookmarks snippet. This is both elegant and immediately useful to me. Thanks for sharing!

Glad it is useful. Just a note of advice - prefix your bookmarks with a symbol that is not used to start directory names (was @ in my case).

This is useful for two things - 1) avoiding clashes with existing directories, 2) having a quick command to list all the bookmarks: cd @

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

#23

So certainly not impressive, and morally ambiguous, but when chatGPT first released, I worked with it to create a python script that crawled The New Yorker sitemaps, found articles with embedded audio versions, downloaded the mp3 by reconstructing the file url using the article ID in the page source, and then renamed the file to match the page title and saved it to a well structured Google Drive directory. Now when I…

"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)".

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

#25
post #17

I actually just opensourced a personal project/tool I've been using often. https://github.com/robswc/docker-essential-aliases When deep diving into containers, I got tired of typing/tabbing out container names and docker formatting lol Nothing revolutionary but it has saved me a ton of combined time.

This seems really nice! Makes me want to build my own with Gum filters, TBH.

is it this?

https://github.com/charmbracelet/gum

If so, you just introduced me to an incredible looking project ahah.

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

#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
https://github.com/pkos98/Dotfiles/blob/master/config/i3/con...

I probably scratched some parts together from the internet a couple of years ago.

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

#29
I've created a tool for replaying HTTP archives:

https://github.com/Tade0/emergency-poncho

There are many like it, but this one is mine.

Useful when you're a front-end developer and the backend app is not easily deployable locally and the test environment is down.

Also with it you can make a blazing-fast, browsable snapshot of JIRA.

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

#30
I used to work with a cardiac electrophysiology group. The software used for acquisition and analysis was quite old, written for DOS back in the mid-1990s. At acquisition, files were named like YYMMDDXX.0nn where XX stands for the setup where the acquisition took place, and the nn in the end was the ordinal number of each file. These were encrypted binary files, so we were completely dependent on the original software.

At analysis, files were containing multiple sweeps were averaged to reduce random noise (YYMMDDXX.Ann files), then these files were exported as a CSV-like series of time-voltage paires (YYMMDDXX.Tnn files). Tables containing the calculated variables were also generated, and exported (YYMMDD.Nnn files). The fun part is that these files had to be named MANUALLY. Each and every one of them. I can't stress hard enough how repetitive this got... We generated double-digit number of files every day, and analyzing each file thorougly required around 30-50 keypresses to move around in the menu and to name the files. Lucky for me, no mouse use was required, and keypresses could at least be automated.

I used DOSBox on Debian to do the analysis, and I ended up creating a bash script that could automatically analyze whole folders of these files in a few minutes. To achieve this, I generated xmacro files that would be played back while the DOSBox window was opened. Opening the file was also put in these xmacro files. The generation of the files was wrapped inside a bash script that kept track both of the files in the folder and of the files generated by the analysis. If a file was supposed to be there but some something broke inside DOSBox, it would just stop playing the macro for the next file, so it could be restarted relatively easily.

A few months later, I met the guy who wrote the software for our team, and asked him if he could write us a script to unpack the binaries into CSVs. From there, I could come up with my own completely automated solution for analysis, and everything was much-much faster. I also showed him the macro-monster I created. I'm still not sure if he was amazed or he just thought that I was impatient.

Post reply on HN