Live data from Hacker News

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

news.ycombinator.com

11–20 of 340 posts

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

#11
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, a fresh install of the same OS left her almost unable to perform.

My jobs have all had the same opportunity for the same experience, and I've tried to leave it alone. I spend maybe 2/3 of my time logged into someone else's server, and I don't doubt myself, even knowing fully well it's a personal preference above all.

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

#12
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'm approaching your threshold of "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"

Can you share a repo with your "custom right-click menus and Emacs-style keychords" to save me some time?

Love hacker news!

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

#13

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…

Pretty impressive to be able to create such a script when you haven't programmed before.

I used to freelance when I learnt to code in college and I wrote many such small automation scripts for quite a few people. Looks like the AI is already taking away some jobs ;)

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

#14

  drag () {
        dragon --and-exit --on-top "$@"
  }
I write a lot of extremely simple but handy shell functions.

This one lets me drag/and drop things out of a terminal session (kind of) into applications with https://github.com/mwh/dragon and i use it way too often!

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

#15
I have a neat Hacker News scraping setup that I'm really pleased with.

The problem: I want to know when content from one of my sites is submitted to Hacker News, and keep track of the points and comments over time. I also want to be alerted when it happens.

Solution: https://github.com/simonw/scrape-hacker-news-by-domain/

This repo does a LOT of things.

It's an implementation of my Git scraping pattern - https://simonwillison.net/2020/Oct/9/git-scraping/ - in that it runs a script once an hour to check for more content.

It scrapes https://news.ycombinator.com/from?site=simonwillison.net (scraping the HTML because this particular feature isn't supported by the Hacker News API) using shot-scraper - a tool I built for command-line browser automation: https://shot-scraper.datasette.io/

The scraper works by running this JavaScript against the page and recording the resulting JSON to the Git repository: https://github.com/simonw/scrape-hacker-news-by-domain/blob/...

That solves the "monitor and record any changes" bit.

But... I want alerts when my content shows up.

I solve that using three more tools I built: https://datasette.io/ and https://datasette.io/plugins/datasette-atom and https://datasette.cloud/

This script here runs to push the latest scraped JSON to my SQLite database hosted using my in-development SaaS platform, Datasette Cloud: https://github.com/simonw/scrape-hacker-news-by-domain/blob/...

I defined this SQL view https://simon.datasette.cloud/data/hacker_news_posts_atom which shows the latest data in the format required by the datasette-atom plugin.

Which means I can subscribe to the resulting Atom feed (add .atom to that URL) in NetNewsWire and get alerted when my content shows up on Hacker News!

I wrote a bit more about how this all works here: https://simonwillison.net/2022/Dec/2/datasette-write-api/

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

#16

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!

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

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

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

#18
I work at a database heavy company as an infra engineer. From time to time we get requests from devs or customer success to run a query on all customer databases to see or certain assertions hold (e.g. If the latest update fixed a problem or estimate the impact of a change).

To automate this process, we have some ansible playbook to automate most of it: give it a query and you'll get a bunch of files with the results.

While useful, the setup and cleanup can get tidious. So, I whipped up a little shell script that creates a temporary directory and symlink it to a location somewhere in $XDG_STATE_HOME. I created a few subcommands to create the directory structure, add a query, run the query, aggregate results and destroy the state. This keeps things simple for me. Even if I forget to cleanup after myself, a reboot will make sure nothing is left behind. The symlink trick to xdg state home helps me a lot to track my state, while I work on a certain problem. It allows me to easily handle multiple request at the same time, when necessary.

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

#19
I write a ton of CSS and could not find a command line stylesheet checker. I did find the NuHTML checker from W3C, which also checks the file’s CSS: https://github.com/validator/validator/releases/tag/20.6.30

AFAIK it doesn’t have an option to check a standalone CSS file.

I wrote a script to insert a CSS file into a dummy one-line HTML file, so that I can pass a CSS file to the script, and when errors are generated from the CSS, they are given using the correct line number.

I have written many more complex and perhaps more interesting Scripps, but this is the one I am, by far the most proud of.

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

#20
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.
Post reply on HN