Live data from Hacker News

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

news.ycombinator.com

31–40 of 340 posts

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

#32
post #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)".

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

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

#33
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…

https://codeberg.org/dnkl/foot/wiki#user-content-spawning-ne...

Maybe something like this could do the same? But could also rely on that specific terminal emulator

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

#34
post #7

All of my favorite things are little AutoHotkey shortcuts. I have several that basically just execute a Regex replace on whatever text is currently highlighted. It's ridiculously convenient to just have those functions ready to go any time. But I started accumulating so many of them, it got to be a problem just remembering all the ones I had and how to trigger them. I had to start finding new ways of keeping them all…

I did something similar but using Autoit

I used the dialog box to create little 'applications' such as listing all the printers in the building (along with description) and allowing the staff to choose the printers they wanted to use (back around 2005 ish)

I had loads of these little scripts for staff to use - and some server side stuff (mainly windows) such as generating daily configs and collecting all the logs and looking for differences

I pretty much automated half my job, allowing me to do more interesting stuff

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

#35

    # Sort list by most common terms
    alias sorn='sort | uniq -c | sort -n'
    # Most common IP addresses:
    $ cat access_log | awk '{ print $2 }' | sorn

    # Last 30 modified files.
    function new() {
        ls -lat "$@" | head -30 ;
    }
    # I just downloaded something, where is it?
    $ new ~/Downloads

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

#36
Years ago, when I was receiving a very high volume of a predictable and pretty malicious looking spam, I wrote an ugly Python script to report the unwanted mail to the originating network owner. It worked well at the time and I think definitely made the lives of spammers more difficult. The volume of spam I receive has been much lower since then.

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

#37
I keep thinking about publishing it, but I have a script which takes a Raspberry Pi SD card image, extracts it, modifies it (mostly by automatically editing cmdline.txt and fstab) to be suitable for network booting, and then pushes it to my netboot server.

This way I can quickly boot any Pi in my house (and there are quite a few now) to any arbitrary OS image just by renaming a symlink on the server.

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

#39
I have a script listed in package.json for my site. Often I don't really care about commit messages here, not because I don't find them valuable, but because so often its from editing and publishing articles. I don't really want to think of messages all the time so often end up typing random crap.

I use this now:

    import { execSync } from 'child_process';

    execSync('git add -A');

    const modifiedFiles = execSync('git status --porcelain')
        .toString()
        .trim()
        .split('\n')
        .map((line) => line.replace(/^\s*[MADRCU?!]{1,2}\s+/, ''));

    const fileList = modifiedFiles.join(', ');
    const commitMessage = `Change: ${fileList}`;

    execSync(`git commit -am '${commitMessage}'`);


    
    "changes:summary": "tsx ./tools/changes-summary.ts",

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

#40
Rewrote grabbing car sales ads from Selenium to Playwright and exported the data of a specific search to a spresdsheet. Could easily derive trend lines for price over mileage and price over age and since there is a nice unified JSON somewhere in each page with all the features per car, I could see if a more expensive one was worth it due to more features, or not. Served me well when buying but also selling a car.
Post reply on HN