<?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>A developers life</title>
	<atom:link href="http://www.tobiasbraner.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tobiasbraner.de</link>
	<description>Java Ruby PHP and more</description>
	<lastBuildDate>Mon, 04 Jul 2011 13:34:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Windows: Get the mouse position with Ruby</title>
		<link>http://www.tobiasbraner.de/2011/07/04/windows-get-the-mouse-position-with-ruby/</link>
		<comments>http://www.tobiasbraner.de/2011/07/04/windows-get-the-mouse-position-with-ruby/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 13:30:06 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Allgemeines]]></category>

		<guid isPermaLink="false">http://www.tobiasbraner.de/?p=72</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 require 'Win32API' &#160; getCursorPos = Win32API.new&#40;&#34;user32&#34;, &#34;GetCursorPos&#34;, &#91;'P'&#93;, 'V'&#41; lpPoint = &#34; &#34; * 8 # store two LONGs getCursorPos.Call&#40;lpPoint&#41; x, y = lpPoint.unpack&#40;&#34;LL&#34;&#41; # get the actual values print &#8230; <a href="http://www.tobiasbraner.de/2011/07/04/windows-get-the-mouse-position-with-ruby/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'Win32API'</span>
&nbsp;
getCursorPos = Win32API.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;user32&quot;</span>, <span style="color:#996600;">&quot;GetCursorPos&quot;</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'P'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#996600;">'V'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
lpPoint = <span style="color:#996600;">&quot; &quot;</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">8</span> <span style="color:#008000; font-style:italic;"># store two LONGs</span>
getCursorPos.<span style="color:#9900CC;">Call</span><span style="color:#006600; font-weight:bold;">&#40;</span>lpPoint<span style="color:#006600; font-weight:bold;">&#41;</span>
x, y = lpPoint.<span style="color:#9900CC;">unpack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;LL&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># get the actual values</span>
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;x: &quot;</span>, x, <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;y: &quot;</span>, y, <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># hf ;)</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/07/04/windows-get-the-mouse-position-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My entry to a remix contest: Veela &#8211; Night Vision</title>
		<link>http://www.tobiasbraner.de/2011/06/17/my-entry-to-a-remix-contest-veela-night-vision/</link>
		<comments>http://www.tobiasbraner.de/2011/06/17/my-entry-to-a-remix-contest-veela-night-vision/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 08:59:00 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://www.tobiasbraner.de/?p=66</guid>
		<description><![CDATA[Veela &#8211; Night Vision (TBR Dance Remix)]]></description>
			<content:encoded><![CDATA[<p><object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F16941624"></param><param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F16941624" type="application/x-shockwave-flash" width="100%"></embed></object>  <span><a href="http://soundcloud.com/toovy/veela-night-vision-tbr-dance">Veela &#8211; Night Vision (TBR Dance Remix)</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/06/17/my-entry-to-a-remix-contest-veela-night-vision/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lol-patch.com</title>
		<link>http://www.tobiasbraner.de/2011/05/02/lol-patch-com/</link>
		<comments>http://www.tobiasbraner.de/2011/05/02/lol-patch-com/#comments</comments>
		<pubDate>Mon, 02 May 2011 21:02:37 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Allgemeines]]></category>

		<guid isPermaLink="false">http://www.tobiasbraner.de/?p=60</guid>
		<description><![CDATA[I guess not everyone reading this article is a fan of League of Legends (LoL), a famous multiplayer game in which two enemy factions are fighting each other to destroy the enemies base. Nevertheless I&#8217;ve built a website around this &#8230; <a href="http://www.tobiasbraner.de/2011/05/02/lol-patch-com/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I guess not everyone reading this article is a fan of League of Legends (LoL), a famous multiplayer game in which two enemy factions are fighting each other to destroy the enemies base. Nevertheless I&#8217;ve built a website around this game &#8211; or to be more special &#8211; around the patches which are released for it. Officially Riot, the developer and publisher of LoL, just throws out some patch notes each patch, but if you are not able to keep track of each patch, you can easily get lost in the near endless changes. Often you just want to know what changed for a special hero or item. So I sat down and brewed a nice website which can be reached at <a href="http://www.lol-patch.com">http://www.lol-patch.com</a> or <a href="http://www.lol-patch-history.com">http://www.lol-patch-history.com</a>.</p>
<p>This site is built using the famous web technologies Ruby, Nokogiri, HAML and jQuery. Basically I do not own a Rails enabled webspace, so I decided that I just crawl the data on my local Mac, put the data into some HAML templates and generate some HTML, which gets a bit of dynamic using jQuery with its great DOM manipulation functionality.</p>
<p>Some words about the crawling. Basically I&#8217;m using the standard Ruby Net::HTTP classes to make simple get request to the official LoL website to gather information about which champions and items are available. After collecting the basic data I fetch all patch notes with simple HTTP GET request.</p>
<p>The so acquired HTML pages are parsed using the famous Nokogiri parser. So all the data comes together &#8211; champions, items, changes.</p>
<p>First I started off creating some custom HTML. This turned out &#8211; as always &#8211; to be too inflexible as the app grew. So I started to include HAML and built some HAML templates, which basically are saved as HTML afterwards.</p>
<p>Having the feeling that the site needs some search or filter function I first thought that I need some PHP on the server side. But I ended up using jQuery to filter the champions and items, which really turned out to be easy, using the built in jQuery $.each and some regular expressions.</p>
<p>To conclude this post I must say that all this technologies are great and I can only recommend to try them out and use them! Drop me a comment if you like a more detailed post about this topics.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/05/02/lol-patch-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a jQuery plugin with coffeescript</title>
		<link>http://www.tobiasbraner.de/2011/04/12/writing-a-jquery-plugin-with-coffeescript/</link>
		<comments>http://www.tobiasbraner.de/2011/04/12/writing-a-jquery-plugin-with-coffeescript/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 11:46:50 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Sonstiges]]></category>

		<guid isPermaLink="false">http://www.tobiasbraner.de/?p=40</guid>
		<description><![CDATA[Coffescript saves my day, as I don&#8217;t like javascript and the coffeescript syntax is more python/ruby based. Coffeescript itself compiles to javascript. It is very easy to learn, nevertheless it was not easy to create the basic code to register &#8230; <a href="http://www.tobiasbraner.de/2011/04/12/writing-a-jquery-plugin-with-coffeescript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://jashkenas.github.com/coffee-script/">Coffescript </a>saves my day, as I don&#8217;t like javascript and the coffeescript syntax is more python/ruby based. Coffeescript itself compiles to javascript. It is very easy to learn, nevertheless it was not easy to create the basic code to register a new jQuery plugin. The following code serves as template:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">$ = jQuery
&nbsp;
methods =
  init: <span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">-&gt;</span>
    obj = @
    <span style="color:#008000; font-style:italic;"># do something</span>
&nbsp;
$.<span style="color:#9900CC;">fn</span>.<span style="color:#9900CC;">your_plugin_name</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>method<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">-&gt;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> method of methods
    <span style="color:#0000FF; font-weight:bold;">return</span> methods<span style="color:#006600; font-weight:bold;">&#91;</span> method <span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">apply</span><span style="color:#006600; font-weight:bold;">&#40;</span> this, <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">prototype</span>.<span style="color:#9900CC;">slice</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span> arguments, <span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;
  <span style="color:#9966CC; font-weight:bold;">else</span> $.<span style="color:#9900CC;">error</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;Method #{method} does not exist on jQuery.your_plugin_name&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</pre></td></tr></table></div>

<p>This coffeescript compiles to:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> $<span style="color: #339933;">,</span> methods<span style="color: #339933;">;</span>
$ <span style="color: #339933;">=</span> jQuery<span style="color: #339933;">;</span>
methods <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  init<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> obj<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> obj <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">your_plugin_name</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>method<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>method <span style="color: #000066; font-weight: bold;">in</span> methods<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> methods<span style="color: #009900;">&#91;</span>method<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">slice</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> $.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Method &quot;</span> <span style="color: #339933;">+</span> method <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; does not exist on jQuery.your_plugin_name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You would call your plugin e.g. this way (from javascript):</p>
<pre language="JAVASCRIPT" line="1">
$('#target_div').your_plugin_name('init', {your: "option"});
</pre>
<p>If you are still waiting for the *Yeah, I have to use coffeescript!&#8221;-moment read this: </p>
<p>The lines of code of my jQuery plugin were reduced by 50% and the code is much more readable now! Don&#8217;t miss the <a href="http://jashkenas.github.com/coffee-script/">coffeescript page </a>which will give you much more arguments for coffeescript as I could ever do here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/04/12/writing-a-jquery-plugin-with-coffeescript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uninstall all local ruby gems</title>
		<link>http://www.tobiasbraner.de/2011/04/11/uninstall-all-local-ruby-gems/</link>
		<comments>http://www.tobiasbraner.de/2011/04/11/uninstall-all-local-ruby-gems/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 14:38:00 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.tobiasbraner.de/?p=35</guid>
		<description><![CDATA[This ruby script might be useful for people like me who just started using bundler to manage the gems of their webapp and all others, which want to clean up their gems. Caution: all installed gems are removed from rubygems! &#8230; <a href="http://www.tobiasbraner.de/2011/04/11/uninstall-all-local-ruby-gems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This ruby script might be useful for people like me who just started using bundler to manage the gems of their webapp and all others, which want to clean up their gems. Caution: all installed gems are removed from rubygems!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">f = <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;|gem list&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
output = f.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
output.<span style="color:#9900CC;">each_line</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>l<span style="color:#006600; font-weight:bold;">|</span>
	gem_name = l.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot; &quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>
	<span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;gem uninstall --a --ignore-dependencies #{gem_name}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Basically this script just executes the &#8220;gem list&#8221; command, fetches the output, extracts the gem name and uninstalls it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/04/11/uninstall-all-local-ruby-gems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing GIT on Mac with Macports</title>
		<link>http://www.tobiasbraner.de/2011/03/24/installing-git-on-mac-with-macports/</link>
		<comments>http://www.tobiasbraner.de/2011/03/24/installing-git-on-mac-with-macports/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 08:16:31 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Sonstiges]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[macos]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[macports]]></category>

		<guid isPermaLink="false">http://www.tobiasbraner.de/2011/03/24/untitled/</guid>
		<description><![CDATA[This small guide will help to install GIT on Mac using Macports. Environment: Mac Os X &#8211; Leopard 10.6.6 MacPorts 1.9.2 Start of the installation $ sudo port selfupdate $ sudo port install git-core 1st Problem Error: Target org.macports.build returned: &#8230; <a href="http://www.tobiasbraner.de/2011/03/24/installing-git-on-mac-with-macports/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This small guide will help to install GIT on Mac using Macports.</p>
<p><strong>Environment:</strong></p>
<ul>
<li>Mac Os X &#8211; Leopard 10.6.6</li>
<li>MacPorts 1.9.2</li>
</ul>
<h3>Start of the installation</h3>
<p><code>$ sudo port selfupdate<br />
$ sudo port install git-core</code><span id="more-32"></span><br />
<h3>1st Problem</h3>
<p><code>Error: Target org.macports.build returned: shell command failed (see log for details)<br />
Error: Failed to install perl5.12</code></p>
<p>Perl5 is a compilation dependency, but somehow not declared, so install it manually:</p>
<p><code>$ sudo port install perl5</code></p>
<p><strong>And again:</strong></p>
<p><code>$ sudo port install git-core</code></p>
<h3>2nd Problem</h3>
<p><code>Error: db46 requires the Java for Mac OS X development headers.</p>
<p>https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719</code></p>
<p>Interested in why this error comes up?</p>
<p><a href="http://comments.gmane.org/gmane.os.apple.macports.user/22266">http://comments.gmane.org/gmane.os.apple.macports.user/22266</a></p>
<blockquote><p>
Apple&#8217;s most recent security update prior to Mac OS X 10.6.5 (presumably included in 10.6.5 also) deletes a<br />
file that was previously part of the OS, and is now only part of that development package. We don&#8217;t know why<br />
Apple made this change, only that db46 and a handful of other ports break without it, so we detect this and<br />
advise you how to fix it.
</p></blockquote>
<p>Visit with the <a href="https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719">Apple page</a> and fetch the development headers &#8211; be aware that you need an Apple-ID.  </p>
<p><strong>And again:</strong></p>
<p><code>$ sudo port install git-core</code></p>
<p><strong>Success!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/03/24/installing-git-on-mac-with-macports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rake &amp; FTP</title>
		<link>http://www.tobiasbraner.de/2011/03/16/rake-ftp/</link>
		<comments>http://www.tobiasbraner.de/2011/03/16/rake-ftp/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 19:37:41 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://tobiasbraner.de/blog/?p=23</guid>
		<description><![CDATA[Rake is a build tool for ruby, similar to C&#8217;s make or Java&#8217;s ant/maven. Basically you can define a lot of tasks, which can be executed, may have prerequisites and can do a lot boring tasks, from file operations to &#8230; <a href="http://www.tobiasbraner.de/2011/03/16/rake-ftp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Rake is a build tool for ruby, similar to C&#8217;s make or Java&#8217;s ant/maven.</p>
<p>Basically you can define a lot of tasks, which can be executed, may have prerequisites and can do a lot boring tasks, from file operations to building gems.</p>
<p>One great thing is that you can easily deploy your whole project to your FTP server. Searching around I did not find a lot of information about that &#8211; this is the reason I&#8217;ll write about it.</p>
<p><strong>Rake::FtpUploader</strong><br />
Rake has a built in class for handling simple FTP uploads, but this class is not well documented. You can use it this way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rake'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rake/contrib/ftptools'</span>
&nbsp;
task <span style="color:#ff3333; font-weight:bold;">:upload_all</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#6666ff; font-weight:bold;">Rake::FtpUploader</span>.<span style="color:#9900CC;">connect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/path/on/server'</span>, <span style="color:#996600;">'your_host'</span>, <span style="color:#996600;">'your_user'</span>, <span style="color:#996600;">'your_pw'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>ftp<span style="color:#006600; font-weight:bold;">|</span>
    ftp.<span style="color:#9900CC;">verbose</span> = <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#008000; font-style:italic;"># gives you some output</span>
    ftp.<span style="color:#9900CC;">upload_files</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;./your/favorite/folder/**/*&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>The <em>ftp.upload_files</em> method takes a wildcard parameter, which is the same as you would feed into the Dir[wildcard] class. At the end, the FtpTools just use Dir to find all files. For the wildcard it is good to know, that a single * says &#8220;upload all files and folders&#8221;, but a **/* says &#8220;upload all files and folders in a recursive way, including subfolders and their files. Thus said, &#8220;./**/*&#8221; would upload everything from the base dir of your rakefile.</p>
<p><strong>Extending Rake&#8217;s FtpTools for deletion</strong><br />
In my case I was using rake to upload files for a PHP project &#8211; written with the symfony framework. Symfony &#8211; as many other frameworks &#8211; has a cache which needs to be cleared if some settings for the view change. As the cache is simply a folder on the FTP server, I thought that rake could be used to easily clear the cache. Reminding myself of the fact that everything in Ruby is just an object, I just extended the FtpUploader class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Rake
  <span style="color:#9966CC; font-weight:bold;">class</span> FtpUploader
&nbsp;
    <span style="color:#008000; font-style:italic;"># Deletes all files in a folder like cache/management. Does</span>
    <span style="color:#008000; font-style:italic;"># not delete folders</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> delete_files<span style="color:#006600; font-weight:bold;">&#40;</span>folder<span style="color:#006600; font-weight:bold;">&#41;</span>
      delete_files_recursive<span style="color:#006600; font-weight:bold;">&#40;</span>folder<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    private
&nbsp;
    <span style="color:#008000; font-style:italic;"># starts with a folder, like cache/management and deletes</span>
    <span style="color:#008000; font-style:italic;"># all files recursively BUT not the folders.</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> delete_files_recursive<span style="color:#006600; font-weight:bold;">&#40;</span>file_or_folder<span style="color:#006600; font-weight:bold;">&#41;</span>
      folder = <span style="color:#0000FF; font-weight:bold;">true</span>
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        <span style="color:#0066ff; font-weight:bold;">@ftp</span>.<span style="color:#9900CC;">chdir</span><span style="color:#006600; font-weight:bold;">&#40;</span>file_or_folder<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span>
        <span style="color:#008000; font-style:italic;"># this is a file, no folder =&gt; delete</span>
        folder = <span style="color:#0000FF; font-weight:bold;">false</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">if</span> folder
        file_list = <span style="color:#0066ff; font-weight:bold;">@ftp</span>.<span style="color:#9900CC;">nlst</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'*'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        file_list.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> delete_files_recursive<span style="color:#006600; font-weight:bold;">&#40;</span>f<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
        <span style="color:#0066ff; font-weight:bold;">@ftp</span>.<span style="color:#9900CC;">chdir</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'..'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Delete #{file_or_folder}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@verbose</span>
        delete file_or_folder
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># deletes a single file</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> delete<span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Deleting #{file}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@verbose</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        <span style="color:#0066ff; font-weight:bold;">@ftp</span>.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span>
        <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Could not delete file #{file}&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>This snippet only deletes files, no folders. In my case this is wanted, as I&#8217;m not sure what the cache does if you destroy the folder structure, but nevertheless it could be easily extended. After all files of a folder are deleted, after the @ftp.chdir(&#8216;..&#8217;) is executed, the folder could be deleted.<br />
<strong>Usage</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:cache</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  task <span style="color:#ff3333; font-weight:bold;">:clean</span>
    <span style="color:#6666ff; font-weight:bold;">Rake::FtpUploader</span>.<span style="color:#9900CC;">connect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/path/on/server'</span>, <span style="color:#996600;">'your_host'</span>, <span style="color:#996600;">'your_user'</span>, <span style="color:#996600;">'your_pw'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>ftp<span style="color:#006600; font-weight:bold;">|</span>
      ftp.<span style="color:#9900CC;">delete_files</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'cache/subfolder'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/03/16/rake-ftp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby web scraping</title>
		<link>http://www.tobiasbraner.de/2011/01/29/ruby-web-scraping/</link>
		<comments>http://www.tobiasbraner.de/2011/01/29/ruby-web-scraping/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 14:54:05 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[ruby threading]]></category>
		<category><![CDATA[ruby1.9]]></category>
		<category><![CDATA[scraping]]></category>
		<category><![CDATA[simplerss]]></category>
		<category><![CDATA[Watir]]></category>
		<category><![CDATA[webscraping]]></category>

		<guid isPermaLink="false">http://tobiasbraner.de/blog/?p=22</guid>
		<description><![CDATA[I want to share my recent experience with ruby web scraping and RSS. Often I found myself checking the comments for my game iBox3D using http://www.appcomments.com. But the problem is that you can only display the comments by country and &#8230; <a href="http://www.tobiasbraner.de/2011/01/29/ruby-web-scraping/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I want to share my recent experience with ruby web scraping and RSS. </p>
<p>Often I found myself checking the comments for my game iBox3D using http://www.appcomments.com. But the problem is that you can only display the comments by country and my app does so far only have comments in Germany, USA and UK. But the website does not show where you have comments or not. It was hard to say, if there were new comments or not. So I decided to write a small ruby script which should compile all comments and display them. The script evolved as I continued to optimize it:</p>
<ul>
<li>v1: I used WATIR to automate the internet explorer and to get the HTML from the website</li>
<li>v2: I used the built in RSS lib to fetch the RSS</li>
<li>v3: I used simple-rss to fetch the RSS</li>
<li>v4: I used simple-rss to fetch the RSS and used threads to do that for all countries simultaneously</li>
</ul>
<p>This post will handle following topics:</p>
<ul>
<li>Ruby 1.9</li>
<li>Watir</li>
<li>RSS with the build-in RSS lib and simple-rss</li>
<li>utf8 vs. ASCII</li>
<li>Threading</li>
<li>JRuby and Ruby</li>
</ul>
<h3>Version 1: Watir</h3>
<p>Watir is a lib that helps to automate the browser. For those who want to install Watir at Ruby 1.9 you need to install the ruby devtools and then install the gem with the &#8211;platform=ruby option. Here is the script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'watir'</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### hide or show the internet explorer</span>
<span style="color:#ff6633; font-weight:bold;">$HIDE_IE</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># declare some variables</span>
source_url = <span style="color:#996600;">&quot;http://appcomments.com/app/iBox3D&quot;</span>
comments = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span>
country_links = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### open the internet explorer and navigate to the source url</span>
ie = <span style="color:#6666ff; font-weight:bold;">Watir::IE</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
ie.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span>source_url<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### fetch the links to the different countries</span>
ie.<span style="color:#9900CC;">links</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>link<span style="color:#006600; font-weight:bold;">|</span>
	<span style="color:#9966CC; font-weight:bold;">if</span> link.<span style="color:#9900CC;">href</span> =~ <span style="color:#006600; font-weight:bold;">/</span>iBox3D\?country=<span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>
		country_links <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> link.<span style="color:#9900CC;">href</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### loop over all country links</span>
country_links.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>link<span style="color:#006600; font-weight:bold;">|</span>
	<span style="color:#008000; font-style:italic;"># go to the country specific link</span>
	ie.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span>link<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
	<span style="color:#008000; font-style:italic;"># due to unknown reasons sometimes the DIV was not there =&gt; reload</span>
	<span style="color:#9966CC; font-weight:bold;">until</span>  ie.<span style="color:#9900CC;">div</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;review_dropdowns&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">exists</span>? <span style="color:#9966CC; font-weight:bold;">do</span>
		<span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		ie.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span>link<span style="color:#006600; font-weight:bold;">&#41;</span>
		<span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#008000; font-style:italic;"># get the DIV with id = review_dropdowns</span>
	review = ie.<span style="color:#9900CC;">div</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;review_dropdowns&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#008000; font-style:italic;"># get the country text from the SPAN in the DIV</span>
	country = review.<span style="color:#9900CC;">divs</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">spans</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">text</span>
	<span style="color:#008000; font-style:italic;"># loop over all DIVs</span>
	ie.<span style="color:#9900CC;">divs</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>d<span style="color:#006600; font-weight:bold;">|</span>
		<span style="color:#008000; font-style:italic;"># check the DIV class, if it has &quot;comment&quot;, then proceed</span>
		<span style="color:#9966CC; font-weight:bold;">if</span> d.<span style="color:#9900CC;">class_name</span>.<span style="color:#9900CC;">downcase</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\bcomment\b<span style="color:#006600; font-weight:bold;">/</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
			<span style="color:#008000; font-style:italic;"># initialize a hash for the comment information</span>
			inf = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span>
			<span style="color:#008000; font-style:italic;"># the first link in the div is the title/header</span>
			inf<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:header</span><span style="color:#006600; font-weight:bold;">&#93;</span> = d.<span style="color:#9900CC;">links</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">text</span>
			<span style="color:#008000; font-style:italic;"># the second link in the div is the user</span>
			inf<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user</span><span style="color:#006600; font-weight:bold;">&#93;</span> = d.<span style="color:#9900CC;">links</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">text</span>				
			<span style="color:#008000; font-style:italic;"># loop over all DIVs in the DIV and find the comment_right class (rating)</span>
			d.<span style="color:#9900CC;">divs</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>star_div<span style="color:#006600; font-weight:bold;">|</span>
				<span style="color:#9966CC; font-weight:bold;">if</span> star_div.<span style="color:#9900CC;">class_name</span>.<span style="color:#9900CC;">downcase</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\bcomment_right\b<span style="color:#006600; font-weight:bold;">/</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
					<span style="color:#008000; font-style:italic;"># count the start image tags</span>
					counter = <span style="color:#006666;">0</span>
					star_div.<span style="color:#9900CC;">images</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>img<span style="color:#006600; font-weight:bold;">|</span>
						counter <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
					<span style="color:#9966CC; font-weight:bold;">end</span>
					inf<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:stars</span><span style="color:#006600; font-weight:bold;">&#93;</span> = counter
				<span style="color:#9966CC; font-weight:bold;">end</span>
			<span style="color:#9966CC; font-weight:bold;">end</span>
			<span style="color:#008000; font-style:italic;"># get the description of the rating</span>
			inf<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:text</span><span style="color:#006600; font-weight:bold;">&#93;</span> = d.<span style="color:#9900CC;">ps</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">text</span>
			<span style="color:#008000; font-style:italic;"># store the information in the comments hash</span>
			comments<span style="color:#006600; font-weight:bold;">&#91;</span>country<span style="color:#006600; font-weight:bold;">&#93;</span> = inf
		<span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### show the result</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> comments.<span style="color:#9900CC;">inspect</span></pre></td></tr></table></div>

<p>To understand the coding I suggest that you use Firebug or the Internet Explorer Developer Tools to have a look at the HTML of the coding of <a href="http://appcomments.com/app/iBox3D">http://appcomments.com/app/iBox3D</a>. The comments should be enough to understand the coding &#8211; at least I hope so. Nevertheless I want to tell you why I did not stop here and continued to search for alternatives:</p>
<ul>
<li>if the html structure changes, the script will not work any more (no interface contract)</li>
<li>it takes very long to start of the internet explorer and to visit each page</li>
<li>this script is not platform independent, for other platforms you would have to use e.g. firewatir</li>
<li>if I would use threads for parallelisation it would be very memory intense, because many IE instances take a lot memory</li>
</ul>
<p>Then I noticed the RSS feed on appcomments.com.</p>
<h3>Version 2: Ruby and RSS</h3>
<p>RSS in ruby should be simple:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rss/1.0'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rss/2.0'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
&nbsp;
source = <span style="color:#996600;">'http://appcomments.com/rss/376860218?country=143443'</span>
&nbsp;
content = <span style="color:#996600;">&quot;&quot;</span> <span style="color:#008000; font-style:italic;"># raw content of rss feed will be loaded here</span>
<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>source, <span style="color:#ff3333; font-weight:bold;">:proxy</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://proxy:8080&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> content = s.<span style="color:#9900CC;">read</span> <span style="color:#9966CC; font-weight:bold;">end</span>
rss = <span style="color:#6666ff; font-weight:bold;">RSS::Parser</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>content, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<p>But try to run it! It will fail with the error:</p>
<p><code><br />
C:/dev/runtime/Ruby191/lib/ruby/1.9.1/rss/rexmlparser.rb:24:in `rescue in _parse': This is not well formed XML (RSS::NotWellFormedError)<br />
#encoding ::CompatibilityError: incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)<br />
[...]<br />
Exception parsing<br />
Line: 12<br />
Position: 462<br />
Last 80 unconsumed characters:<br />
< ![CDATA[Brilliantes Spiel fÃ¼rs iPhone]]&gt;<br />
[...]<br />
</code></p>
<p>German umlauts! (ä,ö,ü) Somehow ruby 1.9, which claims to have UTF-8 support, introduces a lot problems. The german character ü cannot be parsed by the internal rexml. I found the simple solution to force ruby to think that the content string is utf-8, using the force_encoding method. Then parsing works.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rss/1.0'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rss/2.0'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
&nbsp;
source = <span style="color:#996600;">'http://appcomments.com/rss/376860218?country=143443'</span>
&nbsp;
content = <span style="color:#996600;">&quot;&quot;</span> <span style="color:#008000; font-style:italic;"># raw content of rss feed will be loaded here</span>
<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>source, <span style="color:#ff3333; font-weight:bold;">:proxy</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://proxy:8080&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> content = s.<span style="color:#9900CC;">read</span> <span style="color:#9966CC; font-weight:bold;">end</span>
content.<span style="color:#9900CC;">force_encoding</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
rss = <span style="color:#6666ff; font-weight:bold;">RSS::Parser</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>content, <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<h3>Version 3: Simple-RSS</h3>
<p>Before I found that out I tried the ruby lib simple-rss, which could parse the ü (german umlaut). Nevertheless I had to do the same trick as above when I wanted to access the parsed content. At this point I want to introduce the next evolution step of my script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'simple-rss'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
&nbsp;
<span style="color:#ff6633; font-weight:bold;">$base_html</span> = <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span>EOF
<span style="color:#006600; font-weight:bold;">&lt;</span>?xml version=<span style="color:#996600;">&quot;1.0&quot;</span> encoding=<span style="color:#996600;">&quot;utf-8&quot;</span>?<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span> !DOCTYPE html PUBLIC <span style="color:#996600;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
    <span style="color:#996600;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>html xmlns=<span style="color:#996600;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>head<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>title<span style="color:#006600; font-weight:bold;">&gt;</span>@@title<span style="color:#006600; font-weight:bold;">&lt;/</span>title<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;/</span>head<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>body<span style="color:#006600; font-weight:bold;">&gt;</span>
EOF
&nbsp;
<span style="color:#ff6633; font-weight:bold;">$base_html_2</span> = <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span>EOF
<span style="color:#006600; font-weight:bold;">&lt;/</span>body<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;/</span>body<span style="color:#006600; font-weight:bold;">&gt;&lt;/</span>html<span style="color:#006600; font-weight:bold;">&gt;</span>
EOF
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> get_content<span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
	content = <span style="color:#CC0066; font-weight:bold;">String</span>.<span style="color:#9900CC;">new</span>
	<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>url, <span style="color:#ff3333; font-weight:bold;">:proxy</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://proxy:8080&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> 
		content = s.<span style="color:#9900CC;">read</span> <span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#0000FF; font-weight:bold;">return</span> content
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> utf8<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">string</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#CC0066; font-weight:bold;">string</span>.<span style="color:#9900CC;">force_encoding</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
source = <span style="color:#996600;">&quot;http://appcomments.com/app/iBox3D&quot;</span>
countries = get_content<span style="color:#006600; font-weight:bold;">&#40;</span>source<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>a href=<span style="color:#996600;">'<span style="color:#000099;">\?</span>country=(<span style="color:#000099;">\d</span>*)'</span>.<span style="color:#006600; font-weight:bold;">+</span>?<span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">+</span>?<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#996600;">&quot;http://proxy:8080&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> rss.<span style="color:#9900CC;">items</span>.<span style="color:#9900CC;">size</span> == <span style="color:#006666;">0</span>
	html <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">&quot;&lt;hr/&gt;&lt;h1&gt;#{country[1]}&lt;/h1&gt;&quot;</span> 
	rss.<span style="color:#9900CC;">items</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
		html <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">&quot;&lt;div&gt;&lt;h3&gt;#{utf8 i.title}&lt;/h3&gt;&lt;p&gt;#{utf8 i.description}&lt;/p&gt;&quot;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### write everything to a file</span>
html <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#ff6633; font-weight:bold;">$base_html_2</span>
local_filename = <span style="color:#996600;">&quot;appcomments.html&quot;</span>
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>local_filename, <span style="color:#996600;">'w:utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
	f.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>html<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Besides the advantages listet below I also added a file output to an HTML file. This is because the RSS description tag contains HTML which can be easily dropped to a HTML file.</p>
<p><strong>Advantages:</strong></p>
<ul>
<li>RSS is a standardized protocoll, so the structure won&#8217;t change in future (interface contract)</li>
<li>instead of opening the browser to perform the scraping open-uri is used, which is faster and not so memory consuming</li>
<li>this script should run on many platforms, including linux, mac os x and windows</li>
<li>the process of making the web request is way easier</li>
</ul>
<h3>Version 4: Threading</h3>
<p>Still my script took very long. No wonder, it had to make a GET request per country and one additional for the overview site to get all the country codes. But using ruby built-in threads it is easy to make all requests parallel! This speeds up the whole script:</p>
</pre>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'simple-rss'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### define the HTML basis</span>
<span style="color:#ff6633; font-weight:bold;">$base_html</span> = <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span>EOF
<span style="color:#006600; font-weight:bold;">&lt;</span>?xml version=<span style="color:#996600;">&quot;1.0&quot;</span> encoding=<span style="color:#996600;">&quot;utf-8&quot;</span>?<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span> !DOCTYPE html PUBLIC <span style="color:#996600;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
    <span style="color:#996600;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>html xmlns=<span style="color:#996600;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>head<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>title<span style="color:#006600; font-weight:bold;">&gt;</span>@@title<span style="color:#006600; font-weight:bold;">&lt;/</span>title<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;/</span>head<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;</span>body<span style="color:#006600; font-weight:bold;">&gt;</span>
EOF
&nbsp;
<span style="color:#ff6633; font-weight:bold;">$base_html_2</span> = <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span>EOF
<span style="color:#006600; font-weight:bold;">&lt;/</span>body<span style="color:#006600; font-weight:bold;">&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;/</span>body<span style="color:#006600; font-weight:bold;">&gt;&lt;/</span>html<span style="color:#006600; font-weight:bold;">&gt;</span>
EOF
&nbsp;
<span style="color:#008000; font-style:italic;">### get request to a URL</span>
<span style="color:#9966CC; font-weight:bold;">def</span> get_content<span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
	content = <span style="color:#CC0066; font-weight:bold;">String</span>.<span style="color:#9900CC;">new</span>
	<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>url, <span style="color:#ff3333; font-weight:bold;">:proxy</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://proxy:8080&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> 
		content = s.<span style="color:#9900CC;">read</span> <span style="color:#9966CC; font-weight:bold;">end</span>
	<span style="color:#0000FF; font-weight:bold;">return</span> content
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### forces the encoding in UTF-8</span>
<span style="color:#9966CC; font-weight:bold;">def</span> utf8<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">string</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	RUBY_PLATFORM == <span style="color:#996600;">'java'</span> ? <span style="color:#CC0066; font-weight:bold;">string</span> : <span style="color:#CC0066; font-weight:bold;">string</span>.<span style="color:#9900CC;">force_encoding</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### define the basic URLs and the filename</span>
source_url = <span style="color:#996600;">&quot;http://appcomments.com/app/iBox3D&quot;</span>
rss_url = <span style="color:#996600;">&quot;http://appcomments.com/rss/376860218?country=&quot;</span>
local_filename = <span style="color:#996600;">&quot;appcomments.html&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### get the main page to get all countries</span>
countries = get_content<span style="color:#006600; font-weight:bold;">&#40;</span>source_url<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>a href=<span style="color:#996600;">'<span style="color:#000099;">\?</span>country=(<span style="color:#000099;">\d</span>*)'</span>.<span style="color:#006600; font-weight:bold;">+</span>?<span style="color:#006600; font-weight:bold;">&gt;</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">+</span>?<span style="color:#006600; font-weight:bold;">&#41;</span>
threads = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
countries.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>country<span style="color:#006600; font-weight:bold;">|</span>	
	threads <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span>
		<span style="color:#008000; font-style:italic;"># construct the URL with the number of the country</span>
		url = rss_url <span style="color:#006600; font-weight:bold;">+</span> country<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
		<span style="color:#008000; font-style:italic;"># get the RSS feed from the URL</span>
		rss = SimpleRSS.<span style="color:#9900CC;">parse</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>url, <span style="color:#ff3333; font-weight:bold;">:proxy</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://proxy:8080&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
		<span style="color:#008000; font-style:italic;"># construct the HTML with the country information and the review</span>
		country_html = <span style="color:#CC0066; font-weight:bold;">String</span>.<span style="color:#9900CC;">new</span>		
		<span style="color:#008000; font-style:italic;"># go to the next country if there are no reviews</span>
		<span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> rss.<span style="color:#9900CC;">items</span>.<span style="color:#9900CC;">size</span> == <span style="color:#006666;">0</span>
		<span style="color:#008000; font-style:italic;"># construct the country header</span>
		country_html <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">&quot;&lt;hr/&gt;&lt;h1&gt;#{country[1]}&lt;/h1&gt;&quot;</span> 
		<span style="color:#008000; font-style:italic;"># construct a div for each review</span>
		rss.<span style="color:#9900CC;">items</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
			country_html <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#996600;">&quot;&lt;div&gt;&lt;h3&gt;#{utf8 i.title}&lt;/h3&gt;&lt;p&gt;#{utf8 i.description}&lt;/p&gt;&quot;</span>
		<span style="color:#9966CC; font-weight:bold;">end</span>
		<span style="color:#008000; font-style:italic;"># set the thread variable for later access</span>
		<span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;html&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = country_html
	<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### join the threads and construct the HTML</span>
threads.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
	<span style="color:#008000; font-style:italic;"># join the threads</span>
	t.<span style="color:#9900CC;">join</span>
	<span style="color:#008000; font-style:italic;"># construct one big HTML chunk out of the small HTML junks</span>
	html <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> t<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;html&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> t<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;html&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### write everything to a file</span>
html <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#ff6633; font-weight:bold;">$base_html_2</span>
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>local_filename, <span style="color:#996600;">'w:utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
	f.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>html<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

</pre>
<p>By the way, this code works also with JRuby, and the only source I had to adjust was the following line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">RUBY_PLATFORM == <span style="color:#996600;">'java'</span> ? <span style="color:#CC0066; font-weight:bold;">string</span> : <span style="color:#CC0066; font-weight:bold;">string</span>.<span style="color:#9900CC;">force_encoding</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>JRuby is able to handle the utf-8 format way better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2011/01/29/ruby-web-scraping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iBox3D released</title>
		<link>http://www.tobiasbraner.de/2010/06/22/ibox3d-released/</link>
		<comments>http://www.tobiasbraner.de/2010/06/22/ibox3d-released/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 16:23:05 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[iBox3D]]></category>
		<category><![CDATA[Stonetrip's Shiva]]></category>
		<category><![CDATA[bloxors]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[cube]]></category>
		<category><![CDATA[cuboid]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[iPod]]></category>
		<category><![CDATA[orangebox]]></category>
		<category><![CDATA[orangecube]]></category>
		<category><![CDATA[Stonetrip]]></category>

		<guid isPermaLink="false">http://tobiasbraner.de/blog/?p=21</guid>
		<description><![CDATA[Back in 2009, on the 23rd of March, I&#8217;ve reported about an easy way to created 3D iPhone games with Shiva, a game creation suite from Stonetrip. Soon it turned out that it was easy to setup a quick prototype &#8230; <a href="http://www.tobiasbraner.de/2010/06/22/ibox3d-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Back in 2009, on the 23rd of March, I&#8217;ve reported about an easy way to created 3D iPhone games with Shiva, a game creation suite from Stonetrip.</p>
<p>Soon it turned out that it was easy to setup a quick prototype which contains only a subset of functionality of the final version. I&#8217;ve worked on iBox3D in my spare time as often as possible, but also I had to take some creative breaks. The more functionality I&#8217;ve built in the game the harder the work was getting. I&#8217;ve learned that a finished and polished product needs a lot of time, more that anyone would estimate. But after I&#8217;ve set a clear target to myself I could concentrate to get there. And finally I&#8217;ve managed to create a game for iPhone / iPod Touch and iPad.</p>
<p><strong>iBox3D can be downloaded for € 0,79 / $ 0,99 in the Apple Appstore.</strong></p>
<p>Also the game has now its own website which can be found here:</p>
<p><a href="http://www.ibox3d.com">http://www.ibox3d.com</a></p>
<p>I appreciate your feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2010/06/22/ibox3d-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bowline on Windows with different Titanium Version</title>
		<link>http://www.tobiasbraner.de/2009/08/13/bowline-on-windows-with-different-titanium-version/</link>
		<comments>http://www.tobiasbraner.de/2009/08/13/bowline-on-windows-with-different-titanium-version/#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Tobias.Braner</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bowline]]></category>
		<category><![CDATA[titanium]]></category>

		<guid isPermaLink="false">http://tobiasbraner.de/blog/?p=20</guid>
		<description><![CDATA[This stuff was tested on Vista but should also work on XP. Two problems are solved in this article: Install bowline on another OS then it was developed on Run bowline with another version of Titanium Desktop then it was &#8230; <a href="http://www.tobiasbraner.de/2009/08/13/bowline-on-windows-with-different-titanium-version/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This stuff was tested on Vista but should also work on XP.</p>
<p>Two problems are solved in this article:</p>
<ul>
<li>Install bowline on another OS then it was developed on</li>
<li>Run bowline with another version of Titanium Desktop then it was developed on</li>
</ul>
<p>Bowline was developed on Mac OS X and uses the version 0.4.4 of Titanium. I have installed it on Vista and tried to run the bowline-twitter example with Titanium 0.6.0. This is how I installed it and how I managed to solve the problems:</p>
<p><strong>1. Install bowline</strong><br />
To install bowline ruby gems can be used:</p>
<p><code>gem install maccman-bowline --source http://gems.github.com</code>I&#8217;ve got some dependency errors. E.g. I had now active support and newgems installed. Install the other gems first (I think gem has also a dependency switch &#8211;include_dependencies or similar &#8211; I&#8217;m not sure).</p>
<p><strong>2. Install Titanium Desktop</strong><br />
Donwload it from <a href="http://www.appcelerator.com/products/titanium-desktop/">http://www.appcelerator.com/products/titanium-desktop/</a> and execute the installer.</p>
<p><strong>3. Get the bowline-twitter example from github</strong><br />
You can get the bowline-twitter example from this URL: <a href="http://github.com/maccman/bowline-twitter/tree/master">http://github.com/maccman/bowline-twitter/tree/master</a>. After unpacking I renamed it to &#8220;twitter&#8221; and saved it c:/dev/bowline/twitter.</p>
<p><strong>4. Building the twitter client</strong><br />
Open a command line, change to the project directory (c:/dev/bowline/twitter in my case) and execute the following command:</p>
<p><code>rake app</code>I&#8217;ve got this error:</p>
<p><code>C:\dev\bowline\twitter>rake app<br />
(in C:/dev/bowline/twitter)<br />
rake aborted!<br />
Exec format error - C:/ProgramData/Titanium/sdk/win32/0.6.0/tibuild.py -d C:/dev/bowline/twitter/build -s C:/ProgramData/Titanium -a C:/ProgramData/Titanium/sdk/win32/0.6.0 C:/dev/bowline/twitter/build/app</code><em>Background</em>: bowline was created on Mac OS X. On the Mac console, which is called bash, files have a line which tells the OS which program should execute them. E.g. the run file in the folder twitter/script:</p>
<p><code>#!/usr/bin/env rubyrequire<br />
File.join(File.dirname(__FILE__), *%w[.. config boot])<br />
require "bowline/commands/run"</code>From the first line Mac Os knows to start this file with ruby. So in the command line you can just type:</p>
<p><code>script/run</code>In windows you have to type:</p>
<p><code>ruby script/run</code>Windows doesn&#8217;t recognice first line. In the build script for bowline a python script should be executed but windows doesn&#8217;t know that it is a python script. Step 5. will explain how you can change it.</p>
<p><strong>5. Changes in the build file app.rake</strong><br />
This file can be  found in</p>
<p><code>%ruby_home%\gems\1.8\gems\maccman-bowline-0.4.6\lib\bowline\tasks</code>Line 146 and following reveal that a python script tibuild.py is called. This is part of Titanium Desktop. So you have to install <a href="http://www.python.org/">Python</a>. I&#8217;ve got Python 2.6 installed. Please also make sure that the Python path is also in you environment variable PATH (Control Panel > System > Advanced System Settings > Environment Varibales > PATH). E.g. my path variable contains besides many other entries C:\dev\Python26\ . Remember that different paths have to be seperated by ; without space.</p>
<p>Back to app.rake. Find the following line (146):</p>
<p><code>command = []</code>And now add another line:</p>
<p><code>command = []<br />
command < < "python"</code>Now the command line error is solved. But there is another thing which has to be changed in app.rake. The python script mentioned above also parses the manifest file of the project which contains meta information, like the author, name and dependencies. It also determines the required runtime version of the project. The twitter client was built on Titanium Desktop 0.4.4, I have 0.6.0 installed. This leads to an error, so I had to change this in the app.rake.</p>
<p>I replaced all versions from 0.4.4 to 0.6.0 in app.rake.</p>
<p><strong>6. Try to build it again</strong><br />
Command Line:</p>
<p></code><code>rake app</code>Still an error:</p>
<p><code>C:\dev\bowline\twitter>rake app<br />
(in C:/dev/bowline/twitter)<br />
Couldn't determine your source distribution for packaging runtime version 0.4.4. Please specify.</code>Still the version error. If you open the manifest in twitter/build/app/ you can see that there is still the version 0.4.4 inserted. So you have to regenerate the manifest (step 7).</p>
<p><strong>7. Regenerate the manifest</strong><br />
Command line:</p>
<p><code>rake app:configure</code><strong>8. Final build</strong><br />
Command line:</p>
<p><code>rake app</code>This builds you app and is not necessarily needed if you just want to run it.</p>
<p><strong>9. Run the twitter client</strong><br />
Command line:</p>
<p><code>ruby script/run</code>Works! <img src='http://www.tobiasbraner.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Bowline is very interesting but also very young. I hope that the Author, Alex MacCaw, will drive the development further so that it really gets usable.</p>
<p>Links:<br />
<a href="http://leadthinking.com/191-bowline-a-ruby-gui-framework">Blog Post of Alex MacCaw</a><br />
<a href="http://www.rubyinside.com/bowline-rails-for-the-desktop-2183.html">Blog Post on RubyInside</a><br />
<a href="http://github.com/maccman/bowline/tree/master">Bowline on github</a><br />
<a href="http://github.com/maccman/bowline-twitter/tree/master">Bowline-Twitter on github</a><br />
<a href="http://www.appcelerator.com/products/titanium-desktop/">Titanium Desktop</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tobiasbraner.de/2009/08/13/bowline-on-windows-with-different-titanium-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

