<?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>Public MindIntern</title>
	<atom:link href="http://publicmind.in/blog/tag/intern/feed/" rel="self" type="application/rss+xml" />
	<link>http://publicmind.in/blog</link>
	<description>Simple and Sophisticated</description>
	<lastBuildDate>Sat, 04 Sep 2010 06:00:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MYSQL: MINUS (Set Difference) Operator</title>
		<link>http://publicmind.in/blog/mysql-minus-set-difference-operator/</link>
		<comments>http://publicmind.in/blog/mysql-minus-set-difference-operator/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 22:26:02 +0000</pubDate>
		<dc:creator>Nitin</dc:creator>
				<category><![CDATA[Nitin's Blog]]></category>
		<category><![CDATA[Intern]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://publicmind.in/blog/?p=192</guid>
		<description><![CDATA[Often we need MINUS operator as defined by the SQL definitions i.e you have two sets P and Q and you want P-Q which gives all the elements in P that are not in Q. But unfortunately, MYSQL does not have any operator for such an operation (yeah, I had the same reaction when I [...]]]></description>
			<content:encoded><![CDATA[<p>Often we need MINUS operator as defined by the SQL definitions i.e you have two sets P and Q and you want P-Q which gives all the elements in P that are not in Q. But unfortunately, MYSQL does not have any operator for such an operation (yeah, I had the same reaction when I heard this!!).</p>
<p>So here is a way how you can implement it in MYSQL. For simplicity let us consider we have two tables <strong>P and Q</strong> (we can also have views, joins, etc instead of the tables here) which have atleast one column in common (say <strong>id</strong>, which usually will be the primary key) and we want to evaluate <strong>P &#8211; Q</strong> which removes all those rows from P whose <strong>id</strong> is present in Q.</p>
<p>Here is the SQL statement for it. The statement is quite self explanatory, but if you still have doubt then leave a comment.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Select <span style="color: #339933;">*</span> from P left join Q on P.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> Q.<span style="color: #006633;">id</span> where Q.<span style="color: #006633;">id</span> is <span style="color: #000066; font-weight: bold;">NULL</span><span style="color: #339933;">;</span></div></div>
<p>Thats is what I could think of. If you are using some better and efficient method, then please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://publicmind.in/blog/mysql-minus-set-difference-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MYSQL: Get the Auto-Increment Values after Insert Statement</title>
		<link>http://publicmind.in/blog/mysql-auto-increment-values/</link>
		<comments>http://publicmind.in/blog/mysql-auto-increment-values/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 12:24:32 +0000</pubDate>
		<dc:creator>Nitin</dc:creator>
				<category><![CDATA[Nitin's Blog]]></category>
		<category><![CDATA[Intern]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://publicmind.in/blog/?p=218</guid>
		<description><![CDATA[Until sometime back, I was unaware of how I could get the value of an auto-incremented field after an Insert Statement. But recently I needed it for two of my projects simultaneously, so I explored the possibilities. As one of my project is in Java and other is in PHP, we will go through both [...]]]></description>
			<content:encoded><![CDATA[<p>Until sometime back, I was unaware of how I could get the value of an auto-incremented field after an Insert Statement. But recently I needed it for two of my projects simultaneously, so I explored the possibilities. As one of my project is in Java and other is in PHP, we will go through both of them. </p>
<p>So, here is the problem. In general, the PRIMARY KEY field is the AUTO_INCREMENT field. Now wen you insert a row, a new key is generated and you can&#8217;t get it through usual way as this row can be accessed only using the primary key.</p>
<p>So here is how it can be done:<br />
<span id="more-218"></span><br />
<strong>In JAVA: </strong></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/*Insert a row into the desired table that generates <br />
an auto increment field*/</span><br />
<br />
stmt.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Insert into tableName (col1, col2) values (val1, val2)&quot;</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astatement+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Statement</span></a>.<span style="color: #006633;">RETURN_GENERATED_KEYS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aresultset+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">ResultSet</span></a> rs <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">getGeneratedKeys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">int</span> autoIncValue <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rs.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;autoIncValue <span style="color: #339933;">=</span> rs.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/*You can get more generated keys if they are generated in your code*/</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p><strong>In PHP</strong>:</p>
<p>The mysql_insert_id() function in PHP returns the AUTO_INCREMENT ID generated from the previous INSERT operation.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$con</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_connect"><span style="color: #990000;">mysql_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hostname&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$con</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error while connecting: '</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/mysql_error"><span style="color: #990000;">mysql_error</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000088;">$db_selected</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_select_db"><span style="color: #990000;">mysql_select_db</span></a><span style="color: #009900;">&#40;</span>database_name<span style="color: #339933;">,</span><span style="color: #000088;">$con</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO tablename VALUES (val1,val2)&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #339933;">,</span><span style="color: #000088;">$con</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;ID of last inserted record is: &quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/mysql_insert_id"><span style="color: #990000;">mysql_insert_id</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.php.net/mysql_close"><span style="color: #990000;">mysql_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>Note: Be sure to call mysql_insert_id() immediately after a query to get the correct value. The function returns 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established. </p>
<p>Enjoy!!</p>
]]></content:encoded>
			<wfw:commentRss>http://publicmind.in/blog/mysql-auto-increment-values/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sorting a 2-Dimensional Array in Java</title>
		<link>http://publicmind.in/blog/sorting-2d-array-java/</link>
		<comments>http://publicmind.in/blog/sorting-2d-array-java/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 21:47:28 +0000</pubDate>
		<dc:creator>Nitin</dc:creator>
				<category><![CDATA[Nitin's Blog]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Intern]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://publicmind.in/blog/?p=199</guid>
		<description><![CDATA[Recently while working for my project, I came across this situation when I had a 2-D array and I needed to sort it twice on 2 of its columns. Consider the following 2D array: String&#91;&#93;&#91;&#93; testString = new String&#91;&#93;&#91;&#93; &#123; &#160; &#160; &#123;&#34;1&#34;, &#34;2&#34;, &#34;6&#34;&#125;, &#160; &#160; &#123;&#34;4&#34;, &#34;5&#34;, &#34;3&#34;&#125; &#160; &#125;; Sorting the above [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Digg Digg Disabled -->Recently while working for my project, I came across this situation when I had a 2-D array and I needed to sort it twice on 2 of its columns. Consider the following 2D array:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> testString <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;1&quot;</span>, <span style="color: #0000ff;">&quot;2&quot;</span>, <span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;4&quot;</span>, <span style="color: #0000ff;">&quot;5&quot;</span>, <span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>Sorting the above 2D array on zero column will give</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;1&quot;</span>, <span style="color: #0000ff;">&quot;2&quot;</span>, <span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;4&quot;</span>, <span style="color: #0000ff;">&quot;5&quot;</span>, <span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>whereas sorting it on second column will give</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;4&quot;</span>, <span style="color: #0000ff;">&quot;5&quot;</span>, <span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;1&quot;</span>, <span style="color: #0000ff;">&quot;2&quot;</span>, <span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>I did not want to do the most common as well as tedious thing, i.e. write my own sorting function like this:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> myOwnSort<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> exampleArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//code for sorting the array according to my wish.</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>I wanted to avoid this for 2 resons:</p>
<ol>
<li>I would have to write the code for it ( lazy me!!).</li>
<li>Secondly, I can possibly never match the efficiency provided by the sorting functions of java.util.Arrays</li>
</ol>
<p><span id="more-199"></span><br />
So, my main aim was to look for a solution that would help me sort my 2-D array using the internal JAVA sorters.</p>
<p>I started digging into the JAVA docs (I must admit, I was a naive in JAVA at this point), and came across the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html">Comparator</a> Interface, using which we can tell the JAVA sorting function (<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html#sort(java.lang.Object[], java.util.Comparator)">Arrays.sort</a>) on how to compare two elements of a 2D array. One must understand that a 2D array is essentially a 1D array with its each element as another 1D array.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> testString <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;1&quot;</span>, <span style="color: #0000ff;">&quot;2&quot;</span>, <span style="color: #0000ff;">&quot;6&quot;</span><span style="color: #009900;">&#125;</span>,<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;4&quot;</span>, <span style="color: #0000ff;">&quot;5&quot;</span>, <span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>Above, there are two arrays containing 3 strings each. We must now compare these two arrays to determine their order in the resultant 2D array. We can compare these two 1-D arrays in any way we like, we can compare them on the first column, third column or on the average length of the strings (just anything!!). Let us implement Comparator interface to define such a compare function:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> 2DcolumnComparator <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomparator+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Comparator</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> columnToSortOn<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//contructor to set the column to sort on.</span><br />
&nbsp; &nbsp; 2DcolumnComparator<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> columnToSortOn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">columnToSortOn</span> <span style="color: #339933;">=</span> columnToSortOn<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Implement the abstract method which tells</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// how to order the two elements in the array.</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> o1, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> o2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// cast the object args back to string arrays</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> row1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>o1<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> row2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>o2<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// compare the desired column values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> row1<span style="color: #009900;">&#91;</span>columnToSortOn<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>row2<span style="color: #009900;">&#91;</span>columnToSortOn<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Above, we create a class 2DcolumnComparator which implements comparator interface and compare 1D array elements on the column passed to the constructor. Now, we can pass an instance of this class to the Arrays.sort function, and the 2D array will sorted on the desired column.</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Analysis <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> childrenArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span>MAXLIMIT<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Populate the Array and sort</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aarrays+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Arrays</span></a>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>childrenArray,<span style="color: #000000; font-weight: bold;">new</span> 2DcolumnComparator<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Here, we instantiate the 2DcolumnComaparator class and pass the column to sort on as parameter to its constructor. Above, the 2D array will be sorted on its fifth column (starting from zero). You can, of course, change the <strong>compare</strong> function to order elements according to your wish.</p>
<p>That is all I needed to sort a 2-D Array. Happy Sorting!!! <img src='http://publicmind.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Useful Resources:</strong><br />
<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html">http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html</a><br />
<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html#sort(java.lang.Object[], java.util.Comparator)">http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html#sort(java.lang.Object[], java.util.Comparator)</a></p>
<p><strong>Recommended Reading:</strong><br />
<a href="http://publicmind.in/blog/books/corejava1" target="_blank">Core Java(TM), Volume I&#8211;Fundamentals (8th Edition)</a><br />
<a href="http://publicmind.in/blog/books/corejava2" target="_blank">Core Java(TM), Volume 2&#8211;Fundamentals (8th Edition)</a>
</p>
<p>Update: If you need to sort a 2D array of objects of any class which implements Comparable, you can look at the <a href="http://publicmind.in/blog/sorting-2d-array-java/#comment-640">comment</a> by Lars. Article last updated on 25 Feb 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://publicmind.in/blog/sorting-2d-array-java/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Drupal: FeedAPI Imagegrabber</title>
		<link>http://publicmind.in/blog/feedapi-imagegrabber/</link>
		<comments>http://publicmind.in/blog/feedapi-imagegrabber/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 07:08:10 +0000</pubDate>
		<dc:creator>Nitin</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Intern]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://publicmind.in/blog/?p=105</guid>
		<description><![CDATA[Feeds Image Grabber (FIG) was released on 3rd March 2010, to support the Feeds module. Introduction FeedAPI Imagegrabber is a add-on module for FeedAPI. It consists of a parser which visits the original URL of a new feed item, and retrieves the main image from the post. Once the main image has been retrieved, it [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Digg Digg Disabled -->
<div class="download"><a href="http://publicmind.in/blog/drupal-feeds-image-grabber">Feeds Image Grabber</a> (FIG) was released on 3rd March 2010, to support the <a href="http://drupal.org/project/feeds">Feeds</a> module.
</div>
<p><strong>Introduction</strong></p>
<p><a href="http://drupal.org/project/feedapi_imagegrabber" target="_blank">FeedAPI Imagegrabber</a> is a add-on module for <a href="http://drupal.org/project/feedapi" target="_blank">FeedAPI</a>. It consists of a parser which visits the original URL of a new feed item, and retrieves the main image from the post. Once the main image has been retrieved, it is then converted into a thumbnail using the <a href="http://drupal.org/project/imagecache" target="_blank">ImageCache</a> module, and stored in the node created by FeedAPI, inside a CCK field.</p>
<p>The purpose of FeedAPI Imagegrabber is to make the feed more informative as well as interesting for the user. As, we all know that &#8220;comics are much better than novels&#8221;, this module appends the feed-item with an appropriate image from its content URL. The goal of the module is to mimic the thumbnail display of websites such as digg.com. This goal is acheived by using FeedAPI to turn RSS feed-items into nodes, and then using FeedAPI Imagegrabber to append these nodes with an appropriate image from the feed-item&#8217;s webpage.<br />
<span id="more-105"></span><br />
<strong>How it works</strong></p>
<p>A classic method of mimicking the behavior of FeedAPI Imagegrabber will be to do the same thing manually. Let us go through the procedure if you were to do it manually:</p>
<ol>
<li>Refresh the feed.</li>
<li>For each feed-item, go to their respective original URL and save the image to display.</li>
<li>Crop the image, convert it into a thumbnail and then upload it in an CCK Image field.</li>
</ol>
<p>FeedAPI Imagegrabber automates the last 2 steps of the three step process described. It uses cURL to download the images and then crop them using Imagecache. Then the image is stored into the CCK Imagefield. The most difficult part which only humans can do is to select the image,  for which I am constantly improving on the heuristics.</p>
<p><strong>Download and Install</strong></p>
<p>Visit the project page : <a href="http://drupal.org/project/feedapi_imagegrabber" target="_blank">FeedAPI Imagegrabber</a></p>
<p><strong>Features and Future Releases</strong></p>
<p>Visit the project page : <a href="http://drupal.org/project/feedapi_imagegrabber" target="_blank">FeedAPI Imagegrabber</a></p>
<p><strong>History</strong></p>
<p>I understand history is boring, but it is only for those who think the other way round. I started working on this module during December 2008.  At the time, when I started working on this module, I had a little or say<em><strong> no idea</strong></em> about Drupal or its API. It took me quite some time to get used to it and start working on the module. In the Initial release, I thought of very simple heuristics and decided to select the largest image available on the web-page. I completed the module in about 1 month and was very happy with my performance, and then a big blow came which delayed the release of FeedAPI Imagegrabber by 2 months. I had to include an external BSD licensed script for converting relative URL&#8217;s to absolute URL&#8217;s but Drupal denied to accept this. They said they allow only GPL licensed code and I started to convince them that both licenses are compatible. Unfortunately, I was unable to convince them and I had to create an external link to that BSD script on sourceforge. And now, the module is released with the hope to enhance the visitor-experience on several websites around the globe.</p>
<p>You may find these posts useful:</p>
<p><a rel="bookmark" href="http://publicmind.in/blog/tutorial-for-feedapi-imagegrabber">Tutorial for FeedAPI ImageGrabber</a><br />
<a class="title" rel="bookmark" href="http://publicmind.in/blog/urltoabsolute/">PHP: Relative URL to Absolute URL</a><br />
<a rel="bookmark" href="http://magicalsilverdrop.blogspot.com/2009/02/open-source-software-and-licenses.html">Open Source Software and Licenses</a></p>
<p>Do Leave your comments to let me know what you think.</p>
<p><strong>Note: </strong>Support queries and requests should be made through the <a href="http://drupal.org/project/feedapi_imagegrabber" target="_blank">FeedAPI Imagegrabber Forum</a>. I may not be able to answer them here. <img src='http://publicmind.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="download">
<p><strong>Updates:</strong></p>
<ul>
<li>The first stable version of the module was released on 7th April, 2009. Check it out now <a href="http://drupal.org/project/feedapi_imagegrabber" target="_blank">here</a>!!</li>
<li>RC1 release for Imagegrabber is now available for download on Project page. It is compatible with the RC1 release of Imagefield. (17 Apr, 2009)</li>
<li>Demonstration Website is up, and is available <a href="http://publicmind.in/feedapi_imagegrabber/demonstration">here</a>. (20 Aug, 2009)</li>
<li>FeedAPI ImageGrabber v1.8 released. Download it from the project website <a href="http://drupal.org/project/feedapi_imagegrabber" target="_blank">here</a>. (20 September 2009)</li>
<li><a href="http://publicmind.in/blog/tutorial-for-feedapi-imagegrabber">Tutorial for FeedAPI ImageGrabber</a> published. (20 September 2009)</li>
<li>FeedAPI ImageGrabber v1.9 released. Download it from the project website <a href="http://drupal.org/project/feedapi_imagegrabber" target="_blank">here</a>. (26 October 2009)</li>
<li>FeedAPI ImageGrabber now supports <a href="http://drupal.org/project/filefield_paths">Filefield Paths</a> module. Download the development snapshot, its stable for use on production site.</li>
<li>As of 02 Dec 2009, Development of FeedAPI ImageGrabber has been halted. You can look out for the <a href="http://drupal.org/project/feeds_imagegrabber" target="_blank">Feeds Image Grabber</a> module which supports <a href="http://drupal.org/project/feeds" target="_blank">Feeds</a> module,  successor of FeedAPI, with the same functionality.</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://publicmind.in/blog/feedapi-imagegrabber/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Schengen Visa to Germany</title>
		<link>http://publicmind.in/blog/schengen-visa-germany/</link>
		<comments>http://publicmind.in/blog/schengen-visa-germany/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 07:50:04 +0000</pubDate>
		<dc:creator>Nitin</dc:creator>
				<category><![CDATA[Nitin's Blog]]></category>
		<category><![CDATA[experiences]]></category>
		<category><![CDATA[germany]]></category>
		<category><![CDATA[Intern]]></category>
		<category><![CDATA[visa]]></category>

		<guid isPermaLink="false">http://publicmind.in/blog/?p=78</guid>
		<description><![CDATA[Note: The procedure given happened to me, I do not guarantee you the same, may be I was lucky or you will be. I leave the details of the trip (tiring but exciting) for my next post, and will try to outline the procedure to get the Schengen Student Visa for Internship from German Consulate [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note</strong>: The procedure given happened to me, I do not guarantee you the same, may be I was lucky or you will be.</p>
<p>I leave the details of the trip (tiring but exciting) for my next post, and will try to outline the procedure to get the <strong>Schengen Student Visa</strong> for <strong>Internship</strong> from<strong> German </strong>Consulate at <strong>Kolkata</strong>. I specifically mentioned Kolkata because my friends faced quite a lot of problems at the Delhi Embassy.</p>
<p>So you start with your documents, here is the list:<br />
<span id="more-78"></span></p>
<ol>
<li>Schengen Application form filled correctly.</li>
<li>Original Invitation letter from German Host, same must be faxed to the consulate by your university.</li>
<li>International Health Insurance, only if it is not mentioned on your invitation letter that host will take care of it.</li>
<li>No Objection Certificate from your home university for the whole period of intern.</li>
<li>Valid Passport of course!!</li>
<li>Photocopy of your air-tickets. They issue the Visa only between your dates of arrival and departure.</li>
<li>Covering letter (see below), a formal request letter for the visa addressed to Consulate General.</li>
<li>ZAV &#8211; mail them before leaving to check if you require this or not. In my case I did not need it.</li>
<li>Details of the sponsor of the trip and the supporting documents.</li>
</ol>
<p>That&#8217;s all. Once you have all documents with you, call them to make an appointment for the day convenient to you. ofcourse, the next step will be to reach the consulate. You can reach there by Rail or Airplane. Howrah station is just 20 minutes away from the consulate whereas Airport is 35-40 minutes away. You can hire a taxi from the station/Airport to reach the consulate (Do ask them to down their meter, so that they don&#8217;t fool you). Reach there at around 8:30 a.m. and collect your token. Then, you will have to wait inside for your Roll call <img src='http://publicmind.in/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><strong>Note:</strong> I see that a lot of people come here looking for the <strong>covering letter</strong>. I believe that if you have the internship/job and the above required documents, then you can just state the facts in your letter, eg. &#8220;I have been accepted by &#8230; company/university for the post of &#8230; , so I need visa for a period of &#8230; months. Kindly grant it&#8221;. That&#8217;s it. I myself wrote it within two minutes while waiting at the embassy as I forgot to write one before leaving.</p>
<p>It takes no more than 10 minutes to submit the application, even less if you filled the application form online. Request them to give you the visa asap and they will readily agree to give you the visa the next day. Collect the Visa the very next day and you are done. You can even catch the evening flight on the same day as I did.</p>
<p>You can find cheap and good accommodation in the near-by area. We stayed at Hotel Asha (unfortunately, there was no asha there) which had both AC (Rs.850/day) and Non-AC (Rs.500/day) rooms and all other basic amenities (TV, shower, room service, etc). The best thing about it was that there was a cyber-cafe right in front of the hotel, so no communication problems <img src='http://publicmind.in/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . Also, be prepared for a very hot, humid climate and pack some extra t-shirts to sweat out.</p>
<p>I wish you luck for your visa application. For more inquiry, call the consulate or leave a comment. Click <a href="http://www.kalkutta.diplo.de/Vertretung/kalkutta/en/Startseite.html" target="_blank">here</a> to move to the website of German consulate, Kolkata.</p>
]]></content:encoded>
			<wfw:commentRss>http://publicmind.in/blog/schengen-visa-germany/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>But where will you live?</title>
		<link>http://publicmind.in/blog/but-where-will-you-live/</link>
		<comments>http://publicmind.in/blog/but-where-will-you-live/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 14:36:24 +0000</pubDate>
		<dc:creator>Nitin</dc:creator>
				<category><![CDATA[Nitin's Blog]]></category>
		<category><![CDATA[Intern]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://publicmind.phpzilla.net/?p=15</guid>
		<description><![CDATA[Recently, my friend Anurag Nilesh got an intern in Switzerland. As I am going to Germany for the internship during summer, I thought of visiting him  and shared my thoughts with him. I was perplexed with his following reaction: Me:  yaar, main tuzhse milne switzerland zaroor aaunga.(I will definitely come to meet you.) nilesh: yaar [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_46" class="wp-caption aligncenter" style="width: 310px"><img class="size-full wp-image-46" title="Kicked Away" src="http://www.publicmind.in/blog/wp-content/uploads/2009/03/dasvidaniya-wallpaper-11-300x2251.jpg" alt="Kicked Away" width="300" height="225" /><p class="wp-caption-text">Kicked Away</p></div>
<p>Recently, my friend Anurag Nilesh got an intern in Switzerland. As I am going to Germany for the internship during summer, I thought of visiting him  and shared my thoughts with him. I was perplexed with his following reaction:</p>
<p><strong>Me</strong>:  yaar, main tuzhse milne switzerland zaroor aaunga.(I will definitely come to meet you.)<br />
<strong>nilesh</strong>:  yaar lekin tu rahega kahan, wahan hotels badey mahangey hai!! (man, but where will you live, I have heard that hotels are too costly there!!)</p>
<p>I feel like the man above, left alone on the Airport. But I am happy that he told me this before I went to meet him.</p>
]]></content:encoded>
			<wfw:commentRss>http://publicmind.in/blog/but-where-will-you-live/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
