Live data from Hacker News

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

news.ycombinator.com

161–170 of 340 posts

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

#161

I have started making bash scripts for converting various backup snapshots from one tool to another. So far I've covered: - Borg to Restic - Borg to Kopia They work quite fine, though Restic and Kopia lack the ability to change the root directory of the backup so if your script extracts to a unique temporary directory for each snapshot then you got some confusing output about no files being cached (Kopia) even though…

Since you have used several backup tools, I wonder which one you recommend.

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

#163
I got annoyed with unlocking my ebike with an app every day, so I created a car key enclosure with a Bluetooth chip to unlock it. So much work! Creating a custom PCB, writing software for the nRF52 chip, learning about BLE, security levels, GATT. Deep sleep and ultra low power usage. I use it every day and am really happy with it.

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

#165
There is a specific small hotel that will remain unnamed, which my partner wanted to book for a long long time. At any given moment if you check the reservations page, it is most likely booked for two years solid. It is famous enough that people book it all the time, but it has lenient cancellation policy of 100% refund if cancelled before 2 weeks. This is not really a problem for them as these vacancies get booked in a matter of hours (as I found out).

I wrote a script on top of Puppeteer that would be called from crontab on my home server, to go to the reservation page, press the buttons to flip through the calendar and extract days with vacancy (the reservation app is an SPA). When there were new vacancies it would send me a message through one of the messaging APIs about new dates available, so I could see if it aligns with our schedule and book immediately from the phone wherever I am.

That actually worked like a charm and I snatched a very convenient reservation after few days.

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

#166
Treat git directories, recursively. Is especially like the fact that I can use it together with git aliases, e.g. I use this at least once a (working) day like `gr -b /path/to/customer/git/repos fap` (--fetch --all --prune).

  #!/usr/bin/env bash

  set -o errexit
  set -o nounset

  usage(){
    printf "[TRACE=...] %s [-b /path/to/clones/root] (%s/w) -- \n" "${0##*/}" "$HOME"
  }

  if [[ -n "${TRACE-}" ]]; then
    set -o xtrace
  fi

  trap 'set +o xtrace' ALRM HUP INT TERM EXIT

  : "${GIT_BASE:=$HOME}"
  while getopts b:h OPT; do
    case "$OPT" in
      b) GIT_BASE="$OPTARG";;
      h) usage; exit 0;;
      *) ;;
    esac
  done
  shift $(( OPTIND - 1 ))

  while read -r REPO; do
    [[ -d "$REPO"/.git ]] || continue
    [[ "$REPO" =~ \.terraform\/modules ]] && continue

    tput setaf 8
    printf "%s … %s\n" "$REPO" "$( git -C "$REPO" config --local --get remote.origin.url )"
    tput sgr0
    if [[ $# -eq 0 ]]; then
      git -C "$REPO" status -sb
    else
      git -C "$REPO" "$@"
    fi
    printf "\n"
  done 

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

#167
post #161

I have started making bash scripts for converting various backup snapshots from one tool to another. So far I've covered: - Borg to Restic - Borg to Kopia They work quite fine, though Restic and Kopia lack the ability to change the root directory of the backup so if your script extracts to a unique temporary directory for each snapshot then you got some confusing output about no files being cached (Kopia) even though…

Since you have used several backup tools, I wonder which one you recommend.

Definitely Kopia. I was skeptical at first, it's a relatively new tool and not much is known about it (at least on HN) but it's uber-fast and compresses extremely well. Detection of duplicate blocks seems both more aggressive and faster compared to Borg and Restic.

It's honestly a win on all fronts. It can sync to remote places -- which I don't care about as I have a local directory where it does its stuff and I then distribute that with `rclone` to several encrypted cloud accounts -- BUT many people do care so to them it's an even bigger win.

So yeah, I tried Borg and Restic and Kopia and Kopia wins by all accounts: size of backup directory and speed of operation at least.

(One thing I should mention is that Kopia is also very aggressive at eliminating duplicate snapshots and sometimes you might find yourself lacking snapshots for e.g. five days as it happened with me; however, upon very close inspection -- think unpacking the two snapshots before and after that period, and checking diffs, it turned out that I lost nothing, everything I wanted was still there. But, it's a disclaimer one way or another. Plus, its policy for retaining stuff is not like that of e.g. Borg. Make sure to read up a bit on it before using. Again, it never loses data but it has a different opinion on what is "the last 10 hourly snapshots" compared to Borg.)

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

#168

A simple diary script. `$ diary` to create/open a file for today's diary in vim: https://github.com/Aperocky/diaryman/blob/master/diaryman.sh Or try `pip install diarycli`: https://github.com/Aperocky/diarycli , for a pip packaged python version that does the exact same thing. I've actually kept diary and work logs, things I did not know I was capable of.

As someone who wrote the shell script with pretty much the same functionality - check out mkdir with -p flag! :-)

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

#169
Maybe this already exists somewhere and I don't know about it ...

Anyway, when working on feature branches I wanted a quick way to switch to master, pull, switch back and finally rebase.

So I made a little script (https://gist.github.com/lelanthran/6c9bd1125f89e7621364878d1...) that pushes the current branch name onto a stack before switching to a new branch, and allows me to switch back to the topmost branch on the stack.

     xgit master # Switch to master from current 
     git pull
     xgit pop # Switches back to 
     git rebase master
I use this now very frequently; when I need to switch to branches I use `xgit `, because then I can switch back easily using `xgit pop`.

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

#170

There is a specific small hotel that will remain unnamed, which my partner wanted to book for a long long time. At any given moment if you check the reservations page, it is most likely booked for two years solid. It is famous enough that people book it all the time, but it has lenient cancellation policy of 100% refund if cancelled before 2 weeks. This is not really a problem for them as these vacancies get booked i…

Was the hotel in NZ? And do you work on a three headed beast?
Post reply on HN