<?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>Veerasundar &#187; How To</title>
	<atom:link href="http://veerasundar.com/blog/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://veerasundar.com/blog</link>
	<description>Java, web and design</description>
	<lastBuildDate>Wed, 16 May 2012 07:13:40 +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>Scroll to top &#8211; JavaScript bookmarklet</title>
		<link>http://veerasundar.com/blog/2012/05/scroll-to-top-javascript-bookmarklet/</link>
		<comments>http://veerasundar.com/blog/2012/05/scroll-to-top-javascript-bookmarklet/#comments</comments>
		<pubDate>Tue, 01 May 2012 16:01:02 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[bookmark]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[navigate]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[toolbar]]></category>
		<category><![CDATA[top]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=3028</guid>
		<description><![CDATA[So, tell me, how many times have you annoyed with very long pages (such as this blog) and wished for a single click way to jump to top of the page!? If your answer is many, then this tip might give you some relief &#8211; add a bookmarklet to your bookmarks toolbar that jumps to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>So, tell me, how many times have you annoyed with very long pages (such as this blog) and wished for a single click way to jump to top of the page!? If your answer is <em>many, </em>then this tip might give you some relief &#8211; <strong>add a bookmarklet to your bookmarks toolbar that jumps to the top of the page for you.</strong></p>
<p>Here&#8217;s the dead simple way to do it. Just drag this link to your bookmarks toolbar: <a href="javascript:window.scrollTo(0,0);">^</a></p>
<p>Here are the manual steps:</p>
<ol>
<li>Add a new bookmark.</li>
<li>In the <em>name </em>field, enter either ^ or UP or *whatever*!</li>
<li>In the location/URL field, enter: <em>javascript:window.scrollTo(0,0);</em></li>
<li>Save it.</li>
</ol>
<p>Happy jumping around!</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/05/scroll-to-top-javascript-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to reset Auto Increment back to 1 in XAMPP MySQL using phpMyAdmin</title>
		<link>http://veerasundar.com/blog/2012/04/how-to-reset-auto-increment-back-to-1-in-xampp-mysql-using-phpmyadmin/</link>
		<comments>http://veerasundar.com/blog/2012/04/how-to-reset-auto-increment-back-to-1-in-xampp-mysql-using-phpmyadmin/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 11:56:04 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[increment]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[reset]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[xampp]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2984</guid>
		<description><![CDATA[When you delete every records from a table, which has an AUTO Increment ID field, the delete option will not reset the Auto Increment number. For example, if the table had 5 rows, and you deleted all the rows (either one by one or through delete from tablename where 1;), and then if you insert a new [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>When you delete every records from a table, which has an AUTO Increment ID field, the <em>delete</em> option will not reset the<em> Auto Increment </em>number. For example, if the table had 5 rows, and you deleted all the rows (either one by one or through <em>delete from tablename where 1;</em>), and then if you insert a new row, it will get a ID value as <strong>6 </strong>not as <strong>1</strong>. Because the auto increment value is not reset.</p>
<p>The easiest way to reset the auto increment number is to use the query <strong>truncate tablename; </strong>which removes all the rows from that table and resets the auto increment back to 1.</p>
<p>But if you want to do it visually, phpMyAdmin provides options for that:</p>
<p style="text-align: center;"><img class="aligncenter  wp-image-2988" title="auto-increment-mysql" src="http://veerasundar.com/blog/wp-content/uploads/2012/04/auto-increment.png" alt="" width="670" height="492" /></p>
<ol>
<li>In phpMyAdmin, open the table for which you want to reset the auto increment number.</li>
<li>Then go to: <strong>Operations -&gt; Table Options. </strong></li>
<li>Reset the <strong>AUTO_INCREMENT </strong>field to whichever value you want and save the changes.</li>
</ol>
<p>That&#8217;s it. The next time, when you insert new records, they will start from the auto increment number you set above.</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/04/how-to-reset-auto-increment-back-to-1-in-xampp-mysql-using-phpmyadmin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to auto reload external code changes in Eclipse project</title>
		<link>http://veerasundar.com/blog/2012/04/how-to-auto-reload-external-code-changes-in-eclipse-project/</link>
		<comments>http://veerasundar.com/blog/2012/04/how-to-auto-reload-external-code-changes-in-eclipse-project/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 02:01:38 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[refresh]]></category>
		<category><![CDATA[reload]]></category>
		<category><![CDATA[sublime]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[synchronize]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2965</guid>
		<description><![CDATA[I have started using Sublime text as my preferred code editor (for JS, CSS, Coffee). But, I still rely on Eclipse for writing Java code because it auto-imports Java packages and auto suggests variables and method names from my custom class files. Working on multiple editors throws in another problem: whenever I make a change [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I have started using <a href="http://veerasundar.com/blog/2012/03/unix-alias-with-parameters-or-opening-sublime-text-editor-from-command-line/">Sublime text</a> as my preferred code editor (for JS, CSS, Coffee). But, I still rely on Eclipse for writing Java code because it auto-imports Java packages and auto suggests variables and method names from my custom class files.</p>
<p>Working on multiple editors throws in another problem: whenever I make a change in some file outside of Eclipse, the IDE does not silently reload. It shows a blank page saying &#8220;The resource is out of sync. Press F5 to reload&#8221;. The message started annoying me soon as I had to switch back and forth often.</p>
<p>It is not just for the multiple editors. Even when I do a <em>git pull,</em> the resources go out of sync.</p>
<p>Then, I found a workaround for this. Eclipse provides a built-in option that auto reloads a resource if its out f sync. Here&#8217;s how you  can enable it.</p>
<p>Go to <strong>Window -&gt; Preferences -&gt; General -&gt; Workspace </strong>and check the option <strong>&#8220;Refresh using native hooks or polling&#8221;</strong>.</p>
<p>So, the next time when you try to open a out of sync file, the IDE will sync it for you (thus saving you a keystroke, one at a time <img src='http://veerasundar.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ).</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/04/how-to-auto-reload-external-code-changes-in-eclipse-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unix alias with parameters or Opening Sublime Text editor from command line</title>
		<link>http://veerasundar.com/blog/2012/03/unix-alias-with-parameters-or-opening-sublime-text-editor-from-command-line/</link>
		<comments>http://veerasundar.com/blog/2012/03/unix-alias-with-parameters-or-opening-sublime-text-editor-from-command-line/#comments</comments>
		<pubDate>Wed, 14 Mar 2012 13:59:13 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[alias]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[sublime]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2952</guid>
		<description><![CDATA[I&#8217;m using Sublime Text 2 in my Ubuntu machine. But unlike Windows, I couldn&#8217;t just right click on any source file and say &#8220;Open with Sublime&#8221; (may be because I just copied the binaries to a folder so that the editor didn&#8217;t register itself to the OS). Because of this, whenever I want to edit [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;m using Sublime Text 2 in my Ubuntu machine. But unlike Windows, I couldn&#8217;t just right click on any source file and say &#8220;Open with Sublime&#8221; (may be because I just copied the binaries to a folder so that the editor didn&#8217;t register itself to the OS). Because of this, whenever I want to edit a file using Sublime, I had to use the <em>File &gt; Open File </em>dialog, which is not an ideal way to do.</p>
<p>Since most of the time I would be inside a terminal when I want to edit a file, I found a workaround for this problem &#8211; <strong>using the Unix alias w/ parameters</strong>.</p>
<p>In Unix, we can create shortcut names to any long commands so that it saves our precious time (which we can invest back in Facebooking!). For my issue, I also need to pass the file name to edit as a parameter to this shortcut alias. So, I needed to create a <em>function.</em></p>
<p>Below is the code for this. I have placed this function definition in my <strong><em>.bashrc</em></strong> file so that it is available at my service whenever I open the terminal.</p>
<script src="https://gist.github.com/2036640.js"></script>
<p>You need to replace the correct path per your installation location!</p>
<p>Reviews of the best <a href="http://www.businesswebhostingplans.com/unix-web-hosting.html">unix hosting providers</a> including information on their prices, uptime, support and features can be found at <a href="http://www.businesswebhostingplans.com">businesswebhostingplans.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/03/unix-alias-with-parameters-or-opening-sublime-text-editor-from-command-line/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WordPress plugin to show the posts and comments count in the sidebar</title>
		<link>http://veerasundar.com/blog/2012/03/wordpress-plugin-to-show-the-posts-and-comments-count-in-the-sidebar/</link>
		<comments>http://veerasundar.com/blog/2012/03/wordpress-plugin-to-show-the-posts-and-comments-count-in-the-sidebar/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 01:58:52 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[stats]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2926</guid>
		<description><![CDATA[As part of this blog&#8217;s re-design, I wanted to show the number of posts and comments as a widget in the sidebar. But I couldn&#8217;t find a plugin that does exactly what I wanted. So, I wrote one on my own. Below is the source code for this wordpress plug-in which you can drop it [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>As part of this blog&#8217;s re-design, I wanted to show the number of posts and comments as a widget in the sidebar. But I couldn&#8217;t find a plugin that does exactly what I wanted. So, I wrote one on my own.</p>
<p>Below is the source code for this wordpress plug-in which you can drop it in your <em>plugins </em>folder and then activate it as usual. Then, in your <em>Widgets</em> section, you&#8217;ll see a new widget that you can use it in your sidebar.</p>
<h2>Source for WordPress StatsBoard plugin to display the posts and comments count:</h2>
<script src="https://gist.github.com/1976268.js"></script>
<p>You can use the plugin however the way you want, of course, at your own risk! <img src='http://veerasundar.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/03/wordpress-plugin-to-show-the-posts-and-comments-count-in-the-sidebar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>root user in Ubuntu</title>
		<link>http://veerasundar.com/blog/2012/02/root-user-in-ubuntu/</link>
		<comments>http://veerasundar.com/blog/2012/02/root-user-in-ubuntu/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 12:45:43 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[permission]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2925</guid>
		<description><![CDATA[Today I got stuck on what could be a simple problem to long time Ubuntu users &#8211; making changes that require root access. I never faced this problem until today because my Ubuntu user account/password was enough to make system level changes as it was treated like admin user by Ubuntu. Today I tried to [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Today I got stuck on what could be a simple problem to long time Ubuntu users &#8211; making changes that require <em>root </em>access.</p>
<p>I never faced this problem until today because my Ubuntu user account/password was enough to make system level changes as it was treated like admin user by Ubuntu.</p>
<p>Today I tried to modify the directory <em>/var/www </em>which is owned by the <em>root</em>. Since the folder is not owned by me, Ubuntu asked me to enter the <em>root</em> password and I typed my Ubuntu user password. It didn&#8217;t work, obviously.</p>
<p>Then I tried to escalate the permission level to <em>root, </em>so I tried the command: <em>su root </em>and gave my Ubuntu user password. This also failed.</p>
<p>After googling sometime, I found out that,</p>
<ol>
<li>Ubuntu does not allow you to directly login as <em>root</em>.</li>
<li>The first Ubuntu account you create is treated like <em>admin</em> account.</li>
</ol>
<p>So, in order to escalate yourself as a <em>root </em>user in Ubuntu terminal, I had to give the command: &#8220;<em><strong>sudo su -&#8221; </strong>(without quotes) </em>and then enter my current Ubuntu user password. After that, I was escalated to <em>root </em>user and then able to modify the <em>/var/www </em>folder as I wanted. Piece of cake!!</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/02/root-user-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How I scrape web pages</title>
		<link>http://veerasundar.com/blog/2012/02/how-i-scrap-web-pages/</link>
		<comments>http://veerasundar.com/blog/2012/02/how-i-scrap-web-pages/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 14:37:02 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[scrap]]></category>
		<category><![CDATA[scraping]]></category>
		<category><![CDATA[scratchpad]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2918</guid>
		<description><![CDATA[Often I need to pull some content out of web pages. Of course, I can always do a simple Ctrl+C. But many times, I want the scrapped content to be in a different format than it&#8217;s already in. So, I used to write Java code that downloads the content and do some XML parsing and then converts [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Often I need to pull some content out of web pages. Of course, I can always do a simple <em>Ctrl+C</em>. But many times, I want the scrapped content to be in a different format than it&#8217;s already in. So, I used to write Java code that downloads the content and do some XML parsing and then converts it into the format I want. But, this became a tedious process soon.</p>
<p>So, these days I figured out another easy way to do the web scraping. JQuery!</p>
<p>IMO, JQuery is the best tool to do the DOM parsing and content extraction. Of course, that&#8217;s why the JQuery library is built for.</p>
<p>But the problem here is, not all websites include JQuery with them and even if they do, you can&#8217;t just go and execute your JavaScript code in amother person&#8217;s website.</p>
<p>Thanks to Scratchpad from Firefox which solves the above problem. Starting last August, Firefox comes with a built-in webdev tool &#8211; <a title="Introducing Scratchpad" href="http://blog.mozilla.com/devtools/2011/08/15/introducing-scratchpad/" target="_blank">Scratchpad</a> that enables you to execute your own JavaScript code in the context of any website.</p>
<p>So, this is what I do to scrape any public content from any web page:</p>
<ol>
<li>Open the page in Firefox.</li>
<li>Press <strong>Shift+F4 </strong>or go to <strong>Firefox menu-&gt;Web developer-&gt;Scratchpad</strong> to open the JavaScript editor.</li>
<li>Include the below lines to add JQuery library to the current page (<a title="Add jQuery to any (or every) webpage" href="http://blogs.ischool.berkeley.edu/i290-04f09/2009/09/12/add-jquery-to-any-or-every-webpage/" target="_blank">thanks to this page</a>).
<pre class="brush:javascript">var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);</pre>
</li>
<li>After that I can use any valid JQuery statement to navigate through the page content and parse it.
<pre class="brush:javascript">var pages = [];
$("#Text1 table a").each(function(){
    pages.push($(this).attr('href'));
});</pre>
</li>
</ol>
<p>Caution: Some websites may prohibit web scraping. So, please make your own judgment before scraping their content! Just saying! <img src='http://veerasundar.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/02/how-i-scrap-web-pages/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shortcut to console.log</title>
		<link>http://veerasundar.com/blog/2012/02/shortcut-to-console-log/</link>
		<comments>http://veerasundar.com/blog/2012/02/shortcut-to-console-log/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 17:10:46 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2911</guid>
		<description><![CDATA[Sometimes, I&#8217;m just lazy to type &#8216;console.log&#8216; to print some data on the Firebug console. I often wanted to have a simple echo() function that spits whatever it gets to the console. So, in every single JavaScript project I work on, I used to have this utility method: function echo(obj){ console.log(obj); } ... echo('Hello World'); [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Sometimes, I&#8217;m just lazy to type &#8216;<em>console.log</em>&#8216; to print some data on the Firebug console. I often wanted to have a simple <em>echo() </em>function that spits whatever it gets to the console.</p>
<p>So, in every single JavaScript project I work on, I used to have this utility method:</p>
<pre class="brush:javascript">function echo(obj){
  console.log(obj);
}
...
echo('Hello World');</pre>
<p>It worked well. But there was a problem. The printed message on the console will always show the line number of <em>console.log  </em>as the source line number instead of showing the where exactly the <em>echo() </em>function is invoked.</p>
<p>There&#8217;s another way to solve this. Instead of creating a new <em>echo() </em>method, I just need to bind it to the existing <em>console.log() </em>to a variable and the logging works like a charm. Like this,</p>
<pre class="brush:javascript">window.echo = console.log.bind(console);
window.oops = console.error.bind(console);
...
echo('hello world');
...
oops('I did it again');</pre>
<p>The the methods became shorter and the correct line numbers printed on the console!</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/02/shortcut-to-console-log/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Every single pixel counts</title>
		<link>http://veerasundar.com/blog/2012/02/every-single-pixel-counts/</link>
		<comments>http://veerasundar.com/blog/2012/02/every-single-pixel-counts/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 13:22:24 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[compiz]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[terminator]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2888</guid>
		<description><![CDATA[At any given point of time, you can find at least 4 windows/editors opened on my screen. As a web developer, it is not unusual for me to work on several files at the same time. So, to reduce the Alt+Tabbing, I try to have most of the windows visible on the screen. Following is [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>At any given point of time, you can find at least 4 windows/editors opened on my screen. As a web developer, it is not unusual for me to work on several files at the same time. So, to reduce the <em>Alt+Tabbing, </em>I try to have most of the windows visible on the screen. Following is a list of tools that help me to do so.</p>
<h2>1. Two monitor setup</h2>
<p>Along with my laptop screen, I have setup one additional monitor. This gives me lots of screen space which I can make use of. In fact, I would like to setup one more monitor too, but the limitation of laptop graphics card holding me back.</p>
<h2>2. Grid plugin in Compiz</h2>
<p>I&#8217;m running Ubuntu on my laptop. I have installed Compiz which provides several plugins to fine tune the Ubuntu UI. <strong>Grid </strong>is one such plugin for re-sizing windows.</p>
<p>Once enabled, you can press <em>Ctrl + Alt + &lt;KeyPad 4&gt;</em> to re-size the current window and fit it on the left side of the screen. You can repeatedly press the same key combo to switch between different window sizes. There are other keyboard shortcuts too which positions the current window in different directions.</p>
<p style="text-align: center;"><a href="http://veerasundar.com/blog/wp-content/uploads/2012/02/grid.png"><img class="aligncenter  wp-image-2896" title="grid" src="http://veerasundar.com/blog/wp-content/uploads/2012/02/grid.png" alt="Compiz Grid" width="560" height="305" /></a></p>
<p>Unfortunately, after upgrading to Ubuntu 11.10, the Grid plugin does not work correctly. There&#8217;s a <a title="Compiz Grid feature under Unity stopped functioning properly" href="https://bugs.launchpad.net/ubuntu/+source/unity/+bug/879218" target="_blank">bug raised</a> for this and hopefully it&#8217;ll be fixed and the world will come to an order.</p>
<h2>3. Terminator</h2>
<p><strong>Terminator </strong>lets me to run multiple terminals inside a single window. Initially it opens with a single terminal window. Then, I could split up that window either horizontally or vertically to get additional terminals. I can go further and split them again until I get the number of terminal I want. Pretty neat!</p>
<p style="text-align: center;"><a href="http://veerasundar.com/blog/wp-content/uploads/2012/02/terminator.png"><img class="aligncenter  wp-image-2897" title="terminator" src="http://veerasundar.com/blog/wp-content/uploads/2012/02/terminator.png" alt="Terminator Ubuntu" width="560" height="243" /></a></p>
<p>You can download Terminator from the Ubuntu Software center.</p>
<h2>4. Eclipse split editors</h2>
<p>Fortunately, Eclipse comes with a built-in support for having two editors side-by-side. Just drag the editor until it sits on its own space and you&#8217;re all set.</p>
<p>Now the only things that concerns me is the default file manager in Ubuntu. I do not feel the Nautilus file manager is that effective. For instance, I couldn&#8217;t copy the current path name or split the screens to have two folders opened at the same time.</p>
<p>I&#8217;m still looking for a workaround for this. Would appreciate if you are using any better file manager than Nautilus, please leave a comment! <img src='http://veerasundar.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Edit: </strong>Nautilus already does both the things. Thanks to <a href="http://leafac.com/" rel="external nofollow">Leandro Facchinetti</a> for the awesome tip (in the comments section)!</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/02/every-single-pixel-counts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Backbone JS &#8211; Hello World tutorial</title>
		<link>http://veerasundar.com/blog/2012/01/backbone-js-hello-world-tutorial/</link>
		<comments>http://veerasundar.com/blog/2012/01/backbone-js-hello-world-tutorial/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 15:39:11 +0000</pubDate>
		<dc:creator>Veera</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[backbone]]></category>
		<category><![CDATA[helloworld]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://veerasundar.com/blog/?p=2855</guid>
		<description><![CDATA[Backbone.js is recently getting lots of traction among the web developers because of its ability to organize the JavaScript code. It provides the structure (Model-View) around which we can build our JavaScript heavy web applications. I have started learning backbone.js for my personal project and I&#8217;m going to document my learning along the way. Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://documentcloud.github.com/backbone/">Backbone.js</a> is recently getting lots of traction among the web developers because of its ability to organize the JavaScript code. It provides the structure (Model-View) around which we can build our JavaScript heavy web applications.</p>
<p>I have started learning backbone.js for my personal project and I&#8217;m going to document my learning along the way. Let&#8217;s start with a simplest possible example: A Hello World tutorial in Backbone.js (duh!)</p>
<p>You are welcomed to point out any anti-patterns/mistakes that I made in this tutorial so that I can update the content for better.</p>
<p><a title="Backbone JS - Hello World tutorial" href="http://veerasundar.com/app/hello-backbone/" target="_blank">Demo</a> | <a title="Fork the source code in GitHub" href="https://github.com/vraa/hello-backbone" target="_blank">Source code</a></p>
<h2>The need for Backbone.js</h2>
<p>Generally, we use JavaScript to handle UI events (<em>click</em>, <em>keypress</em>, etc), to process the UI data (<em>innerHTML,</em> etc) and to render DOM elements (<em>appendChild, </em>etc).</p>
<p>Without a framework like Backbone.js, each developer would implement the above logic in his/her own coding style. This might cause some maintenance issues if multiple developers are involved.</p>
<p>Backbone.js provides a structure to do the above operations so that it is easy to write a maintainable code with less effort.</p>
<p>With Backbone, you get the following constructs:</p>
<ol>
<li><strong>Model </strong>- used to represent your application data. For example, an <em>Employee</em> model.</li>
<li><strong>Collection </strong>- used to hold a list of your model objects. For example, an <em>Employees </em>collection which contains a list of <em>Employee </em>model.</li>
<li><strong>Views </strong>- each model &amp; collection can be associated with a Backbone view. You can also create a view for an existing DOM element so that the view can respond to events generated from that DOM element.</li>
</ol>
<p>That said, Let&#8217;s start building our application step by step.</p>
<h2>0. Requirement</h2>
<p>Our requirement is to <a href="http://veerasundar.com/app/hello-backbone/" target="_blank">create a application</a> that gets a name from the user and says &#8216;Hello {name}&#8217; and appends it to a list.</p>
<h2>1. Create the User Interface</h2>
<p>Let&#8217;s create our user interface first.</p>
<pre class="brush:html">	&lt;body&gt;
		&lt;header&gt;
			&lt;h1&gt;Backbone JS - Hello World Tutorial!&lt;/h1&gt;
			&lt;h5&gt;&amp;lt;= &lt;a href='#'&gt;back to the article&lt;/a&gt;&lt;/h5&gt;
		&lt;/header&gt;

		&lt;section id='UserInput'&gt;
			&lt;fieldset&gt;
				&lt;legend&gt;Enter a name and click say hello!&lt;/legend&gt;
				&lt;input type="text" name="hello" placeholder="your friend name" value="veera" /&gt; &amp;#160; &lt;button&gt;Say hello&lt;/button&gt;
			&lt;/fieldset&gt;
		&lt;/section&gt; 

		&lt;ol id="HelloList"&gt;

		&lt;/ol&gt;

		&lt;script type="text/javascript" src="jquery-1.7.1.min.js"&gt;&lt;/script&gt;
		&lt;script type="text/javascript" src="underscore-min.js"&gt;&lt;/script&gt;
		&lt;script type="text/javascript" src="backbone-min.js"&gt;&lt;/script&gt;
		&lt;script type="text/javascript" src="hello.js"&gt;&lt;/script&gt;
	&lt;/body&gt;</pre>
<p>As you can see, it&#8217;s a simple HTML document with a textbox, button to accept user input and a empty OL element to hold the list of hello messages.</p>
<h2>2. Create the Backbone Views to represent the UI elements</h2>
<p>We have two views in our UI: One that accepts user input and one that shows the accepted inputs as a list. So, we&#8217;ll create two Backbone views for this. Open the <em>hello.js </em>and type in the below code.</p>
<pre class="brush:javascript">(function($) {

	var UserInputView = Backbone.View.extend({

		el : '#UserInput',

		initialize : function() {
			this.helloListView = new HelloListView();
		},

		events : {
			'click button' : 'addToHelloCollection'
		},

		addToHelloCollection : function(e) {
		}
	});

	var HelloListView = Backbone.View.extend({

		el : '#HelloList',

	});

	new UserInputView();

})(jQuery);</pre>
<p>Because we are creating the Backbone views to represent the existing DOM elements, we can mention the elements in <em>el<strong> </strong></em>option. You can use the CSS3 selector syntax here and Backbone will find the element for you.</p>
<p>All Backbone objects has an <em>initialize() </em>function. Above we are initializing the <em>UserInputView </em>with a reference to the <em>HelloListView</em>.</p>
<p>Each view can accept a <em>events</em> object. Within this, you can specify what are all the events this view will trigger and method name to handle the event. In our case, we have a <em>click </em>event for the <em>button </em>element and a method <em>addToHelloCollection</em> to handle the click event. It is important to note that Backbone searches for the elements mentioned inside the <em>events </em>hash (in this case <em>button</em>) inside the <em>el</em>. So the <em>el</em> element should contain whatever element you give in the <em>events </em>object.</p>
<h2>3. Create Backbone Model, Collection and a view to represent the model</h2>
<p>It&#8217;s time to create a Backbone Model to hold our application data. We can map each hello message to a model. Since we have list of messages, we&#8217;ll create a Backbone Collection too. Lets look at the code.</p>
<pre class="brush:javascript">var Hello = Backbone.Model.extend({
		initialize : function() {
			this.name = 'name'
		}
	});

	var HelloView = Backbone.View.extend({
		tagName : 'li',
		render : function() {
			$(this.el).html('Hello ' + this.model.get('name'));
			return this;
		}
	});

	var HelloList = Backbone.Collection.extend({
		model : Hello
	});</pre>
<p><em>Hello</em> is the model object with a property <em>name </em>initialized to &#8216;name&#8217;. <em>HelloList</em> is the collection and we set this collection <em>model </em>property to our <em>Hello</em> model.</p>
<p>In Backbone, each Model and Collection can have it&#8217;s own view to render themselves. So, we created a <em>HelloView</em> for the <em>Hello</em> model with the <em>render() </em>method to generate the HTML output. Since this view is not associated with any existing DOM elements and Backbone needs a wrapper tag to surround the rendered output, we provide the <em>tagName </em>property with &#8216;li&#8217;. Because of this, when the <em>Hello</em> model generates its HTML code (in <em>render() </em>method), it will be surrounded by <em>li </em>tag.</p>
<h2>4. Combine everything: The final code for hello.js</h2>
<p>Lets update our <em>hello.js </em>file with this final JavaScript.</p>
<pre class="brush:javascript">(function($) {

	var UserInputView = Backbone.View.extend({

		el : '#UserInput',

		initialize : function() {
			this.helloListView = new HelloListView();
		},

		events : {
			'click button' : 'addToHelloCollection'
		},

		addToHelloCollection : function(e) {
			var hello = new Hello({
				name : this.$('input').val()
			});
			this.helloListView.collection.add(hello);
		}
	});

	var Hello = Backbone.Model.extend({
		initialize : function() {
			this.name = 'name'
		}
	});

	var HelloView = Backbone.View.extend({
		tagName : 'li',
		render : function() {
			$(this.el).html('Hello ' + this.model.get('name'));
			return this;
		}
	});

	var HelloList = Backbone.Collection.extend({
		model : Hello
	});

	var HelloListView = Backbone.View.extend({

		el : '#HelloList',

		initialize : function() {
			_.bindAll(this, 'render', 'appendToHelloUL');
			this.collection = new HelloList();
			this.collection.bind('add', this.appendToHelloUL);
		},

		render:function(){

			$.each(this.collection.models, function(i, helloModel){
				self.appendToHelloUL(helloModel);
			});
		},

		appendToHelloUL : function(helloModel) {
			var helloView = new HelloView({
				model : helloModel
			});
			$(this.el).append(helloView.render().el);
		}
	});

	new UserInputView();

})(jQuery);</pre>
<p>As you can see, we have two Backbone views:</p>
<ol>
<li><em>UserInputView</em> &#8211; which listens to the user interface events(<em>button click</em>) and update the model object with user input.</li>
<li><em>HelloListView</em> &#8211; which listens to the changes in our model(<em>add </em>event) and update the user interface with the model values.</li>
</ol>
<div>Everything starts when we create a <em>new UserInputView() </em>which triggers <em>initialize </em>function for each objects and sets up event listeners. When user interacts with the view, the respective event listeners are called and the model gets updated. Then the <em>HelloListView</em> which is listening to model changes gets triggered and the user interface is updated.</div>
<p>Well, that concludes this tutorial. You can see the <a title="Backbone JS - Hello World tutorial" href="http://veerasundar.com/app/hello-backbone/" target="_blank">completed application in action</a> or <a title="Github source" href="https://github.com/vraa/hello-backbone" target="_blank">fork the code in GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://veerasundar.com/blog/2012/01/backbone-js-hello-world-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

