Angry Docker Purge

If you receive No Space left error on Docker this the brute force solution:

It would stop and delete ALL containers, images and volumes.

docker stop $(docker ps -aq); docker rm $(docker ps -aq); docker volume rm $(docker volume ls -qf dangling=true);docker system prune -af


Run same command on different input/inputs

If you have to run the same command repetitively over different input/inputs.

Example input:



pbpaste | xargs -I id docker image rm id

Note: pbpaste is clipboard paste command for Mac, would be different for operating systems.


Check for IKEA item availability

A bit of a hack, but we want to be notified if an item becomes available at IKEA.

This is just a shell script that should work on any *NIX that has curl installed.

This is how their API response looks like (replace th with your country code):

There are only two stores in Thailand, both of which are close enough to the Oozou office, we only care that it's available in one of those stores.

#!/usr/bin/env bash


# This is the string that we want to see changed

while true; do
  # Get the API response and return as string
  text=$(curl -s "$url")

  # Get a count of how many times the substring matches
  count=`grep -o "$string" <<< "$text" | wc -l`

  # If less than 2, then it's available!
  if (( $count < 2 )); then
    echo "AVAILABLE, yay.";
    # Notify us via Slack
    curl -X POST --data-urlencode "payload={\"channel\": \"…\", \"username\": \"ikea\", \"text\": \"Item $1 is now available at IKEA.\", \"icon_emoji\": \":shooping_bags:\"}"…
    # If not available, sleep for 30s
    echo "$1 not in stock"
    sleep 30

Pass in your item ID to start:

$ ./ S99067497


Go through a file Git history (GUI)

$ gitk --follow file


Kill unresponsive SSH session

Occasionally an SSH session may become unresponsive. If I put my laptop to sleep this happens fairly often. Rather than killing the tab you can use SSH Escape Characters to kill the session

$ ~.

To view all escape characters check man ssh and search for ESCAPE CHARACTERS $ /ESCAPE CHARACTERS


Kill rails that got stuck

I'd like to kill rails running w/specific port. (My laptop running several rails servers. )

kill -9 $(lsof -i :3000|grep ruby|head -1|awk '{print $2}')


Using Git's aliases feature

Git allows you to create aliases internally through the config. Your global config should be located here ~/.gitconfig

  aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort
  count = shortlog -sn
  l = log
  co = checkout
  ca = commit -C HEAD --amend
  c  = commit
  cm = commit -m
  a  = add
  s  = status
  b  = branch
  p  = push
  mt = mergetool
  dt = difftool
  o  = origin
  rc = rebase --continue
  rs = rebase --skip
  pd  = !git checkout develop && git pull origin develop && git branch --merged | grep -v '*' | grep -v 'master' | xargs git branch -d && git fetch --prune origin
  pm  = !git checkout master && git pull origin master && git branch --merged | grep -v '*' | grep -v 'develop' | xargs git branch -d && git fetch --prune origin
  pr = pull-request -c -m

Most are self explanatory...

git pd (prune develop) - checks out to develop, fetches latest changes, deletes all stale branches except develop (will delete master too)

git pm (prune master) - does the same as prune develop for master


See deleted files in previous commits [git]

$ git log --diff-filter=D --summary --oneline


Find a branch based on a commit

$ git log --oneline --all --grep=pretty

c198bb715 Make default expired description logic pretty

$ git branch --contains c198bb715

* deploy/staging


Check if command exists with shell script

if ! type gem > /dev/null; then
  echo 'gem command not found.'


Delete merged git branches

Handy git command for deleting all local git branches that already merged git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d


Watch CI status on Github

When you have Github's hub installed, you can get the ci-status of your current branch like this:

$ hub ci-status

If you install watch (e.g. brew install watch) you can continuously see the state:

$ watch hub ci-status


Bash aliases and magic

I have a seperate file in my user folder named ~/.aliases. I use this to store all of my bash aliases. I use aliases a lot and add new ones regularly so I created a bash function to add new aliases on the fly.

addalias() {
  echo 'alias '$1'="'$2'"' >> ~/.aliases
  source ~/.aliases

Now you can add an alias from the terminal which will be available to the current session and all new sessions... shell $ addalias foo 'echo "bar"'

If I find myself using commands over and over I will create aliases shell alias g='git' alias b='bundle' alias be='bundle exec' alias bu='bundle update' alias r='bin/rails' alias rr='bin/rails routes' alias migration='bin/rails generate migration' alias migrate='bin/rails db:migrate; bin/rails db:migrate RAILS_ENV=test' alias rollback="rake db:rollback; RAILS_ENV=test rake db:rollback" alias push='git push origin HEAD' alias pr='git pull-request -c -m' alias ppr="git push origin HEAD && git pull-request -m" alias pulls='git browse -- pulls' alias prs='git pr list' pull() { git browse -- pull/'$1' } alias la='ls -a' alias ll='ls -al'


Force push previous commit to repo

If you push some code and want to force push a previous commit you can do so with shell git push origin +commit_sha^:branch_name

Where git interprets sha^ as the parent of sha and + as a forced non-fastforward push.

You can also use HEAD^ where ^ is the parent of HEAD so HEAD^^^ would push the commit 3 commits before the current commit. e.g. shell git push origin +HEAD^^^:feature/i_did_an_oopsie


Get current git branch name

git rev-parse --abbrev-ref HEAD


Back up a file with same name + prefix

$ cp todo.txt !#:1.bak
cp todo.txt todo.txt.bak

NOTE: Actually you can use !#:1 in every command 'cause that's last argument passed to a command.

UPDATED: Now it works with zsh


Delete already-merged branchs in Git

$ git branch --merged | egrep -v 'master|develop' | xargs -n 1 git branch -d

You can safelist more branches in egrep -v 'master|develop|foo|bar'


Diff a local file with remote version in Git

Easily run the below command and get a diff version from the remote

$ git diff origin/master -- [local-path]


Remove unwanted commit from your branch

git rebase -p --onto SHA^ SHA


Send messages to Slack using cURL

Slack allows you to send messages via the Webhooks service

Create a webhook for any channel and then you can send notification using curl.

$ curl -X POST -H 'Content-type: application/json' --data '{"text": "Something important"}'


List directory structure except one or more dirs

Ever wanted to display the structure of the current directory except or two directories?

#NPM or yarn project
tree -I node_modules

# Elixir Mix project
tree -I 'deps|test'


Use `host` to get more information about domains

You might be using dig to find out A/CNAME/MX etc records of a domain from DNS servers. But if you just want to get a quick overview, use host:

$ host has address has address has address mail is handled by 1 mail is handled by 5 mail is handled by 5 mail is handled by 10 mail is handled by 10


Zsh function to list file tree

Add this to your .zshrc

lst() {
    if [ "$1" != "" ] # or better, if [ -n "$1" ]
        ls -R $1 | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
        ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

Then you can run

$ lst spec

It should list all sub directory in spec folder in tree format.

You could change spec to any path you want.

or just use tree



Create your own git commands (aliases)

Ever wanted to shorten a git command? You can go with shell alilas for sure but you have to always include context so that you don't forget what each ailas stands for but you can define your own commands in git using aliases.

git config --global alias.  

For example; I'm too lazy to type git status so I want to shorten this to git s

git config --global alias.s status

And here we go now you can just type git s and get the status of current repository.


Amazon AWS S3 CLI copy with set perms

Open term (or equivalent) and paste the following:

S3 copy

  • to upload a world-readable file:
aws s3 cp source.file s3://bucket/path/dest.file --acl public-read

Options for --acl parameters are:

  • private - visibility to owner only
  • public-read - readable by all
  • public-read-write - readable and writable by all

Restore a deleted file in Git

# Find in which commit it's been deleted
$ git rev-list -n 1 HEAD -- 
# Restore it back
$ git checkout 4058ef780d2f6c4c6d57cfd7fd4ebe14c9dc28b3^ -- 


make a pr from command line using hub

install hub first with brew: brew install hub then use a simple command, like at the example below: hub pull-request -m "best pr ever" -b oozou:develop -h feature/awesome-improvements

or even smarter:

hub pull-request -m "best pr ever" -b oozou:develop -h $(git rev-parse --abbrev-ref HEAD)

for more detailed info how to make pull requests see at hub pull-request --help


Shallow clone a old repo

If you don't need the full git history for a repo you will be working on you can supply a clone depth to only clone x revisions of the repo.

git clone --depth=1