Posts

Digital signature in Node.js

What is a digital signature? In short it is a piece of data sent by the sender to the receiver to establish the identity of the sender. Upon receiving the data, receiver can identify if the sender is the one it says it is. It is made possible by making use of Asymmetric Cryptography . Sender encrypts some data with the private key, to generate the signature. The signature and public key will be sent to the receiver. Receiver decrypts the signature using the public key and compares the decrypted value, to the expected data (data encrypted by the sender). Both the sender and receiver has to agree beforehand, on what will be the data they would be using. Wiki Link:  Digital Signature Node.js Implementation - Sender const crypto = require('crypto'); const privateKey = `-----BEGIN RSA PRIVATE KEY-----MIICXQIBAAKBgQDCtTEic76GBqUetJ1XXrrWZcxd8vJr2raWRqBjbGpSzLqa3YLvVxVeK49iSlI+5uLX/2WFJdhKAWoqO+03oH4TDSupolzZrwMFSylxGwR5jPmoNHDMS3nnzUkBtdr3NCfq1C34fQV0iUGdlPtJai...

How do I choose between swimming and running?

Image
                      VS  Both swimming and running are excellent forms of exercise. It is very difficult to pick one of the two. People usually do a mix of both or pick one based on their preference or goals. Comparison: Effect - Swimming is a full body exercise. In addition to leg kicking, upper body(arms and shoulders) also needs to work hard to drive forward. Running is more of a lower body exercise. Core needs to be strong to have a good running form. But while running, upper body is less used compared to lower body. Injury - Running is more injury prone. Gravity takes its toll while running. Every step during running, creates a reaction force from the ground which travels up the body and can lead to injuries. Depending on the running speed, the force can be up-to 4G (4 times the body weight). And for the same reason, lots of strength training should go with running. But while swimming, because of the b...

Fun with Docker

Background It has been long since the Docker buzzword has been around. On how it is different from Virtual Machines. On creating/downloading images and running them as containers. But I haven't got any opportunity to get my hands dirty with Docker. I gave it a try once, but had to stop it midway because of other priorities. Recently while travelling in train, I heard a group of guys discussing about Docker. I realized that people use it commonly and I felt bad I don't know it yet. High time to learn it. Learning Docker Docker Image is like the blueprint of a context. The context can be an OS, build environment, development environment, runtime environment or a combination of the above. We can also bundle our code or data, together with the above contexts. Prebuilt images are available in the docker hub. Additionally we can create our own images and push it to the docker hub, which can be used by others. Once we have the image, we need to run the image. A runn...

ASP.Net Core saves me $4 a month!

Image
Background It has been more than 2 years since my website www.codingsoldier.com was conceived. It was created in ASP.Net MVC. Since then the site has evolved a lot technology wise. The website is used as a repository of my studies, as a means to publish my technical thoughts and also a place where I can try out the technologies/areas that I don’t usually get to do as part of my regular office work like full time DevOps or migrating sites to newer technologies without having to convince the management. Technology Migration History Initially created in ASP.Net MVC with SQL server as the database. Site was hosted in IIS in a windows server. It was migrated to Node.Js + Express and later to Node.js + React. Database was MongoDb and site hosted in Node in a windows server. Of late, the site has been migrated to ASP.Net core with SQLite as the Database. Site runs on a Linux instance, with Kestrel as the web server and Nginx as the Reverse Proxy. Migrating to ASP.Net Core...

Investments are not all about Finance!

Image
Why Invest? Often we hear the comment: “Live the present and don’t worry about the future”. Please don’t take anything for granted. The assets that we have now would be gone in the blink of an eye. Unless we plan and put enough effort to the investments, we are going to be in trouble in the future. Peace of mind is a must for an individual to lead a normal life. It is a result of the combination of the present state of mind and a sense of security of the future. Allow me to enlighten you with a simple example. For a moment, think you are millionaire in your late 30’s, with huge amounts of money in your account. You think your future is secure. Let’s say you didn’t invest enough in your health department. You are discovered with a terminal illness, that may have been avoided had you took care of your health early enough. Now all the security is gone. You may have to spend out the money that you had saved. You may not be able to go to work. You mental state goes for a toss. T...

From Callbacks to Promises to AsyncAwait

Image
Single Threaded Node In spite of having a single threaded architecture, Node is not blocked while doing parallel operations. How does Node achieve this ? Even though Node is single threaded, it is event driven and makes use of background workers to complete the tasks. Tasks are pushed off to workers from the main thread. Main thread is not blocked and continues to listen to other requests. When the task is done, the result of the task(if any) is put back to the event loop for further processing which is accomplished by callback. In this write up, I will be discussing on the evolution of callbacks. The way they evolved to Promises and most recently to Async-Await. Event Loop is outside the scope of this topic, for which there are plenty of articles available online. CallBacks As I said before, callbacks are a means by which the background workers intimate the main thread of the completion of the asynchronous task they were performing. Initially when the task was i...

My First Full Marathon

Image
Marathon Thoughts It was the first week of August 2017. My last run was on January 2017 after which I had knee pain and was diagnosed with meniscus strain. So I was mostly on rest since then, in the sense I did no running and very less badminton. I t was towards the end of July when I saw a youtube video of David Goggins . He was a navy seal and he explains how he had to do a 24 hour 100 mile run with shin splits and stress fractures in the last 20 miles of the race. It was appalling to me the way he pushed himself that last 20 miles. I had always dreamt of running a full marathon after having done 5 half marathons. David Goggins was doing 100 miles while a full marathon is just 26.2 miles. Am I not strong enough to do a full marathon? I had thought myself to be a tough person and running the marathon would be a good enough test. So the motivational talk by David Goggins was a good reason, that implanted in me the idea of running the Wipro Chennai Marathon 2017 . Another re...