<?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>tomputer &#187; code</title>
	<atom:link href="http://droza.net/blog/blog/tags/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://droza.net/blog</link>
	<description>Software. Gadgets. Music. Rants. By Tom D\&#039;Roza</description>
	<lastBuildDate>Thu, 23 Dec 2010 13:26:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Custom events in JQuery</title>
		<link>http://droza.net/blog/2009/01/25/custom-events-in-jquery/</link>
		<comments>http://droza.net/blog/2009/01/25/custom-events-in-jquery/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 18:49:54 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://droza.net/blog/?p=129</guid>
		<description><![CDATA[For a project at work this week I needed to modify a Javascript library so that under a particular condition it would generate a JS event that could be handled elsewhere in the application.  Why use JS events rather than just call a regular JS function? Well, I guess partly to maintain consistency with the [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p>For a project at work this week I needed to modify a Javascript library so that under a particular condition it would generate a JS event that could be handled elsewhere in the application.  Why use JS events rather than just call a regular JS function? Well, I guess partly to maintain consistency with the way that other events are handled within the app, and partly because it&#8217;s a more elegant solution: When an event is thrown, if there&#8217;s nothing to catch and handle the event it doesn&#8217;t matter but when you call a JS function you need to be sure that the function exists otherwise you&#8217;ll end up with JS errors on the page so you have to first test that the function exists before you call it. Also an event can <a href="http://www.quirksmode.org/js/events_order.html">propagate</a> up through the ancestory of objects on your page so it can be handled at whichever level is most appropriate or handled in different ways at different levels.</p>
<p>In JQuery the syntax for creating an event handler is exremely simple, for example, given the following HTML:</p>
<pre class="brush: jscript; title: ;">
&lt;div id='container'&gt;
   Click me!
&lt;/div&gt;
</pre>
<p>&#8230;the JQuery code to handle for the click event would be:</p>
<pre class="brush: jscript; title: ;">
$('#container').click(function() {
   alert('You clicked me!');
});
</pre>
<p>In the above example, the &#8220;click&#8221; method is a shorthand utility method provided by JQuery, but is the same as:</p>
<pre class="brush: jscript; title: ;">
$('#container').bind('click', function(e) {
   alert('You clicked me!');
});
</pre>
<p>There&#8217;s a whole bunch of <a title="Event reference on W3Schools" href="http://www.w3schools.com/jsref/jsref_events.asp" target="_blank">standard HTML events</a> that the browser may generate in response to user input (and that can be handled in similar fashion). You can also get JQuery to generate these events programatically.</p>
<p>It turns out that you can create a handler for your own custom event in exactly the same way, just change the name of the event (&#8220;click&#8221; in the example above), to the name of the event you want to create and be sure to use the longhand &#8220;bind&#8221; method. E.g.</p>
<pre class="brush: jscript; title: ;">
$('#container').bind('myEvent', function(e) {
   alert('My event just fired');
});
</pre>
<p>Then, when you want to trigger this event, use the err&#8230; &#8220;trigger&#8221; function:</p>
<pre class="brush: jscript; title: ;">
   $('#container').trigger('myEvent');
</pre>
<p>Because we&#8217;re using events rather than a straight method call (and JQuery 1.3 or later) we could write another handler for myEvent but on an ancestor of #container &#8211; the document body in this case. The handlers would be called in order, first on #container, then on the body. If we want to prevent the event from bubbling up through the DOM we can kill it with the <a title="See the JQuery Event documentation" href="http://docs.jquery.com/Events/jQuery.Event#event.stopPropagation.28.29" target="_blank">stopPropagation()</a> function:</p>
<pre class="brush: jscript; title: ;">
$('#container').bind('myEvent', function(e) {
   e.stopPropagation();
   alert('My event just fired');
});
</pre>
<p>I was surprised by just how simple this was once I realised that the process for custom events is exactly the same as that for standard browser events.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F&amp;title=Custom+events+in+JQuery" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F&amp;title=Custom+events+in+JQuery" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F&amp;title=Custom+events+in+JQuery" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F&amp;title=Custom+events+in+JQuery" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F&amp;title=Custom+events+in+JQuery', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F&amp;title=Custom+events+in+JQuery" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2009%2F01%2F25%2Fcustom-events-in-jquery%2F&amp;title=Custom+events+in+JQuery" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2009/01/25/custom-events-in-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TinyURL Bookmarklet</title>
		<link>http://droza.net/blog/2008/12/03/tinyurl-bookmarklet/</link>
		<comments>http://droza.net/blog/2008/12/03/tinyurl-bookmarklet/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 22:16:16 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[jsonp]]></category>
		<category><![CDATA[tinyurl]]></category>
		<category><![CDATA[wtframework]]></category>

		<guid isPermaLink="false">http://droza.net/blog/?p=97</guid>
		<description><![CDATA[If you just want to try this out, drag the link below to your bookmarks toolbar, then click the new bookmark. I&#8217;ve only tested in Firefox 3.04 so far so your mileage may vary if you use another browser. Let me know in the comments if you find this useful or have any problems. Tiny [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<div id="attachment_119" class="wp-caption aligncenter" style="width: 442px"><a href="http://droza.net/blog/wp-content/uploads/2008/12/tiny_bookmarklet.gif" rel="lightbox[97]"><img class="size-full wp-image-119" title="TinyURL bookmarklet" src="http://droza.net/blog/wp-content/uploads/2008/12/tiny_bookmarklet.gif" alt="TinyURL bookmarklet in action" width="432" height="101" /></a><p class="wp-caption-text">TinyURL bookmarklet in action</p></div>
<p>If you just want to try this out, drag the link below to your bookmarks toolbar, then click the new bookmark. I&#8217;ve only tested in Firefox 3.04 so far so your mileage may vary if you use another browser. Let me know in the comments if you find this useful or have any problems.</p>
<blockquote><p><a class="aligncenter" title="TinyURL Bookmarklet" href="javascript:var%20el=document.getElementById('__tiny');if(el){document.body.removeChild(el)}else{var%20scriptTag=document.createElement('script');scriptTag.type='text/javascript';scriptTag.src='http://json-tinyurl.appspot.com/?callback=window.tinyCallback&amp;url='+document.location;scriptTag.id='__tinyURL_script';document.body.appendChild(scriptTag)}if(!window['tinyCallback']){window.tinyCallback=function(data){var%20c=document.createElement('span');c.id='__tiny';c.style.opacity='0.7';c.style.filter='alpha(opacity=70)';c.style.border='solid%202px%20%23fff';c.style.textDecoration='none';c.style.textAlign='left';c.style.position='fixed';c.style.zIndex='9000';c.style.top='15px';c.style.right='20px';c.style.background='#000';c.style.styleFloat='right';c.style.padding='7px%2010px';c.style.color='%23fff';c.style.font='12px%20Lucida%20Grande,Helvetica,Tahoma';c.style.MozBorderRadius='5px';c.style.WebkitBorderRadius='5px';c.style.WebkitBoxShadow='0px%200px%2020px%20%23000';c.style.MozBoxShadow='0px%200px%2020px%20%23000';document.body.appendChild(c);c.innerHTML=&quot;&lt;input%20id='__tiny_text'%20type='text'%20value='&quot;+data.tinyurl+&quot;'%20style='border:0px;background:transparent;color:#fff;'/&gt;&quot;;document.getElementById('__tiny_text').focus();document.getElementById('__tiny_text').select();var%20x=document.getElementById('__tinyURL_script');if(x){document.body.removeChild(x)}}}void(0);"><span style="font-size: x-large; font-weight: bold;">Tiny</span></a></p>
<p>(v1.1 updated Dec 6th: The generated tiny url is now automatically selected ready to be copied)</p></blockquote>
<p>Read on for a description of how it works&#8230;</p>
<p><span id="more-97"></span></p>
<p><span style="text-decoration: underline;"><strong>What it does</strong></span><br />
Inspired by the <a title="WTFramework" href="http://blog.olicio.us/2008/11/08/wtframework-bookmarklet/" target="_blank">WTFramework</a> bookmarklet I decided to create a TinyURL bookmarklet that would generate a shortened url without opening a new browser window and without navigating the user away from the current page. It took me a little while to figure out how to define a callback function within a bookmarklet (thanks to <a title="Dion's blog" href="http://almaer.com/blog/">Dion Almaer</a> for a useful <a title="Dion's blog post" href="http://almaer.com/blog/translate-select-any-text-in-the-browser-and-have-it-convert-to-english-or-your-language">tutorial</a>) but I got it working in a couple of hours and I quite like it. Thanks also to <a title="About Oskar" href="http://blog.olicio.us/the-dude" target="_blank">Oskar Krawczyk</a> for the CSS which I &#8220;borrowed&#8221; from the aforementioned WTFramework.</p>
<p><span style="text-decoration: underline;"><strong>How it works<br />
</strong></span>When you click the bookmarklet, I first check whether the UI element is visible and if it is, remove it:</p>
<pre class="brush: jscript; title: ;">
var el=document.getElementById('__tiny');
if (el){
document.body.removeChild(el);
}
</pre>
<p>This makes the bookmarklet act as a toggle: Click once to show the UI, click again to remove it. The WTFramework bookmarklet also removes the UI when the user clicks on the UI element itself  but I removed that functionality from this bookmarklet as the user is likely to want to click and select the tinyurl to copy it which would be difficut if the UI disappears on mouse click.</p>
<p>If the UI is not present, I generate a URL which is called via script injection to circumvent the browser&#8217;s same origin policy (i.e. I generate as <code>script</code> tag, set its <code>src</code> attribute and add the tag to the DOM):</p>
<pre class="brush: jscript; title: ;">
var scriptTag = document.createElement('script');
scriptTag.type='text/javascript';
scriptTag.src='http://json-tinyurl.appspot.com/?callback=window.tinyCallback&amp;amp;amp;url=' + document.location;
scriptTag.id='__tinyURL_script';
document.body.appendChild(scriptTag);
</pre>
<p>The response is a JSONP formatted string. TinyURL provides a very simple API (e.g. <a title="TinyURL API example" href="http://tinyurl.com/api-create.php?url=http://scripting.com/" target="_blank">http://tinyurl.com/api-create.php?url=http://www.droza.net/blog</a>) but doesn&#8217;t offer a JSONP interface &#8211; I was going to create one with Yahoo Pipes, but found that a suitable JSONP wrapper for TinyURL already exists, hosted in Google&#8217;s AppEngine (e.g. http://json-tinyurl.appspot.com/?callback=window.tinyCallback&amp;url=http://www.droza.net/blog) so I use that instead (thanks <a title="Simon Willison" href="http://simonwillison.net/2008/Aug/27/jsontinyurl/" target="_blank">Simon</a>!).</p>
<p>After the script tag is added to the page, the browser will call the API and the response will invoke the tinyCallback function (I check to see whether the function already exists before declaring it to prevent declaring it twice if the bookmarklet is used multiple times on the same page). The callback constructs a semi-transparent UI element positioned in the top-right of the browser page and sets its content to be the generated tiny url. The bulk of the code is CSS:</p>
<pre class="brush: jscript; title: ;">
window.tinyCallback = function(data) {
var c=document.createElement('span');
c.id='__tiny';
c.style.opacity='0.7';
c.style.filter='alpha(opacity=70)';
c.style.border='solid 2px %23fff';
c.style.textDecoration='none';
c.style.textAlign='left';
c.style.position='fixed';
c.style.zIndex='9000';
c.style.top='15px';
c.style.right='20px';
c.style.background='#000';
c.style.styleFloat='right';
c.style.padding='7px 10px';
c.style.color='%23fff';
c.style.font='12px Lucida Grande,Helvetica,Tahoma';
c.style.MozBorderRadius='5px';
c.style.WebkitBorderRadius='5px';
c.style.WebkitBoxShadow='0px 0px 20px %23000';
c.style.MozBoxShadow='0px 0px 20px %23000';
document.body.appendChild(c);
c.innerHTML=data.tinyurl;
</pre>
<p>It then removes the script tag that it added to the DOM, just to keep things tidy:</p>
<pre class="brush: jscript; title: ;">
var x=document.getElementById('__tinyURL_script');
if (x){
document.body.removeChild(x);
}
</pre>
<p>After creating the script I used Dean Edward&#8217;s <a title="Dean's packer" href="http://dean.edwards.name/packer/" target="_blank">packer</a> to minify the code to a single line sans-whitespace suitable for using in the <code>href</code> attribute of an <code>a</code> tag.</p>
<p><span style="text-decoration: underline;"><strong>The full code</strong></span><br />
For reference, the listing below is the full non-minified sourcecode</p>
<pre class="brush: jscript; title: ;">
var el=document.getElementById('__tiny');
if (el){
document.body.removeChild(el);
} else {
var scriptTag = document.createElement('script');
scriptTag.type='text/javascript';
scriptTag.src='http://json-tinyurl.appspot.com/?callback=window.tinyCallback&amp;amp;amp;url=' + document.location;
scriptTag.id='__tinyURL_script';
document.body.appendChild(scriptTag);
}
if (!window['tinyCallback']) {
window.tinyCallback = function(data) {
var c=document.createElement('span');
c.id='__tiny';
c.style.opacity='0.7';
c.style.filter='alpha(opacity=70)';
c.style.border='solid 2px %23fff';
c.style.textDecoration='none';
c.style.textAlign='left';
c.style.position='fixed';
c.style.zIndex='9000';
c.style.top='15px';
c.style.right='20px';
c.style.background='#000';
c.style.styleFloat='right';
c.style.padding='7px 10px';
c.style.color='%23fff';
c.style.font='12px Lucida Grande,Helvetica,Tahoma';
c.style.MozBorderRadius='5px';
c.style.WebkitBorderRadius='5px';
c.style.WebkitBoxShadow='0px 0px 20px %23000';
c.style.MozBoxShadow='0px 0px 20px %23000';
document.body.appendChild(c);
c.innerHTML=data.tinyurl;
var x=document.getElementById('__tinyURL_script');
if (x){
document.body.removeChild(x);
}
}
}
void(0);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2008/12/03/tinyurl-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>XBMChumby sourcecode is now public</title>
		<link>http://droza.net/blog/2008/11/04/xbmchumby-sourcecode-is-now-public/</link>
		<comments>http://droza.net/blog/2008/11/04/xbmchumby-sourcecode-is-now-public/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 22:22:25 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[Chumby]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gadgets]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[widgets]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[xbmc]]></category>

		<guid isPermaLink="false">http://droza.net/blog/?p=90</guid>
		<description><![CDATA[It&#8217;s taken me a while I&#8217;ll admit but I&#8217;ve just got around to releasing the sourcecode for the XBMChumby widget I wrote which displays the XBMC &#8220;Now Playing&#8221; queue on the Chumby. I decided early on that my very basic skills as a flash/ActionScript developer weren&#8217;t up to developing this to it&#8217;s full potential so [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p>It&#8217;s taken me a while I&#8217;ll admit but I&#8217;ve just got around to releasing the sourcecode for the XBMChumby widget I wrote which displays the XBMC &#8220;Now Playing&#8221; queue on the Chumby. I decided early on that my very basic skills as a flash/ActionScript developer weren&#8217;t up to developing this to it&#8217;s full potential so now if anyone is interested in taking it further please checkout the code and get in touch if you have any problems building it etc etc etc.</p>
<p>The sourceforge project page is: https://sourceforge.net/projects/xbmchumby/</p>
<p>&#8230;or you can point your CVS client at xbmchumby.cvs.sourceforge.net</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F&amp;title=XBMChumby+sourcecode+is+now+public" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F&amp;title=XBMChumby+sourcecode+is+now+public" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F&amp;title=XBMChumby+sourcecode+is+now+public" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F&amp;title=XBMChumby+sourcecode+is+now+public" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F&amp;title=XBMChumby+sourcecode+is+now+public', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F&amp;title=XBMChumby+sourcecode+is+now+public" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2008%2F11%2F04%2Fxbmchumby-sourcecode-is-now-public%2F&amp;title=XBMChumby+sourcecode+is+now+public" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2008/11/04/xbmchumby-sourcecode-is-now-public/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drawing graphs with Javascript</title>
		<link>http://droza.net/blog/2007/12/04/drawing-graphs-with-javascript/</link>
		<comments>http://droza.net/blog/2007/12/04/drawing-graphs-with-javascript/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 17:20:42 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[charts]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mochikit]]></category>
		<category><![CDATA[plotkit]]></category>
		<category><![CDATA[web2.0]]></category>

		<guid isPermaLink="false">http://droza.net/blog/2007/12/04/drawing-graphs-with-javascript/</guid>
		<description><![CDATA[window.onload = function() { getData(); } If you&#8217;re viewing this post in your feedreader, head over to the site to see the example graph! I&#8217;ve been experimenting with Javascript libraries for building graphs dynamically in the client browser. In the past if I&#8217;ve wanted to create simple bar graphs I&#8217;ve used divs and css &#8211; [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p><script src="/blog/wp-content/uploads/2007/12/MochiKit-1.3.1/lib/MochiKit/MochiKit.js" type="text/javascript"></script><br />
<script src="/blog/wp-content/uploads/2007/12/plotkit-0.9.1/PlotKit/Base.js" type="text/javascript"></script><br />
<script src="/blog/wp-content/uploads/2007/12/plotkit-0.9.1/PlotKit/Layout.js" type="text/javascript"></script><br />
<script src="/blog/wp-content/uploads/2007/12/plotkit-0.9.1/PlotKit/Canvas.js" type="text/javascript"></script><br />
<script src="/blog/wp-content/uploads/2007/12/plotkit-0.9.1/PlotKit/excanvas.js" type="text/javascript"></script><br />
<script src="/blog/wp-content/uploads/2007/12/plotkit-0.9.1/PlotKit/SweetCanvas.js" type="text/javascript"></script><br />
<script src="/blog/wp-content/uploads/2007/12/BTShareGraph.js" type="text/javascript"></script><br />
<script type="text/javascript" language="javascript">   window.onload = function() {     getData();   } </script><br />
<em> If you&#8217;re viewing this post in your feedreader, head over to the site to see the example graph!</em></p>
<p>I&#8217;ve been experimenting with Javascript libraries for building graphs dynamically in the client browser.  In the past if I&#8217;ve wanted to create simple bar graphs I&#8217;ve used divs and css &#8211; an approach has the advantage of being super lightweight (read &#8220;fast&#8221;) and usually works cross-browser without too much hassle. The big disadvantage is that it&#8217;s inflexible (limited to bar graphs and difficult to update the data once the graph has been rendered) and is a pain to code if there&#8217;s more than a couple of rows of data to be plotted.</p>
<p>A few minutes on Google last week came up with a couple of examples of Javacript libraries that can produce much fancier graphs. I&#8217;ve settled on <a href="http://www.liquidx.net/plotkit/" title="PlotKit">PlotKit</a> because it produces beautiful graphs, works in the major browsers (using either Canvas or SVG)  and has the most developer friendly licence, .</p>
<p>The example below gets a feed of the BT shareprice from Google (fed through a Yahoo Pipe to convert to JSON &#8211; the <a href="http://pipes.yahoo.com/pipes/pipe.info?_id=xLjkFsCd3BGoDvL7yZ1_DQ" title="Shareprice Pipe">pipe </a>can be reused as it takes the ticker symbol as a parameter). It then iterates over the feed data to populate the graph and finally calls render() on the graph object.</p>
<p>A handy library to keep in your developer toolbox!</p>
<p><em>Although not relevant for the data I&#8217;m graphing here, PlotKit can also draw really sweet <a href="http://media.liquidx.net/js/plotkit-tests/svg-sweet.html" title="PlotKit example graphs">pie charts</a>. </em></p>
<div><canvas id="graph" height="300" width="450"></canvas></div>
<p><br/></p>
<div><a href="javascript:setStyle('bar')">View As Bar</a> | <a href="javascript:setStyle('line')">View As Line</a></div>
<p><br/></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F&amp;title=Drawing+graphs+with+Javascript" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F&amp;title=Drawing+graphs+with+Javascript" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F&amp;title=Drawing+graphs+with+Javascript" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F&amp;title=Drawing+graphs+with+Javascript" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F&amp;title=Drawing+graphs+with+Javascript', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F&amp;title=Drawing+graphs+with+Javascript" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F12%2F04%2Fdrawing-graphs-with-javascript%2F&amp;title=Drawing+graphs+with+Javascript" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2007/12/04/drawing-graphs-with-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google gadgets</title>
		<link>http://droza.net/blog/2007/10/24/google-gadgets/</link>
		<comments>http://droza.net/blog/2007/10/24/google-gadgets/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 12:59:19 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[gadgets]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://droza.net/blog/2007/10/24/google-gadgets/</guid>
		<description><![CDATA[So I&#8217;ve been messing around with various different widget frameworks on and off over the last few months as preparation for a workshop I&#8217;m going to be involved with. I started out with Yahoo Widgets (née Konfabulator) mainly because the examples that I&#8217;d seen looked the prettiest. Although perhaps not strictly widgets, I&#8217;ve also started [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p>So I&#8217;ve been messing around with various different widget frameworks on and off over the last few months as preparation for a workshop I&#8217;m going to be involved with. I started out with Yahoo Widgets (née Konfabulator) mainly because the examples that I&#8217;d seen looked the prettiest. Although perhaps not strictly widgets, I&#8217;ve also started to look at facebook applications, but that&#8217;s a subject for another day. My favoured widget framework at the moment is Google Gadgets for a number of reasons:</p>
<ul>
<li>The barrier to entry is low because it&#8217;s pretty much standard javascript and html with an xml descriptor.</li>
<li>You write a gadget once and can view it in <a href="http://www.google.com/ig">iGoogle</a>, <a href="http://desktop.google.com">GoogleDesktop</a>, <a href="http://www.blogger.com">Blogger </a>or in an iframe embedded in any webpage.</li>
<li>As with all Google APIs the <a href="http://www.google.com/apis/gadgets">documentation</a> is great and there&#8217;s a lot of developer support.</li>
<li>It plays nicely with other Google APIs.</li>
<li>&#8230;finally, if you&#8217;re going to back one widget framework, who would bet against Google?</li>
</ul>
<p>I find the best way to learn is just to get stuck in so I created a couple of <a href="http://www.google.com/ig/directory?q=tdroza&amp;btnG=Search+Homepage+Content">simple examples</a>, one to display a user&#8217;s timeline from <a href="http://twitter.com">twitter</a> and another to display recent announcements made on another site I wrote, <a href="http://www2.bt.com/beta/apps/tellm">Tell&#8217;M</a>. They both follow very similar principles: pull down an rss feed, parse it for interesting fields and render the display. Both also have a few user preferences that can be set to customise the feed.</p>
<p><script src="http://gmodules.com/ig/ifr?url=http://www.btinternet.com/~tdroza/gadgets/twitter/index.xml&amp;up_username=tdroza&amp;up_feed=http%3A%2F%2Ftwitter.com%2Fstatuses%2Ffriends_timeline%2F&amp;up_max_items=3&amp;synd=open&amp;w=320&amp;h=200&amp;title=&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script></p>
<p><script src="http://gmodules.com/ig/ifr?url=http://www.btinternet.com/~tdroza/gadgets/tellm/index.xml&amp;up_max_items=3&amp;synd=open&amp;w=320&amp;h=200&amp;title=Tell\\'M+-+announce+it+to+the+world&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script></p>
<p>My interest had moved on to <a href="http://www.bt.com/btfon">other</a> <a href="http://developer.facebook.com/">things</a> recently but this week I started to look at gadgets again because the workshop is coming up soon. I found my two gadgets in the <a href="http://www.google.com/ig/directory?q=tdroza&amp;btnG=Search+Homepage+Content">google directory</a> and was disheartened to see that my twitter gadget had received two negative comments &#8211; one because of a security restriction of ajax (cross-domain policy) and twitter (which will only accept a POST to update status so I can&#8217;t use <a href="http://jayfresh.wordpress.com/2007/09/17/using-script-tags-to-do-remote-http-calls-in-javascript/">script injection</a>). After a bit more digging around I found that Google now display average weekly page views for gadgets and my twitter gadget is receiving <a href="http://www.google.com/ig/directory?synd=open&amp;source=gapi&amp;num=24&amp;url=http://www.btinternet.com/~tdroza/gadgets/twitter/index.xml">14,546</a> page views per week! I guess it&#8217;s easy for a developer to do something just to satisfy their own curiosity and think that nobody else will ever use it. I&#8217;ve now added Google Analytics to both my gadgets just to check that all those page view are not generated by me! <img src='http://droza.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F&amp;title=Google+gadgets" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F&amp;title=Google+gadgets" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F&amp;title=Google+gadgets" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F&amp;title=Google+gadgets" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F&amp;title=Google+gadgets', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F&amp;title=Google+gadgets" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F10%2F24%2Fgoogle-gadgets%2F&amp;title=Google+gadgets" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2007/10/24/google-gadgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to find the size of a database table</title>
		<link>http://droza.net/blog/2007/09/21/how-to-find-the-size-of-a-database-table/</link>
		<comments>http://droza.net/blog/2007/09/21/how-to-find-the-size-of-a-database-table/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 10:40:48 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://droza.net/blog/2007/09/21/how-to-find-the-size-of-a-database-table/</guid>
		<description><![CDATA[Seems there are lots of ways of doing this, but this worked for me (on an Oracle DB). It returns the size of the database table in megabytes: select bytes/1024/1024 from user_segments where segment_name='&#60;table_name&#62;']]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p>Seems there are lots of ways of doing this, but this worked for me (on an Oracle DB). It returns the size of the database table in megabytes:</p>
<pre class="brush: sql; title: ;">
select bytes/1024/1024 from user_segments where segment_name='&lt;table_name&gt;'
</pre>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F&amp;title=How+to+find+the+size+of+a+database+table" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F&amp;title=How+to+find+the+size+of+a+database+table" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F&amp;title=How+to+find+the+size+of+a+database+table" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F&amp;title=How+to+find+the+size+of+a+database+table" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F&amp;title=How+to+find+the+size+of+a+database+table', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F&amp;title=How+to+find+the+size+of+a+database+table" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F09%2F21%2Fhow-to-find-the-size-of-a-database-table%2F&amp;title=How+to+find+the+size+of+a+database+table" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2007/09/21/how-to-find-the-size-of-a-database-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing a user&#8217;s address book with Plaxo</title>
		<link>http://droza.net/blog/2007/08/05/importing-a-users-address-book-with-plaxo/</link>
		<comments>http://droza.net/blog/2007/08/05/importing-a-users-address-book-with-plaxo/#comments</comments>
		<pubDate>Sun, 05 Aug 2007 08:04:53 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[plaxo]]></category>

		<guid isPermaLink="false">http://droza.net/blog/2007/08/05/importing-a-users-address-book-with-plaxo/</guid>
		<description><![CDATA[Despite sounding like a mouthwash, Plaxo is a nifty tool that can be embedded in any site to allow a user to select contacts stored in their address book on Yahoo! Mail, GMail, Hotmail and others. Plaxo interfaces to all of these sites for you so that you don&#8217;t have to write code for several [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p>Despite sounding like a mouthwash, <a href="http://www.plaxo.com/api/widget/">Plaxo </a>is a nifty tool that can be embedded in any site to allow a user to select contacts stored in their address book on Yahoo! Mail, GMail, Hotmail and others. Plaxo interfaces to all of these sites for you so that you don&#8217;t have to write code for several different APIs. Perfect for situations where you want to offer users the ability to send emails from within your application (e.g. &#8220;recommend to a friend&#8221;, &#8220;share this page&#8221; etc).</p>
<p><img src="http://www.plaxo.com/images/abc/widgetscreencapture.gif" align="middle" height="260" width="260" /></p>
<p>Plaxo do some clever javascript/iframe jiggery pokery to circumvent the browser&#8217;s cross-domain restriction. The only issues that I can with this approach is that your users have to submit their username/password via plaxo (although they do promise not to store these details and the  calls back to plaxo are over https). I&#8217;ve knocked together a quick <a href="http://droza.net/plaxo/widget-launch.html">demo</a>.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F&amp;title=Importing+a+user%26%238217%3Bs+address+book+with+Plaxo" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F&amp;title=Importing+a+user%26%238217%3Bs+address+book+with+Plaxo" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F&amp;title=Importing+a+user%26%238217%3Bs+address+book+with+Plaxo" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F&amp;title=Importing+a+user%26%238217%3Bs+address+book+with+Plaxo" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F&amp;title=Importing+a+user%26%238217%3Bs+address+book+with+Plaxo', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F&amp;title=Importing+a+user%26%238217%3Bs+address+book+with+Plaxo" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F08%2F05%2Fimporting-a-users-address-book-with-plaxo%2F&amp;title=Importing+a+user%26%238217%3Bs+address+book+with+Plaxo" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2007/08/05/importing-a-users-address-book-with-plaxo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Playing with Python</title>
		<link>http://droza.net/blog/2007/07/31/playing-with-python/</link>
		<comments>http://droza.net/blog/2007/07/31/playing-with-python/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 21:40:13 +0000</pubDate>
		<dc:creator>tdroza</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://droza.net/blog/2007/07/31/playing-with-python/</guid>
		<description><![CDATA[For something I was playing around with at work, I wanted to be able to retrieve an rss feed, parse it and post the title/description fields to another website site at timed intervals. These days I only really write in Java and JavaScript but Java seemed like such a longhand way to achieve this. I [...]]]></description>
			<content:encoded><![CDATA[
<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> 
<p>For something I was playing around with at work, I wanted to be able to retrieve an rss feed, parse it and post the title/description fields to another website site at timed intervals. These days I only really write in Java and JavaScript but Java seemed like such a longhand way to achieve this. I probably could have written a shell script, but it&#8217;s such a long time since I wrote shell scripts that I&#8217;d have been starting from scratch so I decided to take a look at Python&#8230; and so far I&#8217;m impressed. Very impressed.</p>
<p>From start to finish this probably only took a couple of hours and that includes referring back to the api docs for almost every line I wrote. The code below fetches a feed, and extracts the <code>title</code> field from the <code>item</code>s. Each time it finds an item, it adds its <code>guid</code> to a text file so that it can ignore items that have been previously processed. I&#8217;m sure this can be tidied up lots, but for a first attempt I&#8217;m pretty happy (for simplicity I&#8217;ve removed the code that posts the items </p>
<pre class="brush: python; title: ;">
import urllib
from threading import Timer
from xml.dom import minidom

def retrieveXml(url):
    #get the feed
    f = urllib.urlopen(url)
    xmldoc = minidom.parse(f)
    f.close()

    # read the history (assumes the file already exists)
    historyFile = open('./history.dat','r')
    history = historyFile.read()
    historyFile.close()
    found = False
    # iterate through each item in the feed
    items = xmldoc.getElementsByTagName('item')
    for item in items:
        title = item.getElementsByTagName('title')[0].firstChild.toxml()
        guid = item.getElementsByTagName('guid')[0].firstChild.toxml()
        # if the current item isn't in the history, then use that
        if history.find(guid) &lt; 0:
            found = True
            break
    # if we found a new entry while iterating over the feed...
    if found:
        historyFile = open('./history.dat','a')
        historyFile.write(guid  + &quot;n&quot;)
        historyFile.close()
        # for now just print the title to screen
        print title
    t = Timer(10.0, retrieveXml, [url])
    t.start()

retrieveXml('http://f1.gpupdate.net/en/xml/rss/1.xml')
</pre>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F&amp;title=Playing+with+Python" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F&amp;title=Playing+with+Python" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F&amp;title=Playing+with+Python" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F&amp;title=Playing+with+Python" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F&amp;title=Playing+with+Python', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F&amp;title=Playing+with+Python" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fdroza.net%2Fblog%2F2007%2F07%2F31%2Fplaying-with-python%2F&amp;title=Playing+with+Python" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://droza.net/blog/2007/07/31/playing-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

