Live data from Hacker News

Ask HN: What are some small scripts you use daily?

news.ycombinator.com

21–30 of 59 posts

Re: Ask HN: What are some small scripts you use daily?

#21
- a bat to launch some programs as admin on windows on startup

ahk scripts:

- Easy Window Dragging (KDE style)

- Rocker (click left-right mouse button to go forward in explorer etc, right-left to go back)

- hidedesk (hides desktop icons unless I click on the desktop, sadly a bit buggy)

- some custom script to unify hotkeys for the brightness of my external dell monitor and my laptop screen.

browser fixes:

- some drag to scroll js for greasmonkey

- shortcut for bookmarking to pocket with keyboard only (with tags)

Re: Ask HN: What are some small scripts you use daily?

#23
bash functions:

    # Helper function for running command in each subdirectory under current one.
    function each {
      if [ -z $1 ]; then
        : # If no command is given, then this is a no-op.
      else
        find . -maxdepth 1 -mindepth 1 -not -path '*/\.*' -type d -exec sh -c "(echo {} && cd {} && $* && echo)" \;
      fi
    }
zsh functions:

    # Helper function for navigating tmux sessions
    export WORKSPACE_ROOT=$HOME/workspace
    ws() {
      if [ -z $1 ]; then
        if [ -z $TMUX ]; then
          tmux attach-session
        else
          cd $WORKSPACE_ROOT
        fi
      elif [[ $1 == 'ls' ]]; then
        tmux list-sessions
      else
        tmux attach -t $1 || cd $WORKSPACE_ROOT/$1/src; tmux new-session -s $1
      fi
    }

    # Helper function for running command in each subdirectory under current one.
    each() {
      if [ -z $1 ]; then
        # If no command is given, just exit
      else
        find . -maxdepth 1 -mindepth 1 -not -path '*/\.*' -type d -exec sh -c "(echo {} && cd {} && $* && echo)" \;
      fi
    }

Re: Ask HN: What are some small scripts you use daily?

#24

I have letters like r and b aliased in my bash profile to check for and run a bash script, if it exists, in each project directory (r = ./run.sh, b = ./build.sh). In each of those scripts, I typically have a one liner depending on what the project requires. A simple build one is: #!/usr/bin/env bash make build And run: #!/usr/bin/env bash docker run foo/bar Or maybe: #!/usr/bin/env bash python manage.py runserver I m…

This is brilliant; I think I'll start doing this. One slight modification: name the build and run scripts something that you will never expect to be in that repo (maybe like run-xyz.sh where xyz are my initials, 10 random characters, etc.). Then, the filename can be excluded in a global gitignore file.

Yeah, good points. Maybe putting the script(s) inside a .whatever directory inside the project root like some other dev tools do is worth consideration. What do you think?

Re: Ask HN: What are some small scripts you use daily?

#25
post #5
post #3

Earlier quoted context omitted.

Sharing is caring? :)

Ask and ye shall receive! make-scratch-dir () { local name="$1" local pattern='^[a-z0-9\\-]+$' if [[ "$#" != 1 ]]; then echo "Usage: make-scratch-dir " 1>&2 return 1 elif [[ ! "$name" =~ $pattern ]]; then echo "Invalid name: ${name}" fi local full_path="$HOME/tmp/scratch/$(date +%Y%m%d-%H%M%S)-${name}" mkdir -p "${full_path}" pushd "${full_path}" echo "Now in temp dir: ${full_path}" } The directory change is done via…

I didn't know of pushd, very interesting, may be useful for directory traversal in general.

Re: Ask HN: What are some small scripts you use daily?

#26
This is awk which emits the stream of unique things, as they are seen. it doesn't require sorted input. It runs at the cost of building the obvious hash in memory so can drive you to swap over large inputs, but its portable, does not require post-install s/w typically not on small systems and it delivers outcomes fast.

I use it all the time when I have some UNIX pipe emitting things and I want to "see" the uniques before I do sort | uniq -c type things.

#!/bin/sh awk '{ if (!h[$0]) { print $0; h[$0]=1 } }'

Re: Ask HN: What are some small scripts you use daily?

#27
I'm in sales for a surveying/feedback SaaS co. Before demos I brand the survey/account with the prospect's company's colors & logo. During the demo I send custom branded, inline email surveys to a test gmail account to help my prospect understand the survey respondent POV. I also have to delete that test-survey email every hour so that the next prospect I demo isn't privy to who is exploring us. I often have to do 4-8 demos a day so as you can imagine that got old fast.

I wipe the inbox for my test gmail account every hour at the :45 minute mark using a ruby script. I don't automate the sending because it's part of the education of the prospect.

Re: Ask HN: What are some small scripts you use daily?

#28
I call this blingle. I call it after any long running operation that I want to be notified of. It pops a desktop notification and sends a push message to my phone.

eg: make deploy; blingle

#!/bin/bash

MSG=${@:-"Job complete"}

notify-send "$MSG"

curl -s \

  --form-string "token=TOKEN" \

  --form-string "user=UID" \

  --form-string "message=$MSG" \

  https://api.pushover.net/1/messages.json

Re: Ask HN: What are some small scripts you use daily?

#30
I have a deployment script that is part of my one-click deployment to the customer's webserver. It's kind of a legacy to having really crap interwebs though, as my upload used to be in the 700-900 kbit/sec range, so it strips out anything from the deploy package that isn't absolutely essential to create sort of a delta of changes.

Makes deployments blistering fast now that I've got 30 Megabit/sec up though... :)

Post reply on HN