Fix input on Heroku's rails console

If you end up pasting lots of lines into a rails console on Heroku (or else where), you might get issues with the lines "bleeding" into each other.

Next time this happens, try disabling multiline:

$ heroku run 'bundle exec rails console -- --nomultiline'

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


Create Element with attributes in one line

We normally use this kind of code to create a HTML element with JS:

const a = document.createElement('a')
a.setAttribute('class', 'foo bar')
a.setAttribute('id', 'id')
a.setAttribute('innerHTML', 'Hello World!')
a.setAttribute('href', '')

Or some similar ways. But setting each attribute one by one is tedious!

We can do this in a single line if we want:

Object.assign(document.createElement('a'), {
  id: 'id',
  class: 'whatever class',
  href: '',
  innerHTML: 'This is a link'

One more way to mess up with your JS codebase!


Change Ruby version for single command with rbenv

You can switch Ruby version temporarily with rbenv local

But it'd need to be switched back after you're done. Specially for a single command it's kind of pain. In those cases, you can use RBENV_VERSION env variable.

RBENV_VERSION=2.6.3 ruby -v

This might be useful in a shell script or so.


Go through a file Git history (GUI)

$ gitk --follow file


Reset Postgres table sequence after DELETE

When deleting recent records from a table, you can reset it's sequence counter if auto-increment field continuity is important to you. Consider actions on the following table, users: ``` select max(id) from users;

+-----+ | max | +-----+ | 896 | +-----+ 1 rows in set (0.03 sec) Then, some delete action against most recent rows: delete from users where created_at > timestamp 'yesterday';

96 rows in set (0.15 sec) `` The next auto-increment value foridwould be 897 on the next insert. Use the following command to reduce the sequence value for theusers` table by 96.

select setval('users_id_seq',(select max(id) from users));

| setval |
| 800    |
1 rows in set (0.04 sec)


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


PostgreSQL UPDATE Join

This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;

updating subscription_missions.giftbox_type with rewards.gift_box_type through mission_rewards table (tested on 300k records, crazy level fast)

        subscription_missions sm
        giftbox_type = r.gift_box_type
        mission_rewards mr,
        rewards r
        sm.giftbox_type IS NULL
        AND = mr.subscription_mission_id
        AND mr.reward_id =;