<?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>Gaurav Verma</title>
	<atom:link href="http://www.gauravv.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gauravv.com</link>
	<description></description>
	<lastBuildDate>Tue, 05 Jan 2010 15:15:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Core Graphics Tutorial : How to create a sleek Weather View</title>
		<link>http://www.gauravv.com/2010/01/01/core-graphics-tutorial-how-to-create-a-sleek-weatherview/</link>
		<comments>http://www.gauravv.com/2010/01/01/core-graphics-tutorial-how-to-create-a-sleek-weatherview/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 06:36:13 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=303</guid>
		<description><![CDATA[In this tutorial i will show you how to create a sleek looking and self contained Weather View using Core graphics for iPhone. Also, how to use shadows and gradients to create an impressive UI. We will also see how to use libxml &#038; XPath for easier XML Processing. You can get sample source code on github.


Related posts:<ol><li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2010%2F01%2F01%2Fcore-graphics-tutorial-how-to-create-a-sleek-weatherview%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2010%2F01%2F01%2Fcore-graphics-tutorial-how-to-create-a-sleek-weatherview%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: left;"><img class="size-full wp-image-304 alignleft" style="margin-top: 5px; margin-bottom: 5px; margin-left: 10px; margin-right: 10px;" title="WeatherView for iPhone Screenshot" src="http://www.gauravv.com/wp-content/uploads/2010/01/Screen-shot-2010-01-01-at-11.16.04-AM.png" alt="" width="299" height="222" />Hello All, In this tutorial i will show you how to create a sleek looking and self contained Weather View using Core graphics for iPhone.As you can see from the screenshot, we will also be implementing gradient &amp; shadows to create the whole effect. So, fasten your seat belt and get ready to dive with me in the world of &#8220;Core Graphics&#8221; :)</p>
<p style="text-align: left;">For the purpose of this tutorial i am assuming you are already familiar with basic iPhone Programming concepts.So, i would be starting directly with the WeatherView. Ofcourse, you can download the <a title="Core Graphics Tutorial Sample Code" href="http://github.com/gauravverma/iPhone_projects/tree/master/Weather/" target="_blank">sample code</a> and have a look to understand it better.</p>
<p style="text-align: left;">First lets list down our objective, We want to create a reusable component for iPhone which can display weather data of a city. We also want an optimized solution, hence we will be create a single UIImage on the fly and will cache it for display. Here is the video of the working application that we would be creating in this tutorial. I recommend you to look at the video first to get an idea of our objective here.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/jMLj6n8USPI&amp;hl=en_US&amp;fs=1&amp;" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="385" src="http://www.youtube.com/v/jMLj6n8USPI&amp;hl=en_US&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h3>Step 1. Get Data from Weather API</h3>
<p>We need to fetch weather data, for which i am using Google ig weather API which returns XML data. For parsing we will be using XPath functionality of libxml library. To setup libxml &amp; XPath you can read Matt Gallagher&#8217;s post at <a title="libxml with XPath" href="http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html" target="_blank">http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html</a></p>
<p>Here is the code i am using, please note that this is not production level code. Its just for demonstration, in real world you would want a better solution.</p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>urlData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> dataWithContentsOfURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.google.com/ig/api?weather=%@&quot;</span>,address<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>urlData <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>ac removeFromSuperview<span style="color: #002200;">&#93;</span>;
	loadingMessage.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Network Error!&quot;</span>;
	loadingMessage.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>info <span style="color: #002200;">=</span> PerformXMLXPathQuery<span style="color: #002200;">&#40;</span>urlData, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;//current_conditions/*[@data]/@*&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>info count<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>ac removeFromSuperview<span style="color: #002200;">&#93;</span>;
	loadingMessage.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Information Not Available&quot;</span>;
	loadingMessage.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>city <span style="color: #002200;">=</span> PerformXMLXPathQuery<span style="color: #002200;">&#40;</span>urlData, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;//city[@data]/@*&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>qualifiedCityName <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>city objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span> valueForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;nodeContent&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p></code></p>
<p>Now we have all the data that is required, lets start with Core Graphics,</p>
<h3>Step 2. Using Core Graphics</h3>
<p>We will be creating a single image, so will create a bitmap image context :</p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Start Drawing on new Image Context</span>
CGFloat width <span style="color: #002200;">=</span> 160.0f, height <span style="color: #002200;">=</span> 105.0f;
<span style="color: #11740a; font-style: italic;">// create a new bitmap image context</span>
UIGraphicsBeginImageContext<span style="color: #002200;">&#40;</span>CGSizeMake<span style="color: #002200;">&#40;</span>width, height<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #11740a; font-style: italic;">// get context</span>
CGContextRef context <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #11740a; font-style: italic;">// push context to make it current</span>
<span style="color: #11740a; font-style: italic;">// (need to do this manually because we are not drawing in a UIView)</span>
UIGraphicsPushContext<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p></code></p>
<p>Now lets add shadows to the Text :</p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Add shadows to text</span>
<span style="color: #a61390;">float</span> myColorValues<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#123;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0.9</span><span style="color: #002200;">&#125;</span>;
CGSize myShadowOffset <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span>, <span style="color: #002200;">-</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
CGContextSetRGBFillColor<span style="color: #002200;">&#40;</span>context, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;
CGContextSetShadow<span style="color: #002200;">&#40;</span>context, myShadowOffset, <span style="color: #2400d9;">0.9</span><span style="color: #002200;">&#41;</span>;
CGColorSpaceRef myColorSpace <span style="color: #002200;">=</span> CGColorSpaceCreateDeviceRGB<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
CGColorRef myColor <span style="color: #002200;">=</span> CGColorCreate<span style="color: #002200;">&#40;</span>myColorSpace, myColorValues<span style="color: #002200;">&#41;</span>;
CGContextSetShadowWithColor <span style="color: #002200;">&#40;</span>context, myShadowOffset, <span style="color: #2400d9;">5</span>, myColor<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p></code></p>
<p>Since the images we are getting from google API are not so good looking, we will using <a title="Grzanka's Icons" href="http://voogee.deviantart.com/art/Grzanka-s-Icons-nr-2-44204272" target="_blank">Grzanka&#8217;s Icons</a>, lets draw the image first depending on the API data :</p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Draw Image</span>
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>imageURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>info objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span> valueForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;nodeContent&quot;</span><span style="color: #002200;">&#93;</span>;
imageURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>imageURL pathComponents<span style="color: #002200;">&#93;</span> lastObject<span style="color: #002200;">&#93;</span>;
imageURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>imageURL stringByReplacingOccurrencesOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;.gif&quot;</span> withString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;.png&quot;</span><span style="color: #002200;">&#93;</span>;
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ImageURL : %@&quot;</span>,imageURL<span style="color: #002200;">&#41;</span>;
UIImage <span style="color: #002200;">*</span>wimage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span>imageURL<span style="color: #002200;">&#93;</span>;
wimage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>wimage rescaleImageToSize<span style="color: #002200;">:</span>CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">90</span>, <span style="color: #2400d9;">90</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>wimage drawAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">15</span>,<span style="color: #2400d9;">15</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p></code></p>
<p>Similarly we can draw temperature, humidity, and wind direction. Now lets save the image from context, and use it for the display.</p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// pop context</span>
UIGraphicsPopContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;								
&nbsp;
<span style="color: #11740a; font-style: italic;">// get a UIImage from the image context- enjoy!!!</span>
cityImage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> retain<span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// clean up drawing environment</span>
UIGraphicsEndImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#91;</span>self setNeedsDisplay<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p></code></p>
<p>That is all !! This is all you need to do, download the source code and see it for yourself. If you have any questions then discuss it in comment section. Enjoy !! Happy Coding.</p>
<p>You can get the source code at Github : <a title="Core Graphics Tutorial Sample Code" href="http://github.com/gauravverma/iPhone_projects/tree/master/Weather/" target="_blank">http://github.com/gauravverma/iPhone_projects/tree/master/Weather/</a></p>
<p>And Ya ! Happy New Year :)</p>


<p>Related posts:<ol><li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2010/01/01/core-graphics-tutorial-how-to-create-a-sleek-weatherview/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>iPhone Development Tip : Custom UINavigationBar</title>
		<link>http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/</link>
		<comments>http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 11:30:00 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=289</guid>
		<description><![CDATA[
			
				
			
		
More and more developers are creating custom user elements these days to give &#8216;Branded&#8217; feel to the application. While doing so, we have to keep in mind Human Interface guidelines Apple has provided us. The easiest way to create your own custom element is to subclass Apple&#8217;s existing UI elements. Here is a quick tip on how to create custom UINavigationBar, so that simple properties like background, text color &#38; tint can be customized.
In this Article, i will show you how to subclass UINavigationBar to get the desired look and feel.
Step ...


Related posts:<ol><li><a href='http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Debugging Memory release'>iPhone Development Tip : Debugging Memory release</a> <small>I was struggling with a bug in my latest iPhone...</small></li>
<li><a href='http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/' rel='bookmark' title='Permanent Link: iPhone Development Tip : How to Dynamically Initialize Class in Objective-C'>iPhone Development Tip : How to Dynamically Initialize Class in Objective-C</a> <small>While working on an iPhone project i wanted a way...</small></li>
<li><a href='http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/' rel='bookmark' title='Permanent Link: iPhone Dev Tip: How to find out Available/Free Memory'>iPhone Dev Tip: How to find out Available/Free Memory</a> <small>The iPhone has limited memory,and as developer its our responsibility...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F12%2F29%2Fiphone-development-tip-custom-uinavigationbar%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F12%2F29%2Fiphone-development-tip-custom-uinavigationbar%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="alignleft size-medium wp-image-291" style="margin-top: 5px; margin-bottom: 5px; margin-left: 10px; margin-right: 10px;" title="Custom UINavigationBar Sample Screen1" src="http://www.gauravv.com/wp-content/uploads/2009/12/screen2-300x101.png" alt="Custom UINavigationBar Sample Screen1" width="300" height="101" />More and more developers are creating custom user elements these days to give &#8216;Branded&#8217; feel to the application. While doing so, we have to keep in mind <em>Human Interface guidelines </em>Apple has provided us. The easiest way to create your own custom element is to subclass Apple&#8217;s existing UI elements. Here is a quick tip on how to create custom UINavigationBar, so that simple properties like background, text color &amp; tint can be customized.</p>
<p>In this Article, i will show you how to subclass UINavigationBar to get the desired look and feel.</p>
<h2>Step 1. Subclassing UINavigationBar</h2>
<p>Subclassing is easiest way to implement custom drawing code or add methods to already existing elements. To start, create a new class file. I will name it &#8220;CustomNavigationBar&#8221;. Your header file should look like this when you are done :</p>
<p><code> </code></p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import</span>
<span style="color: #a61390;">@interface</span> CustomNavigationBar <span style="color: #002200;">:</span> UINavigationBar&lt;UINavigationControllerDelegate&gt; <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p></code><br />
This class &#8220;CustomNavigationBar&#8221;, since inherits from UINavigation has exactly same behavior of UINavigationBar.If you were to create a new &#8220;CustomNavigationBar&#8221; object or set a Navigation Barʼs class to &#8220;CustomNavigationBar&#8221; in Interface Builder you would be presented with a standard navigation bar object. However. By over- riding UINavigationBar methods in our classes .m file, we can change the behavior of our navigation bar instance.</p>
<h2>Step 2. Drawing the Custom Bar background</h2>
<p>Drawing a custom background for a UI element can be as simple as over-writing the drawRect method for most UI view inherent elements.for this example we will fill out navigations bar background with a simple 3 x 45 pixel background image. It will stretch automatically, so don&#8217;t worry about that.Modify drawRect: method in implementation file, to look like this :</p>
<p><code> </code></p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect <span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Drawing code</span>
	UIImage <span style="color: #002200;">*</span>image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;navBar.png&quot;</span><span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>image drawInRect<span style="color: #002200;">:</span>rect<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>image release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p></code></p>
<p>PS: if you have to change just the background image, it will work now. But it you want to customize titleView you have to implement UINavigationControllerDelegate also.</p>
<h2>Step 3. Implement UINavigationControllerDelegate</h2>
<p>UINavigationControllerDelegate object will be notified when a new viewController is about to be pushed into navigation stack OR after being pushed  into navigation stack. Since, we have modify titleView property we are more interested when a new viewController is about to be pushed. Add following lines to the implementation file :</p>
<p><code><br />
</code></p>
<p><code> </code></p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark -</span>
<span style="color: #6e371a;">#pragma mark UINavigationDelegate Methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>navigationController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UINavigationController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>navigationController willShowViewController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>viewController animated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>title <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>viewController title<span style="color: #002200;">&#93;</span>;
	UILabel <span style="color: #002200;">*</span>myTitleView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myTitleView setFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont boldSystemFontOfSize<span style="color: #002200;">:</span><span style="color: #2400d9;">18</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myTitleView setTextColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor yellowColor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	myTitleView.text <span style="color: #002200;">=</span> title;
	myTitleView.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myTitleView sizeToFit<span style="color: #002200;">&#93;</span>;
	viewController.navigationItem.titleView <span style="color: #002200;">=</span> myTitleView;
	<span style="color: #002200;">&#91;</span>myTitleView release<span style="color: #002200;">&#93;</span>;
&nbsp;
	viewController.navigationController.navigationBar.tintColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span>0.16f green<span style="color: #002200;">:</span>0.36f blue<span style="color: #002200;">:</span><span style="color: #2400d9;">0.46</span> alpha<span style="color: #002200;">:</span><span style="color: #2400d9;">0.8</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>navigationController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UINavigationController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>navigationController didShowViewController<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIViewController <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>viewController animated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated<span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p></code></p>
<h2>Step 4. Build proper connections in Interface builder</h2>
<p>If you are programmatically creating navigation Controller then you don&#8217;t have to anything in interface builder, you just have to set delegate properly. The sample application with this article is done via Interface builder, hence this step is necessary :</p>
<p><img class="alignleft size-medium wp-image-294" style="margin-top: 5px; margin-bottom: 5px; margin-left: 10px; margin-right: 10px;" title="IB screen" src="http://www.gauravv.com/wp-content/uploads/2009/12/IB-screen-251x300.png" alt="Interface Builder Connections" width="251" height="300" />Once delegate is set, your application is good to go. Launch it and a look around. You can also download sample Application and play with it.</p>
<h3><a title="Custom UINavigationBar Sample Application" href="http://www.gauravv.com/wp-content/uploads/2009/12/NavigationColor.zip">Sample Application : NavigationColor.zip</a></h3>
<p>Thats it. This is all you need for a simple Custom UINavigationBar. Its very simple but at the same time very efficient trick. If you want you can modify titleView to show any image you want, you can add gradient to the text now since effectively it a view now. You can do anything you want with it.</p>
<p>Hope this helps somebody. If you face any problem implementing this, leave a comment here and i will try to help you out.</p>
<p>Good Luck. Happy Programming. :)</p>


<p>Related posts:<ol><li><a href='http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Debugging Memory release'>iPhone Development Tip : Debugging Memory release</a> <small>I was struggling with a bug in my latest iPhone...</small></li>
<li><a href='http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/' rel='bookmark' title='Permanent Link: iPhone Development Tip : How to Dynamically Initialize Class in Objective-C'>iPhone Development Tip : How to Dynamically Initialize Class in Objective-C</a> <small>While working on an iPhone project i wanted a way...</small></li>
<li><a href='http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/' rel='bookmark' title='Permanent Link: iPhone Dev Tip: How to find out Available/Free Memory'>iPhone Dev Tip: How to find out Available/Free Memory</a> <small>The iPhone has limited memory,and as developer its our responsibility...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Awesome Programming Quotes</title>
		<link>http://www.gauravv.com/2009/11/28/awesome-programming-quotes/</link>
		<comments>http://www.gauravv.com/2009/11/28/awesome-programming-quotes/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 22:57:05 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[/dev/brain]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[quotes]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=280</guid>
		<description><![CDATA[There are a lot of great programming quotes out there. Which one do you like? Here are few that i love :]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F11%2F28%2Fawesome-programming-quotes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F11%2F28%2Fawesome-programming-quotes%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">There are a lot of great programming quotes out there. Which one do you like? Here are few that i love :</p>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">Walking on water and developing software from a specification are easy if both are frozen. &#8211; <em>Edward V Berard</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">Hofstadter&#8217;s Law: It always takes longer than you expect, even when you take into account Hofstadter&#8217;s Law.</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;Some people, when confronted with a problem, think &#8220;I know, I’ll use regular expressions.&#8221; Now they have two problems.&#8221; &#8212; <em>Jamie Zawinski</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. &#8211; <em>John Carmack on software patents</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter. &#8211; <em>Nathaniel S Borenstein</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">Memory is like an orgasm. It&#8217;s a lot better if you don&#8217;t have to fake it. &#8211; <em>Seymour Cray on virtual memory</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult. &#8211; <em>C.A.R. Hoare.</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;Perl &#8211; The only language that looks the same before and after RSA encryption.&#8221; &#8211; <em>Keith Bostic</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">C++: an octopus made by nailing extra legs onto a dog. &#8211; <em>Steve Taylor</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">Weeks of coding can save you hours of planning.</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">You can stand on the shoulders of giants OR a big enough pile of dwarfs, works either way.</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">If Java had true garbage collection, most programs would delete themselves upon execution. &#8211; <em>Robert Sewell</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">Every language has an optimization operator. In C++ that operator is ‘//’</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;To iterate is human, to recurse divine.&#8221; &#8211; <em>L. Peter Deutsch</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;C++ : Where friends have access to your private members.&#8221; &#8211; <em>Gavin Russell Baker</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">If we&#8217;re supposed to work in Hex, why have we only got A fingers?&#8217;</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">The generation of random numbers is too important to be left to chance.  - <em>Robert R. Coveyou, Oak Ridge National Laboratory</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">God could create the world in six days because he didn&#8217;t have to make it compatible with the previous version</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">When I am working on a problem I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong.  - <em>R. Buckminster Fuller</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;There are two major products that come out of Berkeley: LSD and BSD. We don&#8217;t believe this to be a coincidence.&#8221; -<em> Jeremy S. Anderson</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;Debugging is like farting &#8211; it&#8217;s not so bad when it&#8217;s your own code.&#8221;</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;Good judgement is the result of experience &#8230; Experience is the result of bad judgement.&#8221;</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">I don&#8217;t care if it works on your machine! We are not shipping your machine! &#8211; <em>Ovidiu Platon</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">The word “experienced” often refers to someone who’s gotten away with doing the wrong thing more frequently than you have. &#8211; <em>Laurence Gonzales</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;Giving pointers and threads to programmers is like giving whisky and car keys to teenagers&#8221; &#8211; <em>P.J O&#8217;Rourke</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">There are 10 types of people. Those who can read ternary, those who can&#8217;t and those who mistake it for binary.</p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships. &#8211; <em>Linus Torvalds</em></p>
</blockquote>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.&#8221; &#8211; <em>Brian W. Kernighan</em></p>
</blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">Although not related to programming in general, but anyways :</p>
<blockquote>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; clear: both; background-position: initial initial; background-repeat: initial initial; padding: 0px; border: 0px initial initial;">&#8220;There are few this in this world that you don&#8217;t want to know about, and for everything else there is Google&#8221;</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/11/28/awesome-programming-quotes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Dev Tip: How to find out Available/Free Memory</title>
		<link>http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/</link>
		<comments>http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 22:26:16 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=274</guid>
		<description><![CDATA[The iPhone has limited memory,and as developer its our responsibility to manage memory optimally. On one hand caching improved performance while on other hand it uses 'expensive' memory, and we must optimally balance between both sides.

Once you received memory warning you can release unwanted objects to free up the memory, but knowing how much memory is available OR free on iPhone will help you make calculated decisions before low memory warning is even triggered. OR simply you can ask user to restart the iPhone and then launch the application.This Tip will help you calculate Available Memory for your application.


Related posts:<ol><li><a href='http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Debugging Memory release'>iPhone Development Tip : Debugging Memory release</a> <small>I was struggling with a bug in my latest iPhone...</small></li>
<li><a href='http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/' rel='bookmark' title='Permanent Link: iPhone Development Tip : How to Dynamically Initialize Class in Objective-C'>iPhone Development Tip : How to Dynamically Initialize Class in Objective-C</a> <small>While working on an iPhone project i wanted a way...</small></li>
<li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F11%2F27%2Fiphone-dev-tip-how-to-find-out-availablefree-memory%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F11%2F27%2Fiphone-dev-tip-how-to-find-out-availablefree-memory%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p>The iPhone has limited memory,and as developer its our responsibility to manage memory optimally. On one hand caching improves performance while on other hand it uses &#8216;expensive&#8217; memory, and we must optimally balance between both sides.</p>
<p>Once you received memory warning you can release unwanted objects to free up the memory, but knowing how much memory is available OR free on iPhone will help you make calculated decisions before low memory warning is even triggered. OR simply you can ask user to restart the iPhone and then launch the application.This Tip will help you calculate Available Memory for your application.</p>
<p>So, here is code to calculate available memory :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import </span>
<span style="color: #6e371a;">#import </span>
&nbsp;
<span style="color: #a61390;">static</span> <span style="color: #a61390;">void</span> print_free_memory <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    mach_port_t host_port;
    mach_msg_type_number_t host_size;
    vm_size_t pagesize;
&nbsp;
    host_port <span style="color: #002200;">=</span> mach_host_self<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;
    host_size <span style="color: #002200;">=</span> <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>vm_statistics_data_t<span style="color: #002200;">&#41;</span> <span style="color: #002200;">/</span> <span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>integer_t<span style="color: #002200;">&#41;</span>;
    host_page_size<span style="color: #002200;">&#40;</span>host_port, <span style="color: #002200;">&amp;</span>amp;pagesize<span style="color: #002200;">&#41;</span>;        
&nbsp;
    vm_statistics_data_t vm_stat;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>host_statistics<span style="color: #002200;">&#40;</span>host_port, HOST_VM_INFO, <span style="color: #002200;">&#40;</span>host_info_t<span style="color: #002200;">&#41;</span><span style="color: #002200;">&amp;</span>amp;vm_stat, <span style="color: #002200;">&amp;</span>amp;host_size<span style="color: #002200;">&#41;</span> <span style="color: #002200;">!=</span> KERN_SUCCESS<span style="color: #002200;">&#41;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Failed to fetch vm statistics&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">/* Stats in bytes */</span>
    natural_t mem_used <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>vm_stat.active_count <span style="color: #002200;">+</span>
                          vm_stat.inactive_count <span style="color: #002200;">+</span>
                          vm_stat.wire_count<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> pagesize;
    natural_t mem_free <span style="color: #002200;">=</span> vm_stat.free_count <span style="color: #002200;">*</span> pagesize;
    natural_t mem_total <span style="color: #002200;">=</span> mem_used <span style="color: #002200;">+</span> mem_free;
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;used: %u free: %u total: %u&quot;</span>, mem_used, mem_free, mem_total<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Happy Coding :)</p>


<p>Related posts:<ol><li><a href='http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Debugging Memory release'>iPhone Development Tip : Debugging Memory release</a> <small>I was struggling with a bug in my latest iPhone...</small></li>
<li><a href='http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/' rel='bookmark' title='Permanent Link: iPhone Development Tip : How to Dynamically Initialize Class in Objective-C'>iPhone Development Tip : How to Dynamically Initialize Class in Objective-C</a> <small>While working on an iPhone project i wanted a way...</small></li>
<li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPhone Development Tip : How to Dynamically Initialize Class in Objective-C</title>
		<link>http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/</link>
		<comments>http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 00:43:07 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacker's Approach]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=267</guid>
		<description><![CDATA[While working on an iPhone project i wanted a way to dynamically initialize classes, and then i found one simple way. Sharing it here since it may help someone someday.


Related posts:<ol><li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
<li><a href='http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Debugging Memory release'>iPhone Development Tip : Debugging Memory release</a> <small>I was struggling with a bug in my latest iPhone...</small></li>
<li><a href='http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/' rel='bookmark' title='Permanent Link: iPhone Dev Tip: How to find out Available/Free Memory'>iPhone Dev Tip: How to find out Available/Free Memory</a> <small>The iPhone has limited memory,and as developer its our responsibility...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F11%2F04%2Fiphone-development-tip-how-to-dynamically-initialize-class-in-objective-c%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F11%2F04%2Fiphone-development-tip-how-to-dynamically-initialize-class-in-objective-c%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p>While working on an iPhone project i wanted a way to dynamically initialize classes, and then i found one simple way. Sharing it here since it may help someone someday.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>NSClassFromString<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Class name&quot;</span><span style="color: #002200;">&#41;</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>That&#8217;s all for now.</p>


<p>Related posts:<ol><li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
<li><a href='http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Debugging Memory release'>iPhone Development Tip : Debugging Memory release</a> <small>I was struggling with a bug in my latest iPhone...</small></li>
<li><a href='http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/' rel='bookmark' title='Permanent Link: iPhone Dev Tip: How to find out Available/Free Memory'>iPhone Dev Tip: How to find out Available/Free Memory</a> <small>The iPhone has limited memory,and as developer its our responsibility...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPhone Development Tip : Debugging Memory release</title>
		<link>http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/</link>
		<comments>http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 17:02:21 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=246</guid>
		<description><![CDATA[I was struggling with a bug in my latest iPhone application, and frankly i got very frustrated with retain-release concept. I missed good old ( well, not that old ) garbage collector, but following code helped me a lot in understanding the release-retain cycle and getting the backtrace of whats actually going on. Here is the code :


Related posts:<ol><li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
<li><a href='http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/' rel='bookmark' title='Permanent Link: iPhone Dev Tip: How to find out Available/Free Memory'>iPhone Dev Tip: How to find out Available/Free Memory</a> <small>The iPhone has limited memory,and as developer its our responsibility...</small></li>
<li><a href='http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/' rel='bookmark' title='Permanent Link: iPhone Development Tip : How to Dynamically Initialize Class in Objective-C'>iPhone Development Tip : How to Dynamically Initialize Class in Objective-C</a> <small>While working on an iPhone project i wanted a way...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F10%2F28%2Fiphone-development-tip-debugging-memory-release%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F10%2F28%2Fiphone-development-tip-debugging-memory-release%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p>I was struggling with a bug in my latest iPhone application, and frankly i got very frustrated with retain-release concept. I missed good old ( well, not that old ) garbage collector, but following code helped me a lot in understanding the release-retain cycle and getting the backtrace of whats actually going on.</p>
<p>First of all include following files in the code :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#include &lt;execinfo.h&gt;</span>
<span style="color: #6e371a;">#include &lt;stdio.h&gt;</span></pre></div></div>

<p>and then add following lines to the implementation file (.m) :</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>release <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">void</span><span style="color: #002200;">*</span> callstack<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">128</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">int</span> i, frames <span style="color: #002200;">=</span> backtrace<span style="color: #002200;">&#40;</span>callstack, <span style="color: #2400d9;">128</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">char</span><span style="color: #002200;">**</span> strs <span style="color: #002200;">=</span> backtrace_symbols<span style="color: #002200;">&#40;</span>callstack, frames<span style="color: #002200;">&#41;</span>;
	<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i <span style="color: #002200;">&amp;</span>lt; frames; <span style="color: #002200;">++</span>i<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;%s<span style="color: #2400d9;">\n</span>&quot;</span>, strs<span style="color: #002200;">&#91;</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">free</span><span style="color: #002200;">&#40;</span>strs<span style="color: #002200;">&#41;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;retainCount = %d&quot;</span>, <span style="color: #002200;">&#91;</span>self retainCount<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#91;</span>super release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Now, look at the console, you will see nice backtrace of release-retain cycle. Hope this helps somebody.</p>


<p>Related posts:<ol><li><a href='http://www.gauravv.com/2009/12/29/iphone-development-tip-custom-uinavigationbar/' rel='bookmark' title='Permanent Link: iPhone Development Tip : Custom UINavigationBar'>iPhone Development Tip : Custom UINavigationBar</a> <small> More and more developers are creating custom user elements...</small></li>
<li><a href='http://www.gauravv.com/2009/11/27/iphone-dev-tip-how-to-find-out-availablefree-memory/' rel='bookmark' title='Permanent Link: iPhone Dev Tip: How to find out Available/Free Memory'>iPhone Dev Tip: How to find out Available/Free Memory</a> <small>The iPhone has limited memory,and as developer its our responsibility...</small></li>
<li><a href='http://www.gauravv.com/2009/11/04/iphone-development-tip-how-to-dynamically-initialize-class-in-objective-c/' rel='bookmark' title='Permanent Link: iPhone Development Tip : How to Dynamically Initialize Class in Objective-C'>iPhone Development Tip : How to Dynamically Initialize Class in Objective-C</a> <small>While working on an iPhone project i wanted a way...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/10/28/iphone-development-tip-debugging-memory-release/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to find Out User’s Geolocation with Javascript on Firefox, Chrome, Safari and IE</title>
		<link>http://www.gauravv.com/2009/06/25/how-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie/</link>
		<comments>http://www.gauravv.com/2009/06/25/how-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 05:24:02 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Headline]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[gears]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/2009/06/25/how-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie/</guid>
		<description><![CDATA[
			
				
			
		

Few days back i shifted to Windows 7 from my old installation of windows XP, after that i was reinstalling all the application.So, i thought lets take firefox 3.5 for a spin, people are saying nice things about it and it has got new features like Private Browsing Mode, new TraceMonkey JavaScript engine, Support for native JSON, HTML5 &#60;video&#62; and &#60;audio&#62; elements, downloadable fonts,HTML5 offline data storage for applications and web worker threads. But main feature that i wanted to try was Location Aware Browsing.Although i knew about this feature ...


Related posts:<ol><li><a href='http://www.gauravv.com/2009/03/25/chrome-extension-to-fix-orkut-width-problem/' rel='bookmark' title='Permanent Link: Chrome Extension to Fix Orkut Width Problem'>Chrome Extension to Fix Orkut Width Problem</a> <small> Google has introduced a basic extensions feature in its...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F06%2F25%2Fhow-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F06%2F25%2Fhow-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.gauravv.com/wp-content/uploads/2009/06/where_am_i.jpg"><img style="border-right-width: 0px; margin: 0px 10px 5px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="where_am_i" src="http://www.gauravv.com/wp-content/uploads/2009/06/where_am_i_thumb.jpg" border="0" alt="where_am_i" width="210" height="227" align="left" /></a></p>
<p>Few days back i shifted to Windows 7 from my old installation of windows XP, after that i was reinstalling all the application.So, i thought lets take firefox 3.5 for a spin, people are <a href="http://lifehacker.com/5295655/top-10-firefox-35-features" target="_blank">saying nice things</a> about it and it has got new features like <a href="http://support.mozilla.com/en-US/kb/Private+Browsing">Private Browsing Mode</a>, new <a href="https://wiki.mozilla.org/JavaScript:TraceMonkey">TraceMonkey</a> JavaScript engine, Support for <a href="http://blog.mozilla.com/webdev/2009/02/12/native-json-in-firefox-31/">native JSON</a>, <a href="https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox" target="_blank">HTML5 &lt;video&gt; and &lt;audio&gt; elements</a>, downloadable fonts,<a href="https://developer.mozilla.org/en/Offline_resources_in_Firefox" target="_blank">HTML5 offline data storage</a> for applications and <a href="https://developer.mozilla.org/En/Using_DOM_workers">web worker threads</a>. But main feature that i wanted to try was <a href="http://www.mozilla.com/firefox/geolocation">Location Aware Browsing</a>.Although i knew about this feature set for quite a time now,but never installed latest version of firefox.Anyways, I tried and i must tell you its amazing, it got my geolocation with a very good accuracy.</p>
<p>Location based browsing opens up a whole new paradigm to web, its not just for mobile applications anymore.Having user’s geolocation means services can show them better content and provide much more localized service. Imagine going to burrp.com and rather than entering where you are it automatically recognizes your geolocation and suggests restaurants accordingly.</p>
<p>In this tutorial i will show you how to get user’s geolocation data using javascript. But, then you will say if this feature is supported in firefox only then what&#8217;s the use ? No, its not only supported on firefox, geolocation can be found out in other browsers too if <a href="http://gears.google.com/" target="_blank">Google Gears</a> is installed on the system.Gears is available for <a href="http://gears.google.com/?platform=win">Windows</a>, Windows Mobile (<a href="http://gears.google.com/?platform=wince">IE Mobile</a>,<a href="http://gears.google.com/?platform=wince-opera">Opera Mobile</a>), Mac (<a href="http://gears.google.com/?platform=mac-firefox">Firefox</a>, <a href="http://gears.google.com/?platform=mac-safari">Safari</a>), <a href="http://gears.google.com/?platform=linux">Linux</a> and Android. Ya ! one more thing, geolocation will work on firefox 3.0 also if <a href="https://people.mozilla.com/%7Edolske/dist/geode/geode-latest.xpi|Geode">Geode plugin</a> is installed.If you like, you can read about the <a href="http://dev.w3.org/geo/api/spec-source.html">standard that has been written for geolocation</a> before going forward. Enough said now, lets get our hand dirty now.</p>
<p>Lets first grab geolocation on firefox, we will work about google gears later.Straight from Mozilla documentation : The geolocation API is published through a <code>geolocation</code> child object within the <code>navigator</code> object. So, now we can test if our firefox supports geolocation or not. What are you saying ? “why not just check for version of firefox ?” No, thats a bad idea, versions can change and you should never rely of browser sniffing rather you should always do feature sniffing. Now, we can check if there is a support for geolocation using following code :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #009966; font-style: italic;">/* geolocation is available */</span>
 <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Geolocation services are not supported by your browser.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Getting the Current position in Firefox</h3>
<p>To get user’s current location, you can call <code>getCurrentPosition()</code> method.This method initiates a asynchronous call to detect user’s position.When position is determined it calls the callback that you have supplied according to the result.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  do_something<span style="color: #009900;">&#40;</span>position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">,</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now we use this information to write our code. here it is,..</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> findUserLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>foundUserLocation<span style="color: #339933;">,</span> noLocationFound<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> foundUserLocation<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> lat <span style="color: #339933;">=</span> position.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> long <span style="color: #339933;">=</span> position.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Found location: '</span> <span style="color: #339933;">+</span> lat <span style="color: #339933;">+</span> <span style="color: #3366CC;">', '</span> <span style="color: #339933;">+</span> long<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> noLocationFound<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Could not find location'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
findUserLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Using Google Gears to find User’s Geolocation</h3>
<p>Now that that we have found user’s geolocation using firefox, lets use google gears now.Make sure you have installed Gears and have <a href="http://code.google.com/apis/gears/tools.html#gears_init">gears_init</a> file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;code&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;gears_init.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> findUserLocation<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> geo <span style="color: #339933;">=</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">factory</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'beta.geolocation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  geo.<span style="color: #660066;">getCurrentPositionfoundUserLocation</span><span style="color: #339933;">,</span>noLocationFound<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> foundUserLocation<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> lat <span style="color: #339933;">=</span> position.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> long <span style="color: #339933;">=</span> position.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Found location: '</span> <span style="color: #339933;">+</span> lat <span style="color: #339933;">+</span> <span style="color: #3366CC;">', '</span> <span style="color: #339933;">+</span> long<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> noLocationFound<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Could not find location'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>&lt;/code&gt;</pre></div></div>

<p>You see there isn’t much difference in finding out geolocation via both methods, If you are using google gears than just include gears_init file that contains function to enable you to communicate  with Gears on user’s machine.Now, we must first initialize gears and create a new variable that can be used to access gears functions.After that we just have to call <code>getCurrentPosition</code> on the variable that we have initialized earlier.Rest of the code remains same.</p>
<p>So, now i will combine these code into one and by using google maps api will show user’s current location on a map.</p>
<ul>
<li>
<h2><a title="See Demo for Geolocation API on firefox,Safari, and Chrome" href="http://www.gauravv.com/demo/demo_geolocation.html" target="_blank">See Demo</a></h2>
</li>
</ul>
<p>Hope you liked it. Leave comments on what you think about this and what sort of possibilities geolocation opens for you.</p>


<p>Related posts:<ol><li><a href='http://www.gauravv.com/2009/03/25/chrome-extension-to-fix-orkut-width-problem/' rel='bookmark' title='Permanent Link: Chrome Extension to Fix Orkut Width Problem'>Chrome Extension to Fix Orkut Width Problem</a> <small> Google has introduced a basic extensions feature in its...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/06/25/how-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Must have Applications on a MAC</title>
		<link>http://www.gauravv.com/2009/05/21/must-have-applications-on-a-mac/</link>
		<comments>http://www.gauravv.com/2009/05/21/must-have-applications-on-a-mac/#comments</comments>
		<pubDate>Thu, 21 May 2009 14:23:46 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[/dev/brain]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/2009/05/21/must-have-applications-on-a-mac/</guid>
		<description><![CDATA[
			
				
			
		

Recently i have shifted to mac, although what i feel now is somewhat similar to a jet lag but still overall experience is great.Expose and spaces are really useful,and by using widgets useful information like currency convertor,calculator is just a button away.Overall i must say experience is lovely.

For most of common day to day needs products from Apple’s iLife suite work just out of the box but what about common need on a developer ?
Here is a list of application that i have recently fallen in love with, they are ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F05%2F21%2Fmust-have-applications-on-a-mac%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F05%2F21%2Fmust-have-applications-on-a-mac%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.gauravv.com/wp-content/uploads/2009/05/picture2.png"><img style="margin: 0px 5px 5px 0px; display: inline; border-width: 0px;" title="Picture 2" src="http://www.gauravv.com/wp-content/uploads/2009/05/picture2-thumb.png" border="0" alt="Picture 2" width="333" height="323" align="left" /></a></p>
<p align="left">Recently i have shifted to mac, although what i feel now is somewhat similar to a jet lag but still overall experience is great.Expose and spaces are really useful,and by using widgets useful information like currency convertor,calculator is just a button away.Overall i must say experience is lovely.</p>
<p align="left">
<p align="left">For most of common day to day needs products from Apple’s iLife suite work just out of the box but what about common need on a developer ?</p>
<p>Here is a list of application that i have recently fallen in love with, they are gr8 to use and increase productivity a lot.</p>
<p><em>**This list is not complete in any way nor the application listed are in any order of greatness or usefulness.**</em></p>
<h3>Coda for Web Development<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://shortdivision.files.wordpress.com/2008/11/coda_logo.png" border="0" alt="" width="99" height="101" align="right" /></h3>
<p>In my opinion <a href="http://www.panic.com/coda/">Coda</a> is a must have application for all developers working on mac. its a one stop solution, after starting coda you don’t need to leave it and go to shell for remote login,publishing,documentation because all feature are inbuilt.As they say</p>
<p>text editor + file transfer + svn + css + terminal + books + more = <em>whoah.</em></p>
<h3>Textmate – the missing editor<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://void-design.net/wp-content/uploads/2009/01/textmate-12-14-07.png" border="0" alt="" width="97" height="97" align="right" /></h3>
<p>while coda is great for web development, what about all other needs like writing shell scripts, perl, python, objective-c ? <a href="http://macromates.com/">Textmate</a> is there to save your day. It supports more than 50 languages, you can run commands from whithin documents, access SVN and lot more.</p>
<p>TIP: If you use YUI heavily, then there is a <a href="http://techfoolery.com/archives/2006/10/29/1406/">YUI bundle for textmate</a> too.</p>
<h3>Cyberduck – FTP/SFTP and lot more<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://www.freemacware.com/wp-content/images/Cyberduck.png" border="0" alt="" width="94" height="90" align="right" /></h3>
<p><a href="http://cyberduck.ch/">Cyberduck</a> is an Open source application for all your FTP/SFTP needs.It supports WebDAV, Mosso Cloud files and Amazon S3 too. It also has a dashboard widget which is really handy.you just drag the file over the widget and voila ! it will be uploaded to the configured location.</p>
<h3>Growl notification system<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://www.emug.ee/uudised/wp-content/uploads/2007/02/growlicon.png" border="0" alt="" width="86" height="86" align="right" /></h3>
<p><a href="http://growl.info">Growl</a> is a notification system, it lets any application display alerts/information unobtrusively. You can customize the look on notification and control which application can show alerts using growl.Notifications can be sent to you on email OR can be spoken to you too.</p>
<p>TIP : If you want similar functionality in your web applications you can use <a href="http://plugins.jquery.com/project/Growl">jQuery growl</a> OR <a href="http://icebeat.bitacoras.com/mootools/growl/">growls mootools</a>.</p>
<h3>Adium – instant messenger<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://adium.im/images/logo.png" border="0" alt="" width="95" height="95" align="right" /></h3>
<p><a href="http://adium.im">Adium</a> is an open source instant messaging solution which can connect to Yahoo, MSN, Gtalk, Jabber, AIM etc.Adium team is working hard on IRC support too.It integrates well with growl notifications which makes complete experience much better.And, it has got a lovely icon too. :)</p>
<h3>Fluid App for Site Specific Browser<a href="http://www.gauravv.com/wp-content/uploads/2009/05/picture1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="Picture 1" src="http://www.gauravv.com/wp-content/uploads/2009/05/picture1-thumb.png" border="0" alt="Picture 1" width="101" height="92" align="right" /></a></h3>
<p><a href="http://fluidapp.com/">Fluid app</a> is gr8, it lets you create what they call site specific browser or native application of your favorite web application.So essentially gmail, google reader etc will behave like any other native application.although similar thing can be achieved on windows using <a href="http://labs.mozilla.com/projects/prism/">Mozilla prism</a> or <a href="http://google.com/chrome">google chrome</a> but what i really like is little badges that appear over the icons in dock just like in the image displayed at right.</p>
<h3>Omnigraffle<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://www.omnigroup.com/images/icons/96/omnigraffle.png" border="0" alt="" align="right" /></h3>
<p><a href="http://www.omnigroup.com/applications/OmniGraffle/">Omnigraffle</a> is easy to use,powerful diagramming application.You can easily create beautiful graphs, diagrams, flowcharts, mockups easily.There are lot of ready to use stencils available like iphone mockup,YUI design elements and much more. You can download stencils from <a href="http://graffletopia.com/">graffletopia</a> which is integrate inside the application very seamlessly.</p>
<h3>ScreenFlow for making wonderful screencasts<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://macapper.com/wp-content/uploads/2008/02/screenflow-icon.jpg" border="0" alt="" width="99" height="99" align="right" /></h3>
<p>If you create screencasts of application, <a href="http://www.telestream.net/screen-flow/overview.htm">ScreenFlow</a> is best app out there.It has got very good editing tool, ability to add callouts,cursor highlight and much more. It lets you easily add pan &amp; zoom effects, trim clips, add shadow and reflection. You can combine exiting media too.It allows you to add mouse effects and and overlay showing your key strokes too.</p>
<h3>AppCleaner – name says it all<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://thespinningbeachball.com/index_files/appcleaner_icon.png" border="0" alt="" width="102" height="102" align="right" /></h3>
<p>although uninstalling a application in mac is as easy as drag n drop, but it leaves some some files here and there in the system. <a href="http://www.freemacsoft.net/AppCleaner/">AppCleaner</a> finds all these files and safely deletes them.Application usage is very easy, you just have to drag n drop application onto the AppCleaner window.</p>
<h3>Backdrop<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" src="http://macmembrane.com/wp-content/uploads/2008/09/backdrop-icon.png" border="0" alt="" width="102" height="78" align="right" /></h3>
<p>while you are taking screenshots or making screenshots,you don’t want whole wide world to see whats there on your desktop Do you ? use <a href="http://johnhaney.com/backdrop/">Backdrop</a> so you don’t have to clean your desktop before taking screenshot or creating videos.You can also use this to let you focus on one window a time.gr8 app.</p>
<p>So, all said you must be thinking is there any application that i miss. Yes, there is. Take a guess,..let me give you a hint : Its a microsoft’s application. Does that ring any bell ??</p>
<h3><img style="border-right-width: 0px; margin: 0px 5px 5px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" src="http://windowsteamblog.com/cfs-filesystemfile.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/windowsexperience/WLWriter_5F00_256x256_5F00_1E97C442.png" border="0" alt="" width="94" height="94" align="left" /> Windows Live Writer</h3>
<p><a href="http://download.live.com/writer">Windows Live Writer</a> is a desktop blogging tool, and NO its not just for microsoft live.It supports all major blogging platform out there like Wordpress, LiveJournal, typePad, and many more.Features include in place photo editing, Instant preview etc.You can find many useful plugins too.I really miss this application on mac, in my opinion there are aren’t any competing application in windows too. one of the best application created by microsoft i guess.</p>
<p>If i have missed your favorite application then please let me know in comments, i will make sure it gets added to the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/05/21/must-have-applications-on-a-mac/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chrome Extension to Fix Orkut Width Problem</title>
		<link>http://www.gauravv.com/2009/03/25/chrome-extension-to-fix-orkut-width-problem/</link>
		<comments>http://www.gauravv.com/2009/03/25/chrome-extension-to-fix-orkut-width-problem/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 09:15:42 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Hacker's Approach]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[orkut]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=195</guid>
		<description><![CDATA[
			
				
			
		
Google has introduced a basic extensions feature in its popular Chrome browser, although its still availble in developer release.So, i thought i should try to write my popular Orkut 99% width greasemonkey script for chrome because normally i use chrome. I am in love with the speed and responsiveness of chrome,only thing that make me open firefox is use of firebug,web developer toolbox or yslow.I miss my extensions for firefox, but speed matters most for me.
Anyways, here i will show you how to enable extensions for google chrome,and to install ...


Related posts:<ol><li><a href='http://www.gauravv.com/2009/06/25/how-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie/' rel='bookmark' title='Permanent Link: How to find Out User’s Geolocation with Javascript on Firefox, Chrome, Safari and IE'>How to find Out User’s Geolocation with Javascript on Firefox, Chrome, Safari and IE</a> <small> Few days back i shifted to Windows 7 from...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F03%2F25%2Fchrome-extension-to-fix-orkut-width-problem%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F03%2F25%2Fchrome-extension-to-fix-orkut-width-problem%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<div id="attachment_200" class="wp-caption aligncenter" style="width: 570px"><a href="http://www.gauravv.com/wp-content/uploads/2009/03/orkut1.jpg"><br />
<img class="size-full wp-image-200" title="Orkut Fluid Width on Chrome by Using extension developed by Gaurav Verma" src="http://www.gauravv.com/wp-content/uploads/2009/03/orkut1.jpg" alt="Orkut Fluid Width on Chrome by Using extension developed by Gaurav Verma" width="560" height="350" /></a><p class="wp-caption-text">Orkut Fluid Width on Chrome after using extension developed by Gaurav Verma</p></div>
<p>Google has introduced a basic extensions feature in its popular <a title="Google Chrome" href="http://www.google.com/chrome" target="_blank">Chrome browser</a>, although its still availble in developer release.So, i thought i should try to write my popular <a title="Orkut fix width script by Gaurav Verma" href="http://www.gauravv.com/2007/08/28/how-to-resize-orkut-so-as-to-fit-widescreen/" target="_blank">Orkut 99% width greasemonkey script</a> for chrome because normally i use chrome. I am in love with the speed and responsiveness of chrome,only thing that make me open firefox is use of firebug,web developer toolbox or yslow.I miss my extensions for firefox, but speed matters most for me.</p>
<p>Anyways, here i will show you how to enable extensions for google chrome,and to install this extension.Purpose of this extension is to change the width of orkut pages,which leaves lot of space unused if you are using a widescreen monitor.Here is the step by step process :</p>
<ol>
<li>Install the developer-channel version of Google Chrome : Since extension feature is still in development you need a developer version of chrome,You can read instructions on <a title="Installing Developer release of chrom" href="http://dev.chromium.org/getting-involved/dev-channel" target="_blank">how to switch to the developer version here</a>.It will take 3-4 minutes depending on you internet speed. Developer version has many more new features than public one like full screen mode (by pressing &#8216;F11&#8242;), new faster javascript engine etc.</li>
<li>Now create a directory somewhere in your computer, you can create directory anywhere but for the purpose of this example we will be using <strong>C:myextension</strong> .Chrome requires a manifest file which contains the information about extension like name,description, which URL patterns should be matched,which file to load and a unique ID of the extension.Create a file <strong>manifest.json</strong> inside the directory with following contents.

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;format_version&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;31f6da32730aca7203c1fb8636444a6e2607551b&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;version&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1.0&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Orkut 99% width&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;description&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Converts orkut container width to 99% ,useful for users having widescreen.&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;content_scripts&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #3366CC;">&quot;matches&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;http://*.orkut.com/*&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;http://*.orkut.co.in/*&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #3366CC;">&quot;js&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;orkut-fix-width.js&quot;</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Also create another file <strong>orkut-fix-width.js</strong> in the same directory with following content :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</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: #003366; font-weight: bold;">function</span> do_widen<span style="color: #009900;">&#40;</span>id<span style="color: #339933;">,</span> min<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> container <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>container<span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>min<span style="color: #009900;">&#41;</span>
      container.<span style="color: #660066;">style</span>.<span style="color: #660066;">minWidth</span> <span style="color: #339933;">=</span> min<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    do_widen<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;headerin&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;99%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    do_widen<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;container&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;99%&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Orkut99percent exception: '</span> <span style="color: #339933;">+</span> e <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;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Edit your chrome shortcut and add these flags to it:
<p>chrome.exe &#8211;enable-extensions &#8211;load-extension=&#8221;c:myextension&#8221;</p>
<p>Start Chrome and navigate to</p>
<p>chrome-ui://extensions</p>
<p>This page lists all installed extensions. It also shows any errors that have occured in the extension system since it started up.</li>
<li>Go to http://www.orkut.com and you should see the difference.</li>
</ol>
<p>For more information on extensions on chrome visit this <a title="Google Chrome Extenstions Howto" href="http://dev.chromium.org/developers/design-documents/extensions/howto" target="_blank">howto</a></p>


<p>Related posts:<ol><li><a href='http://www.gauravv.com/2009/06/25/how-to-find-out-users-geolocation-with-javascript-on-firefox-chrome-safari-and-ie/' rel='bookmark' title='Permanent Link: How to find Out User’s Geolocation with Javascript on Firefox, Chrome, Safari and IE'>How to find Out User’s Geolocation with Javascript on Firefox, Chrome, Safari and IE</a> <small> Few days back i shifted to Windows 7 from...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/03/25/chrome-extension-to-fix-orkut-width-problem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Say no to Side Middle Birth</title>
		<link>http://www.gauravv.com/2009/02/13/say-no-to-side-middle-birth/</link>
		<comments>http://www.gauravv.com/2009/02/13/say-no-to-side-middle-birth/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 09:18:12 +0000</pubDate>
		<dc:creator>Gaurav Verma</dc:creator>
				<category><![CDATA[/dev/brain]]></category>
		<category><![CDATA[railways]]></category>

		<guid isPermaLink="false">http://www.gauravv.com/?p=183</guid>
		<description><![CDATA[
			
				
			
		
Today Railway Minister Lalu Prasad Yadav presented the interim Railway Budget for 2009-10 in Parliament, fares will be reduced,new trains are launched and everything but what i seriously complain about railway is not fares but Side Middle berth.
I know that number of people travelling by trains in india is far greater than the resources railway ministry has,and they are doing something about it.But Side Middle brith is not a good option,i get it.. its way to increase the capacity of a carriage but not a good option,certainly not for passenger travelling on these berths.
But whats ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F02%2F13%2Fsay-no-to-side-middle-birth%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.gauravv.com%2F2009%2F02%2F13%2Fsay-no-to-side-middle-birth%2F&amp;source=princeverma&amp;style=compact" height="61" width="50" /><br />
			</a>
		</div>
<div id="attachment_184" class="wp-caption aligncenter" style="width: 506px"><a href="http://www.gauravv.com/wp-content/uploads/2009/02/side-middle-berth.jpg"><img class="size-full wp-image-184" title="side-middle-berth" src="http://www.gauravv.com/wp-content/uploads/2009/02/side-middle-berth.jpg" alt="New Side Middle Birth in Indian Railways" width="496" height="423" /></a><p class="wp-caption-text">New Side Middle Birth in Indian Railways</p></div>
<p>Today Railway Minister Lalu Prasad Yadav presented the interim Railway Budget for 2009-10 in Parliament, fares will be reduced,new trains are launched and everything but what i seriously complain about railway is not fares but Side Middle berth.</p>
<p>I know that number of people travelling by trains in india is far greater than the resources railway ministry has,and they are doing something about it.But <a title="Side Middle Birth in Indian Railways" href="http://www.gauravv.com/2009/02/13/say-no-to-side-middle-birth/" target="_self">Side Middle brith</a> is not a good option,i get it.. its way to increase the capacity of a carriage but not a good option,certainly not for passenger travelling on these berths.</p>
<p>But whats the point of rambling speech here,If we can&#8217;t do anything about it.It turns out that we CAN,and we SHOULD.So if you ever travelled in such awkward and discomforting position you can go to indian railways site and fill out a <a title="Opinion Poll for Side Middle Birth" href="http://www.trainenquiry.com/poll/OpPoll.asp" target="_blank">opinion poll form</a> and hope that railways Ministry will not implement it.</p>
<p>Here is the Link to the Form : <a href="http://www.trainenquiry.com/poll/OpPoll.asp">http://www.trainenquiry.com/poll/OpPoll.asp</a></p>
<p>Forward <a title="Say no to middle birth" href="http://www.gauravv.com/2009/02/13/say-no-to-side-middle-birth/" target="_blank">this post&#8217;s link</a> or link to the opinion form to as many people as you can to help yourself and other fellow passengers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gauravv.com/2009/02/13/say-no-to-side-middle-birth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
