Author: abhijit

Promises and Async / Await

I always struggle with understanding how async / await works.

So, I decided to write the code down and refer to this rather than trying to think it though every time!

I’ll start with the simple XMLHttpRequest

var req = new XMLHttpRequest();

req.onreadystatechange = function () {

  req.onload = function () {
    if (req.status == 200) {
      console.info('success')
      var arr = JSON.parse(req.responseText);
      populatePage(arr);
    }
    else {
      console.info('error')
    }
  }
}

req.open('GET', baseURL, true);
req.send();

Here, I’m hitting baseURL (defined outside of this code) and doing something with the received array with the populatePage function outside as well.

I wrote it like this so that I don’t add other code which is not relevant to the call.

Continue reading

Hide commands from bash history temporarily

There’s been a number of times I’ve wanted to not include some commands that I type into bash from being added to bash_history

The most convenient is to start a subshell by typing in bash again. This ensures that the commands in the subshell don’t get added to the history.

There are additional ways of achieving this as well.

Continue reading

Export SQLite table to CSV

A number of times I’ve needed to export a specific table from an SQLite database to a CSV file.

The sqlite program itself gives a very clean interface for this.

sqlite3 -header -csv database.sqlite "SELECT * FROM artists;" > ./artists.csv

Conversely, if I need do this from the SQLite prompt, I need to do it slightly differently.

Continue reading

mesg: ttyname failed: Inappropriate ioctl for device

While running a cron job in Linux, I sometimes get this error and I had been struggling to solve this until I came across this post.

Although that particular post mentions the cause being Vagrant, mine was due to a cron job.

First the solution …

Modify .profile under home folder

Open ~/.profile

Replace the following line –

mesg n || true

with

tty -s && mesg n

The reason for this is given very well in the post linked above.

Continue reading

Postgres DB migration error due to replication

We got a weird error today when running the latest migration on a production Postgres DB.

cannot update table "schema_info" because it does not have a replica identity and publishes updates

The table schema_info is created when we run ruby Sequel migrations. This table stores just the version number of the latest migration applied under a column called version.

We had set up a replica database some time ago and it looked like the issue was because of this.

Continue reading

Copyright © 2025 the möbius trip

Theme by Anders NorenUp ↑