Month: April 2022

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

Copyright © 2024 the möbius trip

Theme by Anders NorenUp ↑