Wednesday, November 8, 2017

Developing Hello World applicafion for IBM Bluemix and IBM Node SDK

Image result for ibm bluemixImage result for node js


IBM Bluemix : For those of you who have not heard about IBM Bluemix, IBM Bluemix is the latest PAAS environment from IBM, which is based on open technologies like CloudFoundry, supporting various development languages and service. 

Before you go further reading a bit on IBM Bluemix would help : Bluemix Introduction
Bluemix supports lot of popular runtimes including Node.js which makes it platform of choice for all the recent deployements, customer demos etc. by my team. If you do not have a Bluemix account, you can register here : Registration for Bluemix


Node.js : Node.js uses the popular javascript language for server-side business applications, instead of the conventional client-side logic. Its based on an event-driven model, so you basically develop functions which can executed on occurrence of specific events. A great place to get started with Node.js and download all installers is the home page https://nodejs.org/en/. Download and install the version which matches your OS.


Lets get on with Developing a Hello World Application using IBM SDK Node.js and IBM Bluemix.

High Level Architecture of Hello World Application





Steps
  1.  You can use 2 ways to create Skelton Node js application and deploy it to Bluemix.
     
  2.   First way is to do it directly from IBM Bluemix Web Dashboard. Navigate to IBM Bluemix from your browser (https://console.bluemix.net)

  3. From Dashboard click on Create button, under apps section.

     
  4.  Select SDK for Node.js from the section Cloud Foundry Apps

  5.  Enter the AppName and you can leave rest of the boxes as default. Kindly note Host name would be the public route to your application.

  6.  That is it, our boilerplate Node application is ready and can be downloaded for any modifications.
  7. Second way is to create a sample node application locally and push it to bluemix.

  8.  Use the npm init command to create the node project skelton.

  9. Next install express dependency locally in your project using the command npm install express
  10. Create your main javascript file, named app.js.
    This can be done through command
    touch app.js.
  11. Content of your app.js could be
    var express = require('express');
    var app = express();
    app.get('/', function(req, res){
                    res.send('Hello World');
    });
    app.listen(8080);
    console.log("Sample Node application is now running on port 8080");

  12. You can test this application locally by running it on local node server, using the command
    node app.js


  13. You can open the application in browser through url : http://localhost:8080/


  14. 1.       Now let’s push this app to our Bluemix server, you can use below commands
                      a.       bluemix login  -o user@ibm.com -s dev -sso
    b.       Get the one time code and paste in back for authentication to proceed.
    c.       bluemix app push bluemixnodesampleapplication



     



Tuesday, August 8, 2017

Solving Commodity Price Prediction puzzle using Collaborative Cognition

Trading of commodities is an extremely complicated and equally well researched area. One reason why it is so popular is that Procurement teams are always under pressure to bring down procurement costs and success in solving the trading puzzle could translate directly into earned or saved dollars. Very recently, my team was thrown the challenge for coming up with solution for a specific commodity price prediction. The problem made us to explore innovative solutions in areas of machine learning, agent based modelling, cognitive cognition and last but not the least economics.

Demand and Supply of a Commodity : You would find tonnes of complicated definitions for demand, but in simple words Demand is the quantity people want to buy and supply is the quantity produced by manufacturers which they want to sell in market. Price is where these two graphs intersect each other. How easy is to infer that any increase in supply would cause prices to drop and any increase in demand would cause them to price. This is what the classic economics teaches us.

Now we would not need Machine Learning models and Cognitive technologies if situation on ground was that simple. The actual traded amount may be entirely different from demand and supply intersection point. In a supply strong economy (supply surplus), which is often characterized by falling prices, suppliers may decide to cut-down on the quantity supplied, exactly what OPEC nation does when price of Crude nosedive, they put artificial restrictions on production and thus supply in market. While this may lead to prices increasing temporarily, in long run it may lead to a cut-back in the quantity demanded. Commodities whose demand side is stronger than supply side can lead to very interesting economic situations. So gist of all of this, The "short side" of the market dominates, with limited quantity demanded constraining supply in the demand constrained scenario and limited quantity supplied constraining demand in the supply constrained scenario.

Generally, the markets short side is the demand side. How many times have you witnessed a scenario where there is shortage of shirts when you want to buy them, or how about that dream car. Quantity supplied is nearly always more than quantity demanded, reason why MBA folks in sales make a tonne more than others (or do they ?).  Reality is a salesman would only be happy to make available as many shirts/laptops/consoles as you would want to buy, think you are getting hang of markets in general now. In such economy if you increase quantity supplied, without increasing quantity demanded, price would have zero or minimal impact. But if you increase quantity demanded, even if you don't increase quantity supplied, the quantity bought and sold will increase, pushing up the prices. For some rare commodities however, supply is the constraining side. Specially in Chemical industry, there are lot of examples particularly for those which are downstream of Crude Oil. These markets behave in complete contrast to normal markets. At Industry level, instead of spot procurement, we tend to see long term contracts between buyers and suppliers for the quantity to be traded, however purchase price component may not be fixed and that may be actually decided on delivery date. In these markets seller and buyer relations matter a lot, since seller can easily sell of his produce at spot prices to a different buyer making more money than he would have done by selling as per contract. Buyers also sometimes need to buy from spot market to achieve their procurement quotas and need a mechanism to calculate a fair spot price for such commodities.
In today's connected world, where no industry is an island, there could be altogether different reasons which can upset local demand and supply equilibrium in such economic situations, like sudden spike in demand from foreign markets, increase of decrease in downstream derivatives of commodity, environmental issues causing change in commodity ecosystem, change in political scenario may cause prices to become extremely volatile etc.

What one can infer from above statement is that a true commodity prediction model would need inputs from various diverse and often disconnected data sources and domains. Traditionally this job is left to procurement specialists, who in turn read reports from experts belonging to one of the above domains. It is then left to experience of procurement specialist to make sense of all the diverse signals, bring them together to predict price variations in a commodity. In the software industry, many models like distributed ML, ensemble ML etc. have been used to address this diversity, with far from satisfactory results.

Our team as such decided to build a new Collaborative Cognition (CC) platform, to help converge different price predictions from diverse set of machine learning agents(representing different knowledge worlds) into a single predicted price range. Additionally it helps these autonomous agents become aware of some of features being used by other participating agents, making their individual predictions even better. As CC keeps checking on accuracy of predictions from these individual agents, by comparing real commodity prices with their predictions, it can over the time start assigning different importance weights to these agents, bringing the predicted range very close to real commodity prices. Combined with innovative user interfaces, not only allows a procurement specialist to visualize predictions, but also why and how those predictions were made. He can switch to view of individual agents view and see what is happening in markets from a specific perspective eg political or regulatory or pure econometric.
More on Collaborative Cognition and use cases IBM IRL team is solving using it, in coming blogs .....


*Note: Thoughts, opinions and expressions made in this article belong to the author alone. They are not reflective of any organization or company to which he may be associated or employed with, neither directly nor indirectly.

Tuesday, January 10, 2017

Tutorial : Converting a java project to Maven project


Why Maven : You would find lot of articles on usage and power of Maven but in my experience biggest advantage is that you do not have to include/maintain those huge jar files in your code repository server. Very often real code or core of project runs into few mb's but if you include all the dependencies the size can become extremely bloated. With Maven in place developers (and consumers) can happily do quick rebase/clone commands, leaving the time consuming job of including dependencies to Maven. Best still if you have downloaded jars for other project, you do not have to download them again, and maven plugins in IDE (like Eclipse) handles the class paths transparently enough for you.

         


Imagine a scenario where you started off developing a java project and now would want to share it with developers/customers/testers etc. by leveraging Maven.There were a lot of hardships in converting your existing java projects into Maven earlier, but IDE plugins have have made developers life easier these days.

                                   


If you are using new releases of Eclipse, you already have a plugin installed m2e, if not you can download it from here : M2E Plugin

Steps to Convert

1. Right click on your existing project in eclipse and choose Configure -> Convert to Maven Project


                



2. Now you can open newly generated pom file in your project and add dependencies, and you can remove references from build path if you had added them manually.

3. If you want to get details on dependencies on jar files, try searching them on maven central. Once you click on the listed jar, you can get information like groupid, artifactid and version you want to use.


4. Once you have added all dependencies, right click on project and choose run as Maven clean, this should trigger download of all dependencies in your maven home directory. This also automatically adds dependencies to referenced libraries of your project, so you do not have to do it manually.

Tuesday, January 3, 2017

Story of an extra leap second and the mayhem it caused.

If you are not a programmer (or even if you are) chances are you missed the news of an extra second being added to clock. This was done to take care of earth slowing down fractionally for its rotation around sun, but that is not what I would be discussing in this blog.


 What I am going to discuss is the mayhem an extra second can cause to software's, specially the ones where performance measurements are done like Load Balancers (F5 etc.) or other DNS servers.

Now the gist of the problem is that developers assume time is Monotonic. In theory there seems nothing wrong with it, but think carefully and you would realize it is not always true. Consider a scenario where I need to calculate performance of a specific module, a quick way is to getTime at start of a function and do a getTime at end of a function and then subtract these 2 values. This seems perfectly correct, after all this is exactly what we do when referring to our stop watches on wrist right.



Important difference here though is no one suddenly makes your stop watch go faster or slower, which is not always true for a computer clock. When the time changes (Daylight or other occurrences like above), good NTP implementations take care of slowing (of fastening) clocks in a smoother manner, bad NTP implementations can change time with jerks on either side.

So your performance function can in all probability tell you that a piece of functionality finished off in less than 0 seconds. Which off-course you know is wrong and can lead to weird functional flows in your application, specially in an application like Load Balancer. 

So never assume time to be monotonic unless it has been guaranteed by underlying library you are using.

Lot of DNS server faced this when clocks stated adjusting to make up for the extra second, case in point being CloudFlare :How and Why leap second affected Cloudflare DNS

Always rely on better mechanisms like currentTimeMillis / nanoTime or if you are using libraries check if they support CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW.

Tuesday, December 13, 2016

Setting up a server based on GIT repository

GIT ( https://github.com/ ) now supports SSH and it is a fabulous way for administrators to keep their server machines updated with latest code from code repositories.





Present Scenario : Whenever you do a git pull using http mechanism, you have to share your credentials. When there are multiple developers/administrators (which is generally the case now), it is nightmarish doing this.

SSH Scenario : This mechanism allows you to have a machine level access instead of user level, which is an excellent way to keep and maintain code on a typical server infrastructure.

  1. Navigate to directory where you would like to clone git repository
  2. To generate a ssh certificate on your machine use the following command
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. Add key information generated earlier to ssh-agent using below commands
            eval "$(ssh-agent -s)"
            ssh-add ~/.ssh/id_rsa
  4. Adding this new SSH key to your GitHub account
    Copy rsa by using command clip < ~/.ssh/id_rsa.pub
    Now navigate in browser to github account and click on Settings -> SSH and GPG keys.
    Paste the copied key in the new key section.
  5. From gitbash prompt add below command to fetch sources to local
    git clone "git@github****/.git"
    Be sure you use SSH url here and not the https.
  6.  and just do a git pull whenever you wish to pull the latest sources.

Note : I find Gitbash extremely convenient when using git on windows.





                                                    
You can download it from here GIT Download Windows



Wednesday, October 12, 2016

Firefox trick : Opening tabs in same window

                                                    
As a developer I love Tabbed browsing experience on browsers like Firefox and Chrome. So when a customer asked me on how he can prevent opening tabs for all the hyperlinks he clicked on, I was left puzzled.



As with life, every individual has his own preferences while browsing any web based application. Some of us like have links open in new tab, while others may consider it a major distraction and annoyance to maintain these tabs. Check below snapshot on crazy number of tabs


                                 




Luckily all browsers allow end users to control how hyperlinks should behave, if they should open the new page in same window or launch a new tab for it. If you are using Firefox, default behavior is opening new tab, but if you want to change it use below instructions.

1. Open about:config
2. Type in browser.link.open_newwindow
3. Change the value to 1 (instead of default being 3).
4. All external links would open in same tab from now onwards.

                            


Thursday, September 22, 2016

Xiaomi Mi Band 2 is finally here !

Xiaomi Mi Band2 is releasing in India finally after a long delay. It would be available on Mi.Com from 27th September and on Amazon from 30th September.



Band promises some serious value for money and can give a headache to competitors like FitBit, who have tasted initial success in Indian market.





Some major features include

1. Insane Battery Life
2. Display (Welcome addition to older model)
3. Great app
4. Sleep monitor
5. Water Resistant


Xiaomi Twiiter Account

Merging and Splitting PDF files

We all use and rely on PDF's. There are occasions though when you want to edit certain portions of a pdf and merge the edited version ba...