<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coffee, Code and Chocolate &#187; General</title>
	<atom:link href="http://blog.ganeshzone.net/blog/index.php/category/general/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ganeshzone.net/blog</link>
	<description>throw new Exception(&#34;#fail&#34;);</description>
	<lastBuildDate>Mon, 26 Jul 2010 19:45:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android for wordpress</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2010/07/android-for-wordpress/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2010/07/android-for-wordpress/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 18:38:02 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/index.php/2010/07/android-for-wordpress/</guid>
		<description><![CDATA[<p>Android for wordpress is a free android app that lets you manage your wordpress blog from your phone. Though quite basic, it certainly seems to be the best blogging solution on the android right now. Making this post using the app. Wonder if we will get the plugins for this app in the near future.</p>
]]></description>
			<content:encoded><![CDATA[<p>Android for wordpress is a free android app that lets you manage your wordpress blog from your phone. Though quite basic, it certainly seems to be the best blogging solution on the android right now. Making this post using the app. Wonder if we will get the plugins for this app in the near future.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2010/07/android-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Program to the interface, not the implementation</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2010/05/interface-not-implementation/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2010/05/interface-not-implementation/#comments</comments>
		<pubDate>Fri, 14 May 2010 17:51:48 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Best practices]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=1195</guid>
		<description><![CDATA[<p>I got this invaluable piece of advice while reading the book Code Complete by Steven Mc Connell. Program to the interface, not the implementation.</p>
<p style="text-align: justify;">Coding to the implementation is a mistake which most developers (including me), are guilty of. Now, digging deep into the external classes for educational purposes is a perfectly healthy activity [...]]]></description>
			<content:encoded><![CDATA[<p>I got this invaluable piece of advice while reading the book <strong>Code Complete</strong> by <strong>Steven Mc Connell. </strong><strong><em>Program </em></strong><strong><em>to the interface, not the implementation</em></strong>.</p>
<p style="text-align: justify;">Coding to the implementation is a mistake which most developers (including me), are guilty of. Now, digging deep into the external classes for educational purposes is a perfectly healthy activity and seeing code written by developers greatly improves your own skills. However, the problem starts when decisions are made based on the internal implementation details of a class. On the surface this might seem a very intelligent thing to do, but it can lead to plenty of unpleasant consequences.</p>
<ul>
<li>For starters, it completely goes against the philosophy of Object Oriented programming that client classes look inside the server object to work out the way they need to make the call. A class should behave like a black box and should only expose to the outer world, what  it wants to. If you need more details, they should come from the documentation and not the source code.</li>
</ul>
<ul>
<li>It also deprives the application developer of the independence to change/optimize/upgrade his own implementation. If the client class is coded on any assumptions, the application will break when they are voided due to changes. This makes the client-server tightly coupled, an arrangement frowned upon by seasoned architects.</li>
</ul>
<ul>
<li>There may be scenarios where you absolutely need to code based on the implementation due to incomplete information at your disposal, but it’s always better to call up the developer and ask him to fix both the interface and the documentation. Because every time a change is made, he is obliged to keep those up to date, but by no means will the developer look into your code and advise you on how to modify it to make it work.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2010/05/interface-not-implementation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to save your application from getting trashed</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2010/05/how-to-save-your-application-from-getting-trashed/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2010/05/how-to-save-your-application-from-getting-trashed/#comments</comments>
		<pubDate>Mon, 03 May 2010 21:36:42 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Best practices]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=1116</guid>
		<description><![CDATA[<p style="text-align: justify;">You spend a lot of time in creating an application, starting with abstractions and slowly moving to the specifics,  hours of heated debate to painstakingly design each and every intricate detail, working on all possibilities for  extensibility, even going through every line of code other developers write to make sure they stick to [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">You spend a lot of time in creating an application, starting with abstractions and slowly moving to the specifics,  hours of heated debate to painstakingly design each and every intricate detail, working on all possibilities for  extensibility, even going through every line of code other developers write to make sure they stick to the design.  Yes, a lot of effort goes into creating and delivering a production quality application which satisfies all the  stakeholders.</p>
<p style="text-align: justify;">Ideally, thats when a developer should say goodbye to the application vowing never to see the code again. Coz, if  he does, he&#8217;d end up mighty disappointed. Future developers would have literally pillaged the application to  systematically eliminate any traces of the original design, the code would be littered with dirty bug fixes and so -called enhancements that don&#8217;t &#8220;enhance&#8221; anything. The customer doesn&#8217;t care because the application still works,  the managers don&#8217;t care because they meet their revenue targets and the timelines, and the developers never cared  in the first place.</p>
<p>Keeping that in mind, I listed down a few ways which might help save your application from meeting the same fate.</p>
<ul>
<li style="text-align: justify;"> <span style="size: 30px"><strong>Keep it Simple</strong></span>:  The oft repeated rule in software design is<strong><em> &#8220;Keep everything as simple as possible, but not  simpler&#8221;</em></strong>. If the design is too complex, then in all probability no developer would take the pains to go through it  and understand the whole thing. Many software engineers are guilty of trying to force fit their code to use a certain design pattern. Instead,look for the pattern which best fits your requirement</li>
</ul>
<ul>
<li style="text-align: justify;"><strong>Keep it Modular</strong>: Dividing your application into logically seperated projects makes it easier to identify the right  places to make the changes. Proper namespaces help too. For e.g. an assembly with the namespace  <em>ABCApplication.HelperObjects.FileIOOperations</em> leaves no space for doubt about what it does.</li>
</ul>
<ul>
<li style="text-align: justify;"><strong>Keep it Visual</strong>: Sure, you might find the 1000 page SMTD an interesting read, but not everyone else will. Remember a  bored developer would be the most likely to introduce a dirty fix in the code. So, to keep things interesting, go  for easy to understand graphics and images. MS Visio is a great tool to model your application, and it supports  automatic code generation as well (Enterprise Architect version). And after creating the model, dont leave it in a  random location that even you would forget in 2 weeks. My advice is to check it in the Source control along with  the code and add it to the Visual Studio Solution.</li>
</ul>
<ul>
<li style="text-align: justify;"><strong>Keep it Commented</strong>: Good commenting is the most potent weapon in your arsenal to guide/warn/ prohibit future  developers from making changes they shouldnt be doing. XML comments are a great way to maintain uniform commenting  standards across the application and can also be used to generate comment documentation automatically (using the  /doc switch while compiling) . A good way to convey how you intended the code to be used is to include a sample code block in the xml comments itself. Keep it mind though, that the comments are stripped out by the compiler, so  if you want comments to appear in the intellisense while using the assemblies, then the generated documentation  file must be packaged along with the assembly.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2010/05/how-to-save-your-application-from-getting-trashed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lifting the .NET Hood &#8211; Part 1 &#8211; Generics</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2010/03/lifting-the-net-hood-part-1-generics/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2010/03/lifting-the-net-hood-part-1-generics/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 21:33:39 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[Generics]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=966</guid>
		<description><![CDATA[<p style="text-align: justify;">I have started this series of posts dedicated to exploring the internals of the .NET framework and runtime. To get started on probing of internals of .NET, we need a debugging extension called SOS (Sons of Strike). Visual Studio comes packaged with this assembly (SOS.dll). The first posts is about one of the [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I have started this series of posts dedicated to exploring the internals of the .NET framework and runtime. To get started on probing of internals of .NET, we need a debugging extension called SOS (Sons of Strike). Visual Studio comes packaged with this assembly (SOS.dll). The first posts is about one of the most important features of .NET 2.0 over 1.1 &#8211; Generics or &#8220;Parametric Polymorphism&#8221;. Wikipedia defines Generics as <em>&#8220;a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters&#8221;</em>.</p>
<p style="text-align: justify;">First, we need to set up Visual studio  to use the Sons of Strike. A few simple steps mentioned below are needed to accomplish this:-</p>
<ul>
<li>Enable Unmanaged Debugging in the Project Properties</li>
</ul>
<p><a href="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/03/unmanaged.jpg"><img class="aligncenter size-medium wp-image-967" title="unmanaged" src="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/03/unmanaged-300x183.jpg" alt="" width="300" height="183" /></a></p>
<ul>
<li style="text-align: justify;">Set the symbol server to  <strong>*C:\localcache*http://msdl.microsoft.com/download/symbols</strong>. The symbol server can be set by going to Tools -&gt; Options-&gt; Debugging. This step allows Visual studio to download the symbols needed for debugging from the Microsoft server.</li>
</ul>
<ul>
<li style="text-align: justify;">Set a breakpoint in the code and press F5 to start the program in debug mode. Once the application hits the breakpoint, load the SOS.dll using the command <strong>.load SOS </strong>in the Immediate Window.</li>
</ul>
<p><a href="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/03/loadDLL.jpg"><img class="aligncenter size-full wp-image-971" title="loadDLL" src="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/03/loadDLL.jpg" alt="" width="525" height="71" /></a></p>
<p style="text-align: justify;">Now we are ready to use the debugging extension. And SOS is also compatible with debugging tools like WinDbg in case you are comfortable with using that. Click <a href="http://geekswithblogs.net/.netonmymind/archive/2006/03/14/72262.aspx" target="_blank">here</a> for a list of SOS commands.</p>
<p style="text-align: justify;">Now, lets see the code that we would use for seeing how generics work. It consists of a Generic Type Customer which contains a list of the generic type and a public integer property.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Employee
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> EmployeeID<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">int</span> age<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Name<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #FF0000;">class</span> Customer<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> CustomerID<span style="color: #008000;">;</span>
        List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> _innerList <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> ListItems <span style="color: #000000;">&#123;</span> get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _innerList<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddItems<span style="color: #000000;">&#40;</span>T _addObject<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _innerList.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>_addObject<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">The main method to call this code is below. We create the Customer class in three types &#8211; a string, an integer and a custom Employee type. Of these the string and Employee are reference types while integer is a primitive value type.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Customer<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> _cxStringObj <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Customer<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Customer<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> _cxIntObj <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Customer<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Customer<span style="color: #008000;">&lt;</span>Employee<span style="color: #008000;">&gt;</span> _cxEmpObj <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Customer<span style="color: #008000;">&lt;</span>Employee<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            _cxStringObj.<span style="color: #0000FF;">CustomerID</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">34</span><span style="color: #008000;">;</span>
            _cxStringObj.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Ganesh&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            _cxIntObj.<span style="color: #0000FF;">CustomerID</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">23</span><span style="color: #008000;">;</span>
            _cxIntObj.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">43</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            _cxEmpObj.<span style="color: #0000FF;">CustomerID</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">34</span><span style="color: #008000;">;</span>
            _cxEmpObj.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Employee<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Every .NET class has two main data structures it uses to maintain type identity  &#8211; the MethodTable and EEClass. Every object has a pointer to its MethodTable, and this methodtable contains a pointer to the EEClass. In .NET 1.1, the EE class was the strongest identifier of Type Identity of an object, however with .NET 2.0 and the implementation of Generics, Generic Types can share the same EEClass, and the MethodTable takes on the mantle of being the unique type identifier.</p>
<p style="text-align: justify;">There are two main ways of implementing Generics which were proposed by the researchers who were working at Microsoft (<a href="http://research.microsoft.com/en-us/um/people/akenn/generics/DesignAndImplementationOfGenerics.pdf">This</a> paper provides details of the implementation).</p>
<ul>
<li style="text-align: justify;">Expansion: In this way, whenever the runtime encounters a generic type, the code could be generated on the fly for the type being called. For e.g. in our code, when the object Customer&lt;string&gt; was encountered, it could have expanded into the string representation of the object. When the type Customer&lt;int&gt; was encountered, a similar expansion can be done for it.</li>
</ul>
<ul>
<li style="text-align: justify;">Code sharing: In this approach only a single instantiation is done for the generic type, and it is reused for all the calls.</li>
</ul>
<p style="text-align: justify;">The method chosen in the end was a mixture of both these approaches. Generic types share as much code as possible They contain the same EEClass as mentioned before, but also have distinct MethodTables. Even though they have distinct MethodTables, code is shared between compatible types (all reference types).</p>
<p style="text-align: justify;">Fire up the debugger and load the SOS.dll. To see the particular instances of the type on the heap give the Command DumpHeap -type . Once all the three objects have been created, lets see the result of this command.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">!</span>DumpHeap <span style="color: #008000;">-</span>type Customer
 Address       MT     Size
01ed35cc 002331d8       <span style="color: #FF0000;">16</span>
01ed3604 00233284       <span style="color: #FF0000;">16</span>
01ed3638 0023336c       <span style="color: #FF0000;">16</span>
total <span style="color: #FF0000;">3</span> objects
Statistics<span style="color: #008000;">:</span>
      MT    Count    TotalSize <span style="color: #FF0000;">Class</span> Name
0023336c        <span style="color: #FF0000;">1</span>           <span style="color: #FF0000;">16</span> GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>GenericsTry.<span style="color: #0000FF;">Employee</span>, GenericsTry<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>
00233284        <span style="color: #FF0000;">1</span>           <span style="color: #FF0000;">16</span> GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Int32</span>, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>
002331d8        <span style="color: #FF0000;">1</span>           <span style="color: #FF0000;">16</span> GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #FF0000;">String</span>, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>
Total <span style="color: #FF0000;">3</span> objects</pre></div></div>

<p style="text-align: justify;">As you can see from the MT column, all the three objects have different MethodTables. Lets see the MethodTables for each of the three type instantiations.</p>
<p style="text-align: justify;">The command is DumpMT -MD . First the Employee type. Think of the MethodTable as an extension to a conventional vtable which simply contains the method pointers. The MethodTable&#8217;s vtable points to 7 slots, 4 of which are inherited from the parent Object class and three which are defined by the object itself. If you see the JIT status, there is a YES and NONE. The NONE means the method has never been called by the JIT Compiler and it points to a temporary stub. The first time the method is called, it is compiled on the fly and the temporary stub is replaced with the actual method pointer. To optimize performance, JIT defers execution and compilation till as late as possible.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">!</span>DumpMT <span style="color: #008000;">-</span>MD 0023336c
EEClass<span style="color: #008000;">:</span> 00231420
Module<span style="color: #008000;">:</span> 00232c5c
Name<span style="color: #008000;">:</span> GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>GenericsTry.<span style="color: #0000FF;">Employee</span>, GenericsTry<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>
mdToken<span style="color: #008000;">:</span> 02000004  <span style="color: #000000;">&#40;</span>Projects\GenericsTry\GenericsTry\bin\Debug\GenericsTry.<span style="color: #0000FF;">exe</span><span style="color: #000000;">&#41;</span>
BaseSize<span style="color: #008000;">:</span> 0x10
ComponentSize<span style="color: #008000;">:</span> 0x0
Number of IFaces <span style="color: #0600FF;">in</span> IFaceMap<span style="color: #008000;">:</span> <span style="color: #FF0000;">0</span>
Slots <span style="color: #0600FF;">in</span> VTable<span style="color: #008000;">:</span> <span style="color: #FF0000;">7</span>
<span style="color: #008000;">--------------------------------------</span>
MethodDesc Table
   Entry MethodDesc      JIT Name
70766aa0   705e4a34   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
70766ac0   705e4a3c   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>
70766b30   705e4a6c   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">GetHashCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
707d7550   705e4a90   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">Finalize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
0023c058   0023313c     NONE GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">get_ListItems</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
0023c060   00233148     NONE GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.__Canon<span style="color: #000000;">&#41;</span>
0023c068   00233154      JIT GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>..<span style="color: #0000FF;">ctor</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p style="text-align: justify;">Lets see the MethodTable for the integer type. As you can see the EEClass for the Integer and Employee types are not same, this is because they are not compatible types and hence no code sharing can take place</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">!</span>DumpMT <span style="color: #008000;">-</span>MD 00233284
EEClass<span style="color: #008000;">:</span> 002314b4
Module<span style="color: #008000;">:</span> 00232c5c
Name<span style="color: #008000;">:</span> GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Int32</span>, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>
mdToken<span style="color: #008000;">:</span> 02000004  <span style="color: #000000;">&#40;</span>\GenericsTry\GenericsTry\bin\Debug\GenericsTry.<span style="color: #0000FF;">exe</span><span style="color: #000000;">&#41;</span>
BaseSize<span style="color: #008000;">:</span> 0x10
ComponentSize<span style="color: #008000;">:</span> 0x0
Number of IFaces <span style="color: #0600FF;">in</span> IFaceMap<span style="color: #008000;">:</span> <span style="color: #FF0000;">0</span>
Slots <span style="color: #0600FF;">in</span> VTable<span style="color: #008000;">:</span> <span style="color: #FF0000;">7</span>
<span style="color: #008000;">--------------------------------------</span>
MethodDesc Table
   Entry MethodDesc      JIT Name
70766aa0   705e4a34   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
70766ac0   705e4a3c   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>
70766b30   705e4a6c   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">GetHashCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
707d7550   705e4a90   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">Finalize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
0023c080   00233254     NONE GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Int32</span>, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">get_ListItems</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
0023c088   00233260     NONE GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Int32</span>, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span>Int32<span style="color: #000000;">&#41;</span>
0023c090   0023326c      JIT GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">Int32</span>, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>..<span style="color: #0000FF;">ctor</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p style="text-align: justify;">The last one is the string type. This brings us to interesting conclusions. Compare the first MethodTable with the last one. Both are reference types and hence compatible with other. It can be observed that the string and Employee tables have the same EEClass <strong>00231420</strong>. The integer type however has the EEClass <strong>002314b4</strong>. There is no way for primitive value types to share code with each other since they differ in size. For e.g. If we created a bool type for Customer class, it would still have a different EEClass and MethodTables.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">!</span>DumpMT <span style="color: #008000;">-</span>MD 002331d8
EEClass<span style="color: #008000;">:</span> 00231420
Module<span style="color: #008000;">:</span> 00232c5c
Name<span style="color: #008000;">:</span> GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #FF0000;">String</span>, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>
mdToken<span style="color: #008000;">:</span> 02000004  <span style="color: #000000;">&#40;</span>\GenericsTry\GenericsTry\bin\Debug\GenericsTry.<span style="color: #0000FF;">exe</span><span style="color: #000000;">&#41;</span>
BaseSize<span style="color: #008000;">:</span> 0x10
ComponentSize<span style="color: #008000;">:</span> 0x0
Number of IFaces <span style="color: #0600FF;">in</span> IFaceMap<span style="color: #008000;">:</span> <span style="color: #FF0000;">0</span>
Slots <span style="color: #0600FF;">in</span> VTable<span style="color: #008000;">:</span> <span style="color: #FF0000;">7</span>
<span style="color: #008000;">--------------------------------------</span>
MethodDesc Table
   Entry MethodDesc      JIT Name
70766aa0   705e4a34   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
70766ac0   705e4a3c   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>
70766b30   705e4a6c   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">GetHashCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
707d7550   705e4a90   PreJIT <span style="color: #000000;">System</span>.<span style="color: #FF0000;">Object</span>.<span style="color: #0000FF;">Finalize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
0023c058   0023313c     NONE GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">get_ListItems</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
0023c060   00233148     NONE GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.__Canon<span style="color: #000000;">&#41;</span>
0023c068   00233154      JIT GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>..<span style="color: #0000FF;">ctor</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p style="text-align: justify;">One more thing of notice is the Method Descriptors for the first and third types. The AddItems method in Customer class has the same Method descriptor for both the string and Employee implementation. So even after a MethodTable is duplicated, both those entries still point to the same Method Description. Even the name has the type System.__Canon, which is dynamically replaced by the type on which the method is called. This is an illustration of the second approach of code sharing given by the researchers from Microsoft.</p>
<p style="text-align: justify;">Once the code for AddItems method is called for the first time, it is JIT Compiled and assigned a code address. The Method Descriptor holds this code address which is assembly code and can be viewed by the SOS command !u.  Till the method is Jitted, there is junk value in this field on the MethodDescriptor.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">!</span>DumpMD 00233148
Method Name<span style="color: #008000;">:</span> GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.__Canon<span style="color: #000000;">&#41;</span>
<span style="color: #FF0000;">Class</span><span style="color: #008000;">:</span> 00231420
MethodTable<span style="color: #008000;">:</span> 0023316c
mdToken<span style="color: #008000;">:</span> 06000005
Module<span style="color: #008000;">:</span> 00232c5c
IsJitted<span style="color: #008000;">:</span> yes
CodeAddr<span style="color: #008000;">:</span> 00aa0298</pre></div></div>

<p>Running the CodeAddress would give you a bunch of assembly code that is executed when the method is called.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">!</span>u 00aa0298
Normal JIT generated code
GenericsTry.<span style="color: #0000FF;">Customer</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">AddItems</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.__Canon<span style="color: #000000;">&#41;</span>
Begin 00aa0298, size <span style="color: #FF0000;">42</span>
<span style="color: #008000;">&gt;&gt;&gt;</span> 00AA0298 <span style="color: #FF0000;">55</span>               push        ebp
00AA0299 8BEC             mov         ebp,esp
00AA029B <span style="color: #FF0000;">57</span>               push        edi
00AA029C <span style="color: #FF0000;">56</span>               push        esi
00AA029D <span style="color: #FF0000;">53</span>               push        ebx
00AA029E 83EC34           sub         esp,34h
00AA02A1 33C0             xor         eax,eax
00AA02A3 8945F0           mov         dword ptr <span style="color: #000000;">&#91;</span>ebp<span style="color: #008000;">-</span>10h<span style="color: #000000;">&#93;</span>,eax
00AA02A6 33C0             xor         eax,eax
00AA02A8 8945E4           mov         dword ptr <span style="color: #000000;">&#91;</span>ebp<span style="color: #008000;">-</span>1Ch<span style="color: #000000;">&#93;</span>,eax
00AA02AB 894DC4           mov         dword ptr <span style="color: #000000;">&#91;</span>ebp<span style="color: #008000;">-</span>3Ch<span style="color: #000000;">&#93;</span>,ecx
00AA02AE 8955C0           mov         dword ptr <span style="color: #000000;">&#91;</span>ebp<span style="color: #008000;">-</span>40h<span style="color: #000000;">&#93;</span>,edx
00AA02B1 833D142E230000   cmp         dword ptr ds<span style="color: #008000;">:</span><span style="color: #000000;">&#91;</span>00232E14h<span style="color: #000000;">&#93;</span>,<span style="color: #FF0000;">0</span>
00AA02B8 <span style="color: #FF0000;">7405</span>             je          00AA02BF
00AA02BA E8BABC3571       call        71DFBF79 <span style="color: #000000;">&#40;</span>JitHelp<span style="color: #008000;">:</span> CORINFO_HELP_DBG_IS_JUST_MY_CODE<span style="color: #000000;">&#41;</span>
00AA02BF <span style="color: #FF0000;">90</span>               nop
00AA02C0 8B45C4           mov         eax,dword ptr <span style="color: #000000;">&#91;</span>ebp<span style="color: #008000;">-</span>3Ch<span style="color: #000000;">&#93;</span>
00AA02C3 8B4804           mov         ecx,dword ptr <span style="color: #000000;">&#91;</span>eax<span style="color: #008000;">+</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#93;</span>
00AA02C6 8B55C0           mov         edx,dword ptr <span style="color: #000000;">&#91;</span>ebp<span style="color: #008000;">-</span>40h<span style="color: #000000;">&#93;</span>
00AA02C9 <span style="color: #FF0000;">3909</span>             cmp         dword ptr <span style="color: #000000;">&#91;</span>ecx<span style="color: #000000;">&#93;</span>,ecx
00AA02CB E8E0F1D16F       call        707BF4B0 <span style="color: #000000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Collections</span></span>.<span style="color: #0000FF;">Generic</span>.<span style="color: #0000FF;">List</span>`<span style="color: #FF0000;">1</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.__Canon, mscorlib<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.__Canon<span style="color: #000000;">&#41;</span>, mdToken<span style="color: #008000;">:</span> 060019f1<span style="color: #000000;">&#41;</span>
00AA02D0 <span style="color: #FF0000;">90</span>               nop
00AA02D1 <span style="color: #FF0000;">90</span>               nop
00AA02D2 8D65F4           lea         esp,<span style="color: #000000;">&#91;</span>ebp<span style="color: #008000;">-</span>0Ch<span style="color: #000000;">&#93;</span>
00AA02D5 5B               pop         ebx
00AA02D6 5E               pop         esi
00AA02D7 5F               pop         edi
00AA02D8 5D               pop         ebp
00AA02D9 C3               ret</pre></div></div>

<p>In this post, we have looked at how the CLR treats Generics and how it takes care of performance implications of Generics code by sharing as much code as possible without having to needlessly box and unbox the types being passed to the Generic classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2010/03/lifting-the-net-hood-part-1-generics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chrome Extension for displaying Vancouver Olympics Medals tally</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2010/02/chrome-extension-for-displaying-vancouver-olympics-medals-tally/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2010/02/chrome-extension-for-displaying-vancouver-olympics-medals-tally/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 18:07:48 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=949</guid>
		<description><![CDATA[<p style="text-align: justify;">The Vancouver Olympics has been generating considerable bit of interest with everyone speculating on the country which bags the most number of golds. To make it easier to keep up to date with the medals tally, I wrote a Chrome extension which displays the top 10 countries. It can be downloaded at the chrome site here.</p>
<p [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">The Vancouver Olympics has been generating considerable bit of interest with everyone speculating on the country which bags the most number of golds. To make it easier to keep up to date with the medals tally, I wrote a Chrome extension which displays the top 10 countries. It can be downloaded at the chrome site <a href="https://chrome.google.com/extensions/detail/bpohbjolihanngodhglbobaodakjocdp">here</a>.</p>
<p style="text-align: justify;">As with the Twitter Trends, I wasn&#8217;t able to find any RSS feed which gives the details of the medals. So I had to scrape the HTML page for the data and then dynamically create the table and display it. The <strong>manifest.json</strong> file gives the details of the gadget.</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{
  &quot;name&quot;: &quot;Vancouver Medals Tally&quot;,
  &quot;version&quot;: &quot;1.0&quot;,
  &quot;description&quot;: &quot;Displays latest medals tally from Vancouver 2010 olympics&quot;,
  &quot;icons&quot;: { &quot;128&quot;: &quot;icon.png&quot; },
  &quot;browser_action&quot;: {
    &quot;default_title&quot;: &quot;Vancouver Medals Tally&quot;,
    &quot;default_icon&quot;: &quot;icon.png&quot;,
    &quot;popup&quot;: &quot;Background.html&quot;
  },
  &quot;permissions&quot;: [
    &quot;tabs&quot;,
    &quot;http://www.vancouver2010.com/*&quot;
  ]
}</pre></div></div>

<p style="text-align: justify;">The stylesheet gives the basic styling of the table and the banner above it. The banner has two states, one where the gadget is loading and hence its smaller in size. After the gadget increases in size, the banner must also be made to fit. This is done in CSS. The switching is done through javascript.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">  body <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> helvetica<span style="color: #00AA00;">,</span> arial<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#title</span>
  <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#mainDiv</span>
  <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">min-width</span><span style="color: #00AA00;">:</span><span style="color: #933;">205px</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
th <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span> <span style="color: #933;">11px</span> <span style="color: #ff0000;">&quot;Trebuchet MS&quot;</span><span style="color: #00AA00;">,</span> Verdana<span style="color: #00AA00;">,</span> Arial<span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span>
	<span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#6D929B</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#C1DAD7</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#C1DAD7</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#C1DAD7</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">letter-spacing</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-transform</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">uppercase</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6px</span> <span style="color: #933;">6px</span> <span style="color: #933;">6px</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#CAE8EA</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
  td
  <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#C1DAD7</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#C1DAD7</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#6D929B</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
   <span style="color: #cc00cc;">#bannerDiv</span><span style="color: #6666ff;">.expanded</span>
   <span style="color: #00AA00;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">18px</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
   <span style="color: #00AA00;">&#125;</span>
&nbsp;
   <span style="color: #cc00cc;">#bannerDiv</span><span style="color: #6666ff;">.collapsed</span>
   <span style="color: #00AA00;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
       <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span>
   <span style="color: #00AA00;">&#125;</span>
&nbsp;
   <span style="color: #cc00cc;">#bannerDiv</span><span style="color: #6666ff;">.collapsed</span> img
   <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
   <span style="color: #00AA00;">&#125;</span>
&nbsp;
    <span style="color: #cc00cc;">#bannerDiv</span><span style="color: #6666ff;">.expanded</span> img
   <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">28px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">56px</span><span style="color: #00AA00;">;</span>
   <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">In the JavaScript, we retrieve the HTML table from the website, create a table using DOM and populate it with the data and append it to the main div. The challenge here was to parse the HTML page into the XML DOM structure to allow JavaScript manipulation. Chromer and Firefox support a class called DOMParser which can be used to construct a DOM structure from the AJAX response text. However, this was giving an error because of the script tags. After much googling, I found a solution at Stack Overflow where the user had removed the data between script tags and then parsed the document. This worked!! and once we the data could be manipulated, all that remained was creating a HTML table and appending the proper rows to the table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Developer  : Ganesh Ranganathan
    * Date        : 02/15/2010
    * Description : This is a Google Chrome Extension created to display latest medals
                    tally for Vancouver olympic games 2010
    * Disclaimer  : I have checked that this extension doesnt violate any copyrights
                    However, if you feel otherwise please point me towards the documentation
                    and I will take corrective measures */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> req<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> _feedURL <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://www.vancouver2010.com/olympic-medals/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Call the loading method after a slight delay to allow</span>
    <span style="color: #006600; font-style: italic;">//Chrome to load the extension body. Else it looks ugly with</span>
    <span style="color: #006600; font-style: italic;">//the pressed button waiting for the feed to load.</span>
    setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;delayedCall()&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> delayedCall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    _req <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//Hooking up the readystate changed event handler.</span>
    _req.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_req.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">&amp;&amp;</span> _req.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">//Come here only if all data is loaded.</span>
            <span style="color: #003366; font-weight: bold;">var</span> doc <span style="color: #339933;">=</span> _req.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">//This workaround is for parsing the HTML string into</span>
            <span style="color: #006600; font-style: italic;">//an xml Dom. The script tags are removed from the HTML</span>
            <span style="color: #006600; font-style: italic;">//since they cause a lot of parser errors</span>
            <span style="color: #003366; font-weight: bold;">var</span> _tempDiv <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             _tempDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> doc.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;script (.|\s)*?\/script&gt;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">//Get medals table - There is one 1</span>
            <span style="color: #003366; font-weight: bold;">var</span> medalsTable <span style="color: #339933;">=</span> _tempDiv.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'table'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> tableRows <span style="color: #339933;">=</span> medalsTable<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sortMe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> mainDiv <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainDiv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            mainDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//resetting existing html to null</span>
            <span style="color: #003366; font-weight: bold;">var</span> table <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'table'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            table.<span style="color: #660066;">cssClass</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'medalsTally'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Setting CSS Class</span>
            <span style="color: #003366; font-weight: bold;">var</span> tbody <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tbody'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            table.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>LoadHeader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> tableRows.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">//Iterate through each of the table nodes </span>
                <span style="color: #006600; font-style: italic;">//and create a new table for displaying in the extension</span>
                <span style="color: #003366; font-weight: bold;">var</span> _childNodes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span>tableRows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'c2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nextSibling</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'td'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'40%'</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span>tableRows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'c3'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'td'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'15%'</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span>tableRows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'c4'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'td'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'15%'</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span>tableRows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'c5'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'td'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'15%'</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span>tableRows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'c6'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'td'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                _childNodes<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'15%'</span><span style="color: #339933;">;</span>
                <span style="color: #006600; font-style: italic;">//Appending everything in the array to the row</span>
                <span style="color: #003366; font-weight: bold;">var</span> _tempRow <span style="color: #339933;">=</span> AppendAllData<span style="color: #009900;">&#40;</span>_childNodes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                tbody.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>_tempRow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #006600; font-style: italic;">//append body to table</span>
            table.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>tbody<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">//Changing Banner size</span>
            document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'bannerDiv'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'expanded'</span><span style="color: #339933;">;</span>
            mainDiv.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>table<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">//Without these two the AJAX request would never get sent.</span>
    _req.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span> _feedURL<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    _req.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Helper function ofr loading the header cells</span>
<span style="color: #003366; font-weight: bold;">function</span> LoadHeader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> thead <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'thead'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> headerRow <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> countryName <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'CountryName'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'th'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> gold <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Gold'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'th'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> silver <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Silver'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'th'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> bronze <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Bronze'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'th'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> total <span style="color: #339933;">=</span> createTableCell<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Total'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'th'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    headerRow.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>countryName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    headerRow.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>gold<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    headerRow.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>silver<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    headerRow.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>bronze<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    headerRow.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>total<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    thead.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>headerRow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> thead<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> createTableCell<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span>tag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> _tempCell <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> _txtNode <span style="color: #339933;">=</span> document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    _tempCell.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>_txtNode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> _tempCell<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> AppendAllData<span style="color: #009900;">&#40;</span>_childNodes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> _tempRow <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> _childNodes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        _tempRow.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>_childNodes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> _tempRow<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>The HTML is just two div tags &#8211; one for the content and one for the banner. Please download the extension and let me know your valuable feedback</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2010/02/chrome-extension-for-displaying-vancouver-olympics-medals-tally/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a Google Chrome extension for displaying Twitter trending topics</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2010/02/writing-a-google-chrome-extension-for-displaying-twitter-trending-topics/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2010/02/writing-a-google-chrome-extension-for-displaying-twitter-trending-topics/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 21:13:07 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=922</guid>
		<description><![CDATA[<p style="text-align: justify;">Google Chrome recently opened up their extensions API. Though Chrome had supported extensions quite early on in its lifecycle, the API was still a work in progress and one needed to open Chrome in the developer mode to play around. A few weeks back, Chrome announced that extensions are now enabled in normal [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Google Chrome recently opened up their extensions API. Though Chrome had supported extensions quite early on in its lifecycle, the API was still a work in progress and one needed to open Chrome in the developer mode to play around. A few weeks back, Chrome announced that extensions are now enabled in normal mode as well.</p>
<p style="text-align: justify;">So I decided to poke around the API and write a simple extension. Though it doesnt compare to FireFox yet with much of the browser still not accessible, but I am sure future versions will bring much better customization capability. The extension I wrote is very simple and just displays the latest trending topics from twitter. The source can be downloaded <a href="http://www.ganeshzone.net/Files/TrendingTopics.zip">here </a> and the packaged version <a href="http://www.ganeshzone.net/Files/TrendingTopics.crx">here</a>.</p>
<p>Lets see the anatomy of a Chrome Extension. An Extension consists of three main parts</p>
<ul>
<li>Manifest</li>
<li>UI</li>
<li>All your other files like scripts, stylesheets, images, etc</li>
</ul>
<p>The manifest is a json file which contains the metadata about your extension. Details like Title, Author etc</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{
  &quot;name&quot;: &quot;Twitter Trends&quot;,
  &quot;version&quot;: &quot;1.0&quot;,
  &quot;description&quot;: &quot;Displays Current Trending Topics&quot;,
  &quot;icons&quot;: { &quot;128&quot;: &quot;icon.png&quot; },
  &quot;browser_action&quot;: {
    &quot;default_title&quot;: &quot;Twitter Trends&quot;,
    &quot;default_icon&quot;: &quot;icon.png&quot;,
    &quot;popup&quot;: &quot;Background.html&quot;
  },
  &quot;permissions&quot;: [
    &quot;tabs&quot;,
    &quot;http://twitter.trends.free.fr/*&quot;
  ]
}</pre></div></div>

<p style="text-align: justify;">As you can see, it contains basic details like name, version, icon etc. The popup attribute tells us the page to open when the browser button is clicked. As you can see I have specified a normal HTML page here. A popup extension is nothing but a simple HTML page opened when the toolbar button is clicked. Another interesting part is the permissions section. Here we can specify what all websites the extension can make AJAX calls to retrieve data. Since it matches based on wildcards, a * denotes all possible subdirectories under the website.</p>
<p style="text-align: justify;">Now the HTML part. Since its a normal HTML page, you can include references to scripts, images, style sheets etc. The extension directory works as the root and all paths must be relative to it. Since its a simple page, I included all the scripts and styling information in a single page.</p>
<p>First the styling information. Always helps to keep this separate.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">  body <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> helvetica<span style="color: #00AA00;">,</span> arial<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ddeef6</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#title</span>
  <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#mainDiv</span>
  <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">min-width</span><span style="color: #00AA00;">:</span><span style="color: #933;">175px</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #6666ff;">.topicDisplayClass</span>
  <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">2.2em</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #6666ff;">.linkClass</span>
  <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#2276bb</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #6666ff;">.topicDisplayClass</span><span style="color: #3333ff;"><span style="color: #00AA00;">:</span>Hover
  </span><span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#edfeff</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Next the javascript. This is the most important part of the extension. What we do here is retrieve the RSS feed for the trending topics and parse it as an xmlDocument. After iterating thorough this xml, a span element is dynamically created for each item and it is appended into our main content holder. This main function call is delayed using the setTimeout function. We do this in order to let the user see the popup and see some progress which data is being fetched. Writing this in the onload event would make the user wait for the whole process to complete before seeing the popup.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Developer  : Ganesh Ranganathan
* Date       : 02/12/2010
* Description: This is a Google Chrome Extension created to display
            latest trending topics on twitter. */</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Global variables: the xmlHttpRequest and Feed URL</span>
<span style="color: #003366; font-weight: bold;">var</span> _req<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> _feedURL <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://twitter.trends.free.fr/feed/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Call the loading method after a slight delay to allow</span>
    <span style="color: #006600; font-style: italic;">//Chrome to load the extension body. Else it looks ugly with</span>
    <span style="color: #006600; font-style: italic;">//the pressed button waiting for the feed to load.</span>
    setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;delayedCall()&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> delayedCall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//No browser compatibility code Yay!!!</span>
    _req <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//Hooking up the readystate changed event handler.</span>
    _req.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_req.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> _req.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">//Come here only if all data is loaded.</span>
            <span style="color: #003366; font-weight: bold;">var</span> doc <span style="color: #339933;">=</span> _req.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> parser <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> DOMParser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">//Parsing the Data into the XML dom for manipulation</span>
            <span style="color: #003366; font-weight: bold;">var</span> xmlDoc <span style="color: #339933;">=</span> parser.<span style="color: #660066;">parseFromString</span><span style="color: #009900;">&#40;</span>doc<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> mainDiv <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mainDiv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            mainDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #006600; font-style: italic;">//Getting all the items</span>
            <span style="color: #003366; font-weight: bold;">var</span> items <span style="color: #339933;">=</span> xmlDoc.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> items.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">//Iterating through all the items and getting the title</span>
                <span style="color: #006600; font-style: italic;">//and link. The description isnt a big deal in this feed.</span>
                <span style="color: #003366; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> items<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> items<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #006600; font-style: italic;">//Create an anchor and a span</span>
                <span style="color: #003366; font-weight: bold;">var</span> spanNode <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> linkNode <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #006600; font-style: italic;">//Set Link to span</span>
                linkNode.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> link<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                linkNode.<span style="color: #660066;">innerText</span> <span style="color: #339933;">=</span> title<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
                linkNode.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'linkClass'</span><span style="color: #339933;">;</span>
                spanNode.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>linkNode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                spanNode.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'topicDisplayClass'</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> link<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nodeValue</span>
                <span style="color: #006600; font-style: italic;">//Hooking the click event handler to the span</span>
                <span style="color: #006600; font-style: italic;">//It calls the chrome tabs API to open the clikced</span>
                <span style="color: #006600; font-style: italic;">//URL in a new tab</span>
                spanNode.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;clickHandler('&quot;</span><span style="color: #339933;">+</span>str<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                mainDiv.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>spanNode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//Without these two the AJAX request would never get sent.</span>
    _req.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span> _feedURL<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    _req.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> clickHandler<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    chrome.<span style="color: #660066;">tabs</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> url<span style="color: #339933;">:</span> str <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: justify;">The markup is largely simple. Just the main content holder which contains a  progress bar which is displayed to user while we load the data. Once that is done, the progress bar is replaced with the span nodes containing the trending topics.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;span id=&quot;title&quot;&gt;Trending Topics&lt;/span&gt;
&lt;div id=&quot;mainDiv&quot;&gt;
&lt;!-- A Progress Bar to show the user something is being done --&gt;
&lt;img src=&quot;ajax-loader.gif&quot; alt=&quot;&quot; width=&quot;175px&quot; /&gt;&lt;/div&gt;</pre></div></div>

<p style="text-align: justify;">Now the manifest, html and image files need to be in a single folder. After that go to Chrome and click the customize dropdown button, and select Extensions. In the extensions page, select Load Unpacked Extension and select the folder where the extension files reside.</p>
<p><a href="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/loadExt.jpg"><img class="aligncenter size-full wp-image-938" title="loadExt" src="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/loadExt.jpg" alt="" width="573" height="159" /></a></p>
<p>Once the extension is loaded, it shows as unpacked and you can do all the testing here by reloading it everytime any changes are done.<br />
<a href="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/unpacked.jpg"><img class="aligncenter size-full wp-image-941" title="unpacked" src="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/unpacked.jpg" alt="" width="328" height="80" /></a></p>
<p style="text-align: justify;">
<p style="text-align: justify;">After testing, we can choose the pack option to package the extension for download. A .crx file would be generated which can be distributed for download. Below are some screenshots of the extension we just created.</p>
<p style="text-align: justify;">
<div id="attachment_942" class="wp-caption aligncenter" style="width: 286px"><a href="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/inprog.jpg"><img class="size-full wp-image-942" title="inprog" src="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/inprog.jpg" alt="" width="276" height="175" /></a><p class="wp-caption-text">Data is loading</p></div>
<p><a href="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/loaded.jpg"><img class="aligncenter size-full wp-image-943" title="loaded" src="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/02/loaded.jpg" alt="" width="286" height="368" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2010/02/writing-a-google-chrome-extension-for-displaying-twitter-trending-topics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dependency Injection for Test Driven Development</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2010/01/dependency-injection-for-test-driven-development/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2010/01/dependency-injection-for-test-driven-development/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 19:43:48 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=831</guid>
		<description><![CDATA[<p style="text-align: justify;">As applications grow more and more complex, they cost more money to develop, test and maintain. Each bug that leaves the development stage, needs the QA&#8217;s effort to identify and notify the developer who again spends time to fix it and get it signed off from the QA. Hence its imperative that good [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">As applications grow more and more complex, they cost more money to develop, test and maintain. Each bug that leaves the development stage, needs the QA&#8217;s effort to identify and notify the developer who again spends time to fix it and get it signed off from the QA. Hence its imperative that good code is written the first time around. This fundamental need is what gave birth to what we call Test Drive Development (TDD), i.e. where the developer writes an automated test case first, sees it failing and then writes the code for it to verify the test passes. This technique is also called the red-green style of development.</p>
<p style="text-align: justify;">Automated testing is an integral part of Test Driven Development. A developer simply doesn&#8217;t have the time to do functional unit testing of his application, an effort which would neither be reproducible, nor comprehensive. Hence developers use Automated testing tools which decrease the testing effort, even if a little bit more code needs to be written.</p>
<p style="text-align: justify;">The biggest problem while automating testing for applications, especially web applications is the tight coupling between layers making it impossible to test one layer without the another. This can create a lot of complications, since you might get false positives and negatives. Imagine a scenario where you write a test case for a business layer method which retrieves some data from the database and processes it. The aim here is to only test the business layer&#8217;s functionality, but if there is a concrete dependency on the data layer, then the result of the test would inevitably depend on the retrieval of data. This is where you could get false positives or negatives.</p>
<p style="text-align: justify;">Hence the reasoning that the test cases should be limited to only the functionality being tested. Consider the below code.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #008080; font-style: italic;">//Your Business Class</span>
    <span style="color: #FF0000;">class</span> BusinessObjects
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//This is a concrete dependency on the dataLayer Object</span>
        <span style="color: #0600FF;">private</span> DataObjects _dataLayerObj<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> BusinessObjects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Initializing the DataLayer object</span>
            _dataLayerObj <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataObjects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Get the customer's Name in upper case</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetCustomerNameInUpperCase<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> _customerID<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>_dataLayerObj.<span style="color: #0000FF;">RunScalarQuery</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Your Select Query here&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToUpper</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>So If you write a test on the <strong><em>GetCustomerNameInUpperCase</em></strong> method, it would need to have the database up and running in order to pass. To avoid this, a technique called dependency injection is used in which the application&#8217;s layers are loosely coupled with each other enabling us to test each layer&#8217;s functionality independent of each other.</p>
<p style="text-align: justify;">This is accomplished by introducing an interface from which the Data layer would inherit and do its work. The business layer would be aware only of these interfaces. Business layer would no longer care about the implementation and thus would allow us to define our own implementation of the interface. This implementation can be &#8220;<strong>injected</strong>&#8221; through an additional constructor. Lets see the code for the data layer now.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #008080; font-style: italic;">//This is the Interface on which the business layer</span>
    <span style="color: #008080; font-style: italic;">//would depend and not the data layer class itself</span>
    <span style="color: #FF0000;">interface</span> IData
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> RunScalarQuery<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> _selectQuery<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">//Other code is oblivious to the implementation behind</span>
    <span style="color: #008080; font-style: italic;">//the data layer as long as it returns the name</span>
    <span style="color: #FF0000;">class</span> DataObjects<span style="color: #008000;">:</span> IData
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//Implementation of the interface</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> RunScalarQuery<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> _selectQuery<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Do all the database related stuff</span>
            <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;Some Customer's Name&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Now we would need to modify the business layer to make it depend on the interface.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">   <span style="color: #FF0000;">class</span> BusinessObjects
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//It now depends on the interface</span>
        <span style="color: #0600FF;">private</span> IData _dataLayerObj<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> BusinessObjects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Initializing the DataLayer object</span>
            _dataLayerObj <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataObjects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//This is the additional constructor that is used</span>
        <span style="color: #008080; font-style: italic;">//to inject a custom implementation</span>
        <span style="color: #0600FF;">public</span> BusinessObjects<span style="color: #000000;">&#40;</span>IData _dataObject<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>._dataLayerObj <span style="color: #008000;">=</span> _dataObject<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Get the customer's Name in upper case</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetCustomerNameInUpperCase<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> _customerID<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>_dataLayerObj.<span style="color: #0000FF;">RunScalarQuery</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Your Select Query here&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToUpper</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p style="text-align: justify;">Now lets write the test case for this method. Instead of using the default constructor making the Business layer go to the database for the customer&#8217;s name, our very own Mock Class does the trick by supplying a dummy value.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #000000;">&#91;</span>TestFixture<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> BusinessLayerTests
    <span style="color: #000000;">&#123;</span>
        BusinessObjects _bObjects<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>SetUp<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Init<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Pass our own implementation of IDATA using</span>
            <span style="color: #008080; font-style: italic;">//the additional constructor we defined</span>
            _bObjects <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BusinessObjects<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> MockClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> CheckIfUserNameIsUpper<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//User regular Expressions to make sure all upper cases are returned</span>
            <span style="color: #FF0000;">string</span> _returnedName <span style="color: #008000;">=</span> _bObjects.<span style="color: #0000FF;">GetCustomerNameInUpperCase</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2342</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>_returnedName<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Assert.<span style="color: #0000FF;">IsTrue</span><span style="color: #000000;">&#40;</span>Regex.<span style="color: #0000FF;">IsMatch</span><span style="color: #000000;">&#40;</span>_returnedName, <span style="color: #666666;">&quot;^[A-Z]+$&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">//This inherirs from IData</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MockClass <span style="color: #008000;">:</span> IData
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080;">#region IData Members</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> RunScalarQuery<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> _selectQuery<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Simply return a lower case name</span>
            <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;lowercaseName&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p style="text-align: justify;">This does seem like too much work to test such a simple functionality, but believe me, the benefits grow exponentially with the size of the project. As you start following this approach, it would be easier to test as you go, making the chances of missing out on that tiny bug much lesser. And at the end of the day, nothing makes the developer more happy than seeing all his unit tests pass with the large green NUnit bar.</p>
<p style="text-align: justify;"><a href="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/01/testsPass.jpg"><img class="aligncenter size-medium wp-image-848" title="testsPass" src="http://blog.ganeshzone.net/blog/wp-content/uploads/2010/01/testsPass-300x67.jpg" alt="" width="300" height="67" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2010/01/dependency-injection-for-test-driven-development/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>I am finally on Google wave</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2009/12/i-am-finally-on-google-wave/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2009/12/i-am-finally-on-google-wave/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 17:46:47 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=639</guid>
		<description><![CDATA[After months of begging for a google wave invite, I had given up on the possiblilty of ever getting inot GWave at the preview stage. But yesterday my orkut status message got me two invites from friends.
Ever since I got it, am trying to find someone to start a wave with, but as luck would [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">After months of begging for a google wave invite, I had given up on the possiblilty of ever getting inot GWave at the preview stage. But yesterday my orkut status message got me two invites from friends.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Ever since I got it, am trying to find someone to start a wave with, but as luck would have it, everyone seems to be busy. Tried to be a part of a public wave but didnt get the hang of it yet.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">There may be minor glitches on the way, but the idea of redefining something that has existed before Internet did, is truly revolutionary.</div>
<p>After months of begging for a google wave invite, I had given up on the possiblilty of ever getting inot GWave at the preview stage. But yesterday my orkut status message got me two invites from friends.</p>
<p>Ever since I got it, am trying to find someone to start a wave with, but as luck would have it, everyone seems to be busy. Tried to be a part of a public wave but didnt get the hang of it yet.</p>
<p>There may be minor glitches on the way, but the idea of redefining something that has existed before Internet did, is truly revolutionary. Good luck to google on this one!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2009/12/i-am-finally-on-google-wave/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile number portability soon in India</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2009/11/mobile-number-portability-soon-in-india/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2009/11/mobile-number-portability-soon-in-india/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 20:23:30 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Portability]]></category>
		<category><![CDATA[TRAI]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=577</guid>
		<description><![CDATA[<p>This one was lone long due. TRAI has been talking about giving consumers the freedom to switch operators without actually switching the number, but cell phone cos seemed to be dragging their feet on this one. After a long time, a date has been given &#8211; the end of the year Dec 31st 2009.</p>
<p>It doesnt [...]]]></description>
			<content:encoded><![CDATA[<p>This one was lone long due. TRAI has been talking about giving consumers the freedom to switch operators without actually switching the number, but cell phone cos seemed to be dragging their feet on this one. After a long time, a date has been given &#8211; the end of the year Dec 31st 2009.</p>
<p>It doesnt come without its share of restrictions though:-</p>
<ul>
<li>You cannot port a number from one circle to another. It has to be within a service area.</li>
<li>This service is confined to only cities as of now.</li>
<li>You have to wait 90 days before applying for number porting.</li>
</ul>
<p>It makes sense for cell phone cos to make porting as difficult as possible. One they would no longer be able to hold subscribers who pay exorbitant rates just to prevent a number change. And second number porting would cost them money to shift the port.</p>
<p>To avoid any high porting charges, TRAI has come out with a cap on it. The maximum cost is Rs 19, to be paid to the operator whom you are switching to. The operator you are leaving cannot collect any charges. Though I never support interference of the regulatory bodies in pricing as that is best decided by competition, TRAI&#8217;s rules are a positive step in this situation. It makes sure most people can make use of this facility and not be forced to tied to one operator no matter how much it demands.</p>
<p>For the regulations, click <a href="http://www.trai.gov.in/WriteReadData/trai/upload/Regulations/90/Regulation20nov09.pdf">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2009/11/mobile-number-portability-soon-in-india/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whats wrong with Rupert Murdoch</title>
		<link>http://blog.ganeshzone.net/blog/index.php/2009/11/whats-wrong-with-rupert-murdoch/</link>
		<comments>http://blog.ganeshzone.net/blog/index.php/2009/11/whats-wrong-with-rupert-murdoch/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 18:51:12 +0000</pubDate>
		<dc:creator>Ganesh Ranganathan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[bing]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Murdoch]]></category>

		<guid isPermaLink="false">http://blog.ganeshzone.net/blog/?p=387</guid>
		<description><![CDATA[<p>Rupert Murdoch is at it again taking his frustration out at Google, Bing and other search engines.  If the speech at the Beijing conference wasn&#8217;t enough, Murdoch has threatened to block search engines from indexing his news websites. Quite a nice way to say Thank you for getting 40-50% of traffic to his site.</p>
<p>Murdoch&#8217;s idea [...]]]></description>
			<content:encoded><![CDATA[<p>Rupert Murdoch is at it again taking his frustration out at Google, Bing and other search engines.  If the speech at the Beijing conference wasn&#8217;t enough, Murdoch has threatened to block search engines from indexing his news websites. Quite a nice way to say Thank you for getting 40-50% of traffic to his site.</p>
<p>Murdoch&#8217;s idea is to introduce a subscription based model for his news websites similar to conventional media? Though that means fewer hits to the websites, it would mean a larger revenue since the websites wouldn&#8217;t be solely be dependent on advertising for their revenue. Murdoch may be a media mogul but he is misreading the current market scenario by not realizing the huge audience it creates for his conventional media businesses.</p>
<p>Good Luck Mr Murdoch, I anyways liked CNN better.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ganeshzone.net/blog/index.php/2009/11/whats-wrong-with-rupert-murdoch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
