Tag: javascript

PM2 logrotate

One of the things I forgot when I wrote the PM2 post is that PM2 creates logs. And these logs get very big, very fast!!

The pm2-logrotate takes care of this.

To install pm2-logrotate

$> pm2 install pm2-logrotate

The defaults work perfectly fine. It will retain logs for 30 days and rotate the log every day, each with a max-size of 10 MB.

To change any of these settings –

$> pm2 set pm2-logrotate:max_size 1K (1KB)
$> pm2 set pm2-logrotate:compress true (compress logs when rotated)
$> pm2 set pm2-logrotate:rotateInterval '*/1 * * * *' (force rotate every minute)

Installing nvm and node on Linux

I’m using PM2 for managing all the server processes. So, installing node and nvm (node version manager) is now one of the first things I do during an application server setup.

node and nvm, just like ruby and rvm (ruby version manager) are always installed under the non-root user account.

Continue reading

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

Simplest JavaScript & CSS minifier – YUI Compressor

I was looking for a simple JavaScript / CSS minifier. Essentially, a program which will

  1. minify – remove empty lines
  2. obfuscate – shorten variable names

There are many online tools available of course. Of the new ones, Parcel was the best. However, the resulting files had some extraneous code which I could do without.

Then I remembered about YUI Compressor, which I think is one of the first ones introduced many, many years ago.

Continue reading

hack the dinosaur game in Google Chrome

In Chrome, if the internet goes off for whatever reason, we get this cute dinosaur game where the dino needs to jump over cacti and pterodactyls.

There aren’t any lives. So, every time you hit an obstruction you end up starting from 0 again.

Which is a bit of a pain.

So, I saw this hack which makes you go through any obstructions without dying.

Continue reading

Copyright © 2024 the möbius trip

Theme by Anders NorenUp ↑