On ES6 Promises - Running parallely vs sequentially

If you’re new to JavaScript promises then go through this article JavaScript Promises: an Introduction first.

ES6 Promise basics (optional)

A promise is declared as

const taskPromise = new Promise((resolve, reject) => {
	// Do asynchronous task (aka executor)
	
	// if(success) resolve()
	// else reject()
});

As soon as you declare a Promise, the executor is executed before the Promise constructor even returns the created object. For example: Try it yourself

Read more

JS Event Loop

It’s an integral part of understanding how JS works under the hood. Core runtime JS framework consists of: Runtime Stack, WebAPI, Task Queue

1. Initial Program State: Currently executing function is in stack

Read more

Docker basic commands

Docker creates lightweight unique virtual machine, called containers, on your machine. These containers differ from the tradition VM like VirtualBox in a way that all containers shares the same host operating system instead of each virtual machine having it’s own operating system.

A container is running instance of docker image.

Task Command
List all containers docker ps -a
List all containers’ ID docker ps -a -q
List all active containers’ name docker inspect -f $(docker ps -q)
List all docker images on current machine docker images
List all docker images ID docker images -q
List all docker volumes docker volume ls
Stop all containers docker stop $(docker ps -a -q)
Delete all dangling volumes docker volume rm $(docker volume ls -f dangling=true -q)
Delete all volumes docker volume rm $(docker volume ls -q)
Delete all docker containers docker rm $(docker ps -a -q)
Delete all dangling images docker rmi $(docker images -f dangling=true -q)
Delete all docker images docker rmi $(docker images -q)
Show docker stats with Container names instead of ID docker stats $(docker ps –format={{.Names}})
Copy all files in src directory to dest directory docker cp /Users/host/src/. cont1:/home/container/dest
Create new src directory in dest directory docker cp /Users/host/src cont1:/home/container/dest
Delete all empty directories find . -type d -depth -print| xargs rmdir
find . -type d -empty | xargs rmdir
Create volume if not exists docker volume inspect service1-db \|\| docker volume create --name service1-db
Read more

Hello Big Data

I’ve a big news to share today. After a successful and rewardful journey with OSIsoft, I’ve moved to Silicon Valley. I had great opportunities to learn and grow at OSI and believe that it’s a unique committed organization with its people being a huge asset.

A quick highlight of my time at OSIsoft

Read more

Clone an Object with Closures

Background: Object with closure properties

Closure properties can be thought of as a non-persistent property e.g. a web-page with thumbnail of cars and user selects a car with mouse click. Let’s say we have a isSelected closure property.

Read more

JavaScript Data Type Visualizer

JavaScript is a powerful but infamous language. Why JS is notorious [link: Wat]. Personally, I find data types confusing for someone coming from C#, Java world.

I build a small utility to visualize relationship between different data types and their prototype chain.
JavaScript Type Visualizer: jstype.heroku.com

Read more

First work anniversary

This June, I completed my first year at OSIsoft and it’s been a remarkable experience so far. For the past one year, I was not contributing much on my blog rkandhal.com. However, I was working on learning JavaScript, which I now believe is a pretty good language and would be the primary focus of this blog.

It’s time to step back and look what all accomplished in past one year:

Read more

Learning JavaScript

Rules

  1. Focus on basics first. Instead of learning new *.JS framework, learn JavaScript language.
  2. Read books. Internet is great, but not everything written on Internet is correct. I prefer to read online once I am good with fundamentals.
  3. Play with browser developer tools as much as you can.

Recommended books

Read more

Creating JavaScript objects

There are three ways to create objects in Javascript.

Object literal: Easiest and cleanest way to create “one” object. However, Somewhat complex to add functions on prototype.

var foo = { name: "default", age: 25 };

Constructor: Use it if you want to create multiple objects of same type and need more control over the prototype chain.

Read more

Extracting 'n' least significant digits

A simple Javascript helper function to extract 2 least significant digits from a number. E.g.

98314 -> 14,  
4 -> 04,  
1998 -> 98
Read more