<?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>Bin-Blog &#187; code</title>
	<atom:link href="http://www.bin-co.com/blog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bin-co.com/blog</link>
	<description>Learn about the latest in Web Development - as soon as I do.</description>
	<lastBuildDate>Tue, 13 Oct 2009 18:55:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Link Code Insert: A GreaseMonkey UserScript</title>
		<link>http://www.bin-co.com/blog/2009/07/link-code-insert-a-greasemonkey-userscript/</link>
		<comments>http://www.bin-co.com/blog/2009/07/link-code-insert-a-greasemonkey-userscript/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 18:43:33 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[userscript]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=338</guid>
		<description><![CDATA[Link Code Insert inserts the HTML code for creating a link at the active element location when the user presses Ctrl+Alt+A. I use it a lot when I am writing a comment and want to add a link. Just select the text you want to link and the userscript will add the HTML code '<code>&#60;a href=""&#62;</code>' before the selected text and a '<code>&#60;/a&#62;</code>' after it.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2009/07/greasemonkey.png" alt="GreaseMonkey" title="GreaseMonkey" width="192" height="217" class="aligncenter size-full wp-image-337 intro" align="right" /></p>
<p class="intro">Link Code Insert inserts the HTML code for creating a link at the active element location when the user presses Ctrl+Alt+A. I use it a lot when I am writing a comment and want to add a link. Just select the text you want to link and the userscript will add the HTML code &#8216;<code>&lt;a href=""&gt;</code>&#8216; before the selected text and a &#8216;<code>&lt;/a&gt;</code>&#8216; after it.</p>
<p>Technically, this is a UserScript &#8211; and not a plugin. But I prefer to think of a userscript as a plugin of a plugin. So I guess it can be included in the Plugin Week.</p>
<p>Note: You must be using Firefox and must have installed GreaseMonkey for this script to work.</p>
<h3><a href="http://www.openjs.com/scripts/greasemonkey/utilities/link_code_insert/link_code_insert.user.js">Download/Install the UserScript</a></h3>
<h2>Plugin Week 2</h2>
<p>This plugin is part of the Plugin Week 2 series. <strong class="highlight">Plugin Week is a week when I publish a new plugin each day for an entire week</strong>. I have already one this <a href="http://www.bin-co.com/blog/2008/12/wordpress-plugin-week/">one time</a> &#8211; so this is Plugin Week 2. The plugins released so far&#8230;</p>
<ul>
<li><a href="http://www.bin-co.com/blog/2009/07/plugin-week-2-wordpress-plugin-weather-man/">Weather Man</a></li>
<li><a href="http://www.bin-co.com/blog/2009/07/minicart-wordpress-plugin-shopping-cart-for-wordpress/">MiniCart WordPress Plugin</a></li>
<li><a href="http://www.bin-co.com/blog/2009/07/gallifrey-image-gallery-wordpress-plugin/">Gallifrey WordPress Plugin</a></li>
<li><a href="http://www.bin-co.com/blog/2009/07/gimp-plugin-web-2-0-shadows/">GIMP Plugin – Web 2.0 Shadows</a></li>
<li><a href="http://www.bin-co.com/blog/2009/07/drupal-plugin-page-ad/">Drupal Plugin: Page Ad</a></li>
<li><a href="http://www.bin-co.com/blog/2009/07/export-to-wordpress-joomla-plugin/">Export To WordPress: Joomla Plugin</a></li>
</ul>
<p>If you want to get news about the upcoming plugin releases(remember, 1 per day), please <strong class="highlight"><a href="http://feeds2.feedburner.com/bin-blog">subscribe to this site</a>.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2009/07/link-code-insert-a-greasemonkey-userscript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Avoid Duplicate Content &#8211; Use Canonical URL in WordPress</title>
		<link>http://www.bin-co.com/blog/2009/02/avoid-duplicate-content-use-canonical-url-in-wordpress-fix-plugin/</link>
		<comments>http://www.bin-co.com/blog/2009/02/avoid-duplicate-content-use-canonical-url-in-wordpress-fix-plugin/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 18:28:53 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[canonical]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=233</guid>
		<description><![CDATA[The new talk of the SEO world is '<a href="http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html">Canonical URL</a>'. What is canonical URL? This is the definition given in Google's Webmaster Central Blog...]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/10/wordpress_logo.png" alt="WordPress Logo" title="WordPress Logo" width="183" height="145" class="alignnone size-full wp-image-136 intro" align="right" /></p>
<p class="intro">The new talk of the SEO world is &#8216;<a href="http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html">Canonical URL</a>&#8216;. What is canonical URL? This is the definition given in Google&#8217;s Webmaster Central Blog&#8230;</p>
<blockquote><p>a format that allows you to <strong class="highlight">publicly specify your preferred version of a URL</strong>. If your site has identical or vastly similar content that&#8217;s accessible through multiple URLs, this format provides you with more control over the URL returned in search results. It also helps to make sure that properties such as link popularity are consolidated to your preferred version.</p>
<p>Emphasis mine</p>
</blockquote>
<p>It is very easy to specify the canonical URL of a page &#8211; all you have to do is <strong class="highlight">add this line in the head section</strong>&#8230;</p>
<pre><code class="html">&lt;link rel="canonical" href="http://binnyva.com/" /&gt;</code></pre>
<p>The purpose of this tag is to <a href="http://www.dailyseoblog.com/2009/02/duplicate-content-canonical-tag-to-your-rescue/">prevent the problem of duplicate content</a>.</p>
<p>The best thing about this tag is that all three major search engines(<a href="http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html">Google</a>, <a href="http://ysearchblog.com/2009/02/12/fighting-duplication-adding-more-arrows-to-your-quiver/">Yahoo</a> and <a href="http://blogs.msdn.com/webmaster/archive/2009/02/12/partnering-to-help-solve-duplicate-content-issues.aspx">MS Live</a>) support this initiative.</p>
<h2>WordPress</h2>
<p>If you are on wordpress, this tag can be integrated into your theme easily. <a href="http://yoast.com/wordpress/canonical/">There is a plugin</a> to do the job for you &#8211; but you don&#8217;t need a plugin to do something as simple as this.</p>
<h3>header.php</h3>
<p>Go to the <strong class="highlight">theme folder</strong> in wordpress(wp-content/themes/&lt;theme_name&gt;) and <strong class="highlight">open the file <code>header.php</code></strong> in your favorite editor. Now <strong class="highlight">find the line</strong>&#8230;</p>
<pre><code class="html">&lt;/head&gt;</code></pre>
<p>and add the following code <strong class="highlight">before</strong> that line&#8230;</p>
<pre><code class="html">&lt;?php if ( is_singular() ) { ?&gt;
&lt;link rel="canonical" href="&lt;?php the_permalink(); ?&gt;" /&gt;
&lt;?php } ?&gt;</code></pre>
<p>Now, it should look something like this&#8230;</p>
<pre><code class="html">&lt;?php if ( is_singular() ) { ?&gt;
&lt;link rel="canonical" href="&lt;?php the_permalink(); ?&gt;" /&gt;
&lt;?php } ?&gt;
&lt;/head&gt;</code></pre>
<p>That&#8217;s it &#8211; you are done! <strong class="highlight">Save the file and upload it</strong> to your server.</p>
<p>This fix will add the canonical URL tag to all the posts and pages of your blog. If you want to see a blog that have implemented this fix, take a look at the source of this page.</p>
<h2>Related Links</h2>
<ul>
<li><a href="http://www.seobuzzbox.com/what-is-a-canonical-url/">Canonical URL</a></li>
<li><a href="http://mrjavo.com/what-is-a-canonical-url/">What Is A Canonical URL?</a></li>
<li><a href="http://ifacethoughts.net/2009/02/14/canonical-urls-to-avoid-duplicate-content/">Canonical URLs To Avoid Duplicate Content</a></li>
<li><a href="http://www.mattcutts.com/blog/canonical-link-tag/">Learn about the Canonical Link Element in 5 minutes</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2009/02/avoid-duplicate-content-use-canonical-url-in-wordpress-fix-plugin/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Hello Script for Java</title>
		<link>http://www.bin-co.com/blog/2008/06/hello-script-for-java/</link>
		<comments>http://www.bin-co.com/blog/2008/06/hello-script-for-java/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 18:24:01 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=111</guid>
		<description><![CDATA[
After the Hello Script for JavaScript, here is the Hello Script for Java. &#8216;Hello Script&#8217; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet when working with that language.
Warning: I am NOT an expert in Java &#8211; I am just [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/06/java-logo.png" alt="" title="Java Logo" width="125" height="217" class="size-full wp-image-112 intro" align="right" /></p>
<p class="intro">After the <a href="http://www.bin-co.com/blog/2008/05/hello-script-for-javascript/">Hello Script for JavaScript</a>, here is the Hello Script for Java. <strong class="highlight">&#8216;Hello Script&#8217; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet</strong> when working with that language.</p>
<p>Warning: I am NOT an expert in Java &#8211; I am just a beginner. There <strikeout>may</strikeout> will be errors(bad programming methods &#8211; not compiler errors) in the following script. If you notice any such issues, please point them out in the comments.</p>
<h2>Code</h2>
<p>If you want to run the code, save it to a file named &#8216;Hello.java&#8217; and compile in using the command &#8216;javac Hello.java&#8217;. After that you can run the code using the command &#8216;java Hello&#8217;.</p>
<pre><code class="java">
import java.io.*;
import java.util.regex.*;

public class Hello {
	public static void main(String[] Args) {
		// Printing(IO)
		System.out.println("Hello World");

		// Variables, concatenation
		String name = "Binny";
		int year = 2008;

		System.out.println("Hello, " + name + " - welcome to " + year);

		if(year &gt; 2008) {
			System.out.println("Welcome to the future - yes, we have flying cars!");
		} else if(year &lt; 2008) {
			System.out.println("The past - please don't change anything. Don't step on any butterflies. And for the sake of all that's good and holy, stay away from your parents!");
		} else {
			System.out.println("Anything wrong with your time machine? You have not gone anywhere, kiddo.");
		}

		// For loop
		int i=0;
		for(i=0; i&lt;3; i++) {
			System.out.println(i + ") Hi there!");
		}

		//Numerical Array, While
		String rules[] = {"Do no harm", "Obey", "Continue Living"};
		i = 0;
		while(i&lt;rules.length) {
			System.out.println("Rule " + (i+1) + " : " + rules[i]);
			i++;
		}

		// Associated array, foreach
		// Hmm - does Java have Associated arrays? ArrayList?

		String csv_string = "hello,world,how,are,you";
		String csv_values[] = csv_string.split(",");
		// No native Join method

		// Function, argument, return, call
		System.out.println(Hello.hello("Binny")); //The function definition is at the end of this file.	

		//Class stuff...
		Movie ncfom = new Movie("New Country for Old Men"); //It's a sequel!
		ncfom.printMovieDetails();

		// File IO
		// File reading, easy method...
		try {
			File read_file = new File ("/tmp/Hello.txt");
			FileReader in_stream = new FileReader(read_file); // Create a Character Input Stream
			BufferedReader in = new BufferedReader(in_stream);// Filter the Input Stream - buffers characters for efficiency
			try {
				System.out.println(in.readLine()); // read the first line
			} catch(IOException E) {
				System.out.println("No idea what went wrong. Sorry!");
			}
		} catch(FileNotFoundException E) {
			System.out.println("File not found. Sorry!");
		}

		try {
			// Writing to a file
			File out_file = new File("/tmp/HelloJava.txt");
			FileOutputStream out_stream = new FileOutputStream(out_file); // Create an Output Stream
			PrintWriter out = new PrintWriter(out_stream); // Filter bytes to ASCII
			out.println("Hello, from Java"); // Here we actually write to file
		} catch(java.io.FileNotFoundException E) {
			System.out.println("File not found. Sorry!");
		}

		System.out.println("\nLS command results...");
		// Command Executing
		try {
			// Execute a command
			String command = "ls";
			Process child = Runtime.getRuntime().exec (command);

			// Read from an input stream
			InputStream in = child.getInputStream();
			int c;
			while ((c = in.read()) != -1) {
				System.out.print((char)c);
			}
			in.close();
		} catch (IOException e) {
			System.out.println("Error");
		}

		System.out.print("\n");
		//Regular Expression
		String str = new String("Hello World");

		//Find a pattern
		Pattern hell_check = Pattern.compile("^Hell");
		Matcher matches = hell_check.matcher(str);
		if(matches.find()) System.out.println("Yup - its evil");

		//Replace
		System.out.println(str.replaceAll("l([^l])", "$1")); //Remove an 'l' from both words. Should print 'Helo Word'

	}

	//Function declaration.
	private static String hello(String name) {
		return "Hello, " + name;
	}

	// One for the OOP fanboys - Class, members, object and stuff.
	private static class Movie {
		public String name = "";
		public int rating = 0;

		public Movie(String name) {
			this.name = name;
			this.rateMovie();
		}

		public void rateMovie() {
			this.rating = (this.name.length() % 10) + 1; //IMDBs rating algorithm. True story!
		}

		public void printMovieDetails() {
			System.out.println("Movie  : " + this.name);
			System.out.println("Rating : " + this.rating);
		}
	}
}
</code></pre>
<p>Next Hello Script &#8211; C</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/06/hello-script-for-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello Script For JavaScript</title>
		<link>http://www.bin-co.com/blog/2008/05/hello-script-for-javascript/</link>
		<comments>http://www.bin-co.com/blog/2008/05/hello-script-for-javascript/#comments</comments>
		<pubDate>Thu, 22 May 2008 18:26:14 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=108</guid>
		<description><![CDATA[
The next language to get the Hello Script treatment is JavaScript &#8211; my favorite language. Before we go any further, here is the definitions for Hello Script and JavaScript &#8211; just to make sure that we are on the same page&#8230;

Hello Script
&#8216;Hello Script&#8217; is a file that contains the most commonly used elements of a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/05/javascript_logo.jpg" alt="Javascript Rhino Logo" title="Javascript Logo" width="230" height="194" class="alignnone size-full wp-image-109 intro" align="right" /></p>
<p class="intro">The next language to get the <a href="http://www.bin-co.com/blog/2008/03/learning-a-new-programming-language-the-hello-world-method/">Hello Script</a> treatment is <a href="http://www.openjs.com/">JavaScript &#8211; my favorite language</a>. Before we go any further, here is the definitions for Hello Script and JavaScript &#8211; just to make sure that we are on the same page&#8230;</p>
<dl>
<dt>Hello Script</dt>
<dd><strong class="highlight">&#8216;Hello Script&#8217; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet</strong> when working with that language.</dd>
<dt><a href="http://localhost/Sites/openjs/openjs.com/about.php#about-js">JavaScript</a></dt>
<dd>JavaScript is a <strong class="highlight">client side scripting language</strong> that is used in browsers.</dd>
</dl>
<h2>Code</h2>
<p>Warning: Do not run this code &#8211; you will get a lot of alerts. If you have firebug extension, uncomment the first line &#8211; then you can run the code.</p>
<pre><code class="html">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Hello Script for JS&lt;/title&gt;
&lt;script type="text/javascript"&gt;
//alert=console.log;
alert("Hello World");

// Variables, concatination
var name = 'Binny';
var year = 2008;
alert("Hello, " + name + " - welcome to " + year );

//If,else conditions
if (year &gt; 2008) {
	alert("Welcome to the future - yes, we have flying cars!");
}
else if(year &lt; 2008) {
	alert("The past - please don't change anything. Don't step on any butterflies. And for the sake of all thats good and holy, stay away from your parents!");
}
else {
	alert("Anything wrong with your time machine? You have not gone anywhere, kiddo.");
}

// For loop
for(var i=0; i&lt;3; i++) {
	alert(i + ") Hi there!");
}

//Numerical Array, While
var rules = [
	'Do no harm',
	'Obey',
	'Continue Living'
];
var i = 0;
while(i&lt;rules.length) {
	alert("Rule " + (i+1) + " : " + rules[i]);
	i++;
}

// Associated array, foreach
var associated = {
	'hello'	:	'world',
	'foo'	:	'bar',
	'lorem'	:	'ipsum'
}
for(key in associated) {
	alert(key + " : " + associated[key]);
}

// Using Join and Split
csv_values = "hello,world,how,are,you".split(",");
alert(csv_values.join(":"));

// Function, argument, return, call
function hello(name) {
	return "Hello " + name;
}
hello_string = hello("Binny");
alert(hello_string);

// One for the OOP fanboys - Class, members, object and stuff.
function Movie(name) { //Constuctor
	this.name = name;
}
Movie.prototype.rateMovie = function() {
	this.rating = (this.name.length % 10) + 1; //IMDBs rating algorithm. True story!
}

Movie.prototype.printMovieDetails = function() {
	alert("Movie : " + this.name + "\nRating : " + this.rating);
}

//Create the object
ncfom = new Movie("New Country for Old Men"); //It's a sequel!
ncfom.printMovieDetails();

// Regular Expressions
string = "Hello World";
if(string.match(/^Hell/)) alert("Yup - its evil\n");
alert(string.replace(/l([^l])/g, "$1")); //Remove an 'l' from both words. Should alert('Helo Word'

/**
 * Specialized code
 */
window.onload = function() {
	var ele = document.getElementById("div-element");
	alert(ele);
	ele.innerHTML = "Hello World";
	ele.onclick = function() {
		alert("You Clicked?");
	}

	document.getElementById("text").value = "Goodbye World";
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id="div-element"&gt;&lt;/div&gt;

&lt;input type="text" value="3" id="text" /&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/05/hello-script-for-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hello Script for Ruby</title>
		<link>http://www.bin-co.com/blog/2008/05/hello-script-for-ruby/</link>
		<comments>http://www.bin-co.com/blog/2008/05/hello-script-for-ruby/#comments</comments>
		<pubDate>Thu, 01 May 2008 18:05:39 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=104</guid>
		<description><![CDATA[
Hello Script is a file that contains the most commonly used elements of a programming language so that it can be used as a cheatsheet when working with that language. This Hello Script for Ruby is the sixth post in this series.
I have some experience with Ruby. I will not call myself an expert &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.bin-co.com/blog/wp-content/uploads/2008/05/ruby_logo.gif'><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/05/ruby_logo.gif" alt="" title="Ruby Logo" width="105" height="109" align="right" class="intro size-full wp-image-105" /></a></p>
<p class="intro"><a href="http://www.bin-co.com/blog/2008/03/learning-a-new-programming-language-the-hello-world-method/">Hello Script</a> is a <strong class="highlight">file that contains the most commonly used elements of a programming language so that it can be used as a cheatsheet</strong> when working with that language. This Hello Script for Ruby is the sixth post in this series.</p>
<p>I have some experience with Ruby. I will not call myself an expert &#8211; but I am comfortable with Ruby. <a href="http://binnyva.blogspot.com/2005/09/learning-ruby.html">I like ruby.</a> I even have written a few <a href="http://www.bin-co.com/ruby/tk/locater/">applications</a> in it.</p>
<h2>Hello Code</h2>
<pre><code class="ruby">
#!/usr/bin/ruby

print "Hello World\n"

name = "Binny"
year = 2008
print "Hello, " + name + " - welcome to " + year.to_s + "\n"

if (year &gt; 2008) then
	print "Welcome to the future - yes, we have flying cars!"
elsif (year &lt; 2008) then
	print "The past - please don't change anything. Don't step on any butterflies. And for the sake of all that's good and holy, stay away from your parents!"
else
	print "Anything wrong with your time machine? You have not gone anywhere, kiddo."
end
print "\n\n"

# For loop like structure
0.upto(3) { |i|
	print i.to_s + ") Hi there!\n"
}
print "\n"

# Numerical array
rules = ['Do no harm', 'Obey', 'Continue Living']
i = 0
while i&lt;rules.length do
	print "Rule " + (i+1).to_s + ": " + rules[i] + "\n"
	i = i+1
end
print "\n"

# Associated arrays
associated = {
	'hello'	=&gt;	'world',
	'foo'	=&gt;	'bar',
	'lorem'	=&gt;	'ipsum'
}
associated.each { |key,value|
	print key + " : " + value + "\n"
}
print "\n"

# Using Join and Split
csv_values = "hello,world,how,are,you\n".split(",")
print csv_values.join(":")

# Function, argument, return, call
def hello(name)
	return "Hello " + name
end
hello_string = hello("Binny")
print "Function call returned '" + hello_string + "'\n\n"

# One for the OOP fanboys - Class, members, object and stuff.
class Movie
	public
	@name = ''
	@rating = 0

	def initialize(name)
		@name = name
		self.rateMovie()
	end

	def rateMovie()
		@rating = (@name.length % 10) + 1 #IMDBs rating algorithm. True story!
	end

	def printMovieDetails()
		print "Movie : " + @name + "\n"
		print "Rating : " + '*' * @rating + "(" + @rating.to_s + ")\n\n"
	end
end
# Create the object
ncfom = Movie.new("New Country for Old Men") #It's a sequel!
ncfom.printMovieDetails()

# File IO
# File reading, easy method...
file_in = File.new('Hello.rb', 'r')
contents = file_in.read
file_in.close
print "Hello has " + contents.length.to_s + " chars\n"

# Writing to a file
file_out = File.new('/tmp/hello.txt', 'w')
file_out.print "Hello World from Ruby."
file_out.close

# Command Executing
print `ls` #Execute the command 'ls' and print its output
print "\n"

# Regular Expressions
string = "Hello World"
print "Yup - its evil\n" if(/^Hell/.match(string))
print string.gsub(/l([^l])/, '\1') #Remove an 'l' from both words. Should print 'Helo Word' - The second arg must be in single quotes

print "\n"

# Some special/only-in-ruby stuff...
# Using a library
require "fileutils"

#Using yield/code blocks...
def doXTimes(i)
	0.upto(i) {|count|
		yield count+1
	}
end
doXTimes(5) {|count|
	print count.to_s + "th Time\n"
}

</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/05/hello-script-for-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python Hello Script</title>
		<link>http://www.bin-co.com/blog/2008/03/python-hello-script/</link>
		<comments>http://www.bin-co.com/blog/2008/03/python-hello-script/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 18:01:44 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/2008/03/python-hello-script/</guid>
		<description><![CDATA[
As promised in the last post(Hello Script for PHP), this is my Hello Script for Python. &#8216;Hello Script&#8216; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet when working with that language.
A word of caution here &#8211; the blocks in [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.bin-co.com/blog/2008/03/python-hello-script/python-logo/' rel='attachment wp-att-97' title='Python Logo'><img src='http://www.bin-co.com/blog/wp-content/uploads/2008/03/python-logo.gif' alt='Python Logo' class="intro" align="right" /></a></p>
<p class="intro">As promised in the last post(<a href="http://www.bin-co.com/blog/2008/03/hello-script-for-php/">Hello Script for PHP</a>), this is my Hello Script for <a href="http://www.python.org/">Python</a>. <strong class="highlight">&#8216;<a href="http://www.bin-co.com/blog/2008/03/learning-a-new-programming-language-the-hello-world-method/">Hello Script</a>&#8216; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet</strong> when working with that language.</p>
<p>A word of caution here &#8211; the blocks in Python is created using whitespace &#8211; so the indentation is important. So when you see an indentation in the below code, think of it as one tab(instead of four spaces or something).</p>
<p>I want to insert a disclaimer here &#8211; I am not that good with python. We <a href="http://www.bin-co.com/blog/2007/10/tk-verses-gtkand-python-verses-tcl/" title="	Tk Verses Gtk(And Python verses Tcl)">never really clicked</a>. I have done very limited <a href="http://www.bin-co.com/python/programs/frees/" title="Frees - PyGTK Tool to show HardDisk Space Usage">work in Python</a>. So if you notice any problems with the below script, let me know and I&#8217;ll correct it.</p>
<pre><code class="python">
#!/usr/bin/python

print "Hello World\n"

name = "Binny"
year = 2008
print "Hello, " + name + " - welcome to " + str(year) + "\n"

# If,else conditions
if (year &gt; 2008):
	print "Welcome to the future - yes, we have flying cars!\n"
elif(year &lt; 2008):
	print "The past - please don't change anything. Don't step on any butterflies. And for the sake of all thats good and holy, stay away from your parents!\n"
else:
	print "Anything wrong with your time machine? You have not gone anywhere, kiddo.\n"

# For loop
for i in range(0,3):
	print str(i) + ") Hi there!"

print ""

#Numerical Array, While
rules = ['Do no harm','Obey','Continue Living']
i = 0
while(i&lt;len(rules)):
	print "Rule " + str(i+1) + " : " + rules[i]
	i = i + 1
print ""

# Associated array, foreach
associated = {
	'hello'	:	'world',
	'foo'	:	'bar',
	'lorem'	:	'ipsum'
}
for key in associated:
	print key + " : " + associated[key]
print ""

import string
csv_values = string.split("hello,world,how,are,you\n", ",")
print string.join(csv_values, ":")

# Function, argument, return, call
def hello(name):
	return "Hello " + name + "\n"

hello_string = hello("Binny")
print hello_string

# One for the OOP fanboys - Class, members, object and stuff.
class Movie:
	name = ''
	rating = 0

	def __init__(self, name):
		self.name = name
		self.rateMovie()

	def rateMovie(self):
		self.rating = (len(self.name) % 10) + 1 #IMDBs rating algorithm. True story!

	def printMovieDetails(self):
		print "Movie : ",  self.name
		print "Rating : ", '*' * self.rating , "(", self.rating ,")\n"

#Create the object
ncfom = Movie("New Country for Old Men") #It's a sequel!
ncfom.printMovieDetails()

# File IO
# File reading, easy method...
file_in  = open('Hello.py', 'r')
contents = file_in.read()
print "Current file has " + str(len(contents)) + " chars\n"
file_in.close()
# Writing to a file
file_out = open('/tmp/hello.txt', 'w')
file_out.write("Hello World")
file_out.close()

# Command Executing
import commands
import os
print "Result of 'ls' command is " + commands.getoutput('ls') #Execute the command 'ls' and print its output
print

# Regular Expressions
import re
hell_check = re.compile("^Hell")
string = "Hello World"
if hell_check.match(string): print "Yup - its evil (Compiled)"
if re.match('^Hell', string): print "Yup - its evil (Not Compiled)"
print re.sub(r'l([^l])', r'\1', string)

</code></pre>
<p>As I said last time, save this to a file and keep it around for future reference.</p>
<p>Next hello script &#8211; Perl, Ruby or Tcl/Tk? Which one do you want &#8211; leave it in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/03/python-hello-script/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Web Installer: The Code</title>
		<link>http://www.bin-co.com/blog/2007/07/web-installer-the-code/</link>
		<comments>http://www.bin-co.com/blog/2007/07/web-installer-the-code/#comments</comments>
		<pubDate>Tue, 10 Jul 2007 20:50:21 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[installer]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/2007/07/web-installer-the-code/</guid>
		<description><![CDATA[The last two posts on web installer did not include any code. I wanted to dump all code into one post &#8211; this is it. Please note that this is what I did &#8211; you don&#8217;t have to copy my code as it is. Just look at the code and modify it according to your [...]]]></description>
			<content:encoded><![CDATA[<p class="intro">The <a href="http://www.bin-co.com/blog/2007/07/web-application-installer/">last two posts</a> on <a href="http://www.bin-co.com/blog/2007/07/3-simple-steps-to-create-a-web-installer/">web installer</a> did not include any code. I wanted to dump all code into one post &#8211; this is it. Please note that this is what I did &#8211; you don&#8217;t have to copy my code as it is. Just look at the code and modify it according to your needs.</p>
<h2>Getting Database Details</h2>
<h3>The Form/Frontend</h3>
<pre><code class="html">&lt;form action="" method="post"&gt;
&lt;h1&gt;Installation : Step 1&lt;/h1&gt;
Please provide the database connection details...
&lt;fieldset&gt;
&lt;legend&gt;Database Details&lt;/legend&gt;

&lt;label for='host'&gt;Database Host&lt;/label&gt;&lt;input type='text' name='host' value='localhost' /&gt;&lt;br /&gt;
&lt;label for='db_user'&gt;Database User&lt;/label&gt;&lt;input type='text' name='db_user' value='root' /&gt;&lt;br /&gt;
&lt;label for='password'&gt;Database Password&lt;/label&gt;&lt;input type='text' name='password' /&gt;&lt;br /&gt;
&lt;label for='database'&gt;Database&lt;/label&gt;&lt;input type='text' name='database' value='nexty' /&gt;&lt;br /&gt;
&lt;/fieldset&gt;

&lt;input type="hidden" name="step" value="2" /&gt;&lt;br /&gt;
&lt;input type="submit" name="action" value="Continue &gt;&gt;" /&gt;&lt;br /&gt;
&lt;/form&gt;</code></pre>
<h3>Backend</h3>
<p>Make sure that the given database details are correct.</p>
<pre><code class="php">// The First step is Setting up Database connection
//					   (the '2' is NOT a typo)
if($_REQUEST['step'] == 2) {
	//Save the data to the Session
	if(isset($_REQUEST['host'])) $_SESSION['host'] = $_REQUEST['host'];
	if(isset($_REQUEST['db_user'])) $_SESSION['db_user'] = $_REQUEST['db_user'];
	if(isset($_REQUEST['password'])) $_SESSION['password'] = $_REQUEST['password'];
	if(isset($_REQUEST['database'])) $_SESSION['database'] = $_REQUEST['database'];
	if(isset($_REQUEST['url'])) $_SESSION['url'] = $_REQUEST['url'];

	if(mysql_connect($_SESSION['host'],$_SESSION['db_user'],$_SESSION['password'])) { //Try to connect to the DB.
		$QUERY['success'][] = 'Connection to Database server successful';

		if(mysql_select_db($_SESSION['database'])) {//Select the provided database.
			$QUERY['success'][] = "Database '$_SESSION[database]' selected";

		} else {
			$QUERY['error'][] = 'The given database('.$_SESSION['database'].') does not exist. Please povide a valid database.';
			$_REQUEST['step'] = 1;
		}
	} else {
		$QUERY['error'][] = 'Unable to connect to the database. Make sure that the entered details are correct';
		$_REQUEST['step'] = 1;
	}
}</code></pre>
<p>Notice the over use of $_SESSION? That will come in use if I decide to add a Back button that enables the users to modify the data entered previously.</p>
<h2>Database Creation</h2>
<pre><code class="php">//Create the database only if it does not exist
//See if the database exists
$tables_sql = mysql_query("SHOW TABLES") or die(mysql_error());
$necessary_tables = array('Context','Project','Reminder','Setting','Task','TaskContext','User');
while($table = mysql_fetch_row($tables_sql)) {
	$necessary_tables = array_diff($necessary_tables,array($table[0])); //Remove the table from the array if it exists
}

//If there are no tables in the array that means that the all the necessary tables are present in the Database
//If some tables are missing, that means we have to create those tables...
if($necessary_tables) {
	$quries = &lt;&lt;&lt;END
-- Insert all the SQL to create the necessary tables here...
END;

	//Execute all the queries
	$all_quires = explode(";",$quries);
	$query_count = 0;
	foreach($all_quires as $query) {
		$query = trim($query);
		if($query) {
			@mysql_query($query);
			$query_count++;
		}
	}
	$QUERY['success'][] = "Database Populated.";
} else {
	$QUERY['error'][] = "Tables already in Database - I did not overwrite it. If you want to remove the old data, please delete the tables and run the installer script agian.";
}
</code></pre>
<h2>Saving the Database connection details</h2>
<pre><code class="php">
//I don't know how to escape the $ charector in heredocs - so I did this...
$config = '$config';//Heh, Heh <img src='http://www.bin-co.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
$system_installed = '$system_installed';
$configuration = &lt;&lt;&lt;END
&lt;?php
//Configuration file for Nexty
$system_installed = true;
$config = array(
	'db_host'		=&gt;	'$_SESSION[host]',
	'db_user'		=&gt;	'$_SESSION[db_user]',
	'db_password'	=&gt;	'$_SESSION[password]',
	'db_database'	=&gt;	'$_SESSION[database]',
	'url'			=&gt;	'$_SESSION[url]',
	'absolute_path'	=&gt;	'$abs'
);

END;
if(is_writable('../configuration.php')) {
        // ...Write the $config text into the configuration.php file...

	$QUERY['success'][] = 'Saved the configuration file. &lt;a href="'.$_REQUEST['url'].'"&gt;Go to Nexty&lt;/a&gt;';
} else {
	$QUERY['error'][] = 'Configuration file (configuration.php) is not writable. Please copy the configuration code and enter it into the "configuration.php" file. Then press continue.';
}
</code></pre>
<p>See the <a href="https://nexty.svn.sourceforge.net/svnroot/nexty/install/">install folder for Nexty</a> in the Subversion server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2007/07/web-installer-the-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iFrame &#8211; My PHP Framework</title>
		<link>http://www.bin-co.com/blog/2007/05/iframe-my-php-framework/</link>
		<comments>http://www.bin-co.com/blog/2007/05/iframe-my-php-framework/#comments</comments>
		<pubDate>Fri, 18 May 2007 08:35:50 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/2007/05/iframe-my-php-framework/</guid>
		<description><![CDATA[
I have created a number of Web Applications &#8211; Nexty and Jus5 are just a few examples. I used a common code base when creating these sites &#8211; but I did not consider it a full fledged framework. However, now the code base has evolved enough to be called a framework. So, I called it [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.bin-co.com/blog/2007/05/iframe-my-php-framework/iframe-logo/' rel='attachment wp-att-20' title='iFrame Logo'><img class="intro" align="right" src='http://www.bin-co.com/blog/wp-content/uploads/2007/05/iframe.png' alt='iFrame Logo' /></a></p>
<p class="intro">I have created a number of Web Applications &#8211; <a href="http://www.bin-co.com/blog/2007/04/nexty-10-released/">Nexty</a> and <a href="http://www.bin-co.com/blog/2007/05/jus5-light-weight-cms/">Jus5</a> are just a few examples. I used a common code base when creating these sites &#8211; but I did not consider it a full fledged framework. However, now the code base has evolved enough to be called a framework. So, I called it a framework &#8211; <strong class="highlight">the <a href="http://www.bin-co.com/php/scripts/iframe/">iFrame</a> framework</strong>. I know, lame joke &#8211; geek humor <img src='http://www.bin-co.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Before moving further, a word of warning &#8211; <strong class="highlight">Do not use this framework</strong> for your project. There are plenty of great PHP frameworks out there &#8211; use one of those. For example&#8230;</p>
<ul>
<li><a href="http://www.cakephp.org/">CakePHP</a></li>
<li><a href="http://codeigniter.com/">CodeIgniter</a></li>
<li><a href="http://www.symfony-project.com/">Symfony</a></li>
<li><a href="http://framework.zend.com/">ZendPHP</a></li>
</ul>
<p><strong class="highlight">These are professional, enterprise level frameworks</strong>. They are secure, well designed and documented. Use any of those when creating your site &#8211; do not use mine. There are no legal restrictions &#8211; the code for iFrame is under BSD License. These are the reasons why you should not use my framework&#8230;</p>
<h2>Disadvantages</h2>
<dl>
<dt>Documentation</dt>
<dd>Many Users of frameworks complain that there is not enough documentation. My framework has no such problems &#8211; it has <strong>no documentation whatsoever </strong>. They only way to find what a function is supposed to do, is to read the code.</dd>
<dt>Bugs</dt>
<dd>This system is developed, used and tested by just one person &#8211; me. So, there are many yet undiscovered bugs.</dd>
<dt>No <abbr title="Object Relation Mapping">ORM</abbr></dt>
<dd>Those who are in love with ORM will be disappointed when using iFrame &#8211; I have not implemented ORM.</dd>
<dt>Currently, only MySQL is supported</dt>
<dd>There is a database abstraction layer &#8211; but as of yet, only MySQL is supported.</dd>
<dt>And a lot more other reasons</dt>
<dd>The reasons why you should not use this framework is too numerous to list here.</dd>
</dl>
<h2>Advantages</h2>
<p>Despite all the given disadvantages, I will use this framework &#8211; these are the reasons for that&#8230;</p>
<dl>
<dt>Lightweight</dt>
<dd>This is the most lightweight framework that I have ever seen.</dd>
<dt>Helpful functions that reduce coding time</dt>
<dd>
<p>All my PHP functions are available in the framework &#8211; If you know how to use them, these functions save a lot of time. For example&#8230;</p>
<ul>
<li><a href="http://www.bin-co.com/php/scripts/upload_function/">upload()</a></li>
<li><a href="http://www.bin-co.com/php/scripts/dump/">dump()</a></li>
<li><a href="http://www.bin-co.com/php/scripts/xml2array/">xml2array()</a></li>
<li><a href="http://www.bin-co.com/php/scripts/array2json/">array2json()</a></li>
<li>And more&#8230;</li>
</ul>
</dd>
<dt>Encourages clean code</dt>
<dd>iFrame is an MVC framework(although the &#8216;Model&#8217; is a bit limited for now). By default, each controller has its own folder and each action has its own file. This will greatly increase the number of files &#8211; but will reduce the number of lines in each file. Some might find it hard to use &#8211; but I find it more manageable this way.</dd>
<dt>A lot of cool features</dt>
<dd>I will talk about these &#8216;cool features&#8217; in the next post.</dd>
</dl>
<h2>Code</h2>
<p>What good is a framework without the code&#8230;</p>
<p><a href="http://www.bin-co.com/php/scripts/iframe/code/">View the iFrame code online</a></p>
<p>You can get the code from my subversion server &#8211; use this command&#8230;</p>
<p><code>svn checkout http://www.bin-co.com/php/scripts/iframe/code/ iframe</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2007/05/iframe-my-php-framework/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
