<?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>shwango! blog &#187; code</title>
	<atom:link href="http://blog.shwango.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.shwango.com</link>
	<description>life, love and some other stuff...</description>
	<lastBuildDate>Sun, 14 Jun 2009 15:51:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby Timeout::Error</title>
		<link>http://blog.shwango.com/2008/03/06/ruby-timeouterror/</link>
		<comments>http://blog.shwango.com/2008/03/06/ruby-timeouterror/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 17:45:04 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2008/03/06/ruby-timeouterror/</guid>
		<description><![CDATA[I wanted to post this before, but got busy and now I can&#8217;t find the original post about this, but anyway&#8230;
When doing network stuff in Ruby &#8211; using any Net:: libs &#8211; there&#8217;s a little trick to trap for timeouts.  You can&#8217;t simply use &#8220;rescue&#8221; do handle it.  The timeout error is not [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to post this before, but got busy and now I can&#8217;t find the original post about this, but anyway&#8230;</p>
<p>When doing network stuff in Ruby &#8211; using any Net:: libs &#8211; there&#8217;s a little trick to trap for timeouts.  You can&#8217;t simply use &#8220;rescue&#8221; do handle it.  The timeout error is not a subclass of the standard error, so you have to explicitly trap for it:</p>
<p>begin<br />
# Do network stuff<br />
rescue Timeout::Error<br />
# Timeout error<br />
rescue<br />
# Other error<br />
end</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2008/03/06/ruby-timeouterror/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>EJB3 and MyEclipse</title>
		<link>http://blog.shwango.com/2006/03/31/ejb3-and-myeclipse/</link>
		<comments>http://blog.shwango.com/2006/03/31/ejb3-and-myeclipse/#comments</comments>
		<pubDate>Fri, 31 Mar 2006 16:56:57 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2006/03/31/ejb3-and-myeclipse/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>Since MyEclipse doesn&#8217;t natively support EJB3 (yet), you need to include the EJB3 libs in your project &#8211; I&#8217;m using JBoss, so I&#8217;ve got the JBoss EJB libs.  There&#8217;s <a href="http://www.myeclipseide.com/index.php?name=PNphpBB2&#038;file=viewtopic&#038;p=55825#top">great post</a> in the <a href="http://www.myeclipseide.com/PNphpBB2+file-index.html">MyEclipse forums</a> on getting it set up.  I added a few posts over there on which libs I needed &#8211; but here&#8217;s <a href="http://www.market-assist.com/~osterday/pics/screenshots/ejb3-userlibs.png">my screenshot</a> for reference.  (Technically you only need Eclipse, but I use MyEclipse and think it&#8217;s worth the little bit of cash.)</p>
<p>And to use MySQL for the tutorial:</p>
<p>@GeneratedValue(strategy = GenerationType.AUTO)<br />
and remove the @SequenceGenerator annotation &#8211; that worked for me.</p>
<p>Here&#8217;s another <a href="http://www.informit.com/guides/content.asp?g=java&#038;seqNum=239">great EJB3 tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2006/03/31/ejb3-and-myeclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EJB3</title>
		<link>http://blog.shwango.com/2006/03/24/ejb3/</link>
		<comments>http://blog.shwango.com/2006/03/24/ejb3/#comments</comments>
		<pubDate>Fri, 24 Mar 2006 16:39:19 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2006/03/24/ejb3/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>I think I&#8217;ve mentioned before that over the past two years or so I&#8217;ve really been getting into Java and J2EE development.  I&#8217;ve got a cool app running on JBoss using EJBs, Quartz for scheduling and MySQL for the database.  Pretty stable too in the year or so it&#8217;s been in production.  Most of the &#8220;good&#8221; stuff in our TF platform is running on JBoss now too &#8211; not really using the J2EE features yet since there&#8217;s so much old code still there, but making progress.  Anyway&#8230;</p>
<p>I just started playing around with <a href="http://www.jboss.com/products/ejb3">JBoss&#8217; EJB3</a> stuff and I&#8217;m lovin&#8217; it!  I didn&#8217;t mind EJB 2.1 since I have MyEclipse and XDoclet to easy the amount of code I had to write, but this is much better!  I&#8217;ve only just done a few small demo apps, but so far it&#8217;s really great.</p>
<p>Want to listen to a great podcast with Gavin King (of <a href="http://www.hibernate.org/">hibernate</a> fame) discussing EJB3 and JBoss&#8217; new <a href="http://www.jboss.com/products/seam">Seam</a> product, check out the <a href="http://www.javaposse.com/index.php?post_id=59304">Java Posse&#8217;s interview with him</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2006/03/24/ejb3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Going down the wrong PATH</title>
		<link>http://blog.shwango.com/2005/10/19/going-down-the-wrong-path/</link>
		<comments>http://blog.shwango.com/2005/10/19/going-down-the-wrong-path/#comments</comments>
		<pubDate>Wed, 19 Oct 2005 20:23:57 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2005/10/19/going-down-the-wrong-path/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>For the most part, I love my development environment.  I really like the J2EE platform and using MyEclipse/Eclipse/Subclipse/JBoss/Subversion is a great combination and works really well <i>most</i> of the time.</p>
<p>Today I had one of those user errors that is a pain to track down.  I redeployed a custom J2EE app to our production JBoss server that I just updated and suddenly JDom breaks.  Worked fine on my local box.  Scratch head&#8230;</p>
<p>So I start by &#8220;cleaning&#8221; my local projects&#8230; Now my JSPs are coming up saying &#8220;bad class file&#8221; when referring to my classes included from my other project.  Scratch head&#8230;</p>
<p>Tried a bunch of different things&#8230; Bang head against wall&#8230;</p>
<p>Finally after hours of searching the web and recreating the projects, etc&#8230; I come across a post that mentions that the JSPs use javac from the path&#8230;</p>
<p>Crap!  I had put the old 1.4 jdk/bin directory in my path to make it easy to run javac before I was using Eclipse.  So now that I&#8217;m using 1.5 (aka Java 5) the JSPs were still being compiled with the 1.4 javac causing my problem.</p>
<p>Once I removed the 1.4 reference in my XP environment vars the JSPs compiled fine.</p>
<p>Of course I&#8217;m still getting the originally JDom error on production, so I still have to track down what&#8217;s causing that!  Doh!</p>
<p>References: <a href="http://myeclipseide.com/PNphpBB2+file-viewtopic-t-4681.html">Bad class file</a>, <a href="http://myeclipseide.com/PNphpBB2+file-viewtopic-t-9320-highlight-jsp+javac.html">Error running javac</a></p>
<p>My JDom error is this:</p>
<p><code>org.jdom.Element.addContent(Lorg/jdom/Content;)Lorg/jdom/Element;; nested exception is: java.lang.NoSuchMethodError: org.jdom.Element.addContent(Lorg/jdom/Content;)Lorg/jdom/Element;</code></p>
<p>I&#8217;m including JDom 1.0  jar in the EAR file and I don&#8217;t see any other jdom.jar files in the classpath.  Ideas?  Oh, production is using JBoss 4.0.1RC2 and my laptop is using 4.0.3.  I found <a href="http://www.jdom.org/pipermail/jdom-interest/2004-November/014412.html">this post</a>, but I&#8217;m <i>pretty</i> sure I&#8217;m using JDom 1.0 for compiling and running!</p>
<p>UPDATE: After upgrading our production box to JBoss 4.0.3 and JDK 1.5.0 (update 5) the JDom errors went away.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2005/10/19/going-down-the-wrong-path/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cool regex stuff&#8230;</title>
		<link>http://blog.shwango.com/2005/06/28/cool-regex-stuff/</link>
		<comments>http://blog.shwango.com/2005/06/28/cool-regex-stuff/#comments</comments>
		<pubDate>Tue, 28 Jun 2005 17:13:23 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2005/06/28/cool-regex-stuff/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>I was playing around with some regex (<a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>) stuff today and <a href="http://www.regular-expressions.info/lookaround.html">learned about &#8220;lookahead&#8221; and  &#8220;lookbehind&#8221;</a>.</p>
<p>This expression <code>(?<=\{\{).+(?=\}\})</code> will return all the characters, numbers and spaces between two curly brackets, but not the brackets themselves.</p>
<p>For example, the string <code>This is {{a test}} of regex</code> returns just <code>a test</code> when the regex is applied.</p>
<p>I also found the <a href="http://www.weitz.de/regex-coach/">Regex Coach</a> which was a great help in debugging the regular expressions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2005/06/28/cool-regex-stuff/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>So Ajax it is&#8230;</title>
		<link>http://blog.shwango.com/2005/03/18/so-ajax-it-is/</link>
		<comments>http://blog.shwango.com/2005/03/18/so-ajax-it-is/#comments</comments>
		<pubDate>Fri, 18 Mar 2005 17:46:23 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2005/03/18/so-ajax-it-is/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>I guess I&#8217;ll have to accept &#8220;Ajax&#8221; as the official term of the new breed of webapps.  In Monday&#8217;s Wall Street Journal, Lee Gromes posted an article in the Marketplace/Portals section called &#8220;Google Pioneers Use Of Old Microsoft Tools In New Web Programs&#8221; and the first two word are &#8220;Meet Ajax&#8221;.  So <a href="http://www.adaptivepath.com/publications/essays/archives/000385.php">thank you very much</a> Mr. Jesse James&#8230; Garrett, that is.</p>
<p>How about JNX, pronounced jinx for Javascript aNd Xml?  Ok, not the greatest, but that&#8217;s what I came up with of the top of my head&#8230;</p>
<p>Anyway, in the WSJ article, Gromes says the losers are Sun and Microsoft.  There is no need to compare Javascript and Java on the client &#8211; we all know applets are pretty much dead from a mass market standpoint &#8211; but Java on the server is still going strong and Ajax apps can push that market.  Microsoft missed the boat on Ajax &#8211; why didn&#8217;t they push it more?  Why did they push ASP.NET and server side rendering of GUI controls?  I&#8217;m not a ASP.NET programmer, but when I first looked that some of that stuff, I was really confused about what Microsoft was doing.</p>
<p>Whatever it&#8217;s called, it&#8217;s good stuff!  I don&#8217;t care about trying to support browsers that are ancient.  With CSS, Ajax and Firefox or IE, you can do quite amazing things for the user.  (I&#8217;m not sure about all the accessibility stuff though.)  I&#8217;m interested in stuff like <a href="http://www.dojotoolkit.org/">Dojo</a> and other things to work with client side rendering &#8211; versus server side <a href="http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html">MVC</a> stuff like <a href="http://struts.apache.org/">Struts</a>.  I should mention that I don&#8217;t usually do &#8220;web sites&#8221;, but &#8220;web apps&#8221; &#8211; that can make a difference.</p>
<p>I&#8217;m working on making my <a href="http://www.shwango.com/blog/archives/000276.html">iTunes now playing</a> feature auto update!  Not brain surgery, but still cool!</p>
<p>UPDATE: I wonder if a law suit could ensue?  <a href="http://www.colgate.com/app/Colgate/US/HouseholdCare/ProductRecommender/DishwashingLiquid/PDPs.cvsp?product=AjaxDishLiquidandAntibacterialHandsoap_210">Colgate-Palmolive&#8217;s Ajax</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2005/03/18/so-ajax-it-is/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Suggest</title>
		<link>http://blog.shwango.com/2005/01/12/google-suggest/</link>
		<comments>http://blog.shwango.com/2005/01/12/google-suggest/#comments</comments>
		<pubDate>Wed, 12 Jan 2005 15:30:45 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2005/01/12/google-suggest/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>This post is just in order to clean out some <a href="http://www.bloglines.com/public/shwango">bloglines</a> links that I&#8217;ve &#8220;saved for later&#8221; &#8211; which is getting a little out of control!</p>
<p>From a <a href="http://www.google.com/googleblog/2004/12/ive-got-suggestion.html">post</a> from the guy who came up with Google Suggest:</p>
<p><i>The project stemmed from an idea I had a few months ago, and since then I&#8217;ve been working on it in my 20% time, which is a program where Google allows their employees to devote 20% of their working hours to any project they choose. What&#8217;s really amazed me about this project is how in a matter of months, working on my own, I was able to go from a lunch table conversation to launching a new service. In my opinion, this is one of the things that really makes Google a great place; that the company&#8217;s systems, resources and, most important, people are all aligned to make it as easy as possible to take an idea and turn it into something cool.</i></p>
<p>Some info on <a href="http://slashdot.org/comments.pl?sid=132312&#038;cid=11053245">how it&#8217;s done</a> &#8211; <a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html">XMLHttpRequest</a>.  <a href="http://www.sitepoint.com/blog-post-view.php?id=216588">More</a> on auto complete.</p>
<p>UPDATE: More info on how it&#8217;s done: <a href="http://developers.slashdot.org/article.pl?sid=04/12/24/1432254">Google Suggest Dissected, Part II</a> (Slashdot) and the <a href="http://bayardo.youserv.net/Google_Suggest/Analysis.html">direct link</a>.</p>
<p>I&#8217;ve <a href="http://www.shwango.com/blog/archives/000209.html">posted</a> before about XMLHttpRequest and it&#8217;s possibly one of my favorite things in the coding world &#8211; so I guess I can&#8217;t hate Microsoft too much since they&#8217;re the ones that first implemented it!  I&#8217;m just really glad that Mozilla choose to incorporate it too!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2005/01/12/google-suggest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iTunes and a &#8220;Now Playing&#8221; feature</title>
		<link>http://blog.shwango.com/2004/12/29/itunes-and-a-now-playing-feature/</link>
		<comments>http://blog.shwango.com/2004/12/29/itunes-and-a-now-playing-feature/#comments</comments>
		<pubDate>Wed, 29 Dec 2004 14:03:12 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2004/12/29/itunes-and-a-now-playing-feature/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>[UPDATED - see below!]</p>
<p>Here&#8217;s some cool code I hacked together from the iTunes Windows COM SDK docs and some other sites &#8211; <a href="http://blogs.msdn.com/dancre/archive/2004/05/08/128645.aspx">Dan Crevier&#8217;s Blog</a> and <a href="http://blog.andrewcarlson.org/archive/2004/05/18/244.aspx">ajc</a>.</p>
<p>I had already <a href="http://www.shwango.com/blog/archives/000261.html">posted</a> how I did something like this in WinAmp, but I&#8217;ve been using iTunes a lot now and really like it.  There are a few plugins and such out there to post the current track info to a file or site, but the main thing other scripts didn&#8217;t do was to post the stream info if iTunes was playing a stream.</p>
<p>Basically it&#8217;s some JavaScript that runs in the background listening for events from the iTunes applications.  Currently I&#8217;m just using OnPlayerPlayEvent and OnQuittingEvent, but some of the other events might be cool to use.  I just create a little XML and post it to the web server &#8211; this one&#8217;s real time, where my WinAmp one was polled.</p>
<p>I don&#8217;t know how good or efficient this code is, but it hasn&#8217;t crashed my box yet!  I also am posting a simple cgi I hacked up in Perl to snag the bits of XML and output an HTML file that is included in my main page via SSI.</p>
<p>I just start iTunes, then run my script.  When I exit iTunes, the JavaScript code exits as well &#8211; and it tells you it&#8217;s closing.</p>
<p>iTunes JavaScript code: (I think I got the html escaped &#8211; I need a better way to post code!)</p>
<div class="code">var iTunesApp = WScript.CreateObject(&quot;iTunes.Application&quot;);<br />
var iTunesIsRunning = true;</p>
<p>function ITEventTest_OnPlayerPlayEvent(iTrack) {<br />
&nbsp;&nbsp;&nbsp;getCurrentTrackInfo();<br />
}</p>
<p>function ITEventTest_OnPlayerPlayingTrackChangedEvent(iTrack) {<br />
&nbsp;&nbsp;&nbsp;getCurrentTrackInfo();<br />
}</p>
<p>function ITEventTest_OnQuittingEvent() {<br />
&nbsp;&nbsp;&nbsp;iTunesIsRunning = false;<br />
}</p>
<p>function getCurrentTrackInfo() {<br />
&nbsp;&nbsp;&nbsp;var current = iTunesApp.CurrentTrack;<br />
&nbsp;&nbsp;&nbsp;var stream = iTunesApp.CurrentStreamTitle;</p>
<p>&nbsp;&nbsp;&nbsp;var trackType = &quot;&quot;;<br />
&nbsp;&nbsp;&nbsp;var trackName = &quot;&quot;;<br />
&nbsp;&nbsp;&nbsp;var trackArtist = &quot;&quot;;<br />
&nbsp;&nbsp;&nbsp;var trackAlbum = &quot;&quot;;</p>
<p>&nbsp;&nbsp;&nbsp;if (stream != &quot;&quot;) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;streamURL = iTunesApp.CurrentStreamURL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackType=&quot;stream&quot;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackName=stream;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackArtist=current.Name;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackAlbum=streamURL;<br />
&nbsp;&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackType=&quot;file&quot;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackName=current.Name;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackArtist=current.Artist;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trackAlbum=current.Album;<br />
&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;var response = postTrack(trackType, trackName, trackArtist, trackAlbum);<br />
}</p>
<p>function postTrack(trackType, trackName, trackArtist, trackAlbum) {<br />
&nbsp;&nbsp;&nbsp;var xmlTrack = new ActiveXObject(&quot;MSXML2.DOMDocument.4.0&quot;);<br />
&nbsp;&nbsp;&nbsp;xmlTrack.loadXML(&#8217;&lt;?xml version=&quot;1.0&quot; ?&gt;&lt;track/&gt;&#8217;);<br />
&nbsp;&nbsp;&nbsp;var root = xmlTrack.documentElement;<br />
&nbsp;&nbsp;&nbsp;root.setAttribute(&quot;type&quot;, trackType);</p>
<p>&nbsp;&nbsp;&nbsp;var textNode = xmlTrack.createElement(&quot;name&quot;);<br />
&nbsp;&nbsp;&nbsp;textNode.text = trackName;<br />
&nbsp;&nbsp;&nbsp;root.appendChild(textNode);<br />
&nbsp;&nbsp;&nbsp;var textNode = xmlTrack.createElement(&quot;artist&quot;);<br />
&nbsp;&nbsp;&nbsp;textNode.text = trackArtist;<br />
&nbsp;&nbsp;&nbsp;root.appendChild(textNode);<br />
&nbsp;&nbsp;&nbsp;var textNode = xmlTrack.createElement(&quot;album&quot;);<br />
&nbsp;&nbsp;&nbsp;textNode.text = trackAlbum;<br />
&nbsp;&nbsp;&nbsp;root.appendChild(textNode);</p>
<p>&nbsp;&nbsp;&nbsp;var xmlhttp = new ActiveXObject(&quot;MSXML2.XMLHTTP.4.0&quot;);<br />
&nbsp;&nbsp;&nbsp;xmlhttp.open(&quot;POST&quot;, &quot;http://[cgi url]&quot;,false);<br />
&nbsp;&nbsp;&nbsp;xmlhttp.send(xmlTrack);<br />
&nbsp;&nbsp;&nbsp;if (xmlhttp.status != &quot;200&quot;) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WScript.Echo(&quot;Error posting to server.  Code is: &quot; + xmlhttp.status);<br />
&nbsp;&nbsp;&nbsp;}<br />
}</p>
<p>WScript.ConnectObject(iTunesApp, &quot;ITEventTest_&quot;);<br />
WScript.Echo(&quot;Waiting for changes&#8230;&quot;);<br />
getCurrentTrackInfo();</p>
<p>while (iTunesIsRunning) {<br />
&nbsp;&nbsp;&nbsp;WScript.Sleep(1000);<br />
}</p>
<p>var response = postTrack(&quot;OFFLINE&quot;, &quot;offline.&quot;, &quot;&quot;, &quot;&quot;);</p>
<p>WScript.DisconnectObject(iTunesApp);<br />
WScript.Echo(&quot;iTunes was closed, iTunesListener exiting.&quot;);</p></div>
<p>Perl CGI on the server: (Beware: I&#8217;m not a great Perl coder!)</p>
<div class="code">#!/usr/bin/perl</p>
<p>use XML::LibXML;</p>
<p>local $/;</p>
<p>my $parser = XML::LibXML-&gt;new();</p>
<p>my $request = &lt;STDIN&gt;;<br />
my $xmlRequest = $parser-&gt;parse_string($request);</p>
<p>my $root = $xmlRequest-&gt;getDocumentElement;<br />
my $type = $root-&gt;getAttribute(&quot;type&quot;);</p>
<p>my @nodes = $root-&gt;findnodes(&quot;name&quot;);<br />
my $name = $nodes[0]-&gt;string_value();</p>
<p>@nodes = $root-&gt;findnodes(&quot;artist&quot;);<br />
my $artist = $nodes[0]-&gt;string_value();</p>
<p>my @nodes = $root-&gt;findnodes(&quot;album&quot;);<br />
my $album = $nodes[0]-&gt;string_value();</p>
<p>open(file,&quot;&gt;[path writable by web server]/current_song.html&quot;);<br />
print file $name;<br />
print file &quot;&lt;br /&gt;&quot;;<br />
print file $artist;<br />
print file &quot;&lt;br /&gt;&quot;;<br />
print file $album;<br />
print file &quot;\n&quot;;<br />
close(file);</p>
<p>print &quot;Content-type: text/html\n\n&quot;;<br />
print &quot;ok&quot;;</p></div>
<p>And the simple Server Side Include in my html:</p>
<div class="code">&lt;!&#8211;#include virtual=&#8221;../includes/iTunes/current_song.html&#8221; &#8211;&gt;</div>
<p>Works for me and it&#8217;s pretty cool hack I think!  I&#8217;m thinking about some other possiblities&#8230; If I can use iTunes to publish a stream, then I could have some playlist posting and even playlist manipulation &#8211; that could be cool.</p>
<p>Also I found a somewhat cool plugin for iTunes on Windows called <a href="http://www.aqua-soft.org/board/showthread.php?t=20715">&#8220;multi plugin&#8221;</a>.  I only really use the plugin for controlling iTunes with my laptop&#8217;s multimedia buttons when iTunes is minimized &#8211; iTunes should automatically do this like WinAmp did.  I can&#8217;t figure out how to uninstall it though!</p>
<p><b>UPDATE:</b></p>
<p>Seems I deleted some code that is needed so that the getCurrentTrackInfo() function is called when listening to a stream.  The &#8220;OnPlayerPlayEvent&#8221; event is not called when the track a stream is playing changes.  You need to trap for &#8220;OnPlayerPlayingTrackChangedEvent&#8221;, so just add this:</p>
<div class="code">function ITEventTest_OnPlayerPlayingTrackChangedEvent(iTrack) {<br />
&nbsp;&nbsp;&nbsp;getCurrentTrackInfo();<br />
}</div>
<p>I&#8217;ve updated my code above to reflect this.  The full title of the stream sometimes isn&#8217;t present when you first connect &#8211; just reconnect if that bothers you.</p>
<p>Also, I need to add some more error trapping too.  The script crashes if you start the script and iTunes isn&#8217;t playing anything &#8211; at least this happens to me!</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2004/12/29/itunes-and-a-now-playing-feature/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>When you have to use Windows &#8211; GnuWin32</title>
		<link>http://blog.shwango.com/2004/04/15/when-you-have-to-use-windows-gnuwin32/</link>
		<comments>http://blog.shwango.com/2004/04/15/when-you-have-to-use-windows-gnuwin32/#comments</comments>
		<pubDate>Thu, 15 Apr 2004 18:25:27 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2004/04/15/when-you-have-to-use-windows-gnuwin32/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>I hate to admit it, but I still use Windows as my desktop OS.  XP isn&#8217;t too bad for me.  Sure it has its problems, but it&#8217;s what gets the job done.  Linux still needs a few more refinements and apps for me to really switch.  But I do love the command line!  So if you need to use Windows, but want those great utils, head over to the <a href="http://gnuwin32.sourceforge.net/packages.html">GnuWin32 packages page</a> at <a href="http://sourceforge.net/">SourceForge</a>.  These utils make things better, along with <a href="http://www.shwango.com/blog/archives/000137.html">WinSCP</a> and <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2004/04/15/when-you-have-to-use-windows-gnuwin32/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java and TextPad</title>
		<link>http://blog.shwango.com/2004/03/19/java-and-textpad/</link>
		<comments>http://blog.shwango.com/2004/03/19/java-and-textpad/#comments</comments>
		<pubDate>Fri, 19 Mar 2004 18:44:08 +0000</pubDate>
		<dc:creator>osterday</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.shwango.com/2004/03/19/java-and-textpad/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>It seems that no one&#8217;s documented using TextPad&#8217;s Workspaces and Java.  There&#8217;s a lot about using TextPad and Java, but we&#8217;ve been using the Workspace feature of TextPad for several years at work and I figured I&#8217;d document it (complete with screen shots!) so we don&#8217;t have ask each other after a re-install&#8230;</p>
<p>Note: Install TextPad after you install the JDK so you don&#8217;t have to manually enter the default Java &#8220;Tools&#8221; commands in TextPad.</p>
<p><b>Compile Java:</b></p>
<p><a href="http://www.shwango.com/blog/archives/images/TextPad_CompileJava.html" onclick="window.open('http://www.shwango.com/blog/archives/images/TextPad_CompileJava.html','popup','width=516,height=352,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.shwango.com/blog/archives/images/TextPad_CompileJava-thumb.jpg" width="150" height="102" border="0" /></a></p>
<p>Command: javac.exe<br />
Parameters: -g:none -deprecation -classpath $WspDir $File -d $WspDir<br />
Initial Folder: $FileDir</p>
<p><b>Run Java Application:</b></p>
<p><a href="http://www.shwango.com/blog/archives/images/TextPad_RunJavaApplication.html" onclick="window.open('http://www.shwango.com/blog/archives/images/TextPad_RunJavaApplication.html','popup','width=516,height=352,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.shwango.com/blog/archives/images/TextPad_RunJavaApplication-thumb.jpg" width="150" height="102" border="0" /></a></p>
<p>Command: java.exe<br />
Parameters: -classpath $WspDir $Basename<br />
Initial Folder: $FileDir</p>
<p><b>Run Java Applet:</b> (We don&#8217;t really use this too much.)</p>
<p><a href="http://www.shwango.com/blog/archives/images/TextPad_RunJavaApplet.html" onclick="window.open('http://www.shwango.com/blog/archives/images/TextPad_RunJavaApplet.html','popup','width=516,height=352,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.shwango.com/blog/archives/images/TextPad_RunJavaApplet-thumb.jpg" width="150" height="102" border="0" /></a></p>
<p>Command: appletviewer.exe<br />
Parameters: $Basename<br />
Initial Folder: $FileDir</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shwango.com/2004/03/19/java-and-textpad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
