<?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>sp2hari@weblog... &#187; coding</title>
	<atom:link href="http://sp2hari.com/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://sp2hari.com</link>
	<description>I see, learn and rediscover... everyday!</description>
	<lastBuildDate>Thu, 24 Nov 2011 22:06:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Forgot the match again?</title>
		<link>http://sp2hari.com/2008/07/10/forgot-the-match-again/</link>
		<comments>http://sp2hari.com/2008/07/10/forgot-the-match-again/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 14:15:22 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[opc]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[topcoder]]></category>

		<guid isPermaLink="false">http://sp2hari.com/?p=139</guid>
		<description><![CDATA[Do you play Topcoder? If yes, then there might be something for you in this post. If you don&#8217;t know what topcoder is, check http://topcoder.com/tc and then come back here. If you play topcoder, then keeping track of when the &#8230; <a href="http://sp2hari.com/2008/07/10/forgot-the-match-again/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Do you play Topcoder? If yes, then there might be something for you in this post. If you don&#8217;t know what topcoder is, check <a href="http://topcoder.com/tc">http://topcoder.com/tc</a> and then come back here.</p>
<p>If you play topcoder, then keeping track of when the next match is a big headache. There are many many people who login to the arena one day before the contest and ask why there is not many playing today.  Come on, it is not funny to get up at 5.30 in the morning to know that the match is not today and it is tomorrow. The rest think the match is one day later, who curse themselves, bang their head for missing a match. If you want to forget forgetting :P about topcoder matches, follow the simple steps given below. </p>
<p>All you need is a Google Account. </p>
<ul>
<li>Login to google calendars at <a href="http://calendar.google.com/">http://calendar.google.com/</a></li>
<li>Search for &#8220;Topcoder&#8221; in public calendars. ( By clicking &#8220;Search Public Calendars&#8221; button). I got some 50 results when I wrote this. This may increase or decrease later. Choose anything from the list (anything from the first 5 will be good enough).</li>
<li>Click on the &#8220;Add to Calendar&#8221; button.</li>
<li>Go back to your calendar page. You can see the Topcoder calendar in the &#8220;Other calendars&#8221;.</li>
<li>You need to activate mobile setup by activating your phone number. This takes less than a minute. Give your country and phone number. Google will send you a verification code in 1 or 2 minutes. Type that validation code there and voila, you are done with the mobile setup. :-)</li>
<li>Now click on the &#8220;Calendars&#8221; tab in the settings page. </li>
<li>Click the &#8220;Notification&#8221; of your new Topcoder calendar.</li>
<li>Click the &#8220;Add a reminder&#8221; to add new remainders. </li>
<li>You can have upto 5 remainders for this calendar.</li>
</ul>
<p>See my notifications page here.<br />
<a href='http://sp2hari.com/wp-content/uploads/2008/07/topcoder.jpg'><img src="http://sp2hari.com/wp-content/uploads/2008/07/topcoder.jpg" alt="Google Calendar Notification" title="Google Calendar Notification" width="500" height="165" class="alignnone size-full wp-image-141" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2008/07/10/forgot-the-match-again/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Google Maps</title>
		<link>http://sp2hari.com/2008/01/15/google-maps/</link>
		<comments>http://sp2hari.com/2008/01/15/google-maps/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 22:59:56 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[pushpin]]></category>

		<guid isPermaLink="false">http://sp2hari.com/2008/01/15/google-maps/</guid>
		<description><![CDATA[I have been using Google Maps for a long time (a nice way to kill time) and now I am using the Google Map API to create my own site (not a nice way to kill time). Was able to &#8230; <a href="http://sp2hari.com/2008/01/15/google-maps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been using Google Maps for a long time (a nice way to kill time) and now I am using the Google Map API to create my own site (not a nice way to kill time). Was able to start with my work using the  sample examples given in the Google Maps site and by trial and error method.<br />
But came to a dead end when i had to manage many events at the same time. Say for the example, when the user clicks in the map, first an infowindow opens up with a form in it. When the user clicks elsewhere when already an infowindow is open, then an prompt asking for whether he should save the old place or not. If he says no, the show the new infowindow. Else retain the old infowindow. Save the details using an Ajax request so that the page is not reloaded again and again. Mummy&#8230;. </p>
<p>But now, after exploring so much about Google Maps, I was able to manage things now. A simple tutorial about how to handle events in Google Maps. The reason why i choose events is that this is more difficult to grasp AFAIK. :)</p>
<p>First let us start with a simple Google Map as shown in the following url<br />
<a href='http://sp2hari.com/gmap/event-simple.html'  target=_blank> http://sp2hari.com/gmap/event-simple.html</a><br />
The main code which adds the event listener is<br />
<code>        GEvent.addListener(map,"click", function(overlay,latlng) {<br />
        	alert ("Map Clicked");<br />
        });<br />
        GEvent.addListener(map,"click", displayMessage);  </code><br />
Note that for the same event &#8220;click&#8221;, I have added two event listeners. In the first listener, the code to be executed when the event occurs is inline. This is fine if the code is very small. Even then i advice you to follow the second method where the function name to be called is given as argument. Then you can mention all the actions to be done when the event occurs in that function. For example, my displayMessage will look like<br />
<code>   function displayMessage(overlay, latlng) {<br />
	    document.getElementById("message").innerHTML = "Clicked at latitude "+latlng.lat()+ " and longitude "+latlng.lng();<br />
    }</code></p>
<p>Yup. That&#8217;s all it needs to add a simple event listener for Google Maps.<br />
Now let us try something more ;)<br />
How about trying to add a marker at the place where it is clicked and a button to clear all markers?<br />
Check this url<br />
<a href='http://sp2hari.com/gmap/event-addmarker.html'  target=_blank> http://sp2hari.com/gmap/event-addmarker.html</a><br />
In the above file, I just have one event listener for click (you can have as many as you want), and the function I&#8217;m calling after click is &#8220;addMarker&#8221;. The following code adds the event listener.<br />
<code>GEvent.addListener(map,"click", addMarker);  </code><br />
Now the function addMarker has the code to add a marker as shown below<br />
<code>    function addMarker(overlay, latlng) {<br />
    	var marker = new GMarker(latlng);<br />
    	map.addOverlay(marker);<br />
	    document.getElementById("message").innerHTML = "Marker added at latitude "+latlng.lat() + " longitude "+latlng.lng() ;<br />
    }</code></p>
<p>Another function clearAllMarkers is used to clear all the markers used in the map. Check the code for that function.<br />
<code>    function clearAllMarkers() {<br />
    	map.clearOverlays();<br />
    	document.getElementById("message").innerHTML = "All markers cleared";<br />
    }</code></p>
<p>Let&#8217;s play more with markers :)<br />
How about having a infowindow open when you click a marker?<br />
Check the following url<br />
<a href='http://sp2hari.com/gmap/event-showinfowindow.html'  target=_blank> http://sp2hari.com/gmap/event-showinfowindow.html</a><br />
In the above example, we can add markers and we also get an infowindow when we click on the marker. For this the code is very similar to the previous example with a small modification in the addMarker function.<br />
<code>    function addMarker(overlay, latlng) {<br />
    	marker[markerCount] = new GMarker(latlng);<br />
        marker[markerCount].bindInfoWindowHtml("This is Marker number "+markerCount);<br />
        map.addOverlay(marker[markerCount]);<br />
        markerCount = markerCount+1;<br />
	    document.getElementById("message").innerHTML = "Marker added at latitude "+latlng.lat() + " longitude "+latlng.lng() ;<br />
    }</code></p>
<p>As you can see, we have a global array of markers and whenever we create a new marker, we bind an infowindow to the marker using bindInfoWindowHtml method. Simple right? :)<br />
We&#8217;ll see more complex event handling sometime later. :) Feeling sleep right now :)</p>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2008/01/15/google-maps/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Coding Style &#8230;</title>
		<link>http://sp2hari.com/2007/05/23/coding-style/</link>
		<comments>http://sp2hari.com/2007/05/23/coding-style/#comments</comments>
		<pubDate>Wed, 23 May 2007 11:01:00 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[LDTP]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://sp2hari.com/?p=43</guid>
		<description><![CDATA[I have never thought much about coding style before i did my NOSIP in Novell. But once i started coding for ldtprecord, according to the coding style suggested to me by nags, i was surprised to see how nice and &#8230; <a href="http://sp2hari.com/2007/05/23/coding-style/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div style="text-align: justify;">I have never thought much about coding style before i did my <a href="http://www.gnomebangalore.org/?q=nosip">NOSIP</a> in <a href="http://www.novell.com/">Novell</a>. But once i started coding for <a href="http://ldtp.freedesktop.org/">ldtprecord</a>, according to the coding style suggested to me by <a href="http://nagappanal.blogspot.com/">nags</a>, i was surprised to see how nice and neat the final code looks.</div>
<p>Some tips/tricks for nice coding skills are,</p>
<div style="text-align: justify;">1. Do spend some time to think about the variable names and the function names. This sometimes might be bit boring, especially when you want to concentrate much on the program logic and performance. But this is <span style="font-style: italic;">Rule 0</span> for coding conventions. A variable name &#8220;k&#8221; can imply anything like &#8220;kappa, kozhukattai, katthu, kaadhal, kerala, kozhuppu&#8230;&#8221; to someone who might have to read your code later. This is again mentioned <a href="http://developer.gnome.org/doc/guides/programming-guidelines/code-style.html">here</a> clearly. Many thanks to emacs, you can always use the auto complete, if your variable name is too long. :-) .</div>
<p>
<div style="text-align: justify;">2. The actual coding convention depends much on the language and the standards your team is using already. The following style won&#8217;t work for someone, whose team is already using a totally different style.</div>
<p>A few examples for C is posted here .</p>
<p><span style="font-weight: bold;">Sample Code 1 :</p>
<p></span><span style="font-style: italic;">if (a == 5)  {</span><span style="font-style: italic;"><br /></span>
<div style="text-align: left;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-style: italic;">b = 10;</span></div>
<p><span style="font-style: italic;">}</span><br /><span style="font-style: italic;">else {</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-style: italic;">b = 20;</span> <span style="font-style: italic;"><br />}</span></p>
<p>Things to be noticed in the above snippet are.</p>
<p>1. A space between if and &#8220;(&#8221; .<br />2. Space in both the sides of the comparison operator.<br />3. Space between &#8220;)&#8221; and &#8220;{&#8220;<br />4. Space between both the sides of assignment operator (line 2 &#038; 5) . This is true for almost all the operators.<br />5. Proper indentation of lines 2 &amp; 5. If you are using emacs or vi, check <a href="http://developer.gnome.org/doc/guides/programming-guidelines/code-style.html">here</a> for your .emacs or .vimrc file .</p>
<div style="text-align: justify;">Well, your code will compile and run even if you don&#8217;t give these spaces, but a program coded with a bad coding style is equivalent to an inefficient code.</div>
<p><span style="font-weight: bold;">Sample Code 2</p>
<p></span>Let us have a function which takes two integers and returns their sum .<br />The code should be like<br /><span style="font-style: italic;"><br />int add_numbers (int num1, int num2) {</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-style: italic;">return (num1 + num2);</span> <span style="font-style: italic;"><br />}</span></p>
<p>The function call will be something like,</p>
<p><span style="font-style: italic;">int sum;</span> <span style="font-style: italic;"><br />sum = add_numbers (10, 20);</p>
<p></span>Things to be noticed in the above snippet is</p>
<p>In the first line in the function declaration,</p>
<p>1. The function name should be as clear as possible.<br />2. A space between the end of function name and &#8220;(&#8221; .<br />3. Spaces are given after every &#8220;,&#8221; in the function argument list.<br />4. A space is given between &#8220;)&#8221; and &#8220;{&#8220;.</p>
<p>In the second line in the function declaration,</p>
<p>1. A space before &#8220;(&#8220;.  [ This rule is almost global. Apply it everywhere whenever you use "(" ] .
<div style="text-align: justify;">2. There is a space on both the sides of the addition operator. This is again almost global. A space between both the sides of operator makes the code look real neat.</div>
<p>3. The indentation about which was mentioned earlier.</p>
<p>But yes, if your girl friend is a geek or a nerd or a psycho or a fundoo, then you better go for this. ;-)</p>
<p><span style="font-style: italic;">#define MAGIC &#8220;eilouvy43605321&#8243;</span><br /><span style="font-style: italic;">#define _(p,o,q) (t o#p[0])?(q)</span><br /><span style="font-style: italic;">#define __(p,o,q) _(p,o,t-q)</span><br /><span style="font-style: italic;">int main(){int t, i; for(i=8;i>0;i&#8211;)printf(&#8220;%c&#8221;, MAGIC[(((t=(MAGIC+7)[i-1])==&#8217;_')?62:_(.,==,63):_(@,==,64):__(a,>=,&#8217;a'+36):__(A,>=,&#8217;A'+10):(t-&#8217;0&#8242;))]);}</p>
<p></span>Note :: I wont say the coding style i use is the perfect one. It always depends upon what your team was using till now and how easy it is to read, debug and maintain the code.<span style="font-style: italic;"></p>
<p></span><span>Useful Links :<br /></span>
<div style="text-align: justify;">The guide coding standards in <a href="http://developer.gnome.org/doc/guides/programming-guidelines/book1.html">GNOME</a> is really a nice one.<br />Even better was <a href="http://www.possibility.com/Cpp/CppCodingStandard.html">this one</a> i found recently. Though i didn&#8217;t read it completely, it was quite interesting.<br /><a href="http://www.arcticlabs.com/codingstandards/ArcticLabsCodingStandardsCpp.html">This</a> article was short and sweet. </div>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2007/05/23/coding-style/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

