<?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>Made of Everything You&#039;re Not &#187; JavaScript</title>
	<atom:link href="http://blog.ericlamb.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:00:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Tablekit: HTML Table Enhancements</title>
		<link>http://blog.ericlamb.net/2009/12/tablekit-html-table-enhancements/</link>
		<comments>http://blog.ericlamb.net/2009/12/tablekit-html-table-enhancements/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 21:29:37 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[TableKit]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=2354</guid>
		<description><![CDATA[I&#8217;ve been using Jquery a lot lately and have absolutely fallen in love with it; so much so that I&#8217;ve pretty much walked away from Prototype and Scriptaculous entirely. Not to take anything away from Prototype but Jquery is just a lot more&#8230; well, it&#8217;s just more fun to work with. That being said, I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a title="jQuery" href="http://jquery.com/" onclick="return TrackClick('http%3A%2F%2Fjquery.com%2F','jQuery')" target="_blank">Jquery</a> a lot lately and have absolutely fallen in love with it; so much so that I&#8217;ve pretty much walked away from <a title="Prototype JavaScript Library" href="http://www.prototypejs.org/" onclick="return TrackClick('http%3A%2F%2Fwww.prototypejs.org%2F','Prototype+JavaScript+Library')" target="_blank">Prototype</a> and <a title="script.aculo.us" href="http://script.aculo.us/" onclick="return TrackClick('http%3A%2F%2Fscript.aculo.us%2F','script.aculo.us')" target="_blank">Scriptaculous</a> entirely. Not to take anything away from Prototype but Jquery is just a lot more&#8230; well, it&#8217;s just more fun to work with. That being said, I wanted to give a shout out to one of the cooler toys Prototype has: <a title="TableKit" href="http://www.millstream.com.au/view/code/tablekit/" onclick="return TrackClick('http%3A%2F%2Fwww.millstream.com.au%2Fview%2Fcode%2Ftablekit%2F','TableKit')" target="_blank">TableKit</a>.</p>
<div id="attachment_2749" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/12/TableKit.gif" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F12%2FTableKit.gif','TableKit')"><img class="size-medium wp-image-2749" title="TableKit" src="http://blog.ericlamb.net/wp-content/uploads/2009/12/TableKit-300x216.gif" alt="TableKit" width="300" height="216" /></a><p class="wp-caption-text">TableKit</p></div>
<p>TableKit is a table enhancement JavaScript library written using Prototype provided by <a title="Millstream Software" href="http://www.millstream.com.au/" onclick="return TrackClick('http%3A%2F%2Fwww.millstream.com.au%2F','Millstream+Software')" target="_blank">Millstream Software</a>. In a nutshell TableKit allows you to easily create sortable, resizable and editable tables. Implementation is extremely simple and, according to <a title="Robert Speer" href="http://www.robertspeer.com/blog/tablekit-a-easy-sortable-table-based-on-prototypejs/" onclick="return TrackClick('http%3A%2F%2Fwww.robertspeer.com%2Fblog%2Ftablekit-a-easy-sortable-table-based-on-prototypejs%2F','Robert+Speer')" target="_blank">Robert Speer</a>, designers don&#8217;t have an issue working with it (I haven&#8217;t had the pleasure of having a designer work with it yet):</p>
<blockquote><p>Many times using scripts I find on the Internet turns into kind of a hassle. They are usually unfinished side projects, or are kind of bloated and slow.</p>
<p>TableKit is not one of those scripts, it’s fast &amp; easy to implement. Development time was low, and the designers didn’t complain too much about working with it.</p></blockquote>
<p>Robert&#8217;s right; TableKit is <em>extremely</em> easy to work with. TableKit works by using css class overloading to tell the system how to handle a table. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;table class=&quot;sortable resizable editable&quot;&gt;</pre></div></div>

<p>indicates that the table should, obviously, be sortable, resizable and editable. There are all sorts of other options available, which you can read about in the documentation. If you have to use Prototype for a project and you need some jazz TableKit is a good fit. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/12/tablekit-html-table-enhancements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to jQuery UI</title>
		<link>http://blog.ericlamb.net/2009/11/introduction-to-jquery-ui/</link>
		<comments>http://blog.ericlamb.net/2009/11/introduction-to-jquery-ui/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 13:00:49 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1931</guid>
		<description><![CDATA[Building the fancy, web 2.0 / Ajaxy, user interfaces for a web application we&#8217;ve all come to expect is, frankly, a pain in the ass. Depending on the JavaScript library you&#8217;re using there&#8217;s usually some addon library to extend the functionality for UI which helps make it easier and ease the pain. If you&#8217;re using [...]]]></description>
			<content:encoded><![CDATA[<p>Building the fancy, web 2.0 / Ajaxy, user interfaces for a web application we&#8217;ve all come to expect is, frankly, a pain in the ass. Depending on the JavaScript library you&#8217;re using there&#8217;s usually some addon library to extend the functionality for UI which helps make it easier and ease the pain. If you&#8217;re using <a title="jQuery" href="http://jquery.com/" onclick="return TrackClick('http%3A%2F%2Fjquery.com%2F','jQuery')" target="_blank">jQuery</a> (and to be honest I&#8217;m more of a Prototype guy) a good library is <a title="jQuery Ui" href="http://jqueryui.com/home" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fhome','jQuery+Ui')" target="_blank">jQuery Ui</a>.</p>
<div id="attachment_2609" class="wp-caption aligncenter" style="width: 268px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/11/JQuery_UI_Logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F11%2FJQuery_UI_Logo.png','JQuery+UI')"><img class="size-full wp-image-2609" title="JQuery UI" src="http://blog.ericlamb.net/wp-content/uploads/2009/11/JQuery_UI_Logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F11%2FJQuery_UI_Logo.png','JQuery+UI')" alt="JQuery UI" width="258" height="93" /></a><p class="wp-caption-text">JQuery UI</p></div>
<p>According to the official site:</p>
<blockquote><p>jQuery UI is an open source library of interface components — <a href="http://jqueryui.com/demos" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fdemos','interactions%2C+full-featured+widgets%2C+and+animation+effects')" target="_blank">interactions, full-featured widgets, and animation effects</a> — based on the stellar <a href="http://jquery.com" onclick="return TrackClick('http%3A%2F%2Fjquery.com','jQuery+javascript+library')" target="_blank">jQuery javascript library</a>.  Each component is built according to <a href="http://docs.jquery.com/How_jQuery_Works" onclick="return TrackClick('http%3A%2F%2Fdocs.jquery.com%2FHow_jQuery_Works','jQuery%22s+event-driven+architecture')" target="_blank">jQuery&#8217;s event-driven architecture</a> (find something, manipulate it) and is <a href="http://jqueryui.com/docs/Theming" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fdocs%2FTheming','themeable')" target="_blank">themeable</a>, making it easy for developers of any skill level to integrate and extend into their own code.</p></blockquote>
<p>I only ran into it because of an update to WP-Click-Track and WordPress uses jQuery so I kinda had to. Not that it&#8217;s a bad thing; I like jQuery a little bit more because of jQuery UI.</p>
<p>One of the really cool things about jQuery UI is that there&#8217;s an online tool to generate a custom download specific to the project. Having worked with JavaScript libraries for a while I appreciate the customization and convenience of having the smallest footprint as possible. Kudos to them on that.</p>
<p>There&#8217;s also a <a title="jQuery UI Theme Builder" href="http://jqueryui.com/themeroller/" onclick="return TrackClick('http%3A%2F%2Fjqueryui.com%2Fthemeroller%2F','jQuery+UI+Theme+Builder')" target="_blank">Theme Builder</a> that gives a good overview of what&#8217;s available by default along with some preset themes to test; there&#8217;s a good deal of widgets there to work with. Almost, <em>almost</em>, makes me want to start a project with it.</p>
<div id="attachment_2617" class="wp-caption aligncenter" style="width: 215px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/11/jQuery-UI-ThemeRoller_1257127607785.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F11%2FjQuery-UI-ThemeRoller_1257127607785.png','jQuery+UI+-+ThemeRoller')"><img class="size-medium wp-image-2617" title="jQuery UI - ThemeRoller" src="http://blog.ericlamb.net/wp-content/uploads/2009/11/jQuery-UI-ThemeRoller_1257127607785-205x300.png" alt="jQuery UI - ThemeRoller" width="205" height="300" /></a><p class="wp-caption-text">jQuery UI - ThemeRoller</p></div>
<p>Implementation is really elegant too; if you know how jQuery works it&#8217;ll be pretty obvious. Otherwise take a look at the below for creating tabs:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;div id=&quot;tab-jquery-id&quot;&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;#tab1&quot;&gt;Tab 1&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab2&quot;&gt;Tab 2&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab3&quot;&gt;Tab 3&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab4&quot;&gt;Tab 4&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tab5&quot;&gt;Tab 5&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div id=&quot;tab1&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab2&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab3&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab4&quot;&gt;
&nbsp;
	&lt;/div&gt;
	&lt;div id=&quot;tab5&quot;&gt;
&nbsp;
	&lt;/div&gt;
&lt;/div&gt;
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">//&lt;![CDATA[</span>
jQuery<span style="color: #000;">&#40;</span>document<span style="color: #000;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #000;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #000;">&#40;</span>$<span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//jQuery UI 1.5.2 doesn't expect tab ID's at DIV, so we have to apply a hotfix instead</span>
	<span style="color: #003366; font-weight: bold;">var</span> needs_jquery_hotfix <span style="color: #339933;">=</span> <span style="color: #000;">&#40;</span><span style="color: #000;">&#40;</span>$.<span style="color: #660066;">ui</span>.<span style="color: #660066;">version</span> <span style="color: #339933;">===</span> undefined<span style="color: #000;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>$.<span style="color: #660066;">ui</span>.<span style="color: #660066;">version</span>.<span style="color: #660066;">match</span><span style="color: #000;">&#40;</span><span style="color: #009966; font-style: italic;">/^(1\.[7-9]|[2-9]\.)/</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #000;">&#40;</span><span style="color: #3366CC;">&quot;#tab-jquery-id&quot;</span><span style="color: #339933;">+</span><span style="color: #000;">&#40;</span>needs_jquery_hotfix <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;&gt;ul&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">tabs</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#123;</span>
		selected<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
	<span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span> 
	$<span style="color: #000;">&#40;</span><span style="color: #3366CC;">'.tab5:last'</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'tab5'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>As you can see there&#8217;s not much there in so far as design or class decorators go; most of that&#8217;s handled by jQuery itself as well as the generated css. The only thing to really worry about is adding the wrapper div id in the bottom JavaScript. Still, not a bad thing.</p>
<p>This, of course, barely scratched the surface of jQuery UI but it doesn&#8217;t get much more difficult. If you&#8217;re using jQuery for a library and you need to make something cool it&#8217;s definitely worth checking out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/11/introduction-to-jquery-ui/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bragging Tweets With TweetMeme</title>
		<link>http://blog.ericlamb.net/2009/06/bragging-tweets-with-tweetmeme/</link>
		<comments>http://blog.ericlamb.net/2009/06/bragging-tweets-with-tweetmeme/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 13:00:34 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[promotion]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1974</guid>
		<description><![CDATA[Fuck, I hate Twitter; yet another tool to allow people to collect, well&#8230; people really. As an example, I signed up for a Twitter account so I could test Twitter functionality for some projects I&#8217;m working on. I don&#8217;t use Twitter for anything but testing yet I get notices daily about users now following me [...]]]></description>
			<content:encoded><![CDATA[<p>Fuck, I hate Twitter; yet another tool to allow people to collect, well&#8230; people really. As an example, I signed up for a Twitter account so I could test Twitter functionality for some projects I&#8217;m working on. I don&#8217;t use Twitter for anything but testing yet I get notices <em>daily</em> about users now following me (and none of them are readers of this blog).</p>
<div id="attachment_1976" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/06/tweetmeme_logo.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F06%2Ftweetmeme_logo.jpg','Tweetmeme')"><img class="size-medium wp-image-1976" title="Tweetmeme" src="http://blog.ericlamb.net/wp-content/uploads/2009/06/tweetmeme_logo-300x58.jpg" alt="Tweetmeme" width="300" height="58" /></a><p class="wp-caption-text">Tweetmeme</p></div>
<p>Still, Twitter is all the rage and I do have to admit it is fun working with all the little toys people are making with the Twitter API (playing with the API is really FUN).</p>
<p>One such tool is <a title="TweetMeme" href="http://tweetmeme.com/" onclick="return TrackClick('http%3A%2F%2Ftweetmeme.com%2F','TweetMeme')" target="_blank">TweetMeme</a>.</p>
<p>Accoring to the TweetMeme site:</p>
<blockquote><p>Tweetmeme is a service which aggregates all the popular links on twitter to determine which links are popular. Tweetmeme is able to categorize these links into categories and subcategories, making it easy to filter out the noise to find what your interested in.</p>
<p>We make it easy for you to subscribe to each category and the most popular through aur RSS feeds and Twitter accounts, you can find out more about theses through our <a title="TweetMeme Help" href="http://help.tweetmeme.com/" onclick="return TrackClick('http%3A%2F%2Fhelp.tweetmeme.com%2F','TweetMeme+Help')" target="_blank">help</a>.</p></blockquote>
<p>TweetMeme has a few ways to integrate their data into your site. The easiest way works by giving site owners a little sliver of JavaScript to embed in their site. The JavaScript adds a little button to the page for one click tweeting on Twitter.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>mce<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">--&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;script src=&quot;http://tweetmeme.com/i/scripts/button.js&quot; type=&quot;text/javascript&quot;&gt;&lt;!--mce:1--&gt;&lt;/script&gt;</pre></div></div>

<p>The above creates a little icon:</p>
<div id="attachment_1985" class="wp-caption aligncenter" style="width: 65px"><img class="size-full wp-image-1985" title="TweetMeme Icon" src="http://blog.ericlamb.net/wp-content/uploads/2009/06/tweetmem_icon.jpg" alt="TweetMeme Icon" width="55" height="70" /><p class="wp-caption-text">TweetMeme Icon</p></div>
<p>In theory, the above is all you&#8217;ll need to do; just drop that slip into a page and you&#8217;re good to go. The reality is that there are a couple rules you need to follow.</p>
<p>First, make sure you&#8217;re using a custom title meta for your pages. If you don&#8217;t all your Tweets will have the same title. Not good.</p>
<p>Second, make sure the page in question is open to the Internet. Don&#8217;t try and lock the page behind a log in barrier or TweetMeme won&#8217;t be able to parse the page to get the URL and title information.</p>
<p>Last, TweetMeme caches the data so don&#8217;t expect the update to be instant; you will be disappointed. For example, on the <a title="Dark Void" href="http://blog.ericlamb.net/2009/06/dark-void-blog/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2009%2F06%2Fdark-void-blog%2F','Dark+Void')">Dark Void</a> site we are constantly being hit up by the client about the delay. You probably won&#8217;t see the number in the widget increment for a bit; there&#8217;s nothing you can do about it.</p>
<p>TweetMeme also offers a <a title="TweetMeme Widget" href="http://widget.tweetmeme.com/" onclick="return TrackClick('http%3A%2F%2Fwidget.tweetmeme.com%2F','TweetMeme+Widget')" target="_blank">widget</a>, which I admit I haven&#8217;t used and but it looks like it&#8217;s basically the same thing as <a title="A Look at Tweetizen" href="http://blog.ericlamb.net/2009/04/a-look-at-tweetizen/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2009%2F04%2Fa-look-at-tweetizen%2F','A+Look+at+Tweetizen')">Tweetizen</a>.</p>
<p>It should be noted that I wasn&#8217;t able to get the TweetMeme Widget to work. Ever. It just shows a blank page. Good job, TweetMeme.</p>
<p>And of course, there&#8217;s the TweetMeme API. You just have to have an API to be taken seriously. It does seem a little redundant to have an API that&#8217;s populated with data from the Twitter API but, whatever. I haven&#8217;t looked at the API too much either but it doesn&#8217;t look too outside the norm for most APIs.</p>
<p>Anyway, there you go; TweetMeme. Marketers love it. I&#8217;m ambivalent.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/06/bragging-tweets-with-tweetmeme/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Look at Tweetizen</title>
		<link>http://blog.ericlamb.net/2009/04/a-look-at-tweetizen/</link>
		<comments>http://blog.ericlamb.net/2009/04/a-look-at-tweetizen/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 13:10:55 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[tweetizen]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1555</guid>
		<description><![CDATA[For those of you living under a rock for the past couple years Twitter is all the rage; for what I have no idea though. As I&#8217;ve said previously, Twitter&#8217;s pretty stupid, but fuck man, the clients like it so what are you gonna do. As part of my research into all things Twitter I [...]]]></description>
			<content:encoded><![CDATA[<p>For those of you living under a rock for the past couple years <a href="http://www.twitter.com/" onclick="return TrackClick('http%3A%2F%2Fwww.twitter.com%2F','Twitter')" title="Twitter" target="_blank">Twitter</a> is all the rage; for what I have no idea though. As I&#8217;ve said previously, <a href="http://blog.ericlamb.net/2009/04/arc90-twitter-api-service-part-1/" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2F2009%2F04%2Farc90-twitter-api-service-part-1%2F','Arc90+Twitter+API+Service+Part+1')" title="Arc90 Twitter API Service Part 1">Twitter&#8217;s pretty stupid</a>, but fuck man, the clients like it so what are you gonna do.</p>
<div id="attachment_1556" class="wp-caption aligncenter" style="width: 291px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/04/tweetizen_logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F04%2Ftweetizen_logo.png','Tweetizen')"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/04/tweetizen_logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F04%2Ftweetizen_logo.png','Tweetizen')" alt="Tweetizen" title="Tweetizen" width="281" height="73" class="size-full wp-image-1556" /></a><p class="wp-caption-text">Tweetizen</p></div>
<p>As part of my research into all things Twitter I recently took a look at <a href="http://www.tweetizen.com/index.php" onclick="return TrackClick('http%3A%2F%2Fwww.tweetizen.com%2Findex.php','Tweetizen')" title="Tweetizen" target="_blank">Tweetizen</a>. According the Tweetizen website:</p>
<blockquote><p>
Tweetizen is a simple web-based tool designed to help you filter the daily influx of tweets, and easily find the ones that are relevant to you.
</p></blockquote>
<p>It&#8217;s basically a site that uses the Twitter API to aggregate tags and keywords. Tweetizen doesn&#8217;t have an API of it&#8217;s own though I suspect this is would be a simple thing for them to implement; unless they&#8217;re pussies that is. </p>
<p>Are you pussies Tweetizen?</p>
<p>Instead of an API they do offer a cheap JavaScript widget that can be embedded into a website if you&#8217;re into half-assing the concept of &#8220;sharing&#8221;. Just embed the below into the head of your website:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"> &lt;style type=&quot;text/css&quot;&gt;@import &quot;http://embed.tweetizen.com/embed.css&quot;;&lt;/style&gt;</pre></div></div>

<p>And embed the below somewhere in your site:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;twtzn&quot; class=&quot;tweetizen_embed&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://embed.tweetizen.com/tweetizen.embed.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://embed.tweetizen.com?id=twtzn&amp;g=Breaking+News&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>It looks just like every other widget they offer but you can style it using CSS if you wish. I imagine it would be incredibly tedious to really make the widget stand apart from the pack with just CSS but it&#8217;s all they offer. They do provide a sample CSS file for usage along with instructions on the <a href="http://www.tweetizen.com/faq" onclick="return TrackClick('http%3A%2F%2Fwww.tweetizen.com%2Ffaq','Tweetizen+FAQ')">Tweetizen FAQ</a> page to help the process along.</p>
<p>For me Tweetizen is a lose; but as mentioned above the clients love this shit so I&#8217;m in whether I like it or not.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/04/a-look-at-tweetizen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing Web Sites for Blackberry</title>
		<link>http://blog.ericlamb.net/2009/04/developing-web-sites-for-blackberry/</link>
		<comments>http://blog.ericlamb.net/2009/04/developing-web-sites-for-blackberry/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 12:57:03 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[blackberry]]></category>
		<category><![CDATA[Blackberry Wallet]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1360</guid>
		<description><![CDATA[The other day I read an article on Sitepoint called iPhone Development: 12 Tips To Get You Started that I thought was going to go into the details of iPhone App development. Instead it&#8217;s an article about how to make your website render properly on an iPhone. Not what I was expecting but since I [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I read an article on Sitepoint called <a title="iPhone Development: 12 Tips To Get You Started" href="http://www.sitepoint.com/article/iphone-development-12-tips/" onclick="return TrackClick('http%3A%2F%2Fwww.sitepoint.com%2Farticle%2Fiphone-development-12-tips%2F','iPhone+Development%3A+12+Tips+To+Get+You+Started')">iPhone Development: 12 Tips To Get You Started</a> that I thought was going to go into the details of iPhone App development. Instead it&#8217;s an article about how to make your website render properly on an iPhone. Not what I was expecting but since I <em>am</em> a web developer it was still worth while.</p>
<div id="attachment_1432" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/04/blackberry-browser-basic.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F04%2Fblackberry-browser-basic.jpg','Blackberry+Browser')"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/04/blackberry-browser-basic-300x240.jpg" alt="Blackberry Browser" title="Blackberry Browser" width="300" height="240" class="size-medium wp-image-1432" /></a><p class="wp-caption-text">Blackberry Browser</p></div>
<p>I don&#8217;t have an iPhone so I couldn&#8217;t get too excited about the content though. After reading the article I started thinking about how to get web sites to render nicely on the Blackberry.</p>
<p>RIM (the makers of the Blackberry) provides some extensive documentation on how best to <a title="develop web sites for the Blackberry" href="http://na.blackberry.com/eng/support/docs/subcategories/?userType=21&amp;category=BlackBerry+Browser" onclick="return TrackClick('http%3A%2F%2Fna.blackberry.com%2Feng%2Fsupport%2Fdocs%2Fsubcategories%2F%3FuserType%3D21%26amp%3Bcategory%3DBlackBerry%2BBrowser','develop+web+sites+for+the+Blackberry')" target="_blank">develop web sites for the Blackberry</a>. The topics include:</p>
<ol>
<li><a href="http://na.blackberry.com/eng/deliverables/5687/BlackBerry_Browser-4.7.0-US.pdf" onclick="return TrackClick('http%3A%2F%2Fna.blackberry.com%2Feng%2Fdeliverables%2F5687%2FBlackBerry_Browser-4.7.0-US.pdf','BlackBerry+Browser+-+Fundamentals+Guide')" title="BlackBerry Browser - Fundamentals Guide" target="_blank">BlackBerry Browser &#8211; Fundamentals Guide</a></li>
<li><a href="http://na.blackberry.com/eng/deliverables/5683/CSS_Reference.pdf" onclick="return TrackClick('http%3A%2F%2Fna.blackberry.com%2Feng%2Fdeliverables%2F5683%2FCSS_Reference.pdf','CSS+for+the+BlackBerry+Browser+-+Reference+Guide')" title="CSS for the BlackBerry Browser - Reference Guide" target="_blank">CSS for the BlackBerry Browser &#8211; Reference Guide</a></li>
<li><a href="http://na.blackberry.com/eng/deliverables/5682/HTML_Reference.pdf" onclick="return TrackClick('http%3A%2F%2Fna.blackberry.com%2Feng%2Fdeliverables%2F5682%2FHTML_Reference.pdf','HTML+for+the+BlackBerry+Browser+-+Reference+Guide')" title="HTML for the BlackBerry Browser - Reference Guide" target="_blank">HTML for the BlackBerry Browser &#8211; Reference Guide</a></li>
<li><a href="http://na.blackberry.com/eng/deliverables/5681/JavaScript_Reference.pdf" onclick="return TrackClick('http%3A%2F%2Fna.blackberry.com%2Feng%2Fdeliverables%2F5681%2FJavaScript_Reference.pdf','BlackBerry+Browser+-+JavaScript+Reference')" title="BlackBerry Browser - JavaScript Reference" target="_blank">BlackBerry Browser &#8211; JavaScript Reference</a></li>
</ol>
<p>One of the easiest thing you can do to play nice with the Blackberry browser is to use the Viewport and / or HandheldFriendly meta values.</p>
<p>The HandheldFriendly meta value tells the Blackberry browser the website is exactly what the name implies: handheld friendly. This allows the browser to make some assumptions about layout and structure.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta name=&quot;HandheldFriendly&quot; content=&quot;True&quot; /&gt;</pre></div></div>

<p>The viewport meta value works similarly to the HandheldFriendly meta value but provides for some basic customization of the default view settings.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;meta name=&quot;viewport&quot; content=&quot;initial-scale=1.0&quot; /&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;user-scalable=false&quot; /&gt;</pre></div></div>

<p>It&#8217;s important to recognize the screen resolution of the Blackberry model you&#8217;re aiming for. Like regular web development hand held devices operate at different screen resolutions and with different color counts. For example the Blackberry Bold has a resolution screen size of 480 x 320 with 65,000 colors. Take heed on this if you want your sites to look good.</p>
<p>For the ecommerce sites out there, especially Blackberry application / theme / game sites, there&#8217;s documentation on how to integrate <a title="Blackberry Wallet" href="http://na.blackberry.com/eng/devices/features/browser/wallet.jsp" onclick="return TrackClick('http%3A%2F%2Fna.blackberry.com%2Feng%2Fdevices%2Ffeatures%2Fbrowser%2Fwallet.jsp','Blackberry+Wallet')" target="_blank">Blackberry Wallet</a> into your website payment processing routine. I wasn&#8217;t too familiar with this but according to <a href="http://na.blackberry.com/eng/support/docs/subcategories/?userType=21&amp;category=BlackBerry+Wallet" onclick="return TrackClick('http%3A%2F%2Fna.blackberry.com%2Feng%2Fsupport%2Fdocs%2Fsubcategories%2F%3FuserType%3D21%26amp%3Bcategory%3DBlackBerry%2BWallet','RIM')" target="_blank" title="RIM">RIM</a>:</p>
<blockquote><p>The BlackBerry® Wallet is a BlackBerry device application that is designed to securely store information such as a BlackBerry device user&#8217;s name, shipping and billing addresses, credit card information, and login credentials for web sites and other BlackBerry  device applications. After a user saves information in the BlackBerry Wallet, the BlackBerry Wallet can populate web forms and fields in applications to reduce the effort required by the user to complete data entry tasks.</p></blockquote>
<p>So it essentially allows Blackberry users to shop online with their Blackberry but saves them the pain of entering credit card information over and over again. Nice idea.</p>
<p>Unfortunately, to utilize the Blackberry Wallet takes a lot of work; you have to edit all your forms to allow Blackberry Wallet to manipulate them. Kind of a crappy integration strategy&#8230;</p>
<p>So far that&#8217;s all I&#8217;ve been able to discover but I&#8217;m sure I&#8217;ll post more soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/04/developing-web-sites-for-blackberry/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Google Visualization API Primer</title>
		<link>http://blog.ericlamb.net/2009/03/google-visualization-api-primer/</link>
		<comments>http://blog.ericlamb.net/2009/03/google-visualization-api-primer/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:25:10 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[google visualization api]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1252</guid>
		<description><![CDATA[The Google Visualization API is a JavaScript API for creating those fancy graphs and charts Google displays in all their cool toys like Google Analytics. There&#8217;s just an obnoxious amount of chart types available in the Visualization API Gallery that include code samples along with every example. There&#8217;s also the incredible Google Ajax API Playground [...]]]></description>
			<content:encoded><![CDATA[<p>The <a title="Google Visualization API" href="http://code.google.com/apis/visualization/" onclick="return TrackClick('http%3A%2F%2Fcode.google.com%2Fapis%2Fvisualization%2F','Google+Visualization+API')" target="_blank">Google Visualization API</a> is a JavaScript API for creating those fancy graphs and charts Google displays in all their cool toys like Google Analytics. There&#8217;s just an obnoxious amount of chart types available in the <a title="Google Visualization API Gallery" href="http://code.google.com/apis/visualization/documentation/gallery.html" onclick="return TrackClick('http%3A%2F%2Fcode.google.com%2Fapis%2Fvisualization%2Fdocumentation%2Fgallery.html','Google+Visualization+API+Gallery')" target="_blank">Visualization API Gallery</a> that include code samples along with every example. There&#8217;s also the incredible <a title="The Google Ajax API Playground" href="http://code.google.com/apis/ajax/playground/?type=visualization" onclick="return TrackClick('http%3A%2F%2Fcode.google.com%2Fapis%2Fajax%2Fplayground%2F%3Ftype%3Dvisualization','The+Google+Ajax+API+Playground')" target="_blank">Google Ajax API Playground</a> which lets you play with the API and see real-time output.</p>
<div id="attachment_1253" class="wp-caption aligncenter" style="width: 280px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/03/google_visualization.gif" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Fgoogle_visualization.gif','Google+Visualization')"><img class="size-full wp-image-1253" title="Google Visualization" src="http://blog.ericlamb.net/wp-content/uploads/2009/03/google_visualization.gif" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Fgoogle_visualization.gif','Google+Visualization')" alt="Google Visualization" width="270" height="200" /></a><p class="wp-caption-text">Google Visualization</p></div>
<p>According the official website:</p>
<blockquote><p>
The Google Visualization API lets you access multiple sources of structured data that you can display, choosing from a large selection of visualizations. Google Visualization API enables you to expose your own data, stored on any data-store that is connected to the web, as a Visualization compliant datasource. Thus you can create reports and dashboards as well as analyze and display your data through the wealth of available visualization applications. The Google Visualization API also provides a platform that can be used to create, share and reuse visualizations written by the developer community at large.
</p></blockquote>
<p>I have no real interest in publishing public widgets and I&#8217;ve only used the API by generating the data declarations; so far anyway. That&#8217;s actually what&#8217;s so compelling about the API; since it&#8217;s JavaScript based the API can be used with any server side language.</p>
<p>I&#8217;m mostly interested in using the charts and graphs for displaying data from a database on a website so that&#8217;s all this article is going to focus on. </p>
<p>One more thing to keep in mind; the API is just JavaScript. There&#8217;s nothing too fancy or random being done so even though the below may look complicated don&#8217;t forget; IT&#8217;S JUST JAVASCRIPT.</p>
<h3>Examples</h3>
<h4>Line Chart</h4>
<div id="attachment_1257" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/03/line_chart.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Fline_chart.jpg','Line+Chart')"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/03/line_chart-300x138.jpg" alt="Line Chart" title="Line Chart" width="300" height="138" class="size-medium wp-image-1257" /></a><p class="wp-caption-text">Line Chart</p></div>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	google.<span style="color: #660066;">load</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">&quot;visualization&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000;">&#123;</span>packages<span style="color: #339933;">:</span><span style="color: #000;">&#91;</span><span style="color: #3366CC;">&quot;linechart&quot;</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	google.<span style="color: #660066;">setOnLoadCallback</span><span style="color: #000;">&#40;</span>drawChart<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">function</span> drawChart<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">visualization</span>.<span style="color: #660066;">DataTable</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">addColumn</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'string'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Date'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">addColumn</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'number'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Clicks'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">addRows</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">15</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 14, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 15, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 16, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 17, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 18, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 19, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">6</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 20, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">7</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 21, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 22, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">9</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 23, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 24, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">11</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 25, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">12</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 26, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">13</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 27, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">14</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'March 28, 2009'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>	  
                data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">13</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">27</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">15</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">12</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">15</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">6</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">8</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">7</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">9</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">15</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">9</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">12</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">8</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">11</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">21</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">12</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">13</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		data.<span style="color: #660066;">setCell</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">14</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> chart <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">visualization</span>.<span style="color: #660066;">LineChart</span><span style="color: #000;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'click_chart_div'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		chart.<span style="color: #660066;">draw</span><span style="color: #000;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #000;">&#123;</span>width<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span> <span style="color: #CC0000;">240</span><span style="color: #339933;">,</span> legend<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bottom'</span><span style="color: #339933;">,</span> title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Click Tracks by Date'</span><span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;div id='click_chart_div' style='width: 650px; height: 240px;'&gt;&lt;/div&gt;</pre></div></div>

<h4>Pie Chart</h4>
<div id="attachment_1262" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/03/pie_chart1.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Fpie_chart1.jpg','Pie+Chart')"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/03/pie_chart1-300x227.jpg" alt="Pie Chart" title="Pie Chart" width="300" height="227" class="size-medium wp-image-1262" /></a><p class="wp-caption-text">Pie Chart</p></div>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
google.<span style="color: #660066;">load</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">&quot;visualization&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000;">&#123;</span>packages<span style="color: #339933;">:</span><span style="color: #000;">&#91;</span><span style="color: #3366CC;">&quot;piechart&quot;</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
google.<span style="color: #660066;">setOnLoadCallback</span><span style="color: #000;">&#40;</span>drawChart<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> drawChart<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">visualization</span>.<span style="color: #660066;">DataTable</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">addColumn</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'string'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Day'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">addColumn</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'number'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Clicks'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">addRows</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">7</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Monday'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">56</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Tuesday'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">93</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Wednesday'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">21</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Thursday'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">28</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Friday'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">14</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Saturday'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">17</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">6</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Sunday'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	data.<span style="color: #660066;">setValue</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">6</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">24</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> chart <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">visualization</span>.<span style="color: #660066;">PieChart</span><span style="color: #000;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">'day_chart_div'</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	chart.<span style="color: #660066;">draw</span><span style="color: #000;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #000;">&#123;</span>width<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">,</span> is3D<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Clicks By Day'</span><span style="color: #339933;">,</span> backgroundColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#f9f9f9'</span><span style="color: #339933;">,</span> legend<span style="color: #339933;">:</span> <span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span> legendBackgroundColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#f1f1f1'</span><span style="color: #000;">&#125;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/03/google-visualization-api-primer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shifting Requirements = Better Coder</title>
		<link>http://blog.ericlamb.net/2009/03/shifting-requirements-equals-better-coder/</link>
		<comments>http://blog.ericlamb.net/2009/03/shifting-requirements-equals-better-coder/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 14:00:51 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[friendfeed]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[relative time]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=971</guid>
		<description><![CDATA[So often in the development process shifting requirements can wreak havoc on the entire project. But sometimes, every once in a while, if the moon is in just the right place and the wind is blowing in the proper direction, you can walk away a better coder for it. Take for example my recent experience [...]]]></description>
			<content:encoded><![CDATA[<p>So often in the development process shifting requirements can wreak havoc on the entire project. But sometimes, every once in a while, if the moon is in just the right place and the wind is blowing in the proper direction, you can walk away a better coder for it.</p>
<div id="attachment_998" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/03/rhino.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Frhino.jpg','Rhino')"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/03/rhino-300x199.jpg" alt="Rhino" title="Rhino" width="300" height="199" class="size-medium wp-image-998" /></a><p class="wp-caption-text">Rhino</p></div>
<p>Take for example my recent experience integrating the FriendFeed API into a client&#8217;s site.</p>
<h3>Pop Quiz</h3>
<p>The client has a website that utilizes the FriendFeed API, on the homepage only, to display information about their online activities. Basically, they want the site to be updated automatically whenever they update their MySpace or YouTube pages and the like. They&#8217;ve specified the layout to be something like the below:</p>
<p>&#8220;ClientName&#8221; just published a piece titled &#8220;Title&#8221; on &#8220;Site&#8221;. Published &#8220;X hours ago&#8221;</p>
<p>Pretty simple right? An obvious design would go something like this:<br />
1. Connect to FriendFeed API.<br />
2. Make request for data.<br />
3. Display on the page.</p>
<p>The only issue is the formatting of the date / time difference. No worries though; there&#8217;s php code all over the place for that:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> RelativeTime<span style="color: #000;">&#40;</span><span style="color: #000088;">$timestamp</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$timestamp</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$periods</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;sec&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;min&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;hour&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;day&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;week&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;month&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;years&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;decade&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$lengths</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;60&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;60&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;24&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;7&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;4.35&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;12&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$difference</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span> <span style="color: #666666; font-style: italic;">// this was in the past</span>
		<span style="color: #000088;">$ending</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span> <span style="color: #22f;">else</span> <span style="color: #000;">&#123;</span> <span style="color: #666666; font-style: italic;">// this was in the future</span>
		<span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #000088;">$difference</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ending</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;to go&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">for</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$difference</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$lengths</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$difference</span> <span style="color: #339933;">/=</span> <span style="color: #000088;">$lengths</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$difference</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$difference</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">1</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$periods</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$difference</span> <span style="color: #006699; font-weight: bold;">$periods</span>[<span style="color: #006699; font-weight: bold;">$j</span>] <span style="color: #006699; font-weight: bold;">$ending</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>Using the above you can just execute the output like the below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #22f;">echo</span> <span style="color: #000088;">$me</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' just published a piece titled '</span><span style="color: #339933;">.</span><span style="color: #000088;">$post_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' on '</span><span style="color: #339933;">.</span><span style="color: #000088;">$site</span><span style="color: #339933;">;</span>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">' Published '</span><span style="color: #339933;">.</span>RelativeTime<span style="color: #000;">&#40;</span><span style="color: #000088;">$relative_time</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Feeling pretty proud of yourself you show it off to the Producer in charge of the program and they come back with, &#8220;Nice! But how will it hold up after caching is enabled?&#8221;.</p>
<p>Well, I hadn&#8217;t thought of that (my bad fully)&#8230;</p>
<h3>The Oh Shit Moment</h3>
<p>Turns out, they&#8217;re expecting a lot of traffic (or the website is pretty resource intensive; take your pick) so full page caching is going to be required.</p>
<p>The problem is the timestamp; since all output is going to be cached the generated time, &#8220;5 minutes ago&#8221; or &#8220;2 days ago&#8221;, etc, isn&#8217;t going to change until the cache expires. This is not good&#8230;</p>
<h3>How I Fixed This (The Wrong Way)</h3>
<p>The first thing I did was make the conclusion that if php couldn&#8217;t be used then the job of formatting the string is up to JavaScript. &#8220;OK&#8221;, I thought, &#8220;fine, I&#8217;ll just port the php function to JavaScript and go about my day.</p>
<p>Here&#8217;s what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> getUnixTimestamp<span style="color: #000;">&#40;</span>timeObj<span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> dateObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span>timeObj <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		dateObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #000;">&#40;</span>timeObj<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span> <span style="color: #22f;">else</span> <span style="color: #000;">&#123;</span>
		dateObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
	<span style="color: #22f;">return</span> <span style="color: #000;">&#40;</span>parseInt<span style="color: #000;">&#40;</span>dateObj.<span style="color: #660066;">getTime</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">substring</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> RelativeTime<span style="color: #000;">&#40;</span>timestamp<span style="color: #000;">&#41;</span><span style="color: #000;">&#123;</span>
&nbsp;
	difference <span style="color: #339933;">=</span> getUnixTimestamp<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">-</span> timestamp<span style="color: #339933;">;</span>
	periodArr <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	periods <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;sec,min,hour,day,week,month,years,decade&quot;</span><span style="color: #339933;">;</span>
	periodArr <span style="color: #339933;">=</span> periods.<span style="color: #660066;">split</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	TimeLengths <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
	timelength <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;60,60,24,7,4.35,12,10&quot;</span><span style="color: #339933;">;</span>
	TimeLengths <span style="color: #339933;">=</span> timelength.<span style="color: #660066;">split</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span>difference <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span> <span style="color: #006600; font-style: italic;">// this was in the past</span>
		ending <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span> <span style="color: #22f;">else</span> <span style="color: #000;">&#123;</span> <span style="color: #006600; font-style: italic;">// this was in the future</span>
		difference <span style="color: #339933;">=</span> <span style="color: #339933;">-</span> difference<span style="color: #339933;">;</span>
		ending <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;to go&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">for</span><span style="color: #000;">&#40;</span>j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> difference <span style="color: #339933;">&gt;=</span> TimeLengths<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		difference <span style="color: #339933;">/=</span> TimeLengths<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	difference <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #000;">&#40;</span>difference<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span>difference <span style="color: #339933;">!=</span> <span style="color: #CC0000;">1</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		periodArr<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> periodArr<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;s&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
	text <span style="color: #339933;">=</span> difference<span style="color: #339933;">+</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">+</span>periodArr<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">+</span>ending<span style="color: #339933;">;</span>
	document.<span style="color: #22f;">write</span><span style="color: #000;">&#40;</span>text<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>Feeling sure of myself, <em>again</em>, a thought occurs to me that this still doesn&#8217;t fix the issue 100%. Sure, the date format will be consistent with the relative requirement, but the feed won&#8217;t be updated in &#8220;Real Time&#8221; so the full requirement isn&#8217;t there.</p>
<h3>The Real Solution</h3>
<p>A better idea would be to use AJAX to populate the area of the site where the blurb will be displayed. Since the AJAX request is independent of the rest of the site caching won&#8217;t be an issue. Sure, it&#8217;s a little more complicated but by doing an AJAX call the client gets exactly what they want.</p>
<h3>The Lesson</h3>
<p>Now, I&#8217;m not going to go into detail about the AJAX solution, mostly because I haven&#8217;t written it yet <img src='http://blog.ericlamb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , but, to me, this is the far superior solution. </p>
<p>Admittedly, I was a little frustrated that I didn&#8217;t think of the AJAX solution sooner. That is, until I realized how much I had learned going in the &#8220;wrong&#8221; direction. </p>
<p>I had no idea that generating a UNIX timestamp in JavaScript was &#8220;complicated&#8221;.<br />
I learned a lot about JavaScript string handling.<br />
I got a quick primer in how JavaScript&#8217;s builtin Split function works.<br />
I got a little humility out of the process too.</p>
<p>Sometimes, it&#8217;s good to go astray on a project. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/03/shifting-requirements-equals-better-coder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
