<?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>Scattered Thoughts &#187; code</title>
	<atom:link href="http://www.kunaal84.com/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kunaal84.com/blog</link>
	<description>where you go when not looking for the answer to life, the universe and everything</description>
	<lastBuildDate>Tue, 15 Dec 2009 14:04:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Cheat Sheet Links</title>
		<link>http://www.kunaal84.com/blog/2009/12/16/cheat-sheet-links/</link>
		<comments>http://www.kunaal84.com/blog/2009/12/16/cheat-sheet-links/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 14:04:04 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[aside]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/?p=60</guid>
		<description><![CDATA[Useful resources for programmers, these sites have some interesting cheat sheets Added Bytes &#8211; Cheat Sheet Bookmark Bliss &#8211; The Developer Cheat Sheet]]></description>
			<content:encoded><![CDATA[<p>Useful resources for programmers, these sites have some interesting cheat sheets<br />
<br/><br />
Added Bytes &#8211; <a href="http://www.addedbytes.com/cheat-sheets/">Cheat Sheet</a><br />
<br/><br />
Bookmark Bliss &#8211; <a href="http://www.bookmarkbliss.com/programming/the-developer-cheat-sheet-compilation/">The Developer Cheat Sheet</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2009/12/16/cheat-sheet-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Principles of the PHP Masters</title>
		<link>http://www.kunaal84.com/blog/2008/09/10/10-principles-of-the-php-masters/</link>
		<comments>http://www.kunaal84.com/blog/2008/09/10/10-principles-of-the-php-masters/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 03:32:35 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[aside]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/?p=71</guid>
		<description><![CDATA[Interesting read: 10 Principles of the PHP Masters.]]></description>
			<content:encoded><![CDATA[<p>Interesting read: <a href="http://nettuts.com/articles/10-principles-of-the-php-masters/">10 Principles of the PHP Masters</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2008/09/10/10-principles-of-the-php-masters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Save login info in a cookie using CURL (PHP)</title>
		<link>http://www.kunaal84.com/blog/2008/05/30/save-login-info-in-a-cookie-using-curl-php/</link>
		<comments>http://www.kunaal84.com/blog/2008/05/30/save-login-info-in-a-cookie-using-curl-php/#comments</comments>
		<pubDate>Thu, 29 May 2008 14:13:13 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/?p=49</guid>
		<description><![CDATA[At work I was using a simple script that connected to a secure API, logged in and saved the result. This seems simple enough and is fast enough when calling it a few times, however one of the tasks I was then assigned was actually running this script for different values over 60,000 times! Each [...]]]></description>
			<content:encoded><![CDATA[<p>At work I was using a simple script that connected to a secure API, logged in and saved the result. This seems simple enough and is fast enough when calling it a few times, however one of the tasks I was then assigned was actually running this script for different values over 60,000 times! Each call (including the logging in) would take a little over a second, so calling it 60,000 times would take a while.</p>
<p>It was then decided to try and improve this by making the script only login once and save the session, so that subsequent calls would not have to login each time. This is one of the solutions we came up with ( because finding this online was not very easy <img src='http://www.kunaal84.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p>The first step is the login, the agent variable is being set to trick the API into thinking that the request has come from a browser.</p>
<pre name="code" class="php">
//Set the cookie file name
$cookiefile = tempnam("/tmp", "cookies");
$agent     = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
//Set the user name and password values
$USER      = 'user';
$PASS      = 'pass';
//The API url, to do the login
$url = "https://www.example.com/";

//Initialise CURL
$ch = curl_init();
//Set all the various options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 0); // set POST method
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Set the cookie file you want to use
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_USERPWD, $USER.":".$PASS);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

//execute the CURL
$mRes = curl_exec($ch);
</pre>
<p>Remember not to close curl at this point. Now we look at the loop that will carry out the 60,000 calls to the API</p>
<pre name="code" class="php">
while ($row = [get row value for the 60,000 entries])
{
    $url       = "https://www.example.com/API?check=$row";
    //We do not have to initialise CURL again
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, 0); // set POST method
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    //Remember to use the same cookiefile as above
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    //execute the CURL call
    $mRes = curl_exec($ch);
    //DEAL WITH THE RESULT FROM THE CURL CALL
}
//only close CURL once the work is finished.
curl_close($ch);
</pre>
<p>If you&#8217;d like to know more the various CURL options I have used above like &#8216;CURLOPT_SSL_VERIFYHOST&#8217; etc, have a read through the <a href="http://au.php.net/manual/en/function.curl-setopt.php">curl_setopt page</a> on php.net. You can also read more about <a href="http://au.php.net/curl">CURL</a> there as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2008/05/30/save-login-info-in-a-cookie-using-curl-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>LOLCODE!</title>
		<link>http://www.kunaal84.com/blog/2008/05/21/lolcode/</link>
		<comments>http://www.kunaal84.com/blog/2008/05/21/lolcode/#comments</comments>
		<pubDate>Tue, 20 May 2008 14:43:28 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[funny]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/?p=48</guid>
		<description><![CDATA[I&#8217;m sure most people by now know about the whole Lolcat phenomena, however, for those still living under a rock: A Lolcat, or LOLCAT, is an image combining a photograph, most frequently a cat, with a humorous and idiosyncratic caption in (often) broken English—a dialect which is known as &#8220;Kitty Pidgin&#8221;,[1] &#8220;lolspeak&#8221;, or Lolcat. Lolcat [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure most people by now know about the whole <a href="http://en.wikipedia.org/wiki/Lolcat">Lolcat</a> phenomena, however, for those still living under a rock:</p>
<blockquote><p>A Lolcat, or LOLCAT, is an image combining a photograph, most frequently a cat, with a humorous and idiosyncratic caption in (often) broken English—a dialect which is known as &#8220;Kitty Pidgin&#8221;,[1] &#8220;lolspeak&#8221;, or Lolcat.</p></blockquote>
<p>Lolcat or Kitty Pidgin has been around for a while now, and has been made popular by sites like <a href="http://icanhascheezburger.com/">I Can Has Cheezburger?</a>&#8230;however in spite of its popularity, to find a programming language based on Kitty Pidgin still came as a real surprise to me.</p>
<p><a href="http://lolcode.com/">Lolcode</a>, created on 25 May 2007, is a programming language created by <a href="http://lindsay.at/blog/">Adam Lindsay</a> based on lolcat.<br />
The language is still fairly young and at the moment has the following subset of keywords</p>
<ul>
<li><a href="http://lolcode.com/keywords/btw">btw</a></li>
<li><a href="http://lolcode.com/keywords/byes">byes</a></li>
<li><a href="http://lolcode.com/keywords/can-has">can-has</a></li>
<li><a href="http://lolcode.com/keywords/diaf">diaf</a></li>
<li><a href="http://lolcode.com/keywords/gimmeh">gimmeh</a></li>
<li><a href="http://lolcode.com/keywords/gtfo">gtfo</a></li>
<li><a href="http://lolcode.com/keywords/hai">hai</a></li>
<li><a href="http://lolcode.com/keywords/i-has-a">i-has-a</a></li>
<li><a href="http://lolcode.com/keywords/im-in-yr">im-in-yr</a></li>
<li><a href="http://lolcode.com/keywords/im-outta-yr">im-outta-yr</a></li>
<li><a href="http://lolcode.com/keywords/in-mah">in-mah</a></li>
<li><a href="http://lolcode.com/keywords/iz">iz</a></li>
<li><a href="http://lolcode.com/keywords/kthx">kthx</a></li>
<li><a href="http://lolcode.com/keywords/kthxbye">kthxbye</a></li>
<li><a href="http://lolcode.com/keywords/lol-r">lol-r</a></li>
<li><a href="http://lolcode.com/keywords/operators">operators</a></li>
<li><a href="http://lolcode.com/keywords/visible">visible</a></li>
</ul>
<p>Writing a program in lolcode seems surprisingly easy for people who understand lolcat, the main thing to remember is that <em>HAI</em> is used at the start of a program and <em>KTHXBYE</em> ends the program.<br />
The default hello world program is as simple as </p>
<pre>
HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
</pre>
<p>The language also contains error handling using <em>AWSUM THX</em> on success and <em>O NOES</em> which is the exception block!<br />
The reason you probably haven&#8217;t yet seen a whole slew of lolcode applications yet, is that the language is still being defined with respect to operator priorities and correct syntax. Some compilers, however, already exist, like <a href="http://lolcode.com/implementations/sjlol">this one</a> in python.</p>
<p>For the time being, this is another addition to my &#8216;must try at least once&#8217; list&#8230;<strong>KTHXBYE!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2008/05/21/lolcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Rid Of The Default Gravatar</title>
		<link>http://www.kunaal84.com/blog/2008/04/23/getting-rid-of-the-default-gravatar/</link>
		<comments>http://www.kunaal84.com/blog/2008/04/23/getting-rid-of-the-default-gravatar/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 15:06:09 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/?p=41</guid>
		<description><![CDATA[I&#8217;ve been playing around with WordPress 2.5 and a new theme on the blog over the last few days, and must say that I am quite impressed with all the new bells and whistles. One of the newer inbuilt features, Gravatar has been especially interesting. The Gravatar site has this to say when defining a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with WordPress 2.5 and a new theme on the blog over the last few days, and must say that I am quite impressed with all the new bells and whistles.<br />
One of the newer inbuilt features, <a href="http://en.gravatar.com/">Gravatar</a> has been especially interesting. The Gravatar site has this to say when defining a gravatar</p>
<blockquote><p>A gravatar, or globally recognized avatar, is quite simply an avatar image that follows you from weblog to weblog appearing beside your name when you comment on gravatar enabled sites. Avatars help identify your posts on web forums, so why not on weblogs?</p></blockquote>
<p>Now Gravatars have actually been around for a while, but they have been gaining in popularity expecially since <a href="http://blog.gravatar.com/2007/10/18/automattic-gravatar/">Automattic recently acquired gravatar</a> and WordPress 2.5 released with inbuilt support.<br />
Adding Gravatars to your wordpress theme is fairly easy, all it requires is calling the new <a href="http://codex.wordpress.org/Using_Gravatars">get_avatar()</a> function in your comment template php file</p>
<pre name="code" class="php">
&lt;?php
   echo get_avatar( $comment, $size = '96', $default = '&lt;path_to_url&gt;' );
 ?&gt;
</pre>
<p>where <em>$comment</em> is the authors id and is a required field, <em>$size</em> controls the size of the avatar and <em>$default</em> is the path to your default image.<br />
Now, whenever someone makes a comment on your site, if they have a predefined gravatar, it will show up otherwise your default image will appear.<br />
Initially my default avatar looked something like this<br />
<img src="http://www.kunaal84.com/blog_images/default_gravatar.jpg" alt="default gravatar" /><br />
However while reading the gravatar blog recently, I came across <a href="http://blog.gravatar.com/2008/04/22/identicons-monsterids-and-wavatars-oh-my/">this article</a>, which talks about gravatar&#8217;s new support for <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon/">Identicons</a>, <a href="http://scott.sherrillmix.com/blog/blogger/wp_monsterid/">MonsterID</a>, and <a href="http://www.shamusyoung.com/twentysidedtale/?p=1462">Wavatars</a>.<br />
In a nut shell what these projects try to do is uniquely identify users, using information like IP addresses so that they can generate random images which are then unique to that user, so that whenever they leave a comment on your blog, instead of being presented with the default image they are also treated as part of the &#8216;family&#8217; <img src='http://www.kunaal84.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This led me to play with the <em>$default</em> value in the get_avatars() function and I came across an undocumented feature, if I change the value of $default, my gravatar changes as well!<br />
If you try any of the following,</p>
<pre name="code" class="php">
echo get_avatar( $comment, $size = '96', $default = 'wavatar' );
OR
echo get_avatar( $comment, $size = '96', $default = 'monsterid' );
OR
echo get_avatar( $comment, $size = '96', $default = 'identicon' );
</pre>
<p>you can automatically see the changes to the default gravatars, which is pretty cool (at least in my opinion)<br />
So now I can get unique avatars for each commenter (who are not already using gravatar)<br />
<img src="http://www.gravatar.com/avatar/3ccc5b64bf5f0cdbda7f72f22cf04be2?s=50&#038;d=wavatar&#038;r=G" alt="" /><br />
<img src="http://www.gravatar.com/avatar/3ccc5b64bf5f0cdbda7f7dsf2cf04be2?s=50&#038;d=wavatar&#038;r=G" alt="" /><br />
<img src="http://www.gravatar.com/avatar/ad516503a11cd5ca435ac876523536?s=50&#038;d=wavatar&#038;r=G" alt="" /><br />
<strong>NOTE:</strong> <strike>At the moment for some reason only wavatar seems to be working, the others are throwing &#8217;504 Gateway Time-out&#8217; errors</strike> The others seem to be back up now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2008/04/23/getting-rid-of-the-default-gravatar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with MySQL&#8217;s &#8216;table is full&#8217; error</title>
		<link>http://www.kunaal84.com/blog/2008/03/27/overcoming-mysql-table-is-full-error/</link>
		<comments>http://www.kunaal84.com/blog/2008/03/27/overcoming-mysql-table-is-full-error/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 13:55:02 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/2008/03/27/overcoming-mysql-table-is-full-error/</guid>
		<description><![CDATA[Chances are that if you are dealing with adding really large amounts of data into a MySQL table, you might encounter the infamous table is full error. According to the official MySQL reference manual, MySQL tables (MYISAM only) have size limits and these limits are determined by OS constraints. For Win32 w/ FAT/FAT32 Systems (and [...]]]></description>
			<content:encoded><![CDATA[<p>Chances are that if you are dealing with adding really large amounts of data into a MySQL table, you might encounter the infamous <em>table is full</em> error. According to the official <a href="http://dev.mysql.com/doc/refman/5.0/en/">MySQL reference manual</a>, MySQL tables (MYISAM only) have size limits and these limits are determined by OS constraints.<br />
For Win32 w/ FAT/FAT32 Systems (and other 32 Bit Systems) the limit is 2GB/4GB. It may sound like a lot, but trust me, it does not take long before you have used up the space and see that message on the screen.<br />
After looking for a solution, I came across <a href="http://jeremy.zawodny.com/blog/archives/000796.html">this site</a>. Thanks Jeremy!<br />
One of the fixes suggested is just a simple &#8216;ALTER TABLE&#8217; command.</p>
<pre>
<code>
ALTER TABLE &lt;TABLE_NAME&gt; max_rows = 200000000000 avg_row_length = 50;
</code>
</pre>
<p>(Just note, that there will still be a limit when this is done, but this definitely buys you a lot more time <img src='http://www.kunaal84.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )<br />
 Have a read through the blog post, there are some other useful tips, like making this change while creating the table if you know you will be dealing with large amounts of data&#8230;.or use InnoDB tables instead <img src='http://www.kunaal84.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2008/03/27/overcoming-mysql-table-is-full-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add a Print Stylesheet to your Blog</title>
		<link>http://www.kunaal84.com/blog/2007/11/06/add-a-print-stylesheet-to-your-blog/</link>
		<comments>http://www.kunaal84.com/blog/2007/11/06/add-a-print-stylesheet-to-your-blog/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 14:03:54 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/2007/11/06/add-a-print-stylesheet-to-your-blog/</guid>
		<description><![CDATA[The other day I went to print out one of my posts, and was quite surprised at how it turned out (Check the screenshot below). This would simply not do. There may not be a lot of people wanting to print any of my posts but I still would like the page to print properly. [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I went to print out one of my posts, and was quite surprised at how it turned out (Check the screenshot below). This would simply not do. There may not be a lot of people wanting to print any of my posts but I still would like the page to print properly. Back in the olden days of the wild wild web, the solution would have been to create a separate page meant for printing; but with the dawning of the age of the CSS, it is now as easy as attaching a separate stylesheet to my site which gets called when I want to print it.<br />
<a href="http://www.kunaal84.com/blog_images/print-preview-old.jpg" rel="lightbox" title="Kunaals Blog Print Preview"><img src="http://www.kunaal84.com/blog_images/print-preview-old-small.jpg" alt="Kunaals Blog Print Preview" /></a></p>
<p>Here is what I did to create my print stylesheet<br />
I started by creating a blank css file called &#8216;print.css&#8217; and uploaded it to my site, I then added the following line in the header file of my wordpress template</p>
<pre name="code" class="html">&lt;link rel="stylesheet" href="http://www.SITENAME.com/blog/PATH-TO-FILE/print.css" type="text/css" media="print" /&gt;</pre>
<p>I also changed the call to my default stylesheet from</p>
<pre name="code" class="html">&lt;link rel="stylesheet" href="http://www.SITENAME.com/blog/PATH-TO-FILE/style.css" type="text/css" /&gt;
to
&lt;link rel="stylesheet" href="http://www.SITENAME.com/blog/PATH-TO-FILE/style.css" type="text/css" media="screen" /&gt;
</pre>
<p>(i.e. I added media=&#8221;screen&#8221;, this removes the default stylesheet from the page when printing)</p>
<p>Thats the easy part now taken care of<br />
(A little tip, if you upload your print.css file to the same place your template&#8217;s default css file is, you will be able to edit it via your wordpress admin interface)</p>
<p>Once the file is in place, I looked at what had been printed and identified all the information that while useful online was not required on paper(marked in red in the image). For example, The entire menu, the social network links, the category posted to information, the sidebar and the page footer. I looked into the source code of the page and found the ids and classes that were wrapped around these site elements and entered them into the stylesheet with a &#8216;display:none;&#8217;<br />
This is what the stylesheet starts out with, I want to define the sizes of my logo, tagline, content, and h1&#8242;s etc</p>
<pre name="code" class="css">/*Make sure that the background will remain white*/
body {
   background: white;
   font-size: 12pt;
}
/*Remove the unwanted categories from displaying*/
#header-links, #sidebar, #nav-wrap, .sociable, #respond, #commentform, #footer-wrap, .post-footer {
   display: none;
}
/*Set the font size for the H1s on the page*/
h1 {
   font-size: 14pt;
}
/*Set the font size for the logo "Scattered Thoughts"*/
#logo-text {
   font-size: 20pt;
   text-decoration: none !important;
}
/*Set the font size for the tag line "where good ideas go to die"*/
h2#slogan {
   font-size: 10pt;
}
</pre>
<p>Now all this is pretty good and gives me a fairly plain page when I go to print, but there are still a few things I want to change.<br />
I want the post content to be shifted slightly to the right. My post content is located in a div with the class &#8216;entry&#8217;, so I add the following lines to my stylesheet</p>
<pre name="code" class="css">div.entry {
   margin-left: 5%;
   padding-top: 1em;
   border-top: 1px solid #999;
}</pre>
<p>This pretty much looks exactly like what I want to see when I print the page, except for one last important (to me) thing.<br />
When I add links in a post and I print the page out, those links get lost, because there is no way for me to see which page I was linking to on the piece of paper.<br />
Once again CSS comes to the rescue, using css <a href="http://www.w3schools.com/css/css_pseudo_elements.asp">pseudo-elements</a> I am able to add the physical link address onto the printed page, without actually making any changes to my template, or my posts!</p>
<pre name="code" class="css">a:link:after, a:visited:after {
   content: " (" attr(href) ") ";
}</pre>
<p>Now this will add the physical url in brackets right after the link on the page. This works great, but the links appear this way in the entire printout. Since I do not want all the links on my page appearing with their physical address, I change this CSS slightly to only work for the content within the &#8216;entry&#8217; class</p>
<pre name="code" class="css">.entry a:link:after, .entry a:visited:after {
   content: " (" attr(href) ") ";
}</pre>
<p>This is what the css sheet looks like after everything</p>
<pre name="code" class="css">/*Make sure that the background will remain white*/
body {
   background: white;
   font-size: 12pt;
}
/*Remove the unwanted categories from displaying*/
#header-links, #sidebar, #nav-wrap, .sociable, #respond, #commentform, #footer-wrap, .post-footer {
   display: none;
}
/*Set the font size for the H1s on the page*/
h1 {
   font-size: 14pt;
}
/*Set the font size for the logo "Scattered Thoughts"*/
#logo-text {
   font-size: 20pt;
   text-decoration: none !important;
}
/*Set the font size for the slogan "where good ideas go to die"*/
h2#slogan {
   font-size: 10pt;
}
/*Shift the content a little to the right*/
div.entry {
   margin-left: 5%;
   padding-top: 1em;
   border-top: 1px solid #999;
}
/*To display code on the page*/
code{
  display: block;
  padding: 20px;
  text-align: left;
  overflow: auto;
  font-size: 10pt;
}
/*To add the physical link on the page*/
.entry a:link:after, .entry a:visited:after {
   content: " (" attr(href) ") ";
}</pre>
<p>There are still further useful additions one can make to this code, like expanding abbreviations, writing the physical link as a footnote instead of in brackets etc. I am still working on a couple more changes that I intend to post in the near future. Let me know how these changes go on your site.<br />
Here is what the page looks like now after the addition of the stylesheet<br />
<a href="http://www.kunaal84.com/blog_images/print-preview-new.jpg" rel="lightbox" title="Kunaals Blog Print Preview After"><img src="http://www.kunaal84.com/blog_images/print-preview-new-small.jpg" alt="Kunaals Blog Print Preview After" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2007/11/06/add-a-print-stylesheet-to-your-blog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hide your Email Address Using Microformats</title>
		<link>http://www.kunaal84.com/blog/2007/10/25/hide-your-email-address-using-microformats/</link>
		<comments>http://www.kunaal84.com/blog/2007/10/25/hide-your-email-address-using-microformats/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 15:25:38 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[microformats]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/2007/10/25/hide-your-email-address-using-microformats/</guid>
		<description><![CDATA[Heres a little tip to hide your email address on your site, so that it is only visible to people with microformat readers. Suppose I wanted to advertise an email &#8216;kunaal@somedomain.com&#8217;, normally you would not put that on your website for fear of getting your email inbox choked with spam. Here is another little trick [...]]]></description>
			<content:encoded><![CDATA[<p>Heres a little tip to hide your email address on your site, so that it is only visible to people with microformat readers. </p>
<p>Suppose I wanted to advertise an email &#8216;kunaal@somedomain.com&#8217;, normally you would not put that on your website for fear of getting your email inbox choked with spam. Here is another little trick to hide your email address from everyone without a microformat reader.</p>
<p>Normally, you would write your email address using microformats as so &#8211; <span class="vcard"><span class="fn">Kunaal Ramchandani</span> can be contacted on <span class="email"><span class="value">kunaal@somedomain.com</span></span></span>, which in the code would appear as </p>
<pre name="code" class="html">
&lt;span class="vcard"&gt;&lt;span class="fn"&gt;Kunaal Ramchandani&lt;/span&gt; can be contacted on &lt;span class="email"&gt;&lt;span class="value"&gt;kunaal@somedomain.com&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
</pre>
<p>Now an ordinary scraper can easily pick up the email address mentioned in there, so to get around that we introduce random characters in between the email address, but put them outside the &lt;span class=&#8221;value&#8221;&gt; tags. What I mean is that I separate each character of the email address in a &lt;span class=&#8221;value&#8221;&gt; tag, and I write random letters in between each &lt;span class=&#8221;value&#8221;&gt; &lt;/span&gt; pair, i.e for &#8216;kunaal&#8217; I would convert it to </p>
<pre name="code" class="html">
&lt;span class="value"&gt;k&lt;/span&gt;
&lt;span class="value"&gt;u&lt;/span&gt;
&lt;span class="value"&gt;n&lt;/span&gt;
&lt;span class="value"&gt;a&lt;/span&gt;
&lt;span class="value"&gt;a&lt;/span&gt;
&lt;span class="value"&gt;a&lt;/span&gt;
&lt;span class="value"&gt;l&lt;/span&gt;
</pre>
<p>and then introduce random characters like #,$,! random letters etc in between, making the final code look like</p>
<pre name="code" class="html">
&lt;span class="email"&gt;&lt;span class="value"&gt;k&lt;/span&gt;##&lt;span class="value"&gt;u&lt;/span&gt;!!&lt;span class="value"&gt;n&lt;/span&gt;@@&lt;span class="value"&gt;a&lt;/span&gt;$$&lt;span class="value"&gt;a&lt;/span&gt;%%&lt;span class="value"&gt;l&lt;/span&gt;^^&lt;span class="value"&gt;@&lt;/span&gt;**&lt;span class="value"&gt;s&lt;/span&gt;((&lt;span class="value"&gt;o&lt;/span&gt;))&lt;span class="value"&gt;m&lt;/span&gt;!!&lt;span class="value"&gt;e&lt;/span&gt;@@&lt;span class="value"&gt;d&lt;/span&gt;##&lt;span class="value"&gt;o&lt;/span&gt;$$&lt;span class="value"&gt;m&lt;/span&gt;%%&lt;span class="value"&gt;a&lt;/span&gt;^^&lt;span class="value"&gt;i&lt;/span&gt;**&lt;span class="value"&gt;n&lt;/span&gt;((&lt;span class="value"&gt;. &lt;/span&gt;))&lt;span class="value"&gt;c&lt;/span&gt;!!&lt;span class="value"&gt;o&lt;/span&gt;@@&lt;span class="value"&gt;m&lt;/span&gt;##&lt;/span&gt;&lt;/span&gt;
</pre>
<p>On screen this would appear as <span class="email"><span class="value">k</span>##<span class="value">u</span>!!<span class="value">n</span>@@<span class="value">a</span>$$<span class="value">a</span>%%<span class="value">l</span>^^<span class="value">@</span>**<span class="value">s</span>((<span class="value">o</span>))<span class="value">m</span>!!<span class="value">e</span>@@<span class="value">d</span>##<span class="value">o</span>$$<span class="value">m</span>%%<span class="value">a</span>^^<span class="value">i</span>**<span class="value">n</span>((<span class="value">. </span>))<span class="value">c</span>!!<span class="value">o</span>@@<span class="value">m</span>##</span></span>.</p>
<p>This would make it unreadable to your average person and your normal everyday address parser, and only visible to a microformat parser!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2007/10/25/hide-your-email-address-using-microformats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create Bookmarklets</title>
		<link>http://www.kunaal84.com/blog/2007/10/11/how-to-create-bookmarklets/</link>
		<comments>http://www.kunaal84.com/blog/2007/10/11/how-to-create-bookmarklets/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 15:09:21 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tips&tricks]]></category>
		<category><![CDATA[bookmarklets]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/2007/10/11/how-to-create-bookmarklets/</guid>
		<description><![CDATA[This is actually a pretty neat little trick. For a while now, when I am working on simple JavaScript functions, I have been using my browsers address bar to speed things up. For those not aware, one can actually type simple or complex JavaScript commands in the address bar of most modern browsers (It works [...]]]></description>
			<content:encoded><![CDATA[<p>This is actually a pretty neat little trick. For a while now, when I am working on simple JavaScript functions, I have been using my browsers address bar to speed things up.<br />
For those not aware, one can actually type simple or complex JavaScript commands in the address bar of most modern browsers (It works in Mozilla and I.E at least)<br />
for a quick simple calculator, you can try pasting this in the address bar</p>
<pre name="code" class="js">javascript:eval(567 * 234);</pre>
<p>Now to create a bookmarklet, all you have to do is </p>
<ol>
<li>Create a new bookmark</li>
<li>In the url field or the destination field, paste the javascript code you have written</li>
</ol>
<p>You have now created a bookmarklet, that you can execute whenever you need it.</p>
<p>For example, to read the cookie contents of a site, you can put the following in the address bar</p>
<pre name="code" class="js">javascript:alert('Cookie date:\n' + document.cookie.replace(/; /g,'\n'));</pre>
<p>or you can bookmark this link &#8211; <a href="javascript:alert('Cookie date:\n' + document.cookie.replace(/; /g,'\n'));">View Cookies</a></p>
<p>Another simple bookmarklet to disable external style sheets is</p>
<pre name="code" class="js">Javascript:for ( ss=0; ss&lt;document.styleSheets.length; ss++){void(document.styleSheets.item(ss).disabled=true);}</pre>
<p>bookmarklet -> <a href="Javascript:for ( i=0; i<document.styleSheets.length; i++){void(document.styleSheets.item(i).disabled=true);}">Disable Stlesheets </a></p>
<p>For those looking for more complex bookmarks, check out the following sites<br />
<a href="https://www.squarefree.com/bookmarklets/">Jesse&#8217;s Bookmarklet Site</a><br />
<a href="http://www.bookmarklets.com/tools/categor.html">Bookmarklet tool categories</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2007/10/11/how-to-create-bookmarklets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using .htaccess to password protect a directory</title>
		<link>http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/</link>
		<comments>http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 15:18:25 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[tips&tricks]]></category>
		<category><![CDATA[directory_listings]]></category>
		<category><![CDATA[password_protection]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/</guid>
		<description><![CDATA[I came across this issue a few days ago, I was required to create a secure area on a web server where I could upload large files. The directory where these files were uploaded should be password protected so that only someone authorised can access it, and as a further protection, the directory should have [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this issue a few days ago, I was required to create a secure area on a web server where I could upload large files. The directory where these files were uploaded should be password protected so that only someone authorised can access it, and as a further protection, the directory should have its directory listings display turned off. Client Side password protection like using Javascript is not very good, because it can be disabled<br />
Figured this might make someone else&#8217;s life easier in the future</p>
<ul>
<li>Using a FTP client, login to your server.</li>
<li>Create a new directory in your public folder (www, public_html etc). Remember to keep the name something people will not be able to guess. something like &#8220;S3cr3tF0ld3r&#8221; maybe</li>
<li>Create an empty .htaccess file and upload it to that directory</li>
<li>The first and easiest step to carry out is to disable directory listings. Use the following code (also described <a href="http://www.kunaal84.com/blog/2007/08/27/tips-and-tricks-with-the-htaccess-file-part-1/">here</a>)
<pre><code>Options All -Indexes</code></pre>
</li>
<li>Now comes the slightly trickier part, password protecting the directory:<br />
I first add the following lines to the .htaccess file<br/></p>
<pre><code>AuthUserFile /path/to/.htpasswd
AuthName "My own Login Area"
AuthType Basic</code></pre>
</li>
<li>I then add the username and encrypted password to the .htpasswd file and place it in the same place mentioned in the htaccess above.<br />
The little script below generates the uname:password combination<br/></p>
<p><script type="text/javascript" src="/php_scripts/aja.js"></script></p>
<form name="f1" action="">
  username:<br />
<input name="uname" type="text" /><br/><br />
  password:<br />
<input name="word" type="text" /> <br/> </p>
<input value="Encrypt" type="button" onclick='JavaScript:xmlhttpPost("http://www.kunaal84.com/php_scripts/htpasswd_encrypt.php")' />
<div id="result"></div>
</form>
</li>
<li>You can test this <a href="http://www.kunaal84.com/S3cr3tF0ld3r/d.txt">here</a>, username and password are both &#8216;test&#8217;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
