<?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>Turing tarpit</title>
	<atom:link href="http://www.turingtarpit.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.turingtarpit.com</link>
	<description>Where everything is possible but nothing of interest is easy –Alan Perlis</description>
	<lastBuildDate>Thu, 11 Mar 2010 02:01:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>TCPMon: Monitor TCP Transactions on OSX</title>
		<link>http://www.turingtarpit.com/2010/03/tcpmon-tcp-monitor-for-osx/</link>
		<comments>http://www.turingtarpit.com/2010/03/tcpmon-tcp-monitor-for-osx/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 20:05:22 +0000</pubDate>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.turingtarpit.com/?p=430</guid>
		<description><![CDATA[Essential tool for debugging web services. You can monitor HTTP request headers, returned status codes and content. This is a double clickable version of the classic Apache TCPMon utility. I simply packaged the program&#8217;s files into an application using the Jar Bundler utility that comes with XCode developer tools. Take a look at the tutorial [...]]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-433 post-thumb" title="tcpmon_icon" src="http://www.turingtarpit.com/wp-content/uploads/2010/03/tcpmon_icon.jpg" alt="tcpmon_icon" width="200" height="200" /><span class="post-tagline">Essential tool for debugging web services. You can monitor HTTP request headers, returned status codes and content.</span></p>
<p><a href="http://www.turingtarpit.com/wp-content/uploads/2010/03/TCPMon.app.zip"><img class="alignleft size-full wp-image-313" title="Download wplogger plugin" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/download2_btn.jpg" alt="Download wplogger plugin" width="130" height="30" /></a></p>
<p>This is a double clickable version of the classic <a href="http://ws.apache.org/commons/tcpmon/index.html" target="_blank">Apache TCPMon</a> utility. I simply packaged the program&#8217;s files into an application using the <em>Jar Bundler</em> utility that comes with <em>XCode</em> developer tools.</p>
<p>Take a look at the <a href="http://ws.apache.org/commons/tcpmon/tcpmontutorial.html" target="_blank">tutorial</a> on how to use it. TCPMon is most commonly used as an intermediary &#8211; a proxy that stands between and listens to incoming and outgoing web traffic.</p>
<p><img class="alignnone" src="http://ws.apache.org/commons/tcpmon/images/concept.jpg" alt="" width="490" height="98" /></p>
<p>This is a very useful tool to monitor network transactions when accessing web services using SOAP and REST. You can monitor returned XML and JSON content without inserting trace or debugging statements in the code.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.turingtarpit.com%2F2010%2F03%2Ftcpmon-tcp-monitor-for-osx%2F&amp;title=TCPMon%3A%20Monitor%20TCP%20Transactions%20on%20OSX" id="wpa2a_2"><img src="http://www.turingtarpit.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.turingtarpit.com/2010/03/tcpmon-tcp-monitor-for-osx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress Logger: A plugin that displays log messages to the Safari and Firefox console from PHP</title>
		<link>http://www.turingtarpit.com/2009/05/wordpress-logger-a-plugin-to-display-php-log-messages-in-safari-and-firefox/</link>
		<comments>http://www.turingtarpit.com/2009/05/wordpress-logger-a-plugin-to-display-php-log-messages-in-safari-and-firefox/#comments</comments>
		<pubDate>Tue, 12 May 2009 06:04:05 +0000</pubDate>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
				<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.turingtarpit.com/?p=369</guid>
		<description><![CDATA[This is an essential plugin for developers who are frustrated with debugging plugins and themes with <code>print_r</code> statements. This plugin displays log messages from PHP in the browser console in Safari and Firefox (with firebug). You no longer have to work blind when your templates don't render properly. Just place a log statement and examine the code right on the browser. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://www.turingtarpit.com/wp-content/uploads/2009/05/wplogger_icon.jpg" alt="wplogger_icon" title="wplogger_icon" width="200" height="200" class="alignleft size-full wp-image-390  post-thumb" /><span class="post-tagline">Essential debugging tool for plugin and theme developers.</span></p>
<p>Display log messages from PHP in the browser console in Safari and Firefox (with firebug). You no longer have to use <code>print_r</code> statements from PHP to figure out what is going on in the code. Besides, <code>print_r</code> statements  mess up the DOM and HTML layout. </p>
<p><a href="http://downloads.wordpress.org/plugin/wordpress-logger.zip"><img class="alignnone size-full wp-image-313" title="Download wplogger plugin" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/download2_btn.jpg" alt="Download wplogger plugin" width="130" height="30" /></a></p>
<a name="wptoc_0_0_0"></a><h3>Features</h3>
<ul>
<li>Log debug messages directly from themes and <span>plugins</span>.</li>
<li>Display log messages in the browser console, without muddying up the browser display.</li>
<li>Displays complex structures such as arrays and objects in pretty print.</li>
<li>Shows the line number and file from where the message was logged ( you won&#8217;t lose track of log statements ).</li>
</ul>
<a name="wptoc_0_0_1"></a><h3><span>Screenshots</span></h3>
<p><div id="attachment_376" class="wp-caption alignnone" style="width: 310px"><a title="Firefox console showing debug messages." rel="shadowbox[browser console]" href="http://www.turingtarpit.com/wp-content/uploads/2009/05/screenshot-1.png"><img class="size-medium wp-image-376" src="http://www.turingtarpit.com/wp-content/uploads/2009/05/screenshot-1-300x153.png" alt="Firefox console showing debug messages." width="300" height="153" /></a><p class="wp-caption-text">Firefox console showing debug messages.</p></div><br />
<div id="attachment_378" class="wp-caption alignnone" style="width: 310px"><a title="Safari console showing debug messages" rel="shadowbox[browser console]" href="http://www.turingtarpit.com/wp-content/uploads/2009/05/screenshot-2.png"><img class="size-medium wp-image-378   " title="Safari console" src="http://www.turingtarpit.com/wp-content/uploads/2009/05/screenshot-2-300x150.png" alt="Safari console showing debug messages" width="300" height="150" /></a><p class="wp-caption-text">Safari console showing debug messages</p></div></p>
<a name="wptoc_0_0_2"></a><h3><strong>Installation</strong></h3>
<ol>
<li>Verify that you have PHP5, which is required for this <span>plugin</span>.</li>
<li> <span>Download</span> the whole <code>wplogger</code> folder into the <code>/wp-content/plugins/</code> directory.</li>
<li>Activate the <em>plugin</em> through the <em>Plugins</em> menu in WordPress.</li>
</ol>
<a name="wptoc_0_0_3"></a><h3>Requirements</h3>
<ul>
<li>Make sure that your theme template has a footer ( <em>index.php</em> should have a <em>get_footer()</em> function call at the end).</li>
<li>Turn on the console in your browser:
<ul>
<li><strong>Firefox:</strong> The <a title="Firebug home page" href="http://getfirebug.com/" target="_blank">Firebug</a> extension needs to be installed and activated.</li>
<li><strong>Safari:</strong> Show the <em>Error Console</em> from the <em>Debug</em>/<em>Develop</em> menu.<br />
Details on how to enable the <em>Debug</em> menu for Safari on <a href="http://www.macosxhints.com/article.php?story=20030110063041629" target="_blank">OSX</a> and <a href="http://robrohan.com/2007/06/11/enable-debug-mode-on-safari-windows-error/" target="_blank">Windows</a>.</li>
</ul>
</li>
</ul>
<a name="wptoc_0_0_4"></a><h3>Usage</h3>
<p>After activating the <span>plugin</span>, the following PHP function call can log any PHP expression to the console log.</p>
<div>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$wplogger</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span> php_expression <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> message_type<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</div>
<div>
<p>The message_type is optional and can be any one of the following constants:</p>
<ul>
<li>WPLOG_ERR</li>
<li>WPLOG_WARNING</li>
<li>WPLOG_INFO</li>
<li>WPLOG_DEBUG</li>
</ul>
</div>
<a name="wptoc_0_0_5"></a><h3>Use cases</h3>
<a name="wptoc_5_1_0"></a><h4>Logging from template files</h4>
<p>This is from inside the loop to display post IDs.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$wplogger</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Post ID: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Output:</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">[Information: from line 20 in file index.php] Post ID: 125
[Information: from line 20 in file index.php] Post ID: 116
[Information: from line 20 in file index.php] Post ID: 65</pre></td></tr></table></div>

<a name="wptoc_5_1_1"></a><h4>Logging from PHP files</h4>
<p>This is from  <em>functions.php</em> ( always a good idea to check if <code>$wplogger</code> is available ). Note the message type set to <em>warning</em> through the second parameter.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$wplogger</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wplogger</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'active_plugins'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> WPLOG_WARNING <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Output:</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">[Warning: from line 55 in file functions.&lt;span&gt;php&lt;/span&gt;] array (
	  0 =&gt; 'wplogger/wplogger.php',
	  1 =&gt; '12seconds-widget/12seconds-widget.php',
	  2 =&gt; 'get-the-image/get-the-image.php',
)</pre></td></tr></table></div>

<a name="wptoc_5_1_2"></a><h4>Logging from <span>plugins</span></h4>
<p><span>This is from inside a <em>plugin</em> function. Note the global statement to get <code>$wplogger</code> into current scope.</span></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wplogger</span><span style="color: #339933;">;</span> <span style="color: #000088;">$wplogger</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'No images attached to this post'</span><span style="color: #339933;">,</span> WPLOG_ERR <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Output:</strong></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">[Error: from line 206 in file get-the-image.php] No images attached to this post</pre></td></tr></table></div>

<a name="wptoc_0_0_6"></a><h3>Credits</h3>
<p>Code that forces the wplogger plugin to load first was adapted from the WordPress <a title="FirePHP plugin" href="http://inchoo.net/wordpress/wordpress-firephp-plugin/" target="_blank">FirePHP plugin</a> developed by Ivan Weiller.</p>
<p>This plugin is based on <a title="PEAR Log" href="http://pear.php.net/package/Log" target="_blank">PEAR Log</a>, the logging framework that is part of the PHP PEAR library. Current maintainers Jon Parise, Jan Schneider, and Chuck Hagenbuch. PEAR Log is based on code first developed for the Horde 1.3 framework &#8211; original authors Chuck Hagenbuch, and Jon Parise.</p>
<a name="wptoc_0_0_7"></a><h3>Download Plugin</h3>
<p><a href="http://downloads.wordpress.org/plugin/wordpress-logger.zip"><img class="alignnone size-full wp-image-313" title="Download wplogger plugin" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/download2_btn.jpg" alt="Download wplogger plugin" width="130" height="30" /></a></p>
<a name="wptoc_0_0_8"></a><h3>Feature requests and critiques</h3>
<p>This is the first iteration of the wplogger plugin. Please comment on how you would like to see it improved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.turingtarpit.com/2009/05/wordpress-logger-a-plugin-to-display-php-log-messages-in-safari-and-firefox/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Mounting remote filesystems on OSX Leopard using sshfs, MacFuse and Macfusion</title>
		<link>http://www.turingtarpit.com/2009/04/mounting-remote-filesystems-on-osx-leopard-using-sshfs-macfuse-and-macfusion/</link>
		<comments>http://www.turingtarpit.com/2009/04/mounting-remote-filesystems-on-osx-leopard-using-sshfs-macfuse-and-macfusion/#comments</comments>
		<pubDate>Fri, 01 May 2009 07:06:25 +0000</pubDate>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
				<category><![CDATA[Workflow]]></category>
		<category><![CDATA[SSHFS FUSE filesystems]]></category>

		<guid isPermaLink="false">http://www.turingtarpit.com/?p=315</guid>
		<description><![CDATA[Have you ever wanted to edit the web pages that reside on your commercial web host like they were on your own desktop? Wouldn’t it be nice to mount your entire remote website host directory on the desktop with a nice disk icon? Now you can drag and drop files into it without leaving the Finder. You can also edit files remotely without downloading, editing and uploading. This can be a huge improvement in workflow, and you don’t have to keep track of local and remote versions of files and the inevitable versioning headaches. This post shows you how to combine three free tools to setup this workflow.]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-342 post-thumb" title="macfuse_icon" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/macfuse_icon.jpg" alt="macfuse_icon" width="200" height="200" /><span class="post-tagline">Work on the web pages that reside on your commercial web host like they were on your own desktop.</span></p>
<p>If you have cursed out an FTP client ( under your breath of course ) at any point in a development cycle, welcome to the club. I develop on an OSX machine and I love Cyberduck &#8211; the popular FTP client for the Mac. But wouldn&#8217;t it be nice to mount your  entire remote website host directory on the desktop with a nice disk icon? Now you can drag and drop files into it without leaving the Finder. You can also edit files remotely without downloading, editing and uploading. This can be a huge improvement in workflow, and you don&#8217;t have to keep track of local and remote versions of files and the invariable versioning headaches.</p>
<a name="wptoc_0_0_0"></a><h3>Advantages</h3>
<ul>
<li><strong>Avoid UNIX:</strong> Most hosting plans run on some variant of UNIX/Linux. Stuff that you had to do on the server over SSH using the Terminal can now be done on the desktop. For example, WordPress plugins and themes can be downloaded, unzipped and moved to their proper locations, all from the desktop. You no longer have to execute cryptic commands from the UNIX command line.</li>
<li><strong>Develop on a thin client: </strong>You can develop on a lightweight Netbook with a super fast, but low-capacity solid-state (SSD) drive. You don&#8217;t have to worry about the limited disk space  because your workspace resides on the remote server.</li>
<li><strong>Don&#8217;t have to worry about backups:</strong> Most hosting plans have some sort of incremental backup on the server side. Your workspace will automatically get backed up on the server.</li>
</ul>
<p>First, a caution &#8211; I&#8217;m not advocating editing a live website. Although that is certainly possible, it is not recommended practice. However, there are a myriad of little things that can be done quite efficiently if the remote filesystem was mounted on the desktop. Moving, renaming and deleting files is super easy ( these actions can be a real pain to accomplish using an FTP client). For those perfectionists who incessantly tinker with image files, just open the file, make the change and save it. The huge advantage is the seamless access and the improvement in overall workflow.<span id="more-315"></span></p>
<a name="wptoc_0_0_1"></a><h3>Disadvantages</h3>
<ul>
<li><strong>Filesystem response dependent on network speed: </strong>This is the big caveat. This method is not suitable for editing 100MB Photoshop files. However, it can be very effective for editing web pages.</li>
</ul>
<a name="wptoc_0_0_2"></a><h3><strong>System requirements</strong></h3>
<ul>
<li>You need to have access to a remote server like a commercial web host ( e.g. Dreamhost, Media Temple ).</li>
<li><a href="http://en.wikipedia.org/wiki/Secure_Shell" target="_blank">SSH</a> ( <em>Secure SHell</em> ) remote login has to be available and setup on the server. You can turn on SSH access on most hosting plans through your web panel. Make sure that you test SSH access before proceeding.</li>
<li>The method described here works only on Mac OSX Leopard.</li>
</ul>
<a name="wptoc_0_0_3"></a><h3>Method</h3>
<p>You need to install three applications / frameworks:</p>
<ol>
<li><a href="http://code.google.com/p/macfuse/" target="_blank">MacFuse</a></li>
<li><a href="http://www.macfusionapp.org/support.html" target="_blank">Macfusion</a></li>
<li><a style="text-decoration: none;" href="http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS" target="_blank">sshfs</a> (to update the old version pre-installed with Macfusion)</li>
</ol>
<a name="wptoc_3_1_0"></a><h4>1. Install MacFuse</h4>
<p><img class="alignnone size-full wp-image-317" title="macfuse" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/macfuse.jpg" alt="macfuse" width="250" height="145" /></p>
<p><a href="http://code.google.com/p/macfuse/" target="_blank">MacFuse</a> is an OSX implementation of the <em>Filesystem in Userspace</em> (FUSE) framework. <em>Fuse</em> provides an API to write a <em>virtual file system</em>. Virtual in the sense that a developer can write a file-system like front-end to any structured information source.  Even though the information is accessed and manipulated as files, the actual data doesn&#8217;t need to be files on a disk. For example, there is the Picasa image file system (<em>PicasawebFS)</em>, a virtual filesystem that allows you to mount all your Picasa images like a disk on the desktop. Then theres is the RSS file system (<em>RSSFS)</em> that allows you to mount an RSS feed as a filesystem and access each entry as an individual file. <strong>We will use SSHFS, the </strong><em><strong>Secure SHell FileSystem</strong></em>, that allows you to mount a remote computer directory though a <em>secure shell (SSH) </em>login. If you want additional technical details, watch a <a href="http://video.google.com/videoplay?docid=3138515991250095768" target="_blank">screencast</a> by  Amit Sigh, the project owner of  MacFuse.</p>
<p><strong>Download and install MacFuse from google code:</strong></p>
<p><a href="http://code.google.com/p/macfuse/" target="_blank">http://code.google.com/p/macfuse/</a></p>
<p>MacFuse comes with a nice preference pane to check for updates. The version was 2.0.3 as of this writing.</p>
<a name="wptoc_3_1_1"></a><h4>2. Install Macfusion</h4>
<p><img class="alignnone size-full wp-image-318" title="macfusion-icon" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/macfusion-icon.png" alt="macfusion-icon" width="64" height="64" /></p>
<p>Macfusion is an open source SSHFS mounting application for OSX Leopard. There are a couple of apps out there that do this ( <a href="http://mac.softpedia.com/get/Network-Admin/sshfs.shtml" target="_blank">sshfs 1.0</a>, <a href="http://www.pqrs.org/tekezo/macosx/sshfs/" target="_blank">sshfs for Mac OS X</a> ), but Macfusion is by far the most mature.</p>
<p><strong>Download and install from:</strong></p>
<p><a href="http://www.macfusionapp.org" target="_blank">http://www.macfusionapp.org</a></p>
<a name="wptoc_1_2_0"></a><h5>Add an SSHFS file system</h5>
<p>To add an SSHFS file system click on the plus icon at the bottom of the main window and choose SSHFS.</p>
<div id="attachment_320" class="wp-caption alignnone" style="width: 412px"><img class="size-full wp-image-320" title="add_sshfs" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/add_sshfs.jpg" alt="add_sshfs" width="402" height="126" /><p class="wp-caption-text">Adding an SSHFS filesystem</p></div>
<a name="wptoc_1_2_1"></a><h5>Set SSHFS mount parameters</h5>
<p>Under the <strong>SSH</strong> tab:</p>
<ul>
<li><strong>Host:</strong> The <em>hostname</em> of the server that you SSH to. This is usually the domain name of you website ( e.g. &#8216;yourdomain.com&#8217; ).</li>
<li><strong>User Name: </strong>Your SSH username.</li>
<li><strong>Password: </strong>Your SSH password.</li>
<li><strong>Path: </strong>can be left blank.</li>
</ul>
<p>Under the <strong>SSH Advanced</strong> tab:</p>
<ul>
<li><strong>Port:</strong> The default SSH port is 22 unless your server uses a different one ( just try 22 ).</li>
<li><strong>Follow Symbolic Links: </strong>Leave this checked.</li>
</ul>
<p>Under the <strong>Macfusion</strong> tab:</p>
<ul>
<li><strong>Mount Point and Volume Name:</strong> Can be left blank.</li>
<li><strong>Ignore Apple Double Files: </strong>You must <em>uncheck</em> this if you plan to <em>open/edit/save</em> files on the mounted volume.  For example, if you want to edit an image file using Photoshop, this setting has to be <em>unchecked</em>. However, this powerful feature comes with a downside. Leaving this unchecked will  cause OSX to place .DS_Store and ._ * ( Appledouble ) files on the server.  OSX utilizes these hidden files for enhanced filesystem features and extended file attributes in non OSX native filesystems. For example, a Photoshop file can have icon, thumbnail, and version cue information saved in a separate Appledouble file. These files are invisible in OSX and other filesystems as they start with a dot. Leave this <em>checked</em> if you are just going to <em>copy/move/delete</em> files ( increases speed ). You can leave this checked if editing text files as most apps don&#8217;t save additional file attributes with text files. However, this depends on the application you use, so do some testing first.</li>
<li><strong>Enable Negative VNode Cache:</strong> This is an <a href="http://code.google.com/p/macfuse/wiki/OPTIONS" target="_blank">optimization</a> to increase speed and should generally be left <em>checked </em>unless files can appear on the mounted volume from the server side. For example, if multiple users are using your mounted disk space leave this <em>unchecked</em>.</li>
</ul>
<p><a title="SSH tab" rel="shadowbox[SSHFS settings]" href="http://www.turingtarpit.com/wp-content/uploads/2009/04/ssh.jpg"><img class="size-thumbnail wp-image-323 alignnone" title="ssh" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/ssh-150x150.jpg" alt="ssh" width="120" height="120" /></a> <a title="SSH Advanced tab" rel="shadowbox[SSHFS settings]" href="http://www.turingtarpit.com/wp-content/uploads/2009/04/ssh_advanced.jpg"><img class="size-thumbnail wp-image-324 alignnone" title="ssh_advanced" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/ssh_advanced-150x150.jpg" alt="ssh_advanced" width="120" height="120" /></a> <a title="Macfusion tab" rel="shadowbox[SSHFS settings]" href="http://www.turingtarpit.com/wp-content/uploads/2009/04/macfusion.jpg"><img class="alignnone size-thumbnail wp-image-322" title="macfusion" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/macfusion-150x150.jpg" alt="macfusion" width="120" height="120" /></a></p>
<p>You will now have an SSHFS filesystem ready to mount on your desktop.</p>
<a name="wptoc_1_2_2"></a><h5>Mount the remote filesystem</h5>
<p>Click on the mount button and if the SSH settings are correct, you should have a green disk icon mounted on the desktop.</p>
<div id="attachment_330" class="wp-caption alignnone" style="width: 415px"><img class="size-full wp-image-330" title="mounted" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/mounted.jpg" alt="mounted" width="405" height="111" /><p class="wp-caption-text">Macfusion main window after mounting a remote filesystem</p></div>
<p>You can now access your remote files like they were on an external disk attached to your computer. You can copy, move, rename and delete files at ease. Remember that if you want to edit files on the remotely mounted disk, the <em>Ignore Apple Double Files</em> checkbox should be <em>unchecked</em>. You can easily edit the SSHFS mount settings by unmounting the disk and clicking on the Edit button.</p>
<p>You might have noticed that we completed only two of the three steps but you can already mount your remote filesystem. This is because Macfusion already has SSHFS pre-installed within its application package. However, I found  the mounted filesystem response to be a little sluggish and wondered if the version of SSHFS that came pre-installed with Macfusion was outdated.</p>
<a name="wptoc_3_1_2"></a><h4>3. Update SSHFS</h4>
<p>Let&#8217;s examine the pre-installed version of SSHFS that comes with Macfusion. RIGHT-CLICK ( or CONTROL-CLICK) on the Macfusion app in the Applications folder. You will be presented with a contextual menu. Choose the &#8220;Show Package Contents&#8221; menu option. You will then be presented with a folder containing the application folder hierarchy. Drill down until you see an application called sshfs-static.</p>
<div id="attachment_333" class="wp-caption alignnone" style="width: 268px"><a title="Macfusion application package hierarchy" rel="shadowbox" href="http://www.turingtarpit.com/wp-content/uploads/2009/04/macfusion_folders.jpg"><img class="size-medium wp-image-333" title="macfusion_folders" src="http://www.turingtarpit.com/wp-content/uploads/2009/04/macfusion_folders-258x300.jpg" alt="macfusion_folders" width="258" height="300" /></a><p class="wp-caption-text">Macfusion application hierarchy showing the location of the pre-installed version of SSHFS</p></div>
<p>This is the copy of sshfs that Macfusion uses to do its magic. To check its version, I opened up the Terminal app, changed directory to the parent folder off sshfs-static and typed in ./sshfs-static -V . You don&#8217;t have to do this by-the-way, just skip to the <em>Download and Install SSHFS</em> section.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">% cd /Applications/Macfusion.app/Contents/PlugIns/sshfs.mfplugin/Contents/Resources/
% ls -la
total 5736
drwxr-xr-x  9 chandima  staff      306 Aug  4  2008 .
drwxr-xr-x  5 chandima  staff      170 Aug  4  2008 ..
-rwxr-xr-x  1 chandima  staff    46928 Aug  4  2008 new_sshfs_askpass
-rwxr-xr-x  1 chandima  staff  2756952 Aug  4  2008 sshfs-static
-rw-r--r--  1 chandima  staff    13259 Aug  4  2008 sshfs.png
-rw-r--r--  1 chandima  staff     6796 Aug  4  2008 sshfsAdvanced.nib
-rw-r--r--  1 chandima  staff     7609 Aug  4  2008 sshfsConfiguration.nib
-rw-r--r--  1 chandima  staff    61418 Aug  4  2008 sshfs_icon.icns
-rwxr-xr-x  1 chandima  staff    29280 Aug  4  2008 sshnodelay.so
% ./sshfs-static -V
SSHFS version 1.8 (MacFUSE SSHFS 1.3.0)
MacFUSE library version: FUSE 2.7.3 / MacFUSE 2.0.3
no mount point</pre></td></tr></table></div>

<p>The pre-installed version was 1.8. I wondered if I&#8217;d get a speed increase if SSHFS was updated to the latest version which was 2.2 (as of this writing).</p>
<p><strong>Download SSHFS from:</strong></p>
<p><a href="http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS" target="_blank">http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS</a> (make sure you download <strong>sshfs-static-leopard.gz</strong> ).</p>
<p>After you uncompress the gzip archive, you will end up with a folder called <em>sshfs-binaries</em>. In there, you will see an app called <em>sshfs-static-leopard</em>.</p>
<p><strong>Rename the sshfs executable:</strong></p>
<p>Rename <em>sshfs-static-leopard</em> app to <em>sshfs-static </em>to match the filename that Macfusion expects.</p>
<p><strong>Replace the old version of sshfs with the new version:</strong></p>
<p>Drag and drop the downloaded and renamed <em>sshfs-static</em> executable into the <em>Resources</em> folder to replace the older version within the Macfusion package hierarchy.</p>
<p>You can check the version again to make sure that the new version is recognized.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">% ./sshfs-static -V
SHFS version 2.2 (MacFUSE SSHFS 2.2.0)
MacFUSE library version: FUSE 2.7.3 / MacFUSE 2.0.3
no mount point</pre></td></tr></table></div>

<p>I unmounted and remounted the filesystem and the speed increase was quite significant. I highly recommend that you do this third step.</p>
<a name="wptoc_0_0_4"></a><h3>What to do about those pesky <code>.DS_Store</code> and Appledouble files?</h3>
<p>There is a solution to <a href="http://support.apple.com/kb/HT1629" target="_blank">prevent <code>.DS_Store</code> file creation over network connections</a>.</p>
<p>The real power of this workflow is being able to edit files remotely without first copying them to the local computer. The <em>Ignore Apple Double Files</em> checkbox has to be left <em>unchecked</em> in order to edit images using Photoshop etc. However, as mentioned previously, this will cause OSX to spew  ._ * files on the server. These files, although invisible on the filesystem UI are still accessible through the web. As far as I know, the Appledouble files don&#8217;t contain any sensitive information like passwords and such and can be regarded as relatively harmless ( let me know if this is an incorrect assumption ).</p>
<a name="wptoc_0_0_5"></a><h3>Next steps</h3>
<p>Try it out and post a comment with your thoughts. I am interested in seeing if it does improve the workflow for web developers. For those of you who use a versioning system like subversion, I&#8217;m interested in getting some feedback on how this can be integrated, or if it is overkill.</p>
<p>I&#8217;ve only tested this with my commercial host ( Dreamhost.com ) that runs Linux, although it should work with most hosts that run some variant of UNIX / Linux. There could be permission issues depending on whether the remote filesystem allows extended file attributes. I&#8217;ll try and help out if you do have problems.</p>
<p>If anyone knows of a tutorial / resources on mounting remote filesystems on Windows please post a comment and I&#8217;ll integrate it into the post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.turingtarpit.com/2009/04/mounting-remote-filesystems-on-osx-leopard-using-sshfs-macfuse-and-macfusion/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>12seconds Widget: A Plugin to display 12seconds videos on your WordPress blog</title>
		<link>http://www.turingtarpit.com/2009/03/12seconds-widget/</link>
		<comments>http://www.turingtarpit.com/2009/03/12seconds-widget/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 23:12:11 +0000</pubDate>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
				<category><![CDATA[Plugin]]></category>
		<category><![CDATA[12seconds]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[social networks]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[video blogging]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.turingtarpit.com/?p=274</guid>
		<description><![CDATA[This is a <strong>WordPress plugin</strong> that adds a <strong>sidebar widget</strong> to display 12seconds video status updates. For those of you who are familiar with Twitter; 12seconds is like Twitter, but with video instead of text updates. You can also embed the widget in <em>posts</em> and <em>pages</em> using <em>shortcodes</em>. The widget itself is essentially a video player. It uses the widget embed code (need to login) provided by <em>12seconds.tv</em>. The plugin saves you the hassle of copying and pasting embed code and editing templates.]]></description>
				<content:encoded><![CDATA[<p>This is a <strong>WordPress plugin </strong>that adds a <strong>sidebar widget</strong> to display <a href="http://12seconds.tv">12seconds</a> video status updates. For those of you who are familiar with Twitter; 12seconds is like Twitter, but with video instead of text updates. You can also embed the widget in <em>posts</em> and <em>pages</em> using <em>shortcodes</em>.</p>
<p><a href="http://downloads.wordpress.org/plugin/12seconds-widget.zip"><img class="alignnone size-full wp-image-233" title="download_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/download2_btn.jpg" alt="Download Link" width="130" height="30" /></a></p>
<p>The widget itself is essentially a video player. It uses the <a href="http://12seconds.tv/widgets" target="_blank">widget embed code</a> (need to login) provided by <em>12seconds.tv</em>. The plugin saves you the hassle of copying and pasting embed code and editing templates.</p>
<a name="wptoc_0_0_0"></a><h3>Installation</h3>
<ol>
<li>Verify that you have PHP5, which is required for this plugin.</li>
<li><a href="http://www.turingtarpit.com/wp-content/uploads/2009/03/12seconds-widget.zip">Download</a> the whole <em>12seconds-widget</em> folder into the <code>/wp-content/plugins/</code> directory.</li>
<li> Activate the plugin through the &#8216;Plugins&#8217; menu in WordPress.</li>
</ol>
<a name="wptoc_0_0_1"></a><h3><strong>Usage</strong></h3>
<p>The plugin can be used in two ways:</p>
<ol>
<li>Display the widget in the sidebar</li>
<li>Embed the widget on posts and pages.</li>
</ol>
<a name="wptoc_1_1_0"></a><h4>1, Displaying the widget on a <em>sidebar</em></h4>
<p>After activating the <em>12seconds-widget</em> plugin, go to the <em>widgets</em> section. Now drag the widget into your chosen <em>sidebar</em> and configure.  You must enter a 12seconds <em>username</em>. You can choose to display a <em>skinny</em> (175&#215;290) or <em>fat</em> (380&#215;440) version of the widget. Make sure you click the &#8216;Done&#8217; button and the &#8216;Save Changes&#8217; button after making changes.</p>
<p><img class="alignnone size-full wp-image-280" title="12seconds-config" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/12seconds-config.jpg" alt="12seconds-config" width="284" height="264" /></p>
<p>If you don&#8217;t want a widget title just leave the <em>Title</em> field blank.</p>
<a name="wptoc_1_1_1"></a><h4>2, Displaying the widget on a <em>post</em> or <em>page</em></h4>
<p>Using the <em>shortcodes</em> system in WordPress 2.5 and up, the plugin will allow you to embed the widget into your <em>pages</em> and <em>posts</em>.</p>
<a name="wptoc_1_2_0"></a><h5>Use the &#8220;12suser&#8221; shortcode to display updates for an individual user</h5>
<p><img class="alignnone size-full wp-image-301" title="12suser-shortcode" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/12suser-shortcode.jpg" alt="12suser-shortcode" width="365" height="104" /></p>
<ul>
<li>The username attribute is required and is the login/user name to the 12seconds site.</li>
<li>The *size* attribute is optional and can be &#8220;fat&#8221; or &#8220;skinny&#8221; (default).</li>
</ul>
<a name="wptoc_1_2_1"></a><h5>Use the &#8220;12svideo&#8221; shortcode to display a single video</h5>
<p><img class="alignnone size-full wp-image-302" title="12svideo-shortcode" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/12svideo-shortcode.jpg" alt="12svideo-shortcode" width="190" height="33" /></p>
<ul>
<li> The <em>id</em> attribute is required.</li>
<li>The <em>id</em> is the last set of digits of the URL when viewing a video on the 12seconds.tv site. The URLs takes the form <code>http://12seconds.tv/channel/username/123456</code> . The <em>id</em> in this case would be <code>"123456"</code>.</li>
</ul>
<p><strong>PS: </strong>The <strong>12s</strong> shortcode introduced in version 0.2 will still work, but it has been deprecated.</p>
<a name="wptoc_0_0_2"></a><h3>Styling Guidelines</h3>
<p>The widget embed code tag is assigned CSS class <code>twelve-s-widget</code>.</p>
<p>The caption for individual videos ( when you use the <code>12svideo</code> shortcode ) is assinged CSS class <code>twelve-s-caption</code> to the tag.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="html" style="font-family:monospace;">&lt;span class=&quot;twelve-s-caption&quot;&gt;
 ........... &lt;/span&gt;</pre></td></tr></table></div>

<a name="wptoc_0_0_3"></a><h3>Examples</h3>
<p>The following examples show the status updates and individual videos by the <em>12seconds</em> team.</p>
<iframe class="twelve-s-widget" src="http://embed.12seconds.tv/i/widgetSmall?u=12seconds" scrolling="no" allowtransparency="true" frameborder="0" width="175" height="290"></iframe>
<p>Skinny widget showing the updates for username &#8221;12seconds&#8221;.</p>
<iframe class="twelve-s-widget" src="http://embed.12seconds.tv/i/widgetFull?u=ijustine" scrolling="no" allowtransparency="true" frameborder="0" width="380" height="440"></iframe>
<p>Fat widget showing <a href="http://twitter.com/ijustine" target="_blank">iJustine&#8217;s</a> updates (she&#8217;s not a regular 12er, but the few she did are masterpieces).</p>
<iframe class="twelve-s-widget" src="http://embed.12seconds.tv/i/embed?v=116072" scrolling="no" allowtransparency="true" frameborder="0" width="430" height="360"></iframe><span class="twelve-s-caption"><br/>From <a href="http://12seconds.tv">12seconds.tv</a></span>
<p>Single video showing 12seconds co-founder Sol Lipman explaining what its all about.</p>
<a name="wptoc_0_0_4"></a><h3>Download the plugin</h3>
<p><a href="http://downloads.wordpress.org/plugin/12seconds-widget.zip"><img class="alignnone size-full wp-image-233" title="download_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/download2_btn.jpg" alt="Download Link" width="130" height="30" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.turingtarpit.com/2009/03/12seconds-widget/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Get-the-image-link: Developing a simple WordPress Plugin</title>
		<link>http://www.turingtarpit.com/2009/03/get-the-image-link/</link>
		<comments>http://www.turingtarpit.com/2009/03/get-the-image-link/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 19:41:07 +0000</pubDate>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
				<category><![CDATA[Plugin]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.turingtarpit.com/?p=117</guid>
		<description><![CDATA[One of the really cool things about WordPress is that when you want to extend its functionality, more often-than-not, someone has already written a plugin for it.  However, in my case, the available plugin didn't do exactly what I wanted. So, I decided to write my first Wordpress plugin. Here I describe the basic but very important concepts that a novice plugin developer needs to learn.]]></description>
				<content:encoded><![CDATA[<p>One of the really cool things about WordPress is that extending its functionality is a breeze. Think up a new feature and more often-than-not, someone has already written a plugin for it.  With plugin installation now possible within the admin panel &#8211; things couldn&#8217;t be easier. You can search for, download, install and upgrade plugins without leaving the browser. Gone are the days of downloading, unzipping and messing with the command line on a remote server.</p>
<p>So, why did I end up writing a WordPress plugin? It all began with choosing a theme &#8230;.</p>
<a name="wptoc_0_0_0"></a><h3>Choosing a magazine style theme</h3>
<p>I wanted to use a magazine style theme for this blog. I use K2 for all my other WordPress blogs and have been quite happy with it. However, the visual dazzle of <a href="http://wphacks.com/best-magazine-style-wordpress-themes/" target="_blank">recent magazine style themes</a> left K2 a little wanting. Besides, most of K2s unique features like widget control were now standard in WordPress. I was impressed by the <em>Hamasaki</em> theme, developed by Nurudin Jauhari, on <a href="http://aralbalkan.com" target="_blank">Aral Balkan&#8217;s</a> blog. However, the elements were a little too large for my taste and the prominent place given to the most recent post was not to my liking. In contrast, Jauhari had another magazine style theme called <a href="http://themesarena.com/hijriah/" target="_blank"><em>hijiriah</em></a> (<a href="http://demo.themesarena.com/?wptheme=hijriah" target="_blank">demo</a>) that I took a liking to instantly.</p>
<p>There are some excellent features in this theme. The money features for me were:</p>
<ul>
<li>Built-in ad support ( a nice way to link to my other resources ).</li>
<li>Dynamic hierarchical navigation menu based on categories ( structured  access to eclectic subject matter ).</li>
<li>Auto generated image for each post ( pain free way to add some visual interest to the blog page ).</li>
</ul>
<a name="wptoc_0_0_1"></a><h3>Auto generating an image for each post</h3>
<p>I must say that this is the singular feature that really sold me on this theme. Images are generated automatically using a custom version of the <a href="http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin" target="_blank"><em>Get the Image</em></a> plugin developed by Justin Tadlock. This plugin is like a cascading image seeker. It also degrades gracefully. The following image seeking sequence is from the plugin README file.</p>
<ol>
<li>Looks for an image by custom field.</li>
<li>If no image is found, it grabs an image attached to your post.</li>
<li>If no image is attached, it can extract an image from your post content.</li>
<li>If no image is found at this point, it will default to an image you set.</li>
</ol>
<p>The <em>Get the Image</em> plugin has a function called <code>get-the-image</code> that returns the image element ( img tag ) for the auto generated image. A feature that is lacking is flexible image sizing ( you can only choose from predetermined sizes ).  To scale the image to a custom size, the <em>hijriah</em> theme uses an image resizing script called <a href="http://code.google.com/p/timthumb/" target="_blank">timthumb</a>. This is the whole reason for customizing/hacking the plugin.</p>
<p>The custom version of <em>Get the Image</em> that shipped with hijriah was based on version 0.3. The customization was a simple hack to add an additional function to the plugin called <em>get-the-link</em> that returned the URL of the chosen image for the post ( as opposed to the whole image element ). For some reason, a similar function that existed in <em>Get the Image</em> was now deprecated (probably due to a very good reason unknown to me). The URL to the image chosen by the hacked <em>Get the Image</em> plugin was passed to the <em>timthumb</em> script for resizing and eventually displayed on the blog page.</p>
<p>Another issue was that version 0.3 of  <em>Get the Image</em> had a bug that prevented it from returning an image specified by a custom thumbnail field. Version 0.3.1 fixed this issue.</p>
<a name="wptoc_0_0_2"></a><h3>Upgrading plugins broke image auto generation</h3>
<p>Of course, upgrading the <em>Get the Image</em> plugin to 0.3.1 overwrote the hacked version and the <em>hijriah</em> theme was left without an implementation for the template tag <code>get-the-link</code>.</p>
<p>Modifying the code in the <em>hijriah</em> theme ( I was using a child theme ) to substitute <em>get-the-link</em> tag with the <em>get_the_image</em> tag seemed a little too complicated due to the resizing issue. The other option was to write a new plugin that implemented the <code>get-the-link</code> function.</p>
<p>This was a beginning of my sojourn into plugin development&#8230;</p>
<a name="wptoc_0_0_3"></a><h3><strong><em>Writing a plugin to implement the <code>get-the-link</code> </em>template tag</strong></h3>
<p>Template tags are used within WordPress theme templates to display information dynamically. It is really nothing more than a call to a function internal to WordPress or externally implemented in a <em>plugin</em> or <code>functions.php</code> file. In the case of the <em>hijriah</em> theme, the <code>get-the-link</code> tag is required in the <code>index.php</code> template file.</p>
<p>The purpose of the new plugin clear and simple. Implement the <code>get-the-link</code> function by calling the <code>get_the_image</code> function in the  <em>Get the Image</em> plugin. I just have to use regex to extract the <code>src</code> attribute from the image element and return it. Simple right? Well, there were a few important things that I had to learn first.</p>
<a name="wptoc_0_0_4"></a><h3>Important stuff about plugins</h3>
<p>This is my first attempt at writing a plugin for WordPress. I had to dispel some preconceived ideas.</p>
<p>It&#8217;s been awhile since I did any coding in PHP. Coming from my recent ActionScript 3 background and dabbling extensively in OOP and <a href="http://www.as3dp.com" target="_blank">design patterns</a> I thought the new plugin could simply extend the  <em>Get the Image</em> plugin class and override a method or two. But, noooo! I quickly realized what I was up against as my PHP started to come back.</p>
<p>WordPress has a nice modular architecture, but it is not modular in the OOP sense. Here is the definition of a plugin from the <a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">WordPress Codex</a>.</p>
<blockquote><p>A WordPress Plugin is a program, or a set of one or more functions, written in the PHP scripting language, that adds a specific set of features or services to the WordPress weblog, which can be seamlessly integrated with the weblog using access points and methods provided by the WordPress <a title="Plugin API" href="http://codex.wordpress.org/Plugin_API" target="_blank">Plugin Application Program Interface (API)</a>.</p></blockquote>
<p>Forget about looking for a class to extend. All the plugins I looked at were collections of functions. Here are some things I learned about WordPress plugins that may be useful for a newbie like myself.</p>
<a name="wptoc_4_1_0"></a><h4>The bar to entry is very low</h4>
<p>It was surprising how easy it was to get WordPress to recognize a new plugin. This is a testament to the simplicity of the plugin architecture in WordPress. All you need is to create a new PHP file inside the plugins folder in your WordPress installation and write a comment block on it. Although not a requirement, it is always a good idea to put your plugin files inside a folder. The comment is the <a href="http://codex.wordpress.org/Writing_a_Plugin#File_Headers" target="_blank">plugin information header</a>.</p>
<p><a title="Plugin showing the header block" rel="shadowbox" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/plugin_file.jpg"><img class="alignnon size-full wp-image-208" title="plugin_file" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/plugin_file.jpg" alt="plugin_file" width="542" height="245" /></a></p>
<p>You can now go into the WordPress admin panel and activate it (from the inactive plugins list). You will now see the plugin activated. Of course it doesn&#8217;t do anything, but that was incredibly easy!</p>
<div id="attachment_204" class="wp-caption alignnone" style="width: 310px"><a title="Admin panel showing the activated plugin" rel="shadowbox" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/plugin_admin.jpg"><img class="size-medium wp-image-204   " title="plugin_admin" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/plugin_admin-300x129.jpg" alt="Turing on the plugin from the Admin Panel" width="300" height="129" /></a><p class="wp-caption-text">Activate the plugin from the Admin Panel</p></div>
<a name="wptoc_4_1_1"></a><h4>Plugins are just a collection of functions</h4>
<p>The best way to learn how to write a plugin is by studying other plugins. Good starting point are <em>akismet</em> and the <a href="http://svn.automattic.com/wordpress/trunk/wp-content/plugins/hello.php" target="_blank"><em>hello dolly</em></a> plugins that are included in the default installation. You will quickly see that most plugins have no class definitions, but they are just a collection of functions.</p>
<p>Plugins can take two forms:</p>
<ol>
<li>Plugin as a library.</li>
<li>Plugin as a dependency injector.</li>
</ol>
<a name="wptoc_1_2_0"></a><h5>1. Plugin as library</h5>
<p><span style="font-weight: normal; font-size: 13px;">This is the simplest form of a plugin. A library is simply a collection of functions. The client, a WordPress template in this case, can call the functions. Each function call does some work and returns control to the client.</span></p>
<p><a href="http://codex.wordpress.org/Template_Tags" target="_blank">Template tags</a> are calls to WordPress functions that do something or return some value back to a template. For example,  the <code>bloginfo</code> template tag is a function implemented within WordPress and returns information about the blog based on passed parameters. The &#8216;<code>name</code>&#8216; parameter, shown below,  returns the name of the blog.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Custom template tags can be implemented in plugins. This is a super easy way to extend WordPress functionality. All you need to do is implement a function in your plugin with the name of a template tag you come up with (make sure it is unique &#8211; more on this later). The following figure shows the <code>index.php</code> template calling the <code>get-the-image</code> template tag. The <code>get-the-image</code> function is implemented in the <em>Get the Image</em> plugin.</p>
<p><a href="http://www.turingtarpit.com/wp-content/uploads/2009/03/plugin1.png"><img class="alignncenter size-full wp-image-197" title="plugin1" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/plugin1.png" alt="plugin1" width="414" height="256" /></a></p>
<a name="wptoc_1_2_1"></a><h5><strong>2. Plugin as dependency injector</strong></h5>
<p><strong><span style="font-weight: normal;">This is a more powerful method of extending the functionality of WordPress. Instead of waiting for the template to call the plugin function, the plugin <em>injects</em> the function into the template. Dependency injection using plugins is called <strong>hooks</strong> in WordPress. There are two types of functions that can be injected or hooked into wordpress: <em>Actions</em> and <em>Filters</em>.</span></strong></p>
<p><strong><em>Action</em></strong> functions can be hooked into specific events in WordPress. That means, the function is called or triggered by a specific WordPress event. For example, you can write an action function that informs different search engines when a new article is posted. The  plugin function will hook into the <em>publish_post</em> event. The events that can trigger an action function are numerous. Refer to the <a href="http://codex.wordpress.org/Plugin_API/Action_Reference" target="_blank">Plugin API/Action Reference</a> for the list.</p>
<p><strong><em>Filter</em></strong> functions can be hooked into WordPress  to pass content through the function before being output to the web page. For example, if you want to filter out profanity in comments, write a function that takes the comment text as a parameter and returns the clean content. Now you can hook this filter function to the <em>comment_text</em> filter hook so that it is called before comment text is published on the page. Refer to the <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference" target="_blank">Plugin API/Filter Reference</a> for the list of filter hooks.</p>
<p><a href="http://www.amazon.com/gp/product/1847193595?ie=UTF8&amp;tag=chandimcumara-20&amp;link_code=as3&amp;camp=211189&amp;creative=373489&amp;creativeASIN=1847193595" target="_blank"><img class="alignleft" style="padding-right: 5px;" src="https://images-na.ssl-images-amazon.com/images/I/51Ns3okgLLL._SL160_.jpg" alt="" width="130" height="160" /></a>I won&#8217;t go into detail on writing plugins as dependency injectors. The <a href="http://codex.wordpress.org/Plugin_API" target="_blank">plugin API documentation</a> provides a good introduction. A good example on how to write <em>action</em> functions is to take a look at the <a href="http://svn.automattic.com/wordpress/trunk/wp-content/plugins/hello.php" target="_blank">hello dolly</a> plugin. The book on <a href="http://www.amazon.com/gp/product/1847193595?ie=UTF8&amp;tag=chandimcumara-20&amp;link_code=as3&amp;camp=211189&amp;creative=373489&amp;creativeASIN=1847193595" target="_blank">WordPress Plugin Development</a> by Vladimir Prevolac is quite good and explains action and filter functions very well ( check out the <a href="http://www.packtpub.com/files/wordpress-plugin-development-sample-chapter-2-social-bookmarking.pdf" target="_blank">sample chapter</a> ). Above all, download some plugins and take a look at the code &#8211; you will learn some interesting techniques.</p>
<a name="wptoc_4_1_2"></a><h4><strong>Choose plugin and function names carefully</strong></h4>
<p>Make sure you use a unique name for your plugin and its function names. PHP  and WordPress don&#8217;t take kindly to duplicate function names. The plugin will just not load and you will be left wondering what happened. Searching the WordPress <a href="http://wordpress.org/extend/plugins/" target="_blank">plugin directory</a> before settling on a name is not a bad idea. The dash &#8216;-&#8217; is the recommended separator for words in the filenames and function names for plugins.</p>
<a name="wptoc_4_1_3"></a><h4>Make sure the plugin function exists before you call it</h4>
<p>This is also known as:</p>
<blockquote><p>Looking for a black cat in a dark alley that isn&#8217;t there</p></blockquote>
<p>This is most important for library type plugins that are called directly from templates. The template doesn&#8217;t know if the plugin exists or if it is activated. Therefore, it is a good idea to first check if the function is available before calling it from a template. The PHP statement in the template should be of the form:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get-the-image'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">-</span>the<span style="color: #339933;">-</span>image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The tag function  &#8217;<code>get-the-link</code>&#8216; will only be called if it exists. There is a tight coupling between the template tag and the plugin where the function is implemented. You need to manually add the tag to the new theme templates if you switch themes.</p>
<p>One of the big advantages of injector type plugins is that the hooks are created at runtime. The template files don&#8217;t have to be modified to call the functions. In fact, the template doesn&#8217;t know anything about the plugins or the hooks. Therefore, themes can be switched without requiring any changes in the template files.</p>
<a name="wptoc_0_0_5"></a><h3>Get the Image Link plugin</h3>
<p>Let&#8217;s get back to the issue at hand. The purpose of the new plugin is to implement the <em>get-the-link</em> template tag by calling the <em>get_the_image</em> function in the  <em>Get the Image</em> plugin. We need to return the URL of the image as opposed to the image element.</p>
<p>It is a good idea to take a look at the <a title="Get the Image README file" rel="shadowbox" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/readme.html">README file</a> for the <em>Get the Image</em> plugin before proceeding. First thing to note is that the function takes <a href="http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_query-string-style_parameters" target="_blank">query string style parameters</a> (as opposed to function style parameters). Query string style is desirable when a function has many parameters. The second issue to note is the &#8216;echo&#8217; parameter which is set to true by default. This causes the function to echo the image element text to the output buffer inside the function. We need to set this to false.</p>
<p>The plugin will consist of one function called <code>get-the-link</code> that calls <code>get-the-image</code> in the <em>Get the Image</em> plugin. It then parses the image element to extract the <code>src</code> attribute using regexp and returns it.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_the_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_the_image'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> wp_parse_args<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'echo'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// prevent echo output</span>
&nbsp;
		<span style="color: #000088;">$imageElement</span> <span style="color: #339933;">=</span> get_the_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/src=(['</span><span style="color: #0000ff;">&quot;])?(.*?)<span style="color: #660099; font-weight: bold;">\1</span>/i';
		preg_match(<span style="color: #006699; font-weight: bold;">$pattern</span>, <span style="color: #006699; font-weight: bold;">$imageElement</span>, <span style="color: #006699; font-weight: bold;">$matches</span>);
&nbsp;
		return <span style="color: #006699; font-weight: bold;">$matches[2]</span>;
	}
}</span></pre></td></tr></table></div>

<p><span style="font-weight: normal; font-size: 13px;">You can now call the get-the-link template tag from a template and pass it as a parameter to the <a title="timthump.php script for image resizing" href="http://timthumb.googlecode.com/svn/trunk/timthumb.php" target="_blank">timthumb</a> script for resizing. Look at the <code>timthumb.php</code> comment block for parameters and usage. The <code>timthumb.php</code> file is included in the <em>hijriah</em> theme. </span></p>
<p><span style="font-weight: normal; font-size: 13px;">I must say that writing a library type plugin was much simple than I thought. So, don&#8217;t hesitate to give it a try as the more you learn, the more comfortable you will be about customizing WordPress. I learned a lot about theme development during this process and now feel comfortable enough to develop a custom theme. I&#8217;ll write about that experience in a future post.</span></p>
<a name="wptoc_0_0_6"></a><h3>Download the Plugin</h3>
<p><a href="http://www.turingtarpit.com/wp-content/uploads/2009/03/get-the-image-link.zip"><img class="alignnone size-full wp-image-233" title="Download get-the-image-link.zip" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/download_btn.jpg" alt="download_btn" width="101" height="34" /></a></p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.turingtarpit.com/2009/03/get-the-image-link/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>The tweetcoding learning experience</title>
		<link>http://www.turingtarpit.com/2009/03/the-tweetcoding-learning-experience/</link>
		<comments>http://www.turingtarpit.com/2009/03/the-tweetcoding-learning-experience/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 06:48:48 +0000</pubDate>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[game balance]]></category>
		<category><![CDATA[gameplay]]></category>
		<category><![CDATA[micro blogging]]></category>
		<category><![CDATA[social networks]]></category>
		<category><![CDATA[tweetcoding]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.turingtarpit.com/?p=65</guid>
		<description><![CDATA[I quickly became <span style="text-decoration: line-through;">interested in</span> addicted to Grant Skinner's genius idea: <em>tweetcoding</em>. What is it? It's a programming challenge where you try to develop "something cool" using Actionscript in 140 characters. What can you learn form 140 chars? Quite a bit actually. When the compiler strict mode is off, some very interesting shortcuts are possible. There was a different group learning dynamic that was quite interesting.]]></description>
				<content:encoded><![CDATA[<p>I quickly became <span style="text-decoration: line-through;">interested in</span> <ins>addicted to</ins> Grant Skinner&#8217;s genius idea: <em>tweetcoding</em>. What is it? It&#8217;s a programming challenge where you try to develop &#8220;something cool&#8221; using Actionscript in 140 characters. The 140 chars are a hard limit as you have to submit your code via a tweet.</p>
<p>The &#8220;something cool&#8221; should be taken literally. In this first go-around, the judging criteria was decided after the submission deadline. This reminded me of Seth Godin&#8217;s <a href="http://www.amazon.com/gp/product/1591842336/103-5805607-3547849?ie=UTF8&amp;tag=chandimcumara-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1591842336" target="_blank">Tribes</a> where a tribe leader doesn&#8217;t need to have every detail ironed out. Grant just threw out the idea with some &#8220;gimme&#8221; code,  got the heck out of the way and watched wonderful things happen.</p>
<p>The initial <a href="http://gskinner.com/playpen/tweetcoding.html" target="_blank">rules</a> were all we had to begin with. However, things got really interesting after Robert Cadena developed the tweetcoding integrator at <a href="http://tweetcoding.machine501.com" target="_blank">http://tweetcoding.machine501.com</a>. This page lists all the #tweetcoding tweets with the code submissions compiled into SWFs.  Now we could look at everyone&#8217;s submissions, run the apps on the browser ( as opposed to copying and pasting each into a .fla ) and learn some new tricks ( as well as some bad programming habits ).</p>
<a name="wptoc_0_0_0"></a><h4>What can you learn form 140 chars?</h4>
<p>Quite a bit actually. When the compiler <em>strict mode</em> is off, some very interesting shortcuts are possible. For me, the big ideas were the most interesting as opposed to the little coding efficiencies discovered during the process. Don&#8217;t get me wrong, trying to figure out the best way to implement a loop in the smallest number of characters is a very interesting challenge. However, there was a different group learning dynamic that was more interesting.</p>
<p>I think we spent as much time looking at each others&#8217; submissions and learning new ways of doing things as we did coding our own submissions. Now that submissions have closed, it was cool to take a step back and see how the applications evolved over time as folks learned new techniques from each other.</p>
<a name="wptoc_0_0_1"></a><h4><strong>Learning happened in big leaps</strong></h4>
<p>When you start from the <a href="http://tweetcoding.machine501.com" target="_blank">early entries</a> at the bottom of the page and work your way up it provides an insight into the <em><strong>evolution of collective thought of a learning community</strong></em>. Learning happened, not in incremental steps, but in sudden leaps as  innovative implementations were submitted.</p>
<p>For example, the first few submissions were non-interactive circles and line drawings built on top of Grant&#8217;s first example. Then <a href="http://twitter.com/mikeysee" target="_blank">@mikeysee</a> (Michael Cann) started to use the mouse coordinates. There were a couple of submissions that used mouse coordinates after that. Then there was a stage where folks started to experiment with color. And so it went, with each new innovation or technique adopted by subsequent submissions.</p>
<p>Some of the big learning leaps that come to mind are: Using the Flash 10 3D parameters (cheap motion), using Bitmaps to draw display objects (less code). using Fill interference (cheap visual complexity) ,  cheap particle motion,  using perlin noise, generating audio etc. When I say cheap, I mean an efficient minimalist way of doing something in as few characters as possible.</p>
<a name="wptoc_0_0_2"></a><h4>Settling into comfort zones</h4>
<p>After a while. the episodic learning leaps were not as visible as more and more developers joined in and settled into their comfort zones. Most developers settled on an idea or technique and churned out a few submissions based on that. They then moved onto another technique.</p>
<p>However, there were exceptions like <a href="http://twitter.com/quasimondo" target="_blank">@quasimondo</a> (Mario Klingemann) who churned out an <a href="http://www.quasimondo.com/archives/000686.php" target="_blank">incredible array of eclectic stuff</a> in rapid sequence.</p>
<p>Now the community had more depth with novices and experts with good grasp of mathematics and trigonometry joining in and submitting some really fresh stuff.</p>
<a name="wptoc_0_0_3"></a><h4>My personal learning experience ( described in terms of comfort zones )</h4>
<p>I initially started by trying to create &#8220;something cool&#8221; as that was the only critera that was out there. I remembered a <a href="http://www.gotoandlearn.com/" target="_parent">screencast by Lee Brimelow</a> on some interesting visual effects created with repeated application of  Filters to a BitmapData object. I believe he repeatedly applied the blur and scroll filters to creat an effect like fire. It was an interesting technique in that you draw something on stage and then draw what is on stage onto a transparent BitmapData object with filters and matrix transformations.</p>
<a name="wptoc_0_0_4"></a><h4>Zone 1: Make it colorful and interesting using BitmapData scrolling</h4>
<p>During these early stages I was just trying to get my foot in the door. No great inspirational ideas, just try to make &#8220;something cool.&#8221; However much I tried, I just couldn&#8217;t keep anything that had a blur filter within 140 chars. So, it had to be something that just had scrolling and color. So that was my first comfort zone.</p>
<a name="wptoc_4_1_0"></a><h5>Line scroller</h5>
<p>My first submission was &#8220;Line Scroller&#8221;<strong> </strong>which was very leaky.  The following bug-free version was submitted later. Something I learned in this first submission was a minimalist way to choose a random color.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">b</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">550</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">400</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span>
ls<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">,</span>r<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>1<span style="color: #000066; font-weight: bold;">.</span>67e7<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>lt<span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scroll</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,-</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p><a title="Line Scroller" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/scroll.swf" target="_blank"><img class="alignnone size-full wp-image-39" title="click_to_open_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/click_to_open_btn.jpg" alt="click_to_open_btn" width="101" height="34" /></a></p>
<a name="wptoc_4_1_1"></a><h5>Paint Spill</h5>
<p>Paint Spill is very similar to the line scroller in that it followed the same principle of scrolling. I experimented with bit shifting to choose a random set of  colors in this submission.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">!</span>i<span style="color: #000066; font-weight: bold;">?</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">550</span><span style="color: #000066; font-weight: bold;">,</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>ls<span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">,</span>r<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>1e7<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #004993;">mouseX</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
mt<span style="color: #000000;">&#40;</span>o<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=r<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>lt<span style="color: #000000;">&#40;</span>o<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scroll</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p><a title="Paint Spill" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/paintspill.swf" target="_blank"><img class="alignnone size-full wp-image-39" title="click_to_open_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/click_to_open_btn.jpg" alt="click_to_open_btn" width="101" height="34" /></a></p>
<a name="wptoc_0_0_5"></a><h4>Zone 2: Make it interactive using mouse input</h4>
<p>I tried to have some user interaction in all my submissions. I really liked some of the self-running submissions that drew some amazing recursive shapes with 3D transformations. However, that wasn&#8217;t my comfort zone. I decided to concentrate on giving the user some control to draw &#8220;something cool.&#8221;</p>
<p>The mouse was the cheapest way to record user input and make things interactive. Recording mouse coordinates were very cheap as you can directly access the MouseX and MouseY globals. Intercepting mouse clicks, mouse downs and mouse up were very expensive as they require event handlers.</p>
<p>I was awestruck when the first submission that recorded microphone input came along. Here was another input method that we don&#8217;t usually think about.</p>
<p>My next submission was a painting program. The first &#8220;painting&#8221; type submission was by <a href="http://twitter.com/Scarybug" target="_blank">@scarybug</a>. I went a little further by allowing the user to choose from a set of 10 colors by repeated mouse clicks. This includes something I learned from another submission: You can call a function by  using only its function name ( without the parentheses ) if you just want the default values for its arguments.</p>
<a name="wptoc_5_1_0"></a><h5>Circle Paint</h5>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript3" style="font-family:monospace;">t=<span style="color: #990000;">'mouse'</span><span style="color: #000066; font-weight: bold;">;</span>l=<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000066; font-weight: bold;">;</span>
l<span style="color: #000000;">&#40;</span>t<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'Down'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>ls<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">,</span>1<span style="color: #000066; font-weight: bold;">.</span>67e7<span style="color: #000066; font-weight: bold;">*</span>s<span style="color: #000000;">&#40;</span>m<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">++%</span>10<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>l<span style="color: #000000;">&#40;</span>t<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'Up'</span><span style="color: #000066; font-weight: bold;">,</span>ls<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<p><a title="Circle Paint" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/paint.swf" target="_blank"><img class="alignnone size-full wp-image-39" title="click_to_open_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/click_to_open_btn.jpg" alt="click_to_open_btn" width="101" height="34" /></a></p>
<p>I couldn&#8217;t resist including a little masterpiece drawn with a 140 char paint program.</p>
<p><img class="alignnone size-medium wp-image-87" title="Drawn with Circle Paint" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/2645760-300x218.jpg" alt="Drawn with Circle Paint" width="300" height="218" /></p>
<a name="wptoc_0_0_6"></a><h4>Zone 3: Make it play worthy using casual gaming concepts</h4>
<p>Building on my effort to make things interactive, I decided to concentrate exclusively on games. In 140 characters you can only do so much in terms of gameplay.</p>
<p>The first issue was what can be sacrificed without harming the overall experience. The first to go was the winning condition. I couldn&#8217;t waste precious characters in a game loop that checks to see if the player has won. Winning had to be visual and obvious to the player. For example, if you kill all the aliens, you win. If you drop the ball, you lose.</p>
<p>The next issue was the instructions. These had to go on a separate tweet. The other aspect was to develop 140 char backstory to develop motivation to play. If you thought coding a game in 140 chars was hard, try to write a backstory or game instructions in 140 chars.</p>
<p>Developing games in 140 chars is hard! The key is to figure out quickly if an idea is going to work or not. If not, go onto something else or try a variation. For example, the Juggle submission initially started out as a &#8220;Bubble Wrap&#8221; game. It then moved into a balloon popping game before finally settling into the ball juggler.</p>
<p>Most of the unique features were encountered by pure chance and included. For example, the ball disappearing off the top of the stage when volleyed just happened while I was balancing game parameters. I could see that it added to the gameplay by introducing an additional challenge of predicting where the ball would appear next.</p>
<p>My final three submissions were all games.</p>
<a name="wptoc_6_1_0"></a><h5>The Horde</h5>
<p>Lame backstory:</p>
<p style="padding-left: 30px;">Kill one and another takes its place. The only option is to give up and let em through. Or you will go insane!!!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span><span style="color: #000000;">&#40;</span>a <span style="color: #0033ff; font-weight: bold;">in</span> o<span style="color: #000000;">&#41;</span>a<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">+</span>=s<span style="color: #000000;">&#40;</span>a<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>a<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">hitTestPoint</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>a<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">?</span><span style="color: #000000;">&#40;</span>o<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>=<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=r<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">550</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span></pre></td></tr></table></div>

<p><a title="The Horde" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/horde.swf" target="_blank"><img class="alignnone size-full wp-image-39" title="click_to_open_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/click_to_open_btn.jpg" alt="click_to_open_btn" width="101" height="34" /></a></p>
<a name="wptoc_6_1_1"></a><h5>Juggle</h5>
<p>Instructions:</p>
<p style="padding-left: 30px;">Use mouse pointer to volley the ball. How many times can you volley before it falls?</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>p=u=v=a=<span style="color: #000066; font-weight: bold;">.</span>1<span style="color: #000066; font-weight: bold;">;</span>q=<span style="color: #000000; font-weight:bold;">99</span><span style="color: #000066; font-weight: bold;">;</span>i=m<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#40;</span>q<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span>m=<span style="color: #004993;">mouseX</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000000;">&#40;</span>p<span style="color: #000066; font-weight: bold;">-</span><span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000; font-weight:bold;">400</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>v=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">;</span>u=q<span style="color: #000066; font-weight: bold;">-</span>m<span style="color: #000000;">&#125;</span>
v<span style="color: #000066; font-weight: bold;">+</span>=a<span style="color: #000066; font-weight: bold;">;</span>p<span style="color: #000066; font-weight: bold;">+</span>=v<span style="color: #000066; font-weight: bold;">;</span>q<span style="color: #000066; font-weight: bold;">+</span>=u<span style="color: #000066; font-weight: bold;">*.</span>25<span style="color: #000066; font-weight: bold;">;</span>g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>ls<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>g<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span>q<span style="color: #000066; font-weight: bold;">,</span>p<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><a title="Juggle" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/juggle.swf" target="_blank"><img class="alignnone size-full wp-image-39" title="click_to_open_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/click_to_open_btn.jpg" alt="click_to_open_btn" width="101" height="34" /></a></p>
<a name="wptoc_6_1_2"></a><h5>Guess the Number</h5>
<p>Instructions:</p>
<p style="padding-left: 30px;">Guess the number between 0 and 99 inclusive. Move to mouseY=0 (off top of stage) to guess (2nd num). &gt; &lt; = shows if it&#8217;s too high, low or just right!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>t=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=p=<span style="color: #000000; font-weight:bold;">99</span><span style="color: #000066; font-weight: bold;">;</span>i=<span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>r<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>p<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> g=<span style="color: #004993;">c</span>=<span style="color: #990000;">''</span><span style="color: #000000;">&#125;</span>
a=<span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>g=a<span style="color: #000066; font-weight: bold;">;</span>g<span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">?</span><span style="color: #004993;">c</span>=<span style="color: #990000;">'&amp;gt;'</span><span style="color: #000066; font-weight: bold;">:</span>g<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">?</span><span style="color: #004993;">c</span>=<span style="color: #990000;">'&amp;lt;'</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">c</span>=<span style="color: #990000;">'='</span><span style="color: #000000;">&#125;</span>
t<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=a<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">' '</span><span style="color: #000066; font-weight: bold;">+</span>g<span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">c</span></pre></td></tr></table></div>

<p><a title="Guess the Number" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/guess.swf" target="_blank"><img class="alignnone size-full wp-image-39" title="click_to_open_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/click_to_open_btn.jpg" alt="click_to_open_btn" width="101" height="34" /></a></p>
<a name="wptoc_0_0_7"></a><h4>Judging criteria</h4>
<p>Grant skinner sent this tweet yesterday:</p>
<blockquote><p>#tweetcoding will be judged on aesthetics, idea, interaction, uniqueness, &amp; code. Should have the results early next week.</p></blockquote>
<p>The criteria are pretty good with equal chance for interactive and non-interactive submissions to score well. What are my chances? I&#8217;ll probably score high on <em>idea</em> and <em>interaction</em>. Maybe in <em>uniqueness</em> as well. However, I&#8217;ve done nothing special in terms of <em>aesthetics</em> and <em>code</em>.</p>
<p>Overall it was a fun learning experience. Looking forward to the results.</p>
<a name="wptoc_0_0_8"></a><h4>Update: Results</h4>
<p><a href="http://gskinner.com/playpen/tweetcoding_0/" target="_blank">http://gskinner.com/playpen/tweetcoding_0/</a></p>
<p>&#8220;Juggle&#8221; got an honorable mention. The winning entry by <a href="http://twitter.com/tomee6" target="_blank">@tomee6 </a>was an exceptional <a href="http://gskinner.com/playpen/tweetcoding_0/tc_1267109791.swf" target="_blank">diagonal snake</a> game.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.turingtarpit.com/2009/03/the-tweetcoding-learning-experience/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PureMVC Console &#8211; Shines a light inside the MVC triad</title>
		<link>http://www.turingtarpit.com/2009/03/puremvc-console-shines-a-light-inside-the-mvc-triad/</link>
		<comments>http://www.turingtarpit.com/2009/03/puremvc-console-shines-a-light-inside-the-mvc-triad/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 22:31:38 +0000</pubDate>
		<dc:creator>Chandima Cumaranatunge</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PureMVC]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.turingtarpit.com/?p=26</guid>
		<description><![CDATA[I was checking the PureMVC website today and came across PureMVC Console developed by the good folks at Kap Lab. This is an absolutely invaluable tool to figure out in real-time what is going on inside the Flex PureMVC framework in a running application.]]></description>
				<content:encoded><![CDATA[<p>I was checking the <a href="http://puremvc.org/">PureMVC</a> website today and came across <a href="http://lab.kapit.fr/display/puremvcconsole/PureMVC+Console">PureMVC Console</a> developed by the good folks at <a href="http://lab.kapit.fr/display/kaplabhome/Home">Kap Lab</a>. This is an absolutely invaluable tool to figure out in real-time what is going on inside the Flex PureMVC framework in a running application. PureMVC is quite lightweight and is very good at keeping things hidden under the hood. However, during development it is essential to get a snapshot of application state and the sequence of notifications. This is exactly what PureMVC Console does. It provides you with a flashlight to peer into your Notifications, Commands, Mediators and Proxies and track notifications and application flow in response to user gestures and other events.</p>
<div>
<p>For example, if you need to know the state of your <em>value objects</em> at any point, just click on the <em>Proxies</em>tab and select the proxy.</p>
<p><a title="Inspecting the value objects inside the proxies" rel="shadowbox[PureMVC Console]" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/vos.jpg"><img class="alignnone size-medium wp-image-28" title="Inspecting the value objects inside the proxies" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/vos-300x257.jpg" alt="Inspecting the value objects inside the proxies" width="300" height="257" /></a></p>
<p>If you want to check the sequence of actions taking place in your application from startup, just click on the PureMVC flow tab. This is very useful for debugging as it provides a record of the command invocation sequence and will help answer questions like &#8220;why did this command execute before this other one?&#8221;</p>
<p><a title="Inspecting the flow of the application" rel="shadowbox[PureMVC Console]" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/flow1.jpg"><img class="alignnone size-medium wp-image-32" title="Inspecting the flow of the application" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/flow1-300x259.jpg" alt="Inspecting the flow of the application" width="300" height="259" /></a></p>
<p>I am a big fan of the <a href="http://osflash.org/xray">Xray logger</a> developed for Flash AS2 and had to try out this console right away as this is the first console with similar utility for AS3, I integrated the console into the <a href="http://trac.puremvc.org/Demo_AS3_Flex_EmployeeAdmin">Employee Admin demo</a> (developed by Cliff Hall).</p>
<a name="wptoc_0_0_0"></a><h4>Employee Admin Demo with integrated Console</h4>
<p>Click on the button below to open the Employee Admin demo. Make sure that you hit <strong>Ctrl+Alt+F6</strong> to open the console ( <strong>Alt</strong> = <strong>Option</strong> in OSX ).</p>
<p><a href="http://www.turingtarpit.com/wp-content/uploads/2009/03/employeeadmin.swf" target="_blank"><img class="alignnone size-full wp-image-39" title="click_to_open_btn" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/click_to_open_btn.jpg" alt="click_to_open_btn" width="101" height="34" /></a></p>
<a name="wptoc_0_0_1"></a><h4>Integrating the console into the <em>Employee Admin</em> Demo</h4>
<p>The console is very easy to integrate into a new or existing app &#8211; just follow the <a href="http://lab.kapit.fr/display/puremvcconsole/Integration+Guide">integration guide</a>. The ease of integration is a huge plus as it is simply injected before the application is invoked.</p>
<a name="wptoc_1_1_0"></a><h5>1. Add the PureMVC Console SWC into your library</h5>
<p>First drag-and-drop the PureMVC Console swc file into the libs folder in your Flex project. There is a different swc if you are using the multi-core version of PureMVC.</p>
<p><img class="alignnone size-full wp-image-50" title="project_files" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/project_files.jpg" alt="project_files" width="226" height="199" /></p>
<a name="wptoc_1_1_1"></a><h5>2. Add the console component into your application</h5>
<p>For an MXML app, you need to add an additional  <code>xmlns:kapit="fr.kapit.*"</code> name space attribute to the  <code>&lt;mx:Application&gt;</code> tag and then add the  <code>&lt;kapit:PureMVCConsole/&gt;</code> component before the closing <code>&lt;/mx:Application&gt;</code> tag (see <a href="http://lab.kapit.fr/display/puremvcconsole/Integration+Guide">integration guide</a>). I added this to the <code>EmployeeAdmin.mxml</code> file which is the default application for the project.</p>
<a name="wptoc_1_1_2"></a><h5>3. Add a new SwitchFacade parent class for you application facade</h5>
<p>The next step is to create a new <code>SwitchFacade</code> class and modify your application facade so that it inherits from <code>SwitchFacade</code> ( instead of the PureMVC <code>Facade</code> class ). The <code>SwitchFacade</code> class is the same for all apps and can be copied and pasted from the <a href="http://lab.kapit.fr/display/puremvcconsole/Integration+Guide">integration guide</a>. Make sure you create the <code>SwitchFacade</code> class in the same location in the folder hierarchy where you current application facade class resides. You can right click on the enclosing folder (employeeadmin in my case) and create <strong>New &gt; ActionScript Class</strong> and type in <code>SwitchFacade</code> for the class name. Now copy and paste the code.</p>
<p><img class="alignnone size-full wp-image-54" title="project_files2" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/project_files2.jpg" alt="project_files2" width="345" height="415" /></p>
<p>Injecting the  <code>SwitchFacade</code> class allows you to control the integration of the console using compiler directives as opposed to changing code when it comes time to ship the application. <code>SwitchFacade</code> extends the PureMVC <code>Facade</code> class if the <em>CONFIG::release</em> directive is set. Conversely, if the <em>CONFIG::debug</em> directive is set ( and <em>CONFIG::release</em> is unset), <code>SwitchFacade</code> extends  <code>DebugFacade</code> that has all the debug stuff required by the console.</p>
<a name="wptoc_1_1_3"></a><h5>4. Set the compiler directives</h5>
<p>To control which facade gets extended you need to add the <em>CONFIG::release</em> and <em>CONFIG::debug</em> directives in the compiler options. Right click on the <em>Project folder</em> and choose <em>properties</em> from the contextual menu. Now click on <em>Flex Compiler</em> option to add the additional compiler directives in the <em>Additional Compiler Arguments</em> field.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">-define=CONFIG::release,false -define=CONFIG::debug,true</pre></td></tr></table></div>

<p><a title="Setting compiler options" rel="shadowbox[PureMVC Console]" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/compiler_options.jpg"><img class="alignnone size-medium wp-image-57" title="compiler_options" src="http://www.turingtarpit.com/wp-content/uploads/2009/03/compiler_options-300x240.jpg" alt="compiler_options" width="300" height="240" /></a></p>
<p><a title="Setting compiler options" rel="shadowbox[PureMVC Console]" href="http://www.turingtarpit.com/wp-content/uploads/2009/03/compiler_options.jpg"></a><br />
Reset the directives for the release version.</p>
<p><strong>Recap of cool features:</strong></p>
<ul>
<li>Very easy to integrate into a new or existing app.</li>
<li>Works with the standard version of Flash ( does not need the debugger version ).</li>
<li>Integration is controlled by using compiler options ( just change a compiler option for the release version ).</li>
</ul>
<p>Simple to integrate and keeps out of the way of you doing the job of coding and debugging &#8211; excellent!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.turingtarpit.com/2009/03/puremvc-console-shines-a-light-inside-the-mvc-triad/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 3.140 seconds. --><!-- Cached page generated by WP Super-Cache on 2013-03-07 14:22:17 -->
<!-- super cache -->
