Posts

Web Workers

NB: This is not about web developers or software engineers; though there are some similarities in behaviors of these two.  Web Workers are new set of APIs introduced with HTML5 specifications. This enables web pages to run (long running) scripts in the background threads. Web workers brings following advantage in HTML/ Java Script world.  Running tasks (specially time consuming jobs or repeated jobs like status check etc) behind the scene while UI is interactive to the users. A task parallel programming approach which enable the developers to make use of increasing usage of multi-core processors in the PC/laptop world. Not implemented through loops; but uses message notification mechanism to communicate to and from the main UI thread. Creating a worker    Spawning a working in JavaScript is simple; just need to call the "Worker()" constructor with a URI of script to execute in the worker thread. var worker = new Worker("worker.js"); There are two ma...

Cross Domain RESTful Service in WCF

Image
I had to write a REST API last week, which needed to be accessible from webpages hosted in multiple domains. I thought of writing down one of the technique I followed from the web standard. So, I am going to explain how to create a WCF service, make it RESTful and how to structure it in a way such that you can use/call it from webpage hosted in any domain. Most common examples of this usage is google map, bing map APIs.  Common web standard to make sync/async calls to the service is to use XMLHttpRequest object directly and get the result back in the response text; then use the result accordingly in the page logic. You may use JSON formated request/response in the service to make it easy to use in the web page; specially because almost all the browser has the native support of JSON in JavaScript.   A limitation associated with XMLHttpRequest object is that it will not allow you to access a webpage/service from a different domain other than the host of currently serve...

JavaScript Unit Test - Closure Library

Image
Closure library has a powerful js unit testing framework included. I've used multiple javascript unit testing frameworks and for me closure library looked very easy to understand and use. I will explain step by step process to use it on a basic testing scenario below.   JS unit testing requires following two javascript files for any basic test case, and then you would add other libraries depends of what you use in your project.       <script src="../closure/goog/base.js"></script>   <script>     goog.require('goog.testing.jsunit');   </script> base.js library is where most of the core APIs resides for closure, and goog.testing.jsunit namespace resides under the file ...closure\goog\testing\jsunit.js.   Now, you can include your project libraries and scripts tags below these tags.   I am using a linklist implementation in javascript as a demo to show how t...

HTTP Cookie - size

Wikipedia gives a very detailed info about HTTP Cookies -  http://en.wikipedia.org/wiki/HTTP_cookie , it's usage, advantages, disadvantages etc. I was curious perticularly about the size limitations of HTTP cookie. W3C has published specifications around HTTP State Management Mechanism, which gives further details about recommandations for the brower / server implementation groups about the usage of cookies. Accourding to the official version, it doesn't impose any upper limit to the user agent (browser) about handling cookies, though it says that user agent should atleast support 300 cookies, at least 4096 bytes per cookie, and at least 20 cookies per unique host or domain name.  If you think about this, it's a relatively a big storage if I can use 20*4096 bytes =~ 80KB local storage per domain. Now, I wanted to make sure every thing works as defined before I jump in to a cookie-base application (like a database). So, I created a ...

Dijkstra's Algorithm in JavaScript

Image
I happend to read through a series of blog posts by Nicholas C. Zakas here -  http://www.nczonline.net/blog/2009/06/09/computer-science-in-javascript-binary-search-tree-part-1 . These are really interesting thoughts. So I decided to take it another step by implementing the shortest span/path solution using Dijkstra's Algorithm. A beautiful explanation of the algorithm is available in YouTube at -  http://www.youtube.com/watch?v=8Ls1RqHCOPw  - so that I can stay focussed on the implementation part. Now, let me walk you through the steps taken to implement the algorithm in javascript. First of all, I need to define the graph that I am going to traverse. The best way to represent the graph is in metrix form, where each of the entry will indicate the weighted edge from one node to the other. To do this in JS, I created an array of arrays, with a header element at the first row. Figure 1. The above graph can be represented as follo...

Convert your ASP.Net app to Windows Azure

Image
Introduction  If you are excited about Windows Azure platform and wanted to see how your web application behaves in new cloud environment, this article is for you to follow step by step process to convert your app and move to cloud environment.     Prerequisite You will need to have an account with windows azure to host the app. You may also try the 30 day free pass as described in my  previous article . A list of required software is also available  here  to work with Windows Azure development. Steps I have created a sample website - MySite - to start with the demo. Below are the steps to deploy the same to Windows Azure environment. Step1 . Open the solution in VS 2010. Step 2 . Now we need to add a new windows azure project to the existing solution. So, right click on the solution add a new project. Step 3 . Choose "Cloud" from the installed templates and select Windows Azure Project. Type in a name - MyAzureSite. Step...