<?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>Roshan Kulkarni</title>
	<atom:link href="http://roshankulkarni.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://roshankulkarni.info</link>
	<description>On Technology, Web and Consulting</description>
	<lastBuildDate>Sun, 30 May 2010 18:28:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>OpenSuse 11.2 on Sony Vaio NS25G: Internal Microphone HOW-TO</title>
		<link>http://roshankulkarni.info/2010/05/internal-microphone-on-opensuse-11-2-sony-vaio-ns-25g/</link>
		<comments>http://roshankulkarni.info/2010/05/internal-microphone-on-opensuse-11-2-sony-vaio-ns-25g/#comments</comments>
		<pubDate>Sun, 30 May 2010 17:52:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[vaio]]></category>

		<guid isPermaLink="false">http://roshankulkarni.info/?p=151</guid>
		<description><![CDATA[On my fresh OpenSuse 11.2 setup, the VAIO inbuilt speakers worked well, but the internal mic did not seem to capture. KRecord and Skype did not pick the microphone inputs. Much tinkering and several days later&#8230; My initial suspect of pulse-audio being broken was wrong. The following fix worked: Dig into the Sound card hardware: [...]]]></description>
			<content:encoded><![CDATA[<p>On my fresh OpenSuse 11.2 setup, the VAIO inbuilt speakers worked well, but the internal mic did not seem to capture. KRecord and Skype did not pick the microphone inputs. Much tinkering and several days later&#8230;</p>
<p>My initial suspect of pulse-audio being broken was wrong. The following fix worked:</p>
<p>Dig into the Sound card hardware:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">lspci</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> Audio</pre></div></div>

<pre>00:1b.0 Audio device: Intel Corporation <strong>82801I</strong> (ICH9 Family) HD Audio Controller</pre>
<p>This Intel-compatible audio controller would use the <strong>snd-hda-intel</strong> driver. Let&#8217;s find out:</p>
<p><a href="http://www.roshankulkarni.info/wp-content/uploads/2010/05/yast_sound.jpeg"><img src="http://www.roshankulkarni.info/wp-content/uploads/2010/05/yast_sound.jpeg" alt="yast_sound" title="yast_sound" width="500" /></a></p>
<p style="clear:both;">From the <strong>Yast Control Center</strong> pick <em>Hardware > Sound</em>. In the screenshot below, the last line indicates the <strong>snd-hda-intel</strong> driver. Hit <em>Edit</em> and set the <em>model</em> option to <strong>toshiba-s06</strong>. Hit Next/Ok all the way thru.
</p>
<p><a href="http://www.roshankulkarni.info/wp-content/uploads/2010/05/yast_sound_1.jpeg"><img src="http://www.roshankulkarni.info/wp-content/uploads/2010/05/yast_sound_1.jpeg" alt="YAST Sound Configuration" title="YAST Sound Configuration" style="clear: both;"  width="500"/></a></p>
<p style="clear:both;">You can verify your settings out here:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #660033;">-R</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>modprobe.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">50</span>-sound.conf
options snd-hda-intel <span style="color: #007800;">model</span>=toshiba-s06</pre></div></div>

<p>Use the <strong>alsamixer</strong> to make sure your speaker and capture volumes are cranked up.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">alsamixer</pre></div></div>

<p><a href="http://www.roshankulkarni.info/wp-content/uploads/2010/05/alsa_mixer.jpeg"><img src="http://www.roshankulkarni.info/wp-content/uploads/2010/05/alsa_mixer.jpeg" alt="alsa_mixer" title="alsa_mixer" width="500" /></a></p>
<p style="clear:both;">The references below helped. The Ubuntu forums link below has references to other model names that might work for other laptop models.</p>
<p>[1] https://help.ubuntu.com/community/HdaIntelSoundHowto<br />
[2] http://ubuntuforums.org/showthread.php?t=314383</p>
]]></content:encoded>
			<wfw:commentRss>http://roshankulkarni.info/2010/05/internal-microphone-on-opensuse-11-2-sony-vaio-ns-25g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another Linux quickie &#8211; Determine your Linux distribution</title>
		<link>http://roshankulkarni.info/2010/05/another-linux-quickie/</link>
		<comments>http://roshankulkarni.info/2010/05/another-linux-quickie/#comments</comments>
		<pubDate>Sun, 09 May 2010 07:19:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://roshankulkarni.info/?p=146</guid>
		<description><![CDATA[I find myself staring at a remote shell, not knowing what Linux distribution the box is running. There does not seem to be any uname like universal command for this. Here are a few files to try: OpenSuse: cat /etc/SuSE-release cat /etc/issue Debian and it&#8217;s variants: cat /etc/debian_version RedHat: cat/etc/redhat-release Slackware: cat /etc/slackware-version And this [...]]]></description>
			<content:encoded><![CDATA[<p>I find myself staring at a remote shell, not knowing what Linux distribution the box is running. There does not seem to be any <em>uname</em> like universal command for this. Here are a few files to try:</p>
<p><strong>OpenSuse:</strong><br />
cat /etc/SuSE-release<br />
cat /etc/issue</p>
<p><strong>Debian and it&#8217;s variants:</strong><br />
cat /etc/debian_version</p>
<p><strong>RedHat:</strong><br />
cat/etc/redhat-release</p>
<p><strong>Slackware:</strong><br />
cat /etc/slackware-version </p>
<p>And this one too:<br />
dmesg | head -1</p>
]]></content:encoded>
			<wfw:commentRss>http://roshankulkarni.info/2010/05/another-linux-quickie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Penguin Notes: LCD Brightness, Firefox Annoyances</title>
		<link>http://roshankulkarni.info/2010/05/penguin-notes-lcd-brightness-firefox-annoyances/</link>
		<comments>http://roshankulkarni.info/2010/05/penguin-notes-lcd-brightness-firefox-annoyances/#comments</comments>
		<pubDate>Sun, 09 May 2010 07:12:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[opensuse]]></category>

		<guid isPermaLink="false">http://roshankulkarni.info/?p=142</guid>
		<description><![CDATA[A few notes to self, trying to make my new OpenSuse desktop more hospitable. Annoyance 1: The laptop brightness controls did not adjust the brightness on KDE 4 running on OpenSuse 11.2. (They worked on Ubuntu Jaunty earlier). Neither could I find brightness sliders anywhere in KDE panels. This helped: 1 $ xbacklight -set 70 [...]]]></description>
			<content:encoded><![CDATA[<p>A few notes to self, trying to make my new OpenSuse desktop more hospitable.</p>
<p><strong>Annoyance 1:</strong><br />
The laptop brightness controls did not adjust the brightness on KDE 4 running on OpenSuse 11.2. (They worked on Ubuntu Jaunty earlier). Neither could I find brightness sliders anywhere in KDE panels. This helped:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ xbacklight <span style="color: #660033;">-set</span> <span style="color: #000000;">70</span></pre></td></tr></table></div>

<p>The value range is from 0 thru 100. Oddly, the laptop&#8217;s brightness shortcuts are BIOS controlled, so I wonder why they are dependent on the OS.</p>
<p><strong>Annoyance 2:</strong><br />
A Ctrl+Bksp (Control + Backspace) on the Firefox address bar erased the entire address. I&#8217;m accustomed to using Ctrl + Bksp to erase segments of the URLs (&#8220;/&#8221; separated). The fix was in the Firefox &#8220;about:config&#8221;</p>
<ul>
<li>Firefox Address bar: &#8220;about:config&#8221;</li>
<li>Filter by &#8220;layout&#8221;. Edit this item &#8220;layout.word_select.stop_at_punctuation&#8221;</li>
<li>Change that to a true</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://roshankulkarni.info/2010/05/penguin-notes-lcd-brightness-firefox-annoyances/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Referencing Spring Managed Beans from Non-Spring Java Code</title>
		<link>http://roshankulkarni.info/2010/05/referencing-spring-managed-beans-from-non-spring-java-code/</link>
		<comments>http://roshankulkarni.info/2010/05/referencing-spring-managed-beans-from-non-spring-java-code/#comments</comments>
		<pubDate>Tue, 04 May 2010 07:06:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://roshankulkarni.info/?p=115</guid>
		<description><![CDATA[I encountered the need to reference Spring managed beans from legacy Java code (i.e. Java code which is not managed by Spring). An ideal approach is to avoid mixed-mode code and Spring&#8217;ify everything. But that&#8217;s not always an option in reality. Legacy projects could have a incremental migration to Spring. Another option is to instantiate [...]]]></description>
			<content:encoded><![CDATA[<p>I encountered the need to reference Spring managed beans from legacy Java code (i.e. Java code which is not managed by Spring).</p>
<p>An ideal approach is to avoid mixed-mode code and Spring&#8217;ify everything. But that&#8217;s not always an option in reality. Legacy projects could have a incremental migration to Spring. </p>
<p>Another option is to instantiate the bean object in your non-managed code. Since you would craft such an object by hand, you have to carefully ensure that all the object dependencies are satisfied. If you miss initializing some properties, you are likely to end up with <em>NullPointerExceptions</em> at runtime. </p>
<p>A preferred approach is to let Spring create and initialize the object for you and to get a handle to that object in your legacy code. We create a <em><a href="http://static.springsource.org/spring/docs/1.1.4/api/org/springframework/context/ApplicationContextAware.html">ApplicationContextAware</a></em> bean as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.BeansException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.ApplicationContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.ApplicationContextAware</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SpringApplicationContextAware <span style="color: #000000; font-weight: bold;">implements</span> ApplicationContextAware <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> ApplicationContext applicationContext<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setApplicationContext<span style="color: #009900;">&#40;</span>ApplicationContext context<span style="color: #009900;">&#41;</span>
                                                        <span style="color: #000000; font-weight: bold;">throws</span> BeansException <span style="color: #009900;">&#123;</span>
      applicationContext <span style="color: #339933;">=</span> context<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Object</span> getBean<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> beanName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> applicationContext.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span>beanName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We then declare a singleton instance of this bean using something like this in the Spring config:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;applicationContextAware&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.somedomain.somesubdomain.SpringApplicationContextAware&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>At the time of Spring initialization, Spring will instantiate the bean defined above. And since the class implements the <em>ApplicationContextAware</em> interface, Spring will invoke the setApplicationContext() method on it.</p>
<p>We can then access any named Spring bean as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">MyBean bean <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MyBean<span style="color: #009900;">&#41;</span> SpringApplicationContext.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;whackyBeanName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If you prefer the new Annotation based configuration, then we can skip the <bean> declaration above and use something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:component-scan</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;com.somedomain.somesubdomain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>And use the @Component annotation on the bean as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.beans.BeansException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.ApplicationContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.ApplicationContextAware</span><span style="color: #339933;">;</span>
&nbsp;
@<span style="color: #003399;">Component</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SpringApplicationContextAware <span style="color: #000000; font-weight: bold;">implements</span> ApplicationContextAware <span style="color: #009900;">&#123;</span>
	...
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://roshankulkarni.info/2010/05/referencing-spring-managed-beans-from-non-spring-java-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The holy grail of search!</title>
		<link>http://roshankulkarni.info/2010/03/the-holy-grail-of-search/</link>
		<comments>http://roshankulkarni.info/2010/03/the-holy-grail-of-search/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 03:47:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[reading list]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://roshankulkarni.info/?p=86</guid>
		<description><![CDATA[Recently came across this article in the feb edition of wired magazine &#8211; how big G! keeps it&#8217;s search algorithms ticking. Every year, tens of tweaks are rolled out to the core search algorithms. Invisible to casual observers like us (And you thought doodles were the only thing their search team has been busy with). [...]]]></description>
			<content:encoded><![CDATA[<p>Recently came across <a href="http://www.wired.com/magazine/2010/02/ff_google_algorithm/">this article </a>in the feb edition of wired magazine &#8211; how big G! keeps it&#8217;s search algorithms ticking.</p>
<p>Every year, tens of tweaks are rolled out to the core search algorithms. Invisible to casual observers like us (And you thought <a href="http://en.wikipedia.org/wiki/Google_Doodle#Google_Doodle">doodles</a> were the only thing their search team has been busy with).</p>
<p>I was inspired to read how a team that is already way ahead of the competition, keeps its passion alive to engineer a great product. It was also inspiring to see top engineer and Google Fellow <a href="http://singhal.info/">Amit Singhal</a> being quoted by the Wired mag.</p>
<p>My post today was not triggered by the article on wired. Instead, an interesting goofup I saw during during my daily dose of Google news:</p>
<p><a href="http://www.roshankulkarni.info/wp-content/uploads/2010/03/Google_Stalin_Google_Goofup.jpg"><br />
<img style="clear: both; margin-bottom: 15px;" title="Google_Stalin_Google_Goofup" src="http://www.roshankulkarni.info/wp-content/uploads/2010/03/Google_Stalin_Google_Goofup.jpg" alt="Google_Stalin_Google_Goofup" width="600" /><br />
</a></p>
<p style="text-align: left; clear: both;">Mistaken identity by Google&#8217;s image matching. The <a href="http://en.wikipedia.org/wiki/Stalin" target="_blank">great architect of communism</a> impersonated as the <a href="http://www.mkstalin.net/index_eng.php">deputy chief minister of Tamil Nadu</a>. :)</p>
<p><a href="http://www.roshankulkarni.info/wp-content/uploads/2010/03/google_story.png"><img src="http://www.roshankulkarni.info/wp-content/uploads/2010/03/google_story-213x300.png" alt="google_story" width="150"/></a></p>
<p style="text-align: left; margin-top: 5px; clear: both;">Almost about to finish reading <a href="http://www.thegooglestory.com/">The Google Story</a> by David Vise. I would love to write an excerpt some other time. Next in the stack is Thomas Friedman (The World is Flat) and Vir Sanghvi (<a href="http://www.flipkart.com/men-steel-vir-sanghvi/8174364749-0v23f84tvc" target="_blank">Men of Steel</a>).</p>
]]></content:encoded>
			<wfw:commentRss>http://roshankulkarni.info/2010/03/the-holy-grail-of-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up an Apache2 Virtual Host for a Subdomain</title>
		<link>http://roshankulkarni.info/2009/09/setting-up-apache2-virtual-host-for-your-project/</link>
		<comments>http://roshankulkarni.info/2009/09/setting-up-apache2-virtual-host-for-your-project/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 06:29:36 +0000</pubDate>
		<dc:creator>roshan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://roshankulkarni.info/?p=47</guid>
		<description><![CDATA[I&#8217;ve done this several times before, so noting it for my own quick reference. This might be of help to others finding their way around Apache deployments. I&#8217;ve tried this on a Ubuntu 9.04 (Jaunty Jackalope) with Apache2. Here is what we are trying to setup: Subdomain for your web project: http://mysubdomain.mydomain.com (say, http://staging.mykillerapp.com) You [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done this several times before, so noting it for my own quick reference. This might be of help to others finding their way around Apache deployments.</p>
<p>I&#8217;ve tried this on a Ubuntu 9.04 (Jaunty Jackalope) with Apache2. Here is what we are trying to setup:</p>
<ul>
<li>Subdomain for your web project: <em>http://mysubdomain.mydomain.com (say, http://staging.mykillerapp.com)<br />
</em></li>
</ul>
<ul>
<li>You wish to give restricted access to a people in your team, to deploy the project. You don&#8217;t wish to give them sudo or admin rights to your Linux box.</li>
</ul>
<p><strong>Creating a Sub-domain</strong></p>
<p>Your hosting provider is likely to give you a web-based domain management tool (CPanel or something else). Add a DNS &#8220;A record&#8221; as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">subdomain      PUBLICIPADDRESS      A</pre></div></div>

<p>For example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">staging      x.x.x.x      A</pre></div></div>

<p><strong>Create a non-root user account to manage your application</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ adduser staging</pre></div></div>

<p>I&#8217;m assuming that staging home is the usual <em>/home/staging</em>. Lets create a <em>www </em>under it, which will serve as the root directory for our virtual host<em> /home/staging/www/</em></p>
<p><strong>Enable the Apache Virtual Host Module</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod vhost_alias</pre></div></div>

<p><strong>Create a virtual host configuration for Apache2</strong></p>
<p>Apache2 tracks the virtual hosts configurations in this location:<em> /etc/apache2/sites-available/.</em> There will be a default config file; Lets make a copy of that file at the same directory location.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">cp</span> default staging
$ <span style="color: #c20cb9; font-weight: bold;">vi</span> staging</pre></td></tr></table></div>

<p>Make your virtual host file look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VirtualHost</span> *:80<span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
        ServerName staging.mykillerapp.com
        ServerAdmin appadmin@mykillerapp.com
        DocumentRoot /home/staging/www/
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                Options FollowSymLinks
                AllowOverride All
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> /home/staging/www<span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                Options FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        ErrorLog /var/log/apache2/error.log
&nbsp;
        # Possible values include: debug, info, notice, 
        # warn, error, crit, alert, emerg.
        LogLevel warn
&nbsp;
        CustomLog /var/log/apache2/access.log combined
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><strong>Enable your virtual host</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> a2ensite staging</pre></div></div>

<p>This sets up a soft-link in <em>/etc/apache2/sites-enabled/</em> which points to your virtual host config file.</p>
<p><strong>Finally, restart apache</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> service apache2 restart</pre></div></div>

<p style="text-align: left;"><em>Hit your virtual host <em>at http://staging.mykillerapp.com</em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://roshankulkarni.info/2009/09/setting-up-apache2-virtual-host-for-your-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating Unique Ids in PHP &#8211; A scheme for UUIDs generation in a distributed application</title>
		<link>http://roshankulkarni.info/2009/09/generating-uuids-in-php-a-scalable-scheme-for-generating-unique-identifiers-in-a-distributed-php-application/</link>
		<comments>http://roshankulkarni.info/2009/09/generating-uuids-in-php-a-scalable-scheme-for-generating-unique-identifiers-in-a-distributed-php-application/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 02:42:37 +0000</pubDate>
		<dc:creator>roshan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scalable Applications]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[webapps]]></category>

		<guid isPermaLink="false">http://roshankulkarni.info/?p=3</guid>
		<description><![CDATA[I was recently involved with a project which had 4 nodes running PHP code and a sharded MySQL database in the backend. The PHP nodes create data objects in a distributed manner and then persist them to the database shards. Now, each object needs a unique identifier (key). MySQL auto-increment Ids could not be used [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently involved with a project which had 4 nodes running PHP code and a sharded MySQL database in the backend. The PHP nodes create data objects in a distributed manner and then persist them to the database shards.</p>
<p>Now, each object needs a unique identifier (key). MySQL auto-increment Ids could not be used here since two database shards could pick the same Ids resulting in a collision. We needed an efficient scheme for simultaneously generating unique identifiers on multiple hosts. A few additional constraints apply:</p>
<p><strong>Low Collision Probability:</strong></p>
<ul>
<li> The UUIDs should offer strong guarantees of uniqueness. Even if two nodes create UUIDs at the same instant of time, there would be a very, very low probability of a collision.</li>
</ul>
<p><strong>Scalable:</strong></p>
<ul>
<li> There would be no central node / authority to generate them.  A central node would be a single point of failure. It would also be a bottleneck as our cluster grows.</li>
</ul>
<ul>
<li> The UUIDs should be generated in a distributed manner. Any web-layer node can generate the UUID locally and this should be efficient to generate.</li>
</ul>
<p><strong>Length of the UUID:</strong></p>
<ul>
<li> We were not trying to achieve a theoretical uniqueness here. Yet we were looking at 20-50 million unique objects in our database.</li>
</ul>
<ul>
<li> An 18-20 digit UUID seemed reasonable.</li>
</ul>
<p><strong>Not Cryptographically Secure:</strong></p>
<ul>
<li> We were not particularly looking for something which is hard to predict or something cryptographically secure. So if the Ids were monotonically increasing or somewhat easier to predict, it was acceptable.</li>
</ul>
<p><strong>Non-strict Timestamp Synchronization:</strong></p>
<ul>
<li> Nodes which generate UUIDs might not be strictly synchronized in time &#8211; however they would be within 5-10 seconds of each other.</li>
</ul>
<p/>
<h2>The PHP Solution</h2>
<p>PHP supports the <a href="http://in.php.net/uniqid">uniqid()</a> method (since PHP 4), which generates a unique id based on the current microsecond timestamp of the local system.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>It returns a 13 character hex string &#8211; monotonically increasing timestamp values:<br />
4aa5c7f2c2d33<br />
4aa5c7f2c2d4a<br />
4aa5c7f2c2d4e<br />
4aa5c7f2c2d51&#8230;</p>
<p>In a scenario where multiple nodes simultaneously generate the unique Id, there is a small probability of a collision. We add a 4 digit random prefix, to reduce the collision probability further.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Generate a random prefix.</span>
<span style="color: #000088;">$rand</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$randomPrefix</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rand</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Generate a UniqId having the random prefix.</span>
<span style="color: #666666; font-style: italic;">// (4 digit prefix + 13 digit Uniq) is good enough for us.</span>
<span style="color: #000088;">$uniq</span> <span style="color: #339933;">=</span> <span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$randomPrefix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Modulo and Shard Numbers</h2>
<p>In our scheme, the shard number of an object was determined based on the modulus of the unique Id. Thus:</p>
<blockquote><p>Shard Number = UniqId % TOTAL_SHARDS</p></blockquote>
<p>For very large numbers the PHP mod (%) operator results in an overflow. So we consider only the 5 LSB digits for computing the modulo value.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">function</span> getModulo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$uniqId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Take 5 LSB digits only.</span>
    <span style="color: #000088;">$uuidLsb</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uniqId</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Convert Hex string to Int. Mod only works on Ints.</span>
    <span style="color: #000088;">$intUuidLsb</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #990000;">hexdec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uuidLsb</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Compute Mod</span>
    <span style="color: #000088;">$mod</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$intUuidLsb</span> <span style="color: #339933;">%</span> TOTAL_SHARDS<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$mod</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>UUID Generation &#8211; Final Cut</h2>
<p>We extend the UUID scheme a bit further in order to help us quickly determine the shard number from a given UUID string. We prefix the shard number (mod value) to every UUID. The final version of our scheme looks like this:</p>
<ul>
<li>Generate random number.</li>
<li>Generate UniqId with the random number prefix.</li>
<li>Generate UUID = mod(UniqId) + UniqId</li>
</ul>
<p>Here is the final version of our code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> generateUUID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Generate a random prefix. </span>
    <span style="color: #000088;">$rand</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$randomPrefix</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rand</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Generate a UniqId having the random prefix. </span>
    <span style="color: #666666; font-style: italic;">// (4 digit prefix + 13 digit Uniq) is good enough for us.</span>
    <span style="color: #000088;">$uniq</span> <span style="color: #339933;">=</span> <span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$randomPrefix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Compute modulo.</span>
    <span style="color: #000088;">$modVal</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModulo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uniq</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// UUID = (1 digit mod val + 4 digit prefix + 13 digit Uniq).</span>
    <span style="color: #000088;">$uuid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modVal</span><span style="color: #339933;">.</span><span style="color: #000088;">$uniq</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$uuid</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getModulo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$uuid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Take 5 LSB digits only for the modulo computation.</span>
    <span style="color: #000088;">$uuidLsb</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uuid</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Convert Hex string to Int. Mod only works on Ints.</span>
    <span style="color: #000088;">$intUuidLsb</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #990000;">hexdec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uuidLsb</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Compute Mod</span>
    <span style="color: #000088;">$mod</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$intUuidLsb</span> <span style="color: #339933;">%</span> TOTAL_SHARDS<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$mod</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Please Note that this scheme is not compliant with the UUID <a href="http://www.rfc-archive.org/getrfc.php?rfc=4122">RFC 4122</a>, but should suffice for web applications in general.</p>
]]></content:encoded>
			<wfw:commentRss>http://roshankulkarni.info/2009/09/generating-uuids-in-php-a-scalable-scheme-for-generating-unique-identifiers-in-a-distributed-php-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

