Posted in Random

2016’s Hello World

Writing my first blog post from beautiful Berlin for the year 2016. I managed to achieve quite a bit in 2015. One goal for 2015 was to start talking at technical events/conferences; which was achieved. The other goal was to win a hackathon; which was partly achieved. Another goal was to do Coursera’s Machine Learning course seriously; which never happened!

Here’s a summary of what happened in the year 2015: read more

Few updates to what happened at JSConfAsia, Singapore 2015 and how I achieved my goal of winning a hackathon partially.

On the morning of 19th November, 2015, I was all set to deliver my talk as an international speaker. I was both nervous and excited. Few days back I had volunteered myself to play JSPardy, a Jeopardy like game, but with JavaScript.

(“Jeopardy!” is a classic game show — with a twist. The answers are given first, and the contestants supply the questions. )wiki

The previous morning (18.11.2015), I got a mail from the conference organisers saying I was one of those 3 contestants to be playing this unique JS game show. It doubled my excitement, but little did I know that this game was a part of the inaugural ceremony of JSConfAsia 2015. I was done with my registration for the conference on 19th morning and I was looking for Thomas Gorissen (conference organiser) to know and understand the rules for the game. Once done explaining, he asked me to occupy the front-row seats so that it would be easy to walk up to the stage without any delays.

I can still recall my nervousness on getting to know that the game was to be played before my talk (my talk was scheduled for 10:00 am and the inauguration was at 9:00 am). Following is the excerpt of our conversation –

Me: “What? Is it really going to be before my talk? I don’t think I am ready for this at all”

Thomas: “Well, it is a fun game show. Just enjoy”

Me: “Will I make fun out of myself if I am unable to answer any questions?” (I was nervous, I was all blank about JS, about my talk. All I wanted to do was, leave the place and run away)

Thomas: “I am sure you will have fun”

The game started, and rest was history :). Well, all this while I didn’t mention about the grand prize. The winner would get the all new IPAD Pro and I ended up winning this game with the audience’s support.

This is how I achieved my goal partially (because it wasn’t a hackathon). I was the happiest person on earth. My talk went well, got positive feedback and was applauded by web evangelists.

JSPardy at JSConfAsia

Video of my presentation

The next talk was at Grace Hopper Conference India, 2015. It took place at the Taj Vivanta, Yeshwantpur (Bangalore). My video starts at the 13th minute here

Meanwhile, I had applied for Zalando in October 2015. After visiting Berlin for the first time in September 2015 (diversity scholarship recipient for JSConfEU), I had made up my mind to take up a job in Berlin (I badly wanted to be in this city, I wanted a job here, Berlin is so beautiful. It seemed just perfect to be living here). The week before flying to Singapore, I had completed all my technical interviews for Zalando through Skype. The results were expected when I was in Singapore. My joy knew no bounds when I received the much awaited positive response from Zalando. The whole process was so well organized, from the interviews to the relocation assitance, everybody involved did a commendable job. Presently, I am “onboarded” at Zalando, and I am loving every single day. #ILikeMyNewJob

“Dream is not that you see in sleep, dream is something which doesn’t let you sleep” – A P J Adbul Kalam

These were the best things that took place in 2015. There were few things which didn’t happen too:

The theme which we (me and Navya) opted for the hackathon was ‘Super Workplaces’, and we chose to build a ‘Moods App’: to record moods of employees, use smart ways to detect if anybody’s unhappy and wants to leave the company. There is lot of scope for this project. I will write another blog post to talk more on this idea.

Source code can be found here. We built a simple web-based interface to capture moods. The fun part is, using gestures, nodding head – left/right, one can log moods. Demo

There were positive things from this hackathon:

  • I found a new friend – Navya B Raju. She’s a crazy, loving girl. Our trip to Delhi for the hackathon was indeed successful ;).
  • The joy of staying awake the whole night and coding forth something meaningful, the joy of completing the hackathon is exceptional. The 48 hour sleepless night (I winked my eyes just for 15 minutes during this whole duration) was worthy. We did get lot of appreciation for the project!

I had also enrolled as a volunteer for DataKind’s Bangalore Chapter. So, for me, 2015 ended with a DataDive #Data4Good. All my weekends (second half of 2015) were super productive, being with this amazing community of data good-doers.

With all the positive energy and learnings from 2015, I am all geared up for 2016. New place, new job, new people. It feels good. Gives me a sense of accomplishment 🙂

#DreamBig #HappyCoding

 

 

 

 

Posted in Uncategorized

Tasty JavaScript Curry

JavaScript Curry:

A useful technique to partially evaluate functions.

Coming Soon…


function myFunc(a, b) {
if (arguments.length < 1) {
return myFunc;
} else if (arguments.length < 2) {
return function(c) { return a + c }
} else {
return a + b;
}
}

console.log(myFunc(2,2));

var add4 = myFunc(4);
console.log(add4);

console.log(add4(5));

var add = myFunc();
console.log(add);

var addTwo = add(5,6);
console.log(addTwo);

var addOne = add(1);
console.log(addOne(2));

Posted in Random

A thank you note!

I was going through my twitter feeds and came across WWCode’s tweet which asked to submit a story about how WWCode has impacted our careers. I was getting ready to go to office, but I stopped to write this story.

I have been looking for a way to thank WWCode Bangalore and couldn’t find this form any better!

It all began on 7th May, 2015 when I sent a talk proposal to WWCode Bangalore’s upcoming meetup to Devangana Khokhar (Director of WWC Bangalore).

The talk was about Intel’s RealSense 3D technology and how I had developed a game using my face as a game controller. I am a JavaScript aficionado and the best thing about this game was that it was built entirely on JS. How cool it is to do all of this perceptual computing using JS! Ever since I had accomplished this, I wanted to do a demo of this at WWCode Bangalore and we scheduled a meetup for 8th August, 2015.

That was exactly 3 months after I had sent the proposal ;).

Not many showed up for the meetup, but whoever was present were all taken away by the awesomeness of JS. It turned out to be a great 6 hour session and after that there has been no looking back!

The next day there was DataKind Bangalore Chapter’s sprint session and they were looking for data experts in visualizations and
I got a direct entry to be a part of this awesome team too. Thanks to Devangana and Gaurav Godhwani.

Oh, by the way, I need to make a mention here that I go crazy when you talk about D3.js and visualizations. Next to JS, D3.js and visualizations are close to my heart.
Anand S from Gramener is my inspiration to this!

Following this WWC’s session, I got lot of applauds on Facebook and Twitter.
I also got two enquiries from prospective startups who were interested about my work in perceptual computing. They were (and are still) generous to offer me to use their office space and 3D cameras for any R&D related work. I was thrilled.

Meanwhile, I won a fully paid diversity scholarship to attend JSConf.EU. It was my first international trip and I got to go to one of the most beautiful place – Berlin.

The next big leap was when I was invited to be a speaker at JSConf.Asia.
My first proposal to JSConf.Asia was rejected saying they thought the talk was more about an advertisement to Intel’s RealSense technology.
I didn’t want to give up and sent another proposal, which got accepted and I would be presenting my work at Singapore for JSConf.Asia on 19-20th November, 2015.

The idea behind this talk had generated when I was preparing for my first demo for WWC. This is where I would want to thank WWCode whole heartedly.

Little did I know back then that it would become a hit.
This is a little abstract about my talk for JSConf.Asia: “This talk is about a web based solution to simulate 3D cameras for prototyping, developing and testing perceptual computing, augmented reality applications without using a physical device. I will walk you through the immense possibilities which could be explored through JavaScript and web.”

The next big thing happened when my first technical paper on the above subject got selected for Grace Hopper Conference India 2015 which is scheduled for 3-4th December, 2015.

I got excellent feedback for this.
review

So this has been my summary for 2015 and major credits go to WWCode Bangalore.

It wouldn’t be fair to conclude this thank you note, if I don’t mention Cohan Sujay Carlos, CEO, Aiaioo Labs, the person behind getting me to enjoy coding.
He will always remain as my mentor.

Also, Sreeraman Vaidhyanathan, Co-founder and MD, IStar India Skills Pvt Ltd, for making me realise how fast I can code. Today, if I am able to come up with any crazy ideas and make them a reality, then the credit goes to Sreeram.

Amruth Ravindranath and all my other colleagues at Guru-G Learning Labs have been way too kind to offer me all the required support towards my external fun projects.

Last but not the least, my family who will be always there for me.

Posted in LearningItMyWay

CORS

CORS – Cross Origin Resource Sharing

This is a sequel to my post on cURL.

“Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts, JavaScript, etc.) on a web page to be requested from another domain outside the domain from which the resource originated” from wiki.

The above explanation is self explanatory. For instance, a resource loaded from Domain A (http://A:3000) such as an HTML web page, makes a request for a resource on Domain B (http://B:4000). The Same-Origin Policy restricts the browser from performing certain actions by scripts or documents based on the origin. The origin is everything in the URL before the path (e.g., in http://A:3000/images/bg.png, http://A:3000 is the origin and /images/bg.png is the path). For certain actions, the browser will compare origins and, if they don’t match, won’t allow things to proceed.

We kept getting CORS error, when we were trying to test our REST API. The server sided REST API logic was written on Node.js and was running on port 3000 on one system. The client side logic was also written on Node.js and was also running on port 3000, but on another system. I had initially tested the API using POSTMAN, and it worked great. But, when we tried integrating the front-end with the back-end, it was erroneous. And it was CORS. I had encountered something similar related to CORS, way back in 2011, during my first job, but it was resolved in few minutes. I cannot recall the exact issue, all I remember is that it had to do only with JQuery (front-end only).

This time, I tried understanding CORS in more detail.

Let’s assume, the server-side code was running on http://A:3000 and the client-side code was running on http://B:3000. We were trying to test the login api, i.e. front-end accepts username/password through a form and on button click, submits the values (HTTP POST) to the server. The server then validates the username/password combination. If successful, server returns the user id, else, returns appropriate error messages. We had agreed upon both the input and output to be JSON only.

Things looked alright, when the input type was x-www-form-urlencoded, i.e. normal form data being passed through JQuery AJAX request. But things went awry, when we restricted it to JSON only (POSTMAN still had no issues).

Following is the list of errors when we tried with JSON input, and how I went about solving each one of them.

1. http://B:3000 made a POST request to http://A:3000/login. But instead of POST, it always made a OPTIONS request.

Now the first thing to wonder about was why did this happen. To be honest, I wasn’t sure about the HTTP OPTIONS method until then. But this is what it is. “This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.”
Nobody uses this OPTIONS method, but it is used for CORS access to API’s. When doing a CORS request, the browser will do a ‘preflight’ OPTIONS request to discover if the server will answer the real request.

The next thing to wonder was what is this preflight.

CORS requests are usually preflighted. This request is basically there to ask the server if the full request is permissible. If POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML/JSON payload to the server using application/xml or text/xml or application/json, then the request is preflighted. Only if the server responds positive to this preflight request, the actual POST request will be sent to the server.

At this point it was clear why the POST request always came as an OPTIONS request for JSON input and not for x-www-form-urlencoded.

2. After I understood about OPTIONS method and the preflight request, following was the next error. XMLHttpRequest cannot load http://A:3000/login. The ‘Access-Control-Allow-Origin’ header has a value that is not equal to the supplied origin. Origin ‘null’ is therefore not allowed access.

I was running test.html locally on the browser as file:///E:test.html. Running it this way, always sets the Origin to Null in the request header. This took quite some time for me to understand and resolve. I then created another local Node.js server running on port 4000 to serve test.html. Alternative to this could have been serving test.html through WAMP Server/Apache on port 80. This resolved the null origin issue. The origin was now set to http://localhost:4000.

3. Following was the third error. XMLHttpRequest cannot load http://A:3000/login. The ‘Access-Control-Allow-Origin’ header has a value http://B:3000 that is not equal to the supplied origin. Origin http://B:3000 is therefore not allowed access.

This wasn’t scary, like the earlier one. I could make sense, what was happening here. On my server sided logic in Node.js, I had restricted “Access-Control-Allow-Origin” to http://B:3000 only. res.header("Access-Control-Allow-Origin", "http://B:3000");
On the client side code, I had to add the below line to JQuery AJAX method. When the CORS makes a preflight request, both the client and server should have the same headers set.
beforeSend: function (request) { request.setRequestHeader("Access-Control-Allow-Origin", "http://B:3000"); }

This is the full JavaScript working code after understanding about CORS, OPTIONS, preflight and setting headers through AJAX.

var login = {username: "sadmin", password: "sadminasd"}; $.ajax({ dataType: "json", beforeSend: function (request) { request.setRequestHeader("Access-Control-Allow-Origin", "http://B:3000"); }, contentType: "application/json", type: "POST", data: JSON.stringify(login), url: 'http://A:3000/login', success: function(data) { console.log("Success", data); //alert("Success "+data); }, error: function(err) { console.log("Error", err); //alert("Error "+err) } });

At one point, we took the approach of solving this problem using JSONP. JSONP was initially the solution prior to CORS for making cross domain requests. But JSONP supports only GET and not POST.

In my next blog, I shall talk more about JSONP and also about JSONP vs CORS.

Posted in LearningItMyWay

Node.js on port 80 on Windows

This is a sequel to my last post.

I tried running Node.js server on port 80 on Windows. In my first attempt, I had WAMP Server running on port 80. So i got EADDRINUSE error.

I stopped WAMP Server. Node.js app worked on port 80 on Windows.

Posted in LearningItMyWay

Node.js EACCESS

Yesterday, I tried running a Node.js server on port 80 on Ubuntu. I normally run Node.js server on ports > 3000.

First time when I tried running the server, I was expecting an error, because Apache2 was running on Ubuntu on port 80(default port for Apache2). I stopped Apache2 sudo service apache2 stop.

I tried running Node.js server again, and now it gave me EACCESS error. I was clueless about this.

When I tried to search for this error on Google, I found the answer on stackoverflow.com.

“Non-privileged user (not root) can’t open a listening socket on ports below 1024.” from stackoverflow

I then ran Node.js server using sudo node app. Bingo, it worked.

Also, when I was talking to my colleague Shiv (Guru-g Learning Labs), I learned that if applications run on port 80, then we can access them without the port number.

Eg: http://localhost/ instead of http://localhost:80. The latter option works too, it’s just that, we don’t have to explicitly specify the port numbers for port 80.

P.S: I haven’t tried running Node.js server on port 80 on Windows. Will document my results soon.