Friday, September 11, 2015

Leap motion + JavaScript

Our team had won the yearly hackathon at work few months back. We got an iPhone 6 and a Leap motion controller device as the mega prize. Being a big fan of Android that I am, I was not interested in switching to iPhone and gave it to my wife. I have been playing around with leap motion controller for sometime. Leap motion is a plug-n-play device which can sense your hand movements to control your computer. I was quite surprised at the accuracy with which the device is able to detect the fingers, palms, hands and arms. The visualizer app which comes with the device helps in visualizing your hands in 3-dimensional space. Leap motion provides SDK for us to integrate with our applications. 

HTML5 Copter

Monday, August 24, 2015

Learnings from building the personal site of my son

/Me and my wife were blessed with a baby boy last month. We were as excited as any first-time parents would be. Initial few weeks were quite challenging and beautiful, and we were slowly getting used to parenting. Selecting the name came out as the next big challenge. In our family tradition, newborns are named on their 30th day. We were not constrained by too many things like starting letters, horoscope, etc. I had set only one constraint for myself - the name has to be a Tamil one. After a few back and forth discussions with the wife and the family, we have selected the name as 'Adhiyan' (அதியன்). As soon as the name was finalised, I wanted to give an identity for my son in the digital world. I have reserved a mail account, twitter handle and a domain name for him to use in the future. I have built a personal site for him with some basic information to announce his name to my friends and colleagues. In the process of building the site, I have experimented with some new technologies. Here is a quick summary of my learnings and technical details:

Friday, August 29, 2014

JavaScript 'strict' mode and OOP template

"JavaScript is not a complete programming language. It gives so many chances for us to make errors. The code is not very structured. It is very difficult to follow the control flow." This is a common statement one could hear from back-end developers starting to do client side development. While I agree to that statement to some extent. I still believe that JavaScript is a very nice dynamic language with its own good parts. It is a language which has got a larger role to play in the future of the web. It might take sometime for the beginners to get used to some of the core concepts like prototype, closures, etc. But, once mastered, the language will help you to get your things done quickly (especially on the web). 

Thursday, August 28, 2014

Cross-Origin Resource Sharing

Cross posting an article written by me last year for a technical magazine but was not published.
--
Web is growing fast with lots of new services being added everyday. Advancements in technologies like HTML5, JS, and CSS3 make the web so powerful that we can almost do everything on the web today. With the increase in the number of services, the need for cross referencing the services also increases. A web application providing photo editing service may want to use the service of photo sharing sites like Instagram or Flickr. Almost all the service providers expose APIs for others to consume their services. While consuming the service from a web application back-end is easier, it is not so easy using the client side technologies. Browsers impose lots of restrictions in accessing resources originating from domains other than the current domain. 

Tuesday, March 11, 2014

Andhra Pradesh | Voter ID application status and polling booth info

A colleague of mine has shared some useful information on finding polling booth for those who have registered for their voter ID in the last couple of months in Andhra Pradesh. Cross posting the blog here for the benefit of all.

Thursday, October 3, 2013

JSFoo 2013 – Day 2

This post is a summary of the talks from Day-2 of JSFoo. Check out Day-1 talks here. The second day of JSFoo started with the most awaited talk of the conference. It was the talk by Christian Heilmann (@codepo8) of Mozilla. He gave a keynote address on the topic "HTML5 for the masses - Making the Future the Now" and impressed the crowd who have gathered there early on a Saturday morning.

Wednesday, October 2, 2013

JSFoo 2013 – Day 1

JSFoo is a JavaScript conference organized by the awesome folks at HasGeek. JSFoo 2013, held on 20th and 21st of Sept, is the fifth edition after four successful runs in 2011 and 2012. The focus of this year’s edition was original creations with JavaScript. A series of workshops was also conducted before the conference. My full-time talk proposal (Building components using Polymer) didn’t get selected this time. There were lots of interesting talks and demos on both the days. There was a good number of International speakers this year. The turn around for the conference was quite high. When I walked into the auditorium, I had to spend quite sometime to find a place to sit. The videos of all the talks can be found here – Day-1, Day-2. Attaching the screenshots of mind map I have created during the conference. Click on the images to enlarge them.

Bringing the Open Web and APIs to mobile devices with Firefox OS

Speaker: Robert Nyman(@robertnyman)

Robert Nyman kick-started the conference with a keynote on Firefox OS. This was one of the sessions I was looking forward to. Unfortunately, I couldn’t get to the venue on time and had to miss this session completely (thanks to the delayed overnight journey). I am yet to catch up this session on HasGeek TV.

Frontend Dev Ops

Speaker: Aditya Yadav (@NetRoy)

In this session, Aditya talked about the evolution of tools in managing the web applications. He called for the developers to automate various processes involved in managing the web apps – deployment, flushing cache, performance tweaks, writing clean code, etc. He also briefly talked about some of the deployment models being used in the industry.

Front end Dev ops

Generating tests from code – or How to test better and faster

Speaker: Olivier Crameri (@Oliviercramieri)

This was one of my favorites of the day. I have learnt some new about testing. Olivier talked about his research work based on the concept of Symbolic Execution and how to use it to automate the generation of test cases. He also talked a bit about the solvers they are using at BugBuster. Then, he demonstrated Unite, a tool for generating unit tests from the code. The demo looked cool as the tool generated some of the test cases for a regular expression. However, I am not sure about the completeness of the test cases though. I am gonna spend sometime on this to get a better understanding of the concept of Symbolic Execution. Thanks Olivier.

Generating tests from code

Real-Time peer-to-peer collaboration with JS and HTML5

Speaker: Om Shankar (@om_invincible)

In this session, Om talked about different components involved in making a peer-to-peer connection using WebRTC. He also showed some cool demos. I was looking to see more on data channel. There wasn’t much on data channels though.

WebRTC Real Time Collaboration with JS & HTML5

JavaScript is a DJ

Speaker: Jaison Justus (@jaisonjutus)

This was the first session after lunch. Jaison engaged the audience really well with his crisp talk on WebAudio API. He showed couple of cool demos using WebAudio API. Good job bro.

JavaScript is a DJ

Programming Flying robots

Speaker: Sreekanth Vadagiri (@sreeix)

In this crisp talk, Sreekanth showed off his AR Drone being controlled by a node app. He also demonstrated the TurleDrone which he has built. The audience were really impressed with the demos. I have got one myself last month. Yet to find a good place to fly it.

Flying robots with JavaScript

Using Camera motion detection in JS for gesture based interaction

Speaker: Vinci Rufus (@Areai51)

Vinci talked about the techniques involved in recognizing the gestures. He talked about the Blend mode difference method used for detecting the gestures. Then, he demonstrated cool apps built using getUserMedia() API. I was really impressed with the car demo which Vinci and his folks have built.

Motion detection in js gesture based interaction

RedRaphael – JavaScript graphics library on steroids

Speaker: Sushant Sudharshan

In this talk, Sushant from Fusion Charts talked about the evolution of the graphics library RedRaphael. He talked about some the salient features of the library like Composite shapes, grouping, etc. It would have been great had he shown better demos built using the library.

RedRaphael

Killing passwords with JavaScript

Speaker: Francois Marier (@fmarier)

This was also one of my favorites of the day. Francois talked about some of the problems with the current password system and what an ideal solution should look like. Then, he introduced Personas with the help of a short play. Personas look like an interesting concept. Need to explore more on this.

Killing passwords with JavaScript

Microsoft sponsored Talk (JS / Web stuff)

Speaker: Rajasekharan Vengalil (@avranju)

In this talk, Raj talked about the some of the cool stuff we can do with JavaScript – Pointer events, Full Screen API, Secure WebGL, etc. Some of the demos (GlacierWorks.org, for example) were really awesome. Then, he talked about some of the tools for debugging the JS code – modern.ie, browserstack. The developer tools on IE seems to have improved a lot. Raj’s session was very informative. Kudos to him for picking up some of the lesser known stuffs for demo.

Microsoft sponsored talk

Bot using Node.Js and the HTML5 Audio API

Speaker: Ameya Karve (@ameyakarve)

In this crisp talk, Ameya talked about how he has used Node.js and HTML5 audio API to build his bot. Unfortunately, he couldn’t show the demo of it on stage.

Bot using Node JS

Offline in the browser – with IndexedDB, AppCache and LocalStorage

Speaker: Manan Bharara (@mananbharara)

Manan talked about the different techniques available for building offline apps in his crisp talk. This was the last session of the day.

Offline in the browser

Overall the day was really good. Had some interesting conversations with fellow JS developers. Check out the summary of Day-2 here.

-- Varun

Friday, January 4, 2013

VBot - Arduino based Quadbot

For a Software engineer who is busy writing code all through the day, working on real world objects is really a cool thing to do. Its fun to control the world around you with the code you write. I have been playing with Arduino for quite sometime and have built few hardware hacks based on that. Check out my hardware hacks here. The latest one in that series is VBot. VBot is a four legged robot which can walk, stretch and even dance. Video. There are different ways in which the bot can be controlled. The bot can receive IR signals and can be controlled using an IR remote. I have also built an Android app for controlling the bot. I have ported the firmware to JavaScript and there is a REPL interface to control to the bot from Node.js app. Fork the project on github. This project has increased my interests on hardware hacks significantly. Hoping to do more in the coming months. 

VBot - Android app

-- Varun

Sunday, September 23, 2012

Arduino tweet notifier built with Johnny-Five!

If you have been following this blog, or following me(@varunkumar) on Twitter, by now you would have found out that I am a big fan of JavaScript. JavaScript is everywhere. You can use it to write web servers. You can run it on your mobile devices. You can even use it as a build tool. And, of course, you can use it in its original home, the browser. But, what about running it on embedded devices? Can we control robots with JavaScript? Yes, developers have been successful in controlling robots with JavaScript. Read this interesting article on JavaScript robotics: "The Rise of JS Robotics". In the rest of this post, I will talk about Johnny-Five, a cool JavaScript framework for interfacing with Arduino boards. I will also show how easy it is to build a Tweet notifier (LCD display connected to an Arduino board displaying the count of mentions from Twitter).

What is Johnny-Five?
Johnny-Five is a JavaScript Arduino programming framework written by the awesome JavaScript developer Rick Waldron (@rwaldron). The framework which can be installed as a node module uses Firmata protocol to communicate with Arduino boards. Firmata is a generic protocol for communicating with microcontrollers from software on a host machine. Johnny-Five is a JavaScript implementation of the Firmata protocol which provides easy-to-use modules for interfacing with Arduino boards. Check it out here. Video

Getting started

  • Preparing your Arduino board. The first thing you need to do is to flash your Arduino board with Firmata. You can do it from Arduino IDE (File > Examples > Firmata > StandardFirmata). I tried it out on a Mega ADK board. Now, one end of your communication is ready. Software on the host machine will communicate this board using Firmata protocol. 
  • Installing Johnny-Five. As mentioned above, Johnny-Five is a node module and can be installed using npm (npm install johnny-five). johnny-five depends on node modules firmata and serialport. Note: You might have to build serialport for your environment using "node-gyp configure build".  
  • Writing Hello, world! In the context of Arduino, writing a hello world is nothing but glowing an LED. You have to write a Node.js JavaScript file and include johnny-five module. 

Arduino Tweet notifier
This is just a fun hack I have built with Johnny-Five (This is just for demo. You can do much more with JF). I have connected a 16x2 LCD display to an Arduino Mega ADK board (pins 8-13) and was writing data on it using Johnny-Five. Then, I have employed nTwitter module to get the stream of mentions from twitter. Whenever someone mentions @varunkumar on twitter, LCD will display a notification for the same. Check out the code here.







References:
Johnny-Five. Link.
Arduino & LCD getting started. Link.

-- Varun

Saturday, September 15, 2012

Animated doodle in CSS!

If you are following the developments on web browsers, you must be knowing the kind of changes CSS is going through. Lots of new features are getting added to CSS3 and you can do lots of stuffs with CSS. Here is a short post about an animated doodle which I had built purely using CSS3. I built this animated logo few months ago for a hackathon we had at our workplace. The speciality of this logo is that it is built only using CSS3 - even the circles and rounded corners are built with CSS and no images are used. You can verify the same with the help of any web inspectors. You can hover over the little guy and see him flip his ears, eyes, teeth, arms and legs. I have employed CSS transitions, CSS transforms and others to get the work done. The implementation is complex and not optimal. But, it is built just to demonstrate the power of CSS. Browser support: All latest browsers. The CSS used in this experiment can be found here. If you are not able to view the logo inline, check it out here. Have fun with CSS!! :)

-- Varun

[How to] Install Linux on Android?

As both the Linux and Android OS are open sourced, developers have enjoyed success in porting Linux on to Android and vice versa. Lots of efforts are still going on in this space. Canonical has been busy working on Ubuntu on Android which enables Android devices to run Ubuntu. “Linux on Android” is another awesome project which helps you to install and run a wide range of Linux distros on your Android device. An Android app has been released as part of this project which will guide you through the installation process. I tried it out myself on my Galaxy S2 and the process was very straight forward. Using this app, you will be able to install any distro as this just ‘chroot’ into the Linux image. This technique will run a virtual Linux on top of the Android OS without disturbing your Android OS. You could still use other apps installed on your Android device. We could replace Android with Linux completely but then you wouldn’t be able to use your Android phone as a phone anymore.

Pre-requisites:

  • Android 2.1 or higher. You need to have at least 3.5 GB of free space on your SD card. You can run Linux from internal SD cards as well.
  • Root access. You must have an Android device with Root access.
  • Support for Loop devices. Your Android OS must support loop devices. The stock image on Galaxy S2 didn’t have the support for loop devices. I have flashed the MIUI ROM with a kernel which supports loop devices. 

Steps to install Linux on Android

  • Download and install “Complete Linux Installer” app from Play store. Also, install VNC Viewer and Terminal App from Play store.
  • Launch the application “Complete Linux Installer”. This will guide you through the download links for different Linux distros.
  • Download the image and place it on your sdcard. By default, the launcher looks for the image directly on the sdcard (for ex: /sdcard/ubuntu). This can be configured from the launch menu. You can create a new launch configuration by specifying the image location and a name to it.
  • Select the configuration which you want to launch. This will open up the Terminal app with the chosen Linux image (say Ubuntu) mounted. If everything goes well, you should see this message “root@localhost:/#” on the terminal. This terminal will act like a Ubuntu command line. You can connect to the GUI from any of your favorite VNC viewer app (either on the same device or other devices).
    • You will be prompted for the root password, screen size and other options while mounting the Linux image.
    • If your kernel doesn’t support loop devices, you will get appropriate messages in this phase.
    • If you don’t have sdcard on your device, you might get some mount errors. You can ignore the errors (close the terminal) and re-connect to the mounted device again.
  • You are done. I have tried both LXDE and Unity desktops on S2 and both worked reasonably well.

Terminal Emulator with Ubuntu mounted

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device - LXDE desktop

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device - LXDE desktop

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device - Unity

VNC Viewer app running on Galaxy S2 connected to Ubuntu running on the same device

VNC Viewer running on Mac connected to Ubuntu on Android

VNC Viewer running on Mac connected to Ubuntu on Android

More information about “Linux on Android” can be found here.

-- Varun

Wednesday, August 22, 2012

JS Foo Bangalore 2012

HTML5 makes the web so powerful that we can do almost everything on the web. Till few years back, Flash was commonly used to build rich applications. Things have changed a lot with HTML5. Browsers are also becoming powerful day-by-day. Many desktop developers have already started moving towards web based application development. JavaScript is growing to be the most important programming language. In fact, the famous Khan Academy has chosen JavaScript as the first programming language to teach. As a developer, how do we keep track of the latest happenings? Though there are many online forums (like HTML5Rocks) to help us, the best way to learn is to hang out with fellow developers and the experts from the field. JS Foo is a tech event, organized by the good guys at HasGeek, which facilitates the interaction between JavaScript developers.

About JS Foo

JS Foo is India’s only conference on JavaScript, with editions in Bangalore, Pune and Chennai. It brings together JavaScript developers from different parts of the country, to share their learnings and help others transition to JavaScript. The highlight of the conference is its transparent system of public submission and voting on sessions. Participants have the control over the sessions to be part of the event. Yes, you can go to http://funnel.hasgeek.com/jsfoo/ to suggest a new session or vote for a session which you like. The schedule for the event will be prepared based on that.

JS Foo
About HasGeek

HasGeek is India’s first and only professional, community-focused technology event organizer. It was founded by Kiran (popularly known as @jackerhack) in 2010. HasGeek creates discussion space for geeks to collaborate. HasGeek has organized many successful events in the past like DocType HTML5, JS Foo, AndroidCamp, DroidCon, Meta Refresh, etc. I have personally attended some of their past events and really enjoyed them. Believe me, these guys are really awesome. :)

JS Foo Bangalore 2012

The fourth edition of JS Foo is happening in Bangalore on 19th -20th of October 2012. The theme for this edition is JavaScript everywhere. People are pushing the limits of what can be done with JavaScript on the server, in embedded devices, and in its original home, the browser. You can share your experience working with JavaScript and you can listen to the best practices in code and working style from the experts.

Date: Oct 19-20, 2012
Venue: NIMHANS Convention Centre, Dairy Circle, Bangalore
Pre-requisite: Basics of web development. You don’t have to be an expert in JavaScript.
Registration: http://jsfoo-2012.doattend.com/
Site: http://jsfoo.in (Site is still showing information about previous edition).

My Experience

I have attended the third edition of JS Foo in Chennai. It was an awesome experience. Learnt a lot of new stuffs. Check out my blog post to know about my experience at JS Foo Chennai 2012. You can also find the videos from previous editions here. I will be attending the event and might even give a talk on JS tools (http://funnel.hasgeek.com/jsfoo/). Hope to see you all at the event.

-- Varun

Sunday, July 15, 2012

Binary data processing in JavaScript

Few days ago, I came across an interesting post about Speaker.js on Hacker News. Speaker.js is a client side library which enables text-to-speech using only JavaScript and HTML. The library doesn’t do any server side calls to do the conversion. This made me thinking about the techniques used in JavaScript to process large amount of binary data. Old school JavaScript doesn’t provide any support for storing binary data. Traditionally normal arrays were used to simulate the behavior of binary arrays by storing a number in the range of 0 to 255 for each element. Obviously, the above technique will not be suitable for applications that require processing of large amount of data. Then, with the introduction of HTML canvas element, developers started using Canvas’ ‘ImageData’ to hold any binary data needed for their applications. Canvas ImageData is still one of the most widely used techniques to deal with binary data. If you are following the developments on HTML5 standardization and web browsers, you must be aware of “Typed Arrays”. JavaScript “Typed Arrays” provides a mechanism for accessing raw binary data much more efficiently. Rest of this post will focus on “Typed Arrays” and performance metrics of all these three techniques.

Typed Arrays

JavaScript “Typed Arrays” provide a mechanism for accessing raw binary data much more efficiently. The specification defines two types: buffer – a generic fixed length buffer type, view - accessor types that allow access to the data stored within the buffer.

  • Buffer (implemented by ArrayBuffer). The ArrayBuffer is a data type that is used to represent a generic, fixed-length binary data buffer. You can't directly manipulate the contents of an ArrayBuffer; instead, you can create an ArrayBufferView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer. The following line of code will create a chunk of memory with 16 bytes pre-initialized to 0. Note: You will not be able to access data using the variable buffer.

var buffer = new ArrayBuffer(16);
  • View (implemented by ArrayBufferView and its subclasses). A view provides a context—that is, a data type, starting offset, and number of elements—that turns the data into an actual typed array. Views are implemented by the ArrayBufferView class and its subclasses. Float32Array, Float64Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array are some of the available view classes. There is also a generic view DataView available to read and write data to ArrayBuffer. In the following lines of code, we create a view that treats the data in the buffer as an array of 32-bit signed integers. We can access the data in the buffer just like a normal array. It is possible to create multiple views on the same buffer. By combining a single buffer with multiple views of different types, starting at different offsets into the buffer, we can interact with complex data structures (like data read from a structured file, WebGL, etc).

var int32View = new Int32Array(buffer);
for (var i=0; i<int32View.length; i++) {
int32View[i] = i*2;
}
// 16-bit singed integer view on the same buffer. This is allowed.
var int16View = new Int16Array(buffer);
for (var i=0; i<int16View.length; i++) {
console.log("Entry " + i + ": " + int16View[i]);
}

Browser Support

Performance Tests

 Kanaka has written some test cases to test the performance of these three techniques: Normal Arrays, ImageData and Typed Arrays. The test cases are hosted as part of his noVNC project on github. I ran the same test cases on my Macbook Pro (2 GHz Intel Quad-core i7, 4 GB 1333 MHz DDR3) and it turns out that performance of Chrome is much better than other browsers. In Chrome, ‘Typed Arrays’ proves to be the most efficient technique for manipulating binary data. There are some drastic changes in these metrics when compared to the tests run by Kanaka in April 2011. Test results after averaging out 50 test iterations can be found here.

The Four Tests:

  • Create - For each test iteration, an array is created and then initialized to zero and this is repeated 2000 times.

  • Random read - For each test iteration, 5 million reads are issued to pseudo-random locations in an array.

  • Sequential read - For each test iteration, 5 million reads are issued sequentially to an array. The reads loop around to the beginning of the array when they reach the end of the array.

  • Sequential write - For each test iteration, 5 million updates are made sequentially to an array. The writes loop around to the beginning of the array when they reach the end of the array.

Chrome is the only browser where “Typed Arrays” seems to be performing well. If you want to use a standard technique, then you can go with ‘Typed Arrays’. Otherwise, you will have to wait for other browser vendors to improve the performance of “Typed Arrays”. More information about “Typed Arrays” can be found here.

Update: I have re-ran the test cases after making the changes pointed out by mraleph (here)

  • Explicitly specifying the arraysize while creating normal arrays
  • Instead of creating a single test_something function, created separate functions for each array type. It turns out that performance of other browsers has improved significantly after this change. Interesting inference from this result is that the JS engines in Firefox, Safari and Opera do not seem to handle Polymorphism well.

-- Varun

Saturday, July 7, 2012

Postel’s law and modern day browsers

Today while I was skimming through the feeds from Hacker news, I came across this interesting post -- “A file that’s both an acceptable HTML page and a JPEG image”. Apparently this url (http://lcamtuf.coredump.cx/squirrel/) can be viewed as a HTML document when opened on a browser and the same can be used as a source to the image element. Yes, it does work. As mentioned on the above page, there is no server side trick involved in this. After inspecting the page for sometime and trying out different tools in my arsenal, I have figured that this is related to Postel’s Iaw.

What is Postel’s law?

Postel’s law or the robustness principle is a general design guideline for software: Be conservative in what you do, be liberal in what you accept from others (often reworded as "Be conservative in what you send, liberal in what you accept"). (Definition sourced from Wikipedia.) Modern day browsers follow this principle to a greater extent. Let me explain this with an example. Create an empty file and name it as “something.html”. Just add a line of text without any HTML tags. The browsers will render the content even though there are no HTML tags available. Now add html, head and body tags and leave them open without closing. Browsers render the pages even if they are not well formed. In other words, browsers are liberal enough in accepting the contents to render.

The Squirrel page

Now, lets use Postel’s law to understand how the Squirrel page works. When we request the url as a HTML document or as an image, the same content is being delivered to the browser (check the screenshot of Chrome Network panel). The content sent from the server is actually an image with HTML contents embedded on it. The browser interprets the content depending on the context in which it is used.

Chrome Network panel showing the data transferred when the page is viewed as a HTML document and as an imagePage source showing Junk characters

  • Open the page on a browser to view the HTML contents. If you view the page source, you will find some junk characters in the source. You will find a set of junk characters at the beginning of the file and some more contents at the end of file within HTML comments.
  • The initial set of contents are outside any HTML tag. This corresponds to the headers of the image file and has to be outside of HTML tag for the parsers to pick them as image. However, when we render the url as a HTML document, browser will try to render those junk characters even though they are outside any HTML tag. Hence, they are hidden explicitly on the HTML page with the help of CSS. body { visibility: hidden; }.
  • The actual image contents are placed inside a HTML comment block. Browsers will safely ignore any comments while rendering the page where as when we use it as an image the parsers will understand the contents and parse the image data.

Since the browsers are liberal enough to render the content based on the context, the same url can be used as a HTML document and as an image. Try saving the source and open in your favorite text editor, you will find junk characters. Rename the save file as jpeg, and open the file in browser, the contents will be rendered as image and not HTML.

Update: Just read through the comments on the Hacker news page. Looks like the same technique is used to compress JS files inside PNG files for JS1K contest.

-- Varun

Sunday, March 18, 2012

[Screenshots] Mozilla’s Mobile OS, Boot2Gecko (B2G)

Mozilla has been working on its own Mobile OS code named “Boot to Gecko”(B2G) for quite sometime. B2G is a browser based operating system built using the standard web technology stack. B2G is expected to run on low end smart phones as well. I am impressed with the idea of using standard web technologies for mobile app development (on the similar lines of Windows 8 HTML5 apps). Mozilla claims that they are working on web APIs to expose device capabilities such as telephony and other media devices. The project is still in its early stages. B2G was show running on Samsung Galaxy S2 at the Mobile World Congress last month. If you are interested in contributing to this project, check out the code from here. Neat instructions are provided to build the code and an Android based emulator is also included for testing. B2G uses the same low level building blocks (Linux kernel, libusb, etc) which Android uses. I played around with it last night and here are some screenshots of B2G. The user interface was a bit on the slower side in the emulator.

B2G - Home Screen

B2G - Home Screen

B2G - Home Screen

B2G - Home Screen

B2G - Settings

B2G - Dialer

B2G - Gallery

B2G - Video Playback

B2G - Mozilla Marketplace 

B2G - Music App

B2G - Music Playback

B2G - Penguin Pop Game (Demo)

B2G - Firefox Browser

B2G - Keyboard

B2G - Cut the Rope (HTML5 game)

 B2G - Cut the Rope (HTML5 Game)

-- Varun

Tuesday, March 13, 2012

Insight into Google’s Input / Output machine

Google has just updated its Google I/O site with details about the 2012 edition of the event. Registration for the event opens on March 27th (If I remember correctly, the tickets for Google I/O 2011 were sold out in less than an hour. Good luck for those looking forward for the tickets.). Like the 2011 edition, this year also Google has added some cool stuff on its site. Google I/O 2011 site had an awesome countdown timer (Chrome experiment) which was counting down to start of the event. The brilliant designers at Google have taken it a step further and have built a game called “Input/Output” to play-with till the event. This game is again a Chrome experiment and I am really impressed with it. I played with it for couple of hours and this post is an (unofficial) insight into some of the technologies used in this experiment.

About “Input / Output machine”

The objective of the game is simple: use the tools and machine parts to create a Rube Goldberg-inspired machine that moves a particle from the <input> to the </output>. It looks simple but, believe me, it is very addictive. Its the New Angry Birds!! Once you get going with the machine, you can just unleash your creativity and build some creative ones. Also, Google has promised that some of your creations could be featured at Google I/O 2012. Build your machine and share it on Google+ using #io12.

Google Input / Output machine

Technologies used

The JavaScript code which is the backbone of this whole experiment is not obfuscated, fortunately. That made it easier for me to dig through what is going behind the scene. The whole experiment seems to be heavily dependent on Canvas rendering. HTML5 canvas element is very powerful but it is very difficult to work with when it comes to handling user interactions. Easel.js is a neat solution to this problem – It allows you to retain a full hierarchy of display objects rendered on the canvas and enable interaction on them. (If you have seen the cool charts on Google Zeitgest 2011 site, that was also built using Easel.js). Every tool on the toolbox is rendered as a display object onto the board and then the necessary event handlers are added to facilitate the positioning of the tool on the board.

For calculating the motion of the particle and transforming the particle, JavaScript library “Slyvester – Vector and Matrix Math for JavaScript” has been used. Another interesting JavaScript library used is “Stativus : StateCharts” which is a micro framework for maintaining state charts of an application. Apart from these, there are few utility libraries like “Underscore.js”, “jQuery Easing”, etc being used. All the aforementioned libraries are packaged inside a single JavaScript file named as “experiment.js

JavaScript Libraries used

  • Easel.js – Library to work with HTML5 canvas. It provides a retained graphics mode for canvas including a full, hierarchical display list, a core interaction model, and helper classes to make working with Canvas much easier.
  • Slyvester - Vector and Matrix Math for JavaScript. It includes classes for modeling vectors and matrices in any number of dimensions, and for modeling infinite lines and planes in 3-dimensional space. It lets you write object-oriented easy-to-read code that mirrors the math it represents.
  • Stativus – Library for maintaining the state charts of an application. Statecharts are a great way to organize your web application and make it more robust and increase code reuse.
  • Underscore.js – Utility library that provides a lot of the functional programming support.
  • jQuery Easing Plugin – jQuery plugin to give advanced easing options.

Quick hack to unlock different particles

When you click on the <input>, you get options to position the <input> and you will also see another option to change the particle (as shown in the screenshot below). By default, only the first particle is enabled. As you build the machine and progress on the game (not really sure about the trigger – Chrome particle gets active on remixing some existing machine), you will get few additional particles – Anti-gravity Plus particle, Androidify particle, Chrome fast particle. Here is a quick hack to unlock all those particles by default:

  1. Information about the unlocked particles are stored in a variable called USER_METADATA.
  2. Open JavaScript Console (Cmd + Shift + J) on your Google Chrome.
  3. Enter the following lines: USER_METADATA.hasPlusParticle = true;USER_METADATA.hasAndroidParticle = true;USER_METADATA.hasChromeParticle = true;
  4. Yay! You are all set. Now, you can try out all the available particles.

Google Input / Output machine - Input particles

Well done, Google! It is very addictive and I am going to spend more days on it. Please let me know if there is anything incorrect in this post.

Update: Thomas Reynolds, the lead developer of this project commented on this post with some corrections. “We actually only use Ease.js, which is the Penner Easing Equations from inside Easel. Our canvas renderer is 100% custom. Regarding the particle hack, so glad you found that! There are a ton of "developer" hacks, mostly global variable, just waiting to be tweaked.”

-- Varun

Sunday, February 19, 2012

JSFoo Chennai 2012!

JSFoo is a one day conference on building rich web applications in JavaScript. Having tasted success on its previous editions in Bangalore and Pune, HasGeek organized the Chennai edition of JSFoo on 18-Feb-2012. The turn around for the event was quite good. I had reached the event at around 8:30 AM and was catching up with some of the old friends. The day started with an introduction to HasGeek and what followed was a series of interesting talks in two parallel tracks. Overall it was a good learning experience. The videos of the event will be out in the web shortly. Attaching the screenshots of mind map I have created during the event. Click on the images to enlarge them.

Cross Platform Mobile apps using JQuery Mobile and RhoMobile

The first session I attended was on cross platform mobile app development by Balaji Loganathan. He talked about some of the popular web frameworks to build mobile web app. He briefly compared the mobile web app and the native app and explained the need for cross platform mobile app development API. Then, he talked about RhoMobile and how handy it is for building enterprise mobile applications. 

Cross Platform Mobile apps using JQuery Mobile and RhoMobile

Production ready apps with Flatiron

Flatiron is a framework for building applications using Node.js. Flatiron is sponsored by Nodejitsu and the code is available on github. I have built few apps in Node.js before but have never heard about it. The session was delivered by Pavan Kumar Sunkara (@pksunkara), a student from IIT Madras who is currently doing his internship with Nodejitsu. Flatiron seems to include some interesting components and it is the responsibility of the app developer to pick and choose what he wants. It is still in its early stages – just two months into development but seems to be promising. All the best to the team.

Production ready apps with Flatiron

JavaScript and the compatible Web

The session on the compatible web was delivered by Rajesh (@avranju) from Microsoft. Though the session was meant to be a sponsor session (Microsoft was one of the sponsors for the day), Rajesh didn’t focus much about Microsoft products. He talked about the challenges in building web applications because of the availability of wide range of browsers and OS. He talked about Modernizr and other frameworks / techniques to overcome these compatibility challenges. Nice and interesting session. 

JavaScript and the compatible Web

Data visualisation in JavaScript

The session was delivered by Anand S (@sanand0), chief data scientist at Gramener. He talked about the need for visualization. He said “Don’t take too much into average. Try to plot all the points and visualize them”. For visualizing data, one need to be creative and tools are just helpers in the process. You can build rich visualizations with simple divs in HTML without any complex libraries / tools. He demonstrated some of the cool visualizations he has build at Gramener. His talk was very crisp and clear. One of my favorite sessions for the day.

Data visualisation in JavaScript

Building visualisations that rock using Web Standards

The second session for the day on data visualization was delivered by Harish (@hsivaram), a web developer evangelist at Adobe. This was the first session right after the lunch break but still Harish managed to keep us awake. Great job bro! Harish showed us how passionate he is about the data visualization. The session was more like a Show-n-tell where he built a replica of the cool visualization on Google Zeitgeist 2011 site. He used Easel.js and Tween.js to build the visualization in less than 40 mins.

Building visualisations that rock using Web Standards

Tracking Memory Leaks in Client Side JavaScript Application

This is a session by another sponsor of the event - Directi. Vishnu (@pathsny) from Directi delivered this much useful session. He talked about how to identify memory leaks in JavaScript and some of the good practices to avoid them. His session was very informative and I would rate this as the best one for the day. I have learnt a lot from this session. Looking forward to the video of this session and the demo app he has built. 

Tracking Memory Leaks in Client Side JavaScript Apploication

JavaScript is mischievous. Handle 3rd party content with care!

This interesting session was delivered by Krishna Chaitanya T (@novogeek), a Microsoft MVP for IE. He talked about mashups and the things we need to consider while including third party scripts in our web application. He briefed on the possible attacks because of the usage of third party scripts via script injection or frames. The demo was also quite interesting. This is another session for which I would give the highest ratings.

JavaScript is mischievous. Handle 3rd party conttent with care!

Ajax is history - Build real time apps in JavaScript

The last session of the day was on building real time web application. It was delivered by Srirangan S. He talked about how the web applications have evolved in the last two decades. Then, he demonstrated how he built his site review19 using Node.js and Socket.io.

Ajax is history - Build real time apps in JavaScript

-- Varun

google-site-verification: googlea4d68ed16ed2eea6.html