Posts

Showing posts from 2013

Compile NodeJS from source on Debian (linux)

Steps wget http://nodejs.org/dist/v0.10.16/node-v0.10.16.tar.gz    /// Downloads the source tar -zxf node-v0.10.16.tar.gz  ///extract to local folder su   /// switch to root apt-get install build-essential   ///This command installs the c compiler and other essential build tools.  ./configure && make  /// builds the source

Universal Plug and Play (UPnP) with NodeJS

Image
Introduction UPnP architecture allows devices to device communications among home entertainment devices, consumer electronics devices, wireless device etc. This uses UDP port 1900 and TCP port 2869. Participating devices use Simple Service Device Discovery protocol ( SSDP ) to discover other devices. Enable UPnP in Windows 7 Window 7 support UPnP for sharing videos, photos, and files to other supported devices including Smart TVs, SetTopBox devices etc. Go to Control Panel\All Control Panel Items Network and Sharing Center Choose home group and sharing options Create a homegroup Select the options you wish to enable and click Next Write down the password and 'Finish' Now your pc is set up as a UPnP enabled devices Install NodeJS  The sample code discussed here require nodejs to run. You may find the installation details here (NodeJS) . Search This sample I used is inspired from this github - https://gist.github.com/chrishulbert/895382. This is goo

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

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 simple aspx page with following code