Posts

Showing posts from July, 2013

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 served page. W

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 to use the closure unit test to test the output. I have a linklist.j