<?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>The Inferno &#187; Programming</title>
	<atom:link href="http://www.viren.ca/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.viren.ca/blog</link>
	<description>It is a fallacy to state that something exists just because it can&#039;t be proven that it doesn&#039;t</description>
	<lastBuildDate>Tue, 07 Feb 2012 06:09:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Direct Upload to FTP</title>
		<link>http://www.viren.ca/blog/direct-upload-to-ftp/</link>
		<comments>http://www.viren.ca/blog/direct-upload-to-ftp/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 00:32:54 +0000</pubDate>
		<dc:creator>Viren</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[UploadToFTP]]></category>
		<category><![CDATA[direct image upload to FTP]]></category>
		<category><![CDATA[firefox add on]]></category>
		<category><![CDATA[mozilla firefox extension]]></category>
		<category><![CDATA[uploadToFTP mozilla firefox extension]]></category>

		<guid isPermaLink="false">http://www.viren.ca/blog/?p=638</guid>
		<description><![CDATA[Many&#8217;s the time I&#8217;ve surfed the vast wonders of the cybernetic ocean and wondered, &#8220;Wouldn&#8217;t it be nice to have this bit of coral back home, resting peacefully on the mantelpiece?&#8221;. Well, perendinate no longer! I present to you my first Firefox add-on, an add-on that lets you upload images you see on webpages directly [...]]]></description>
			<content:encoded><![CDATA[<p>Many&#8217;s the time I&#8217;ve surfed the vast wonders of the cybernetic ocean and wondered, &#8220;Wouldn&#8217;t it be nice to have this bit of coral back home, resting peacefully on the mantelpiece?&#8221;. Well, perendinate no longer! I present to you my first Firefox add-on, an add-on that lets you upload images you see on webpages directly to your website. Let me explain. If I see an image I like or wish to re-post on my blog, I have to do the following:</p>
<ol>
<li> Right click on image</li>
<li> Save to hard drive</li>
<li> Fire up an FTP client, Filezilla in this case</li>
<li> Connect to my FTP server</li>
<li> Load the directory with the downloaded image in the left pane, and the appropriate FTP directory in the right pane</li>
<li> Upload the file</li>
</ol>
<p>My add-on automates these steps. Since I don&#8217;t know how to use Javascript to upload a file to an FTP server, the script calls a PHP script which does the heavy lifting. I repeat that again: you must have a PHP-enabled webserver to run this add-on successfully. It doesn&#8217;t need to be a hosted one, I just run apache on my box and point the javascript to localhost. More detailed instructions are at the bottom. First, we look at how it works.</p>
<p>If you&#8217;re on some random site and think you want an image for your personal post or to share with others without being a leech on the original host, you right click on an image to see the context menu augmented by the &#8220;Upload To FTP&#8221; sub-menu.</p>
<p><img class="alignnone" src="http://www.viren.ca/images/contextmenu.png" alt="" width="816" height="630" /></p>
<p>Select the first option, &#8220;Images&#8221;. The second menu, &#8220;Fav 2&#8243; can be customized to whatever you want, if you&#8217;re so inclined, but it&#8217;s mostly there to show that other options can be added. If you right-click on a non-text element the context menu is still augmented. I followed the Mozilla instructions but wasn&#8217;t able to get the sub-menu to not show up on non-image environments. If anyone figures it out after looking at my code, please drop me a line.</p>
<p><img class="alignnone" src="http://www.viren.ca/images/contextmenuonbg.png" alt="" width="813" height="620" /></p>
<p>If you try to upload the non-image element, you get an error message stating that non-images cannot be uploaded at this time.</p>
<p><img class="alignnone" src="http://www.viren.ca/images/errormsg.png" alt="" width="812" height="682" /></p>
<p>Finally, we check the folder on my website where the images were sent to. If you try to add a file with the same name more than once, it increments the file name by the next digit. I don&#8217;t know if this will be useful, but I have often come across several image files with the same name and different content (think Google image search for: Canada) and I&#8217;d hate to see them overwritten and end up being the same file. We see:</p>
<p><img class="alignnone" src="http://www.viren.ca/images/uploadedimages.png" alt="" width="682" height="335" /></p>
<p>Here is the zip file containing both the XPI installer for the Firefox add-on, and the imgupload.php file. You can install the add-on by opening it with Firefox (File -&gt; Open File). I&#8217;ll submit it to the Firefox add-on repository soon.</p>
<p><a href="http://www.viren.ca/images/uploadToFTP.zip">UploadToFTP zip file</a>.</p>
<p>As for the PHP file, note that it does no error-checking whatsoever. Use it at your own risk. You&#8217;ll need to fill in parameters such as the FTP server name, login, password and upload folder. Once that&#8217;s done, host it in the root of your webserver&#8217;s public HTML directory and you&#8217;re done. If you host it in any other location, such as a subfolder or whatnot, then you need to update the &#8220;overlay.js&#8221; file in your Firefox profile&#8217;s <em>extensions/uploadtoftp@viren.kumar/content</em> folder.</p>
<p>Enjoy, and let me know if this is useful for you or if you&#8217;d like to see any upgrades or features.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.viren.ca/blog/direct-upload-to-ftp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Combinations and Permutations</title>
		<link>http://www.viren.ca/blog/combinations-and-permutations/</link>
		<comments>http://www.viren.ca/blog/combinations-and-permutations/#comments</comments>
		<pubDate>Fri, 29 May 2009 19:08:51 +0000</pubDate>
		<dc:creator>Viren</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[combinations]]></category>
		<category><![CDATA[full solution]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[permutations]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.viren.ca/blog/?p=377</guid>
		<description><![CDATA[Recently, a lot of people have expressed interest in generating all combinations and permutations of various objects. While this is a topic covered in second-year Computer Science courses, it seems a fair number of people have no idea how to go about generating them. In this post, I&#8217;ll provide code on how to go about [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" src="http://www.viren.ca/images/cmb,pascal.gif" alt="" width="346" height="400" /></p>
<p>Recently, a lot of people have expressed interest in generating all combinations and permutations of various objects. While this is a topic covered in second-year Computer Science courses, it seems a fair number of people have no idea how to go about generating them. In this post, I&#8217;ll provide code on how to go about doing this in an imperative language (Java). Doing it in a functional language like Haskell is much shorter, only 2 lines or so, but this version is imperative. Also, I&#8217;ve used strings, but feel free to modify it to any sort of container.</p>
<p>For generating combinations of length k, briefly:</p>
<ul>
<li>Extract the first element from the list</li>
<li>Prepend it to all combinations of length k-1 from the leftover list</li>
<li>Calculate all combinations of length k-1 from the leftover list.</li>
</ul>
<p>For generating permutations of length k, briefly:</p>
<ul>
<li>Iterate over the list</li>
<li>Remove one element at a time from the list</li>
<li>Prepend the removed element to all permutations of length k-1 from the leftover list.</li>
</ul>
<p>It&#8217;s really that simple, handle the base cases and you&#8217;re all set. Do a couple of examples on paper if you still don&#8217;t get it. Also, modifying the permutations code to generate all permuations with repetitions should be fairly simple too. Give it a shot.</p>
<p>Run my code to generate all combinations of my name:</p>
<pre>        Combinations c = new Combinations();
        ArrayList&lt;String&gt; result = new ArrayList&lt;String&gt;();
        String test = "viren";
        for(int i = 1; i &lt;= test.length(); i++){
            result.clear();
            result = c.getCombos(test,i);
            System.out.println(result);           
        }</pre>
<p>This results in:</p>
<blockquote><p>[v, i, r, e, n]<br />
[vi, vr, ve, vn, ir, ie, in, re, rn, en]<br />
[vir, vie, vin, vre, vrn, ven, ire, irn, ien, ren]<br />
[vire, virn, vien, vren, iren]<br />
[viren]</p></blockquote>
<p>And similarly, the permutations code results in:</p>
<blockquote><p>[v, i, r, e, n]</p>
<p>[vi, vr, ve, vn, iv, ir, ie, in, rv, ri, re, rn, ev, ei, er, en, nv, ni, nr, ne]</p>
<p>[vir, vie, vin, vri, vre, vrn, vei, ver, ven, vni, vnr, vne, ivr, ive, ivn, irv, ire, irn, iev, ier, ien, inv, inr, ine, rvi, rve, rvn, riv, rie, rin, rev, rei, ren, rnv, rni, rne, evi, evr, evn, eiv, eir, ein, erv, eri, ern, env, eni, enr, nvi, nvr, nve, niv, nir, nie, nrv, nri, nre, nev, nei, ner]</p>
<p>[vire, virn, vier, vien, vinr, vine, vrie, vrin, vrei, vren, vrni, vrne, veir, vein, veri, vern, veni, venr, vnir, vnie, vnri, vnre, vnei, vner, ivre, ivrn, iver, iven, ivnr, ivne, irve, irvn, irev, iren, irnv, irne, ievr, ievn, ierv, iern, ienv, ienr, invr, inve, inrv, inre, inev, iner, rvie, rvin, rvei, rven, rvni, rvne, rive, rivn, riev, rien, rinv, rine, revi, revn, reiv, rein, renv, reni, rnvi, rnve, rniv, rnie, rnev, rnei, evir, evin, evri, evrn, evni, evnr, eivr, eivn, eirv, eirn, einv, einr, ervi, ervn, eriv, erin, ernv, erni, envi, envr, eniv, enir, enrv, enri, nvir, nvie, nvri, nvre, nvei, nver, nivr, nive, nirv, nire, niev, nier, nrvi, nrve, nriv, nrie, nrev, nrei, nevi, nevr, neiv, neir, nerv, neri]</p>
<p>[viren, virne, viern, vienr, vinre, viner, vrien, vrine, vrein, vreni, vrnie, vrnei, veirn, veinr, verin, verni, venir, venri, vnire, vnier, vnrie, vnrei, vneir, vneri, ivren, ivrne, ivern, ivenr, ivnre, ivner, irven, irvne, irevn, irenv, irnve, irnev, ievrn, ievnr, iervn, iernv, ienvr, ienrv, invre, inver, inrve, inrev, inevr, inerv, rvien, rvine, rvein, rveni, rvnie, rvnei, riven, rivne, rievn, rienv, rinve, rinev, revin, revni, reivn, reinv, renvi, reniv, rnvie, rnvei, rnive, rniev, rnevi, rneiv, evirn, evinr, evrin, evrni, evnir, evnri, eivrn, eivnr, eirvn, eirnv, einvr, einrv, ervin, ervni, erivn, erinv, ernvi, erniv, envir, envri, enivr, enirv, enrvi, enriv, nvire, nvier, nvrie, nvrei, nveir, nveri, nivre, niver, nirve, nirev, nievr, nierv, nrvie, nrvei, nrive, nriev, nrevi, nreiv, nevir, nevri, neivr, neirv, nervi, neriv]</p></blockquote>
<p>Without further ado, here&#8217;s the source code. As always, if you find any bugs or have suggestions for improvements, let me know.</p>
<p><a href="http://www.viren.ca/code/Combinations.java">Combinations.java</a></p>
<p><a href="http://www.viren.ca/code/Permutations.java">Permutations.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.viren.ca/blog/combinations-and-permutations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.409 seconds -->

