Jun 18, 2018

JavaScript Callback

javaScript is the new software edge. It has a vivd scope in the mobile first, IoT first and AI first world. Programming paradigm has been shifted from sequential model to event based model. And javaScript tops in it. The fundamental most important part of javaScript is function express and callback.

Function expression
Unlike C or Java a function can be assigned to a variable in javaScript
function sum ( a, b ){
  return a+b;
}
is same as
var sum = function ( a, b ) {
  return a+b;
};
Function sum can be defined in any of the above ways. The second one is called function expression. The advantage of function expression is that since the function is assigned to a variable it can be passed as a parameter to another function.!!!

See the following example.
var sum = function ( a, b ) {
  return a + b;
};
var mul = function (a, b ){
  return a * b;
};

execute ( a, b, method ){
  return method (a, b);
}

console.log ( execute ( 3, 4, sum ) ); // prints 7
console.log ( execute ( 3, 4, mul ) ); // prints 12
In the above sample a method sum or mul is passed to another method execute. It may be a little difficult to understand.

Lets see another example:
greet ( name, cb ) {
  /** method implementations : if any **/
  cb ( 'Hello '+ name );
}

greet (  'Arun', function (msg){
  console.log ( msg );
});
The msg will be 'Hello Arun'. The idea is a callback is passed along with the function call. Inside the function after execution of method implementations, the call back is executed. We can use the return message inside our callback function.
Once this concept is clear,  it is very easy to expertise javaScript. 

A better way to pin point the delivery address.

One problem that is faced by ekart (Flipkart, Amazon, etc.) customers and the delivery people is to find the exact address of the customer. Especially in villages it is a big problem. Delivery people finds it difficult to track the home location. A solution is to provide a QR code of the exact delivery address (latitude, longitude) in the courier.Some updates need to be made in the purchase process. Along with the option for delivery address a map should also be provided on which the buyer can pin point the address. Google/Openstreet maps APIs are available to develop. For QR code also APIs are available. It is easy to integrate this idea to the purchase steps.

I tried to generate QR code of a random location manually. For that,
  • Go to maps.google.com. Pin point a house >  right click and select 'what is here?' option. A box pops up on the bottom of the page as shown.



  • Click  the number at the bottom which is the latitude and longitude of the address.
  • Now click Share on left side menu and copy the link.


  • I selected this location: https://goo.gl/maps/n52YtaxnSyG2
  • To create a QR code for this location go to https://www.qr-code-generator.com/ and select URL option.
  • Paste the location link and click on generate the QR code.
  • That is it then it, now it just need to be printed on the courier. The full address can also be put on the QR code.

This is the QR code that I generated manually.
QR code can be decoded with a QR code scanner. Many apps are there in Playstore/Appstore. Some mobile phones has QR code scanner integrated to the camera app.

Jun 9, 2018

Cryptocurrency — the future of economy

Cryptocurrency a word we often hear in today's economic world. What is it? How is it evolved and what advantages it has over normal currencies.

Before diving into the details of cryptocurrency lets take a look at the economy that we live in. The currency that we use in our daily life is managed, printed and distributed by the governments through various banks. What is the problem with that ? Bank transactions are not open. Only the entities (person or organisations) involved and the bank has access to transaction details. Possibility of corruption is high there. Plenty of examples we have. Take the PNB case for instance. Illegal money transfer in huge quantities can’t be facilitated without the help from inside the banks. Massive financial leaks shakes the economy of a country.

Cryptocurrency is a solution. For a transparent economy what we need is a transparent ledger. Cryptocurrency is founded on this principle. The ledger is transparent, distributed and tamper proof.




Litecoin, Ethereum, Bitcoin, Monerio, Ripple, etc. are some cryptocurrencies available in the market. Take bitcoin for instance. One of the main technology (among may other) used to realize bitcoin is Blockchain.

Blockchain: Each bitcoin transaction is entered into a publicly distributed ledger. And all the transactions are verified and authenticated by cryptographic algorithms. The Ledger is distributed and is synchronized on multiple servers spread geographically apart.

The ledger which has enough entries (transactions) is called a block. It is then passed through an SHA algorithm.



SHA ( hash of previous block + current block + n ) = 0000000…0001010101101010…..0010101100101011

where ‘n’ is a big number which makes the first specific number of the result as zeros. The only way to find ‘n’ is sequentially checking one by one. This is the job of miners. They uses their IT infrastructure to find out this number and attach the total hash to the block. For their work they will get paid by some fraction of bitcoins from the issuers involved in the transactions on that block.


This block is then attached to the existing distributed and solved chain of blocks, hence the name blockchain. Once attached the transactions in that block in finished. The figure below gives a better idea on how blockchain is realised.

Since it is a distributed ledger anyone ( with proper access ) can trace back to all of the transactions that took place since inception. The cryptographic signatures makes the data tamper proof. Each hash calculation involved previous hash and therefore tampering this chain of information is impractical.

Cryptocurrency is the future. We are on the initial stages of an entirely new kind of economy. Latest trends in this space like IOTA confirms a bright future for it. Though with restrictions many countries legalised cryptocurrencies.

For Web Developer

  open -a "Google Chrome" --args --disable-web-security