<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>☠ nofail</title>
	
	<link>http://blog.nofail.de</link>
	<description>it's all about the sugar</description>
	<lastBuildDate>Tue, 14 Feb 2012 20:22: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>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/nofail" /><feedburner:info uri="nofail" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Karotz + Ruby = Love</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/s4hyaV0kpmY/</link>
		<comments>http://blog.nofail.de/2011/12/karotz-ruby-love/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 21:46:35 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[karotz]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=574</guid>
		<description><![CDATA[I made myself a little present this christmas by putting a Karotz under my christmas tree. This little digital bunny robot is the 3rd generation of a gadget that was once known as Nabaztag. Karotz can connect to the internet and you can deploy applications on it. It&#8217;s a tiny multitalent, speaks, blinks, turns his [...]]]></description>
			<content:encoded><![CDATA[<p>I made myself a little present this christmas by putting a <a href="http://www.karotz.com/">Karotz</a> under my christmas tree. This little digital bunny robot is the 3rd generation of a gadget that was once known as <a href="http://en.wikipedia.org/wiki/Nabaztag">Nabaztag</a>.</p>

<p>Karotz can connect to the internet and you can deploy applications on it. It&#8217;s a tiny multitalent, speaks, blinks, turns his ears, takes photos and plays musik. The really cool stuff about all this, is that you can also access it via a <a href="http://dev.karotz.com/api/"><span class="caps">REST</span>-api</a>.</p>

<p>I was a little disturbed by the bad documentation of the api, but since Karotz has had a pretty shaken history, I was willing to see over it. Nevertheless <a href="https://groups.google.com/forum/?hl=en%23%21topic%2Fkarotzdev%2FFPTzH_d8FAU">I had a really hard time figuring out how to use the <span class="caps">API</span></a>, especially the <a href="http://dev.karotz.com/api/interactiveid.html">interactiveMode sessions</a>, which are crucial for interacting with Karotz. That&#8217;s why I wanted to give you a short <span class="caps">HOW</span>-TO wrapup on it.</p>

<h2>Basic Setup</h2>

<p>First of all you need to have a Karotz up and running, like it&#8217;s described in the handbook. Register yourself at karotz.com and click on the <a href="http://www.karotz.com/lab">lab</a> button at the bottom of the page. Once you registered yourself for all the developer stuff, you need to register a new application for yourself in order to get access to the credentials needed to talk to Karotz.</p>

<p>In order to get your own application, you need to create a <a href="http://dev.karotz.com/dev/register_app.html#descriptor-xml">descriptor.xml</a> and package it as a zip-file and then load it up to the appstore and then deploy it to your bunny. Here is an example, which exposes the install-id of your application, which you need to accesss your Karotz:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;descriptor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.0.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;accesses<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tts<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ears<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>led<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>multimedia<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/access<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/accesses<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;deployment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>external<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/deployment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;showInstallUuid&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/descriptor<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>




<p>Have a look at this <a href="http://www.christophs-blog.de/2011/09/karotz-command-line-tool/">Christops Blog</a> if you don&#8217;t get it working for yourself.</p>

<h2>Using the Gem</h2>

<p>There are already some code-examples on the <a href="http://dev.karotz.com/api/signed.html#Php-sample">developer-pages</a> on how to get an <em>interactive_id</em> for your Karotz and some code has been released for Ruby as ruby-karotz <a href="https://github.com/MadsBuus/ruby-karotz">here</a> and <a href="https://github.com/XVI-kondoh/Ruby-Karotz">here</a> none of them exposing a nice <span class="caps">API </span>or describing the process of how to get all the peaces of the puzzle together. That&#8217;s why I am currently writing this&#8230;</p>

<p>So here is an example of how to interact with the <a href="https://rubygems.org/gems/karotz">karotz gem</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Karotz::Configuration</span>.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">install_id</span> = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'KAROTZ_INSTALL_ID'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  config.<span style="color:#9900CC;">api_key</span>    = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'KAROTZ_API_KEY'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  config.<span style="color:#9900CC;">secret</span>     = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'KAROTZ_SECRET'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">Karotz::Client</span>.<span style="color:#9900CC;">session</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>karotz<span style="color:#006600; font-weight:bold;">|</span>
  karotz.<span style="color:#9900CC;">ears</span>
  karotz.<span style="color:#9900CC;">led</span>
  karotz.<span style="color:#9900CC;">say</span>
  karotz.<span style="color:#9900CC;">play</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>This will rotate Karotz ears, blink the <span class="caps">LED, </span>say &#8216;test&#8217; and let it play the A-TEAM theme!</p>

<p><span class="caps">FTW</span>!</p>

<p><a href="http://blog.nofail.de/wp-content/uploads/2011/12/250px-Nabaztagtag_large.jpg"><img src="http://blog.nofail.de/wp-content/uploads/2011/12/250px-Nabaztagtag_large.jpg" alt="" title="250px-Nabaztagtag_large" width="250" height="441" class="aligncenter size-full wp-image-576" /></a></p><img src="http://feeds.feedburner.com/~r/nofail/~4/s4hyaV0kpmY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2011/12/karotz-ruby-love/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2011/12/karotz-ruby-love/</feedburner:origLink></item>
		<item>
		<title>Ruby Quirks</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/dKSEUGJ_2P8/</link>
		<comments>http://blog.nofail.de/2011/12/ruby-quirks/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 19:59:41 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=559</guid>
		<description><![CDATA[Once in a while I come accross some Ruby code where I don&#8217;t know why it is doing stuff the way it does&#8230; Ternary Operator I am using the Ternary Operator quite a lot, because it keeps the code concise and often times more readable then long if-else statements. One thing that I discovered just [...]]]></description>
			<content:encoded><![CDATA[<p>Once in a while I come accross some Ruby code where I don&#8217;t know why it is doing stuff the way it does&#8230;</p>

<h2>Ternary Operator</h2>

<p>I am using the Ternary Operator quite a lot, because it keeps the code concise and often times more readable then long if-else statements. One thing that I discovered just recently is the following:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">val = something ? <span style="color:#996600;">'this'</span> : <span style="color:#996600;">'that'</span></pre></div></div>




<p>If you look closely, you will see that there is not a comparison <code>==</code> but an assignment <code>=</code> operator present. The interesting fact though is where Ruby puts parenthesis in this code:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">val = <span style="color:#006600; font-weight:bold;">&#40;</span>something ? <span style="color:#996600;">'this'</span> : <span style="color:#996600;">'that'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>Makes a lot of sense, but is not obvious, especially if you are debugging some library code.</p>

<p>Another cool thing that you can do with the operator is nesting:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">val == <span style="color:#006666;">0</span> ? <span style="color:#996600;">'zero'</span> : val == <span style="color:#006666;">1</span> ? <span style="color:#996600;">'one'</span> : <span style="color:#996600;">'other'</span>
<span style="color:#008000; font-style:italic;"># is interpreted as</span>
<span style="color:#006600; font-weight:bold;">&#40;</span>val == <span style="color:#006666;">0</span> ? <span style="color:#996600;">'zero'</span> : <span style="color:#006600; font-weight:bold;">&#40;</span>val == <span style="color:#006666;">1</span> ? <span style="color:#996600;">'one'</span> : <span style="color:#996600;">'other'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>But most of the times you are better of with Switch Cases.</p>

<h2>Switch Case</h2>

<p>There are some pretty cool features in the Ruby Switch Case. You can switch by class if you like:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">case</span> <span style="color:#996600;">&quot;some string&quot;</span>
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC0066; font-weight:bold;">Integer</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;i am an int&quot;</span>
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC0066; font-weight:bold;">String</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;i am a string&quot;</span>
<span style="color:#9966CC; font-weight:bold;">else</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;dunno&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>This works, because Ruby uses the <code>===</code> method to compare in a when block. So the when code above evaluates to:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">String</span> === <span style="color:#996600;">&quot;some string&quot;</span></pre></div></div>




<p>The cool thing is that you can implement the <code>===</code> method yourself and add some Ruby magic to the Switch Case.</p>

<p>But be aware of some stuff that might bite you while using Switch Cases! You should know that Ruby allows multiple arguments in a when block:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">case</span> val
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">5</span>, <span style="color:#006666;">7</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;good numbers&quot;</span>
<span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;bad numbers&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>It&#8217;s also important to know that you need to add a newline before writing your block code. It&#8217;s also possible to write oneliners by using a semicolon or the <code>then</code> keyword, otherwise the following code will be interpreted as belonging to the when condition:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">case</span> val
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">5</span>, <span style="color:#006666;">7</span>; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;good numbers&quot;</span>
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">0</span> <span style="color:#9966CC; font-weight:bold;">then</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;empty&quot;</span>
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006666;">1</span>, <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;syntax error&quot;</span>
<span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;bad numbers&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>





<p>Older versions of Ruby also supported a syntax with a <code>:</code> at the end instead of a <code>;</code>, wich looks kind of strange:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">case</span> val
<span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#ff3333; font-weight:bold;">:number</span>: <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;numbers&quot;</span>
<span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;not a numbers&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<h2>Missing something</h2>

<p>Since the Ruby parser allows a lot of flexibility, it&#8217;s possible to implement stuff which does not make sense at all. For example this statement which misses the <code>if</code> at the beginning of the condition:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> test_failing
  <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;invalid&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>Evaluating this method will fail (or even kill the ruby process):</p>



<pre>
warning: else without rescue is useless
syntax error, unexpected keyword_end, expecting $end
</pre>



<p>One thing that happens to me quite often, is that there are implicit things going on if you forget to add commas in your code, while I am not sure how and why they work:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;what&quot;</span> <span style="color:#996600;">&quot;the&quot;</span> <span style="color:#996600;">&quot;fuck&quot;</span> <span style="color:#008000; font-style:italic;"># =&gt; &quot;whatthefuck&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC0066; font-weight:bold;">String</span> <span style="color:#CC0066; font-weight:bold;">Integer</span> <span style="color:#008000; font-style:italic;"># =&gt; Integer</span></pre></div></div>




<h2>Everything is a Method</h2>

<p>Well not everything in Ruby is implemented as a method, but there a lot of things that you can at least use like methods. Did you know for example, that you can call the accessibility modifiers in Ruby like methods? This is pretty handy if you want to mark only some methods:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> my_method; <span style="color:#9966CC; font-weight:bold;">end</span>
private <span style="color:#ff3333; font-weight:bold;">:my_method</span></pre></div></div>




<p>It&#8217;s also quite important to know that method objects provide a lot of interesting information. Especially if you are doing some serious debugging with a lot of inheritance and Ruby magic involved:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#996600;">&quot;&quot;</span>.<span style="color:#9900CC;">method</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">class</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">owner</span> <span style="color:#008000; font-style:italic;"># =&gt; Kernel</span>
<span style="color:#9966CC; font-weight:bold;">class</span> A
  <span style="color:#9966CC; font-weight:bold;">def</span> b;end
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># works only in 1.9</span>
A.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">method</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">source_location</span> <span style="color:#008000; font-style:italic;"># =&gt; [&quot;...test.rb&quot;, 3]</span></pre></div></div>




<p>When talking about methods, it&#8217;s worth knowing the keywords that are used in Ruby and in which context they can be used. A good example for this is the <code>*</code> character, which can be used quite differently:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># as a simple method</span>
<span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">2</span>
<span style="color:#008000; font-style:italic;"># for varargs in method signatures</span>
<span style="color:#9966CC; font-weight:bold;">def</span> method_name<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># for unsplatting arrays</span>
some_method_that_has_three_args<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>You should also be aware that some operators behave different from others:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> some_array
  <span style="color:#0066ff; font-weight:bold;">@some_array</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> doit
  some_array <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span>,<span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># ok</span>
  some_array <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">6</span>,<span style="color:#006666;">7</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># raises undefined method `+' for nil:NilClass</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<h2>Predefined Variables</h2>

<p>In analogy to Pearl, Ruby provides a bunch of <a href="http://www.cs.auckland.ac.nz/references/ruby/ProgrammingRuby/language.html#predefinedvariables">Predefined Variables</a> that are worth knowing. A lot of them contain information about the current environment, code or execution context.</p>

<p>There are f.e. some extra variables for matching groups in Rubys regular expressions:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#996600;">&quot;hey_you&quot;</span> =~ <span style="color:#006600; font-weight:bold;">/</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:#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:#006600; font-weight:bold;">/</span>
$1 <span style="color:#008000; font-style:italic;"># =&gt; hey</span>
$2 <span style="color:#008000; font-style:italic;"># =&gt; you</span>
$0 <span style="color:#008000; font-style:italic;"># =&gt; .../test.rb</span></pre></div></div>




<p>Unfortunately <code>$0</code> has nothing to do with match groups, but is the name of the current executed program&#8230;</p>

<h2>Naming Best Practices</h2>

<p>When working with Ruby you get used to some best practices when it comes to names. This is important, because several thing are evaluated differently depending on up- and downcase:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">CONSTANTS_ARE_UPPER_SNAKE_CASE
ClassesAreCamelCase
<span style="color:#6666ff; font-weight:bold;">Modules::Should::Map::To::Folder::Structure</span></pre></div></div>




<p>So it is quite surprising that Ruby comes with an <code>Array()</code> method which transforms everything it gets into an array unless it&#8217;s already an array:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;string&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># =&gt; [&quot;string&quot;]</span>
<span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;string&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># =&gt; [&quot;string&quot;]</span></pre></div></div>




<p>It&#8217;s also worth having a deep look into the Ruby documentation about Arrays and the Enumerable Module, because they provide a bunch of really cool helpers that can save you an everage developers lifetime if you know them by heart.</p>

<p>For <a href="http://www.rubyinside.com/21-ruby-tricks-902.html">some more cool Ruby tricks have a look at this Rubyinside post</a>.</p>

<p>If you feel like sharing some more Ruby wisdom feel free to post a comment or contribute some sugar!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/dKSEUGJ_2P8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2011/12/ruby-quirks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2011/12/ruby-quirks/</feedburner:origLink></item>
		<item>
		<title>Improved ASIN documentation</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/LZU2dERKd3w/</link>
		<comments>http://blog.nofail.de/2011/09/improved-asin-documentation/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 10:38:52 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ASIN]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=544</guid>
		<description><![CDATA[Beeing sick sucks, but on the other hand there is a lot of spare time&#8230; So, while sitting on my couch, I created a new resource for documentation of my pet project the asin gem, which you can find on heroku: If you have any additions or questions feel free to fork the project or [...]]]></description>
			<content:encoded><![CDATA[<p>Beeing sick sucks, but on the other hand there is a lot of spare time&#8230;</p>

<p>So, while sitting on my couch, I created a new resource for documentation of my pet project the <a href="https://github.com/phoet/asin/">asin gem</a>, which you can <a href="https://github.com/phoet/asin_web">find on heroku</a>:</p>

<p><a href="http://asin.herokuapp.com/"><img src="http://blog.nofail.de/wp-content/uploads/2011/09/Bildschirmfoto-2011-09-29-um-12.01.01.png" alt="ASIN-WEB" title="ASIN-WEB" class="alignmedium size-medium wp-image-545" style="width:80%" /></a></p>

<p>If you have any additions or questions feel free to <a href="https://github.com/phoet/asin_web">fork the project</a> or open up an <a href="https://github.com/phoet/asin_web/issues">issue on github</a>.</p><img src="http://feeds.feedburner.com/~r/nofail/~4/LZU2dERKd3w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2011/09/improved-asin-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2011/09/improved-asin-documentation/</feedburner:origLink></item>
		<item>
		<title>Heroku Cedar Background Jobs for free!</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/78bGWBU_Spc/</link>
		<comments>http://blog.nofail.de/2011/07/heroku-cedar-background-jobs-for-free/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 13:28:49 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Cedar]]></category>
		<category><![CDATA[Clockwork]]></category>
		<category><![CDATA[noSQL]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[Resque]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=528</guid>
		<description><![CDATA[I&#8217;m using Heroku mostly for playing around with latest technology and hosting free apps. Since Heroku changed their pricing model due to the introduction of the new process model some of my apps changed from free to paid, especially those that had some background jobs or nightly crons (I really did not get, why this [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using Heroku mostly for playing around with latest technology and hosting free apps. Since Heroku <a href="http://devcenter.heroku.com/articles/reading-invoice">changed their pricing model</a> due to the introduction of <a href="http://blog.nofail.de/2011/06/migrating-an-existing-app-to-heroku-celadon-cedar-stack/">the new process model</a> some of my apps changed from free to paid, especially those that had some background jobs or nightly crons (I really did not get, why this happend).</p>

<h2>Full Stack Background Processes </h2>

<p>If you want to run a <a href="http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/">resque worker</a> and a <a href="http://adam.heroku.com/past/2010/6/30/replace_cron_with_clockwork/">clockwork process</a> within your web-app, this becomes a costly thing, even if those are just running some minor jobs in the night, because you need to pay for 2 additional dynos.<br />
You could achieve this through defining multiple processes in your Procfile:</p>


<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;"># Procfile
web: bundle exec rails server thin -p $PORT
worker: QUEUE=* bundle exec rake environment resque:work
clock: bundle exec clockwork app/clock.rb</pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku scale <span style="color: #007800;">worker</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">clock</span>=<span style="color: #000000;">1</span></pre></div></div>




<h2>Sharing Addon Connections</h2>

<p>As Heroku officially announced in their <a href="http://newsletterer.heroku.com/2011/07">latest newsletter</a>, it&#8217;s possible to share connections between multiple apps. In my case, this would be a connection to a redis key-value store, that is provided by <a href="http://redistogo.com/">Redistogo</a>. It&#8217;s as simple as copying the environment configuration for the addon over to the second app:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku config <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> DATABASE_URL  <span style="color: #660033;">--app</span> sushi
=<span style="color: #000000; font-weight: bold;">&gt;</span> DATABASE_URL   =<span style="color: #000000; font-weight: bold;">&gt;</span> postgres:<span style="color: #000000; font-weight: bold;">//</span>lswlm...
&nbsp;
heroku config:add <span style="color: #007800;">DATABASE_URL</span>=postgres:<span style="color: #000000; font-weight: bold;">//</span>lswlm... <span style="color: #660033;">--app</span> sushi-analytics
=<span style="color: #000000; font-weight: bold;">&gt;</span> Adding config vars: DATABASE_URL =<span style="color: #000000; font-weight: bold;">&gt;</span> postgres:<span style="color: #000000; font-weight: bold;">//</span>lswlm...m<span style="color: #000000; font-weight: bold;">/</span>ldfoiusfsf
=<span style="color: #000000; font-weight: bold;">&gt;</span> Restarting app... <span style="color: #000000; font-weight: bold;">done</span>, v74.</pre></div></div>




<h2>Going Freemium</h2>

<p>So the solution for getting back to a free worker setup is combining 3 Heroku apps and a shared Redis connection through Redistogo:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku apps:create freemium-web <span style="color: #660033;">--stack</span> cedar <span style="color: #660033;">--remote</span> heroku
<span style="color: #c20cb9; font-weight: bold;">git</span> push heroku master
&nbsp;
heroku apps:create freemium-worker <span style="color: #660033;">--stack</span> cedar <span style="color: #660033;">--remote</span> worker
<span style="color: #c20cb9; font-weight: bold;">git</span> push worker master
&nbsp;
heroku apps:create freemium-clock <span style="color: #660033;">--stack</span> cedar <span style="color: #660033;">--remote</span> clock
<span style="color: #c20cb9; font-weight: bold;">git</span> push clock master
&nbsp;
heroku scale <span style="color: #007800;">web</span>=<span style="color: #000000;">1</span> <span style="color: #660033;">--app</span>=freemium-web
heroku scale <span style="color: #007800;">web</span>=<span style="color: #000000;">0</span> <span style="color: #007800;">worker</span>=<span style="color: #000000;">1</span> <span style="color: #660033;">--app</span>=freemium-worker
heroku scale <span style="color: #007800;">web</span>=<span style="color: #000000;">0</span> <span style="color: #007800;">clock</span>=<span style="color: #000000;">1</span> <span style="color: #660033;">--app</span>=freemium-clock
&nbsp;
heroku addons:add redistogo:<span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #660033;">--app</span>=freemium-web
&nbsp;
heroku config:add <span style="color: #000000; font-weight: bold;">`</span>heroku config <span style="color: #660033;">-s</span> <span style="color: #660033;">--app</span>=freemium-web<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> redis<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #660033;">--app</span>=freemium-worker
heroku config:add <span style="color: #000000; font-weight: bold;">`</span>heroku config <span style="color: #660033;">-s</span> <span style="color: #660033;">--app</span>=freemium-web<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> redis<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #660033;">--app</span>=freemium-clock</pre></div></div>




<p>I created an <a href="https://github.com/phoet/freemium">example project running a Rails 3 application with a mounted Resque web, a Resque worker and a clock process with Clockwork</a>.</p>

<h2>Even simpler</h2>

<p>If you are just looking for a simple solution of running a background process have a look at <a href="https://github.com/thomasjachmann/crony">crony, a bootstrap project</a> using <a href="http://rufus.rubyforge.org/rufus-scheduler/">rufus-scheduler</a>.</p><img src="http://feeds.feedburner.com/~r/nofail/~4/78bGWBU_Spc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2011/07/heroku-cedar-background-jobs-for-free/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2011/07/heroku-cedar-background-jobs-for-free/</feedburner:origLink></item>
		<item>
		<title>Migrating an existing App to Heroku Celadon Cedar Stack</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/9WwyuG-InCc/</link>
		<comments>http://blog.nofail.de/2011/06/migrating-an-existing-app-to-heroku-celadon-cedar-stack/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 20:20:02 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=513</guid>
		<description><![CDATA[It&#8217;s currently not possible to do an automated migration from or to the Heroku Celadon Cedar Stack which started in May. The only help that you get from Heroku is this: Migrating From Bamboo to Cedar Before migrating to Bamboo, you should make sure your app runs on Ruby 1.9.2. If your app is not [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s currently not possible to do an automated migration from or to the <a href="http://devcenter.heroku.com/articles/cedar">Heroku Celadon Cedar Stack</a> which <a href="http://blog.heroku.com/archives/2011/5/31/celadon_cedar/">started in May</a>. The only help that you get from Heroku is this:</p>

<blockquote>
Migrating From Bamboo to Cedar

<p>Before migrating to Bamboo, you should make sure your app runs on Ruby 1.9.2. If your app is not already deployed successfully to bamboo-mri-1.9.2, you should do that first, and then come back and try Cedar.</p>

Once you&#8217;re sure your app is fully compatible with Ruby 1.9.2, create an app on the Cedar stack and push to it. Currently, stack:migrate does not work for moving apps to Cedar.<br />
</blockquote>

<p>Since there seem to be no blogposts of how to do all the stuff with an existing application I will try to cover everything that I did to do the migration manually in this article.</p>

<h2>Cedar is different</h2>

<p>If you are looking at the new stack you will notice that a lot has changed with Cedar. Most of the <a href="http://devcenter.heroku.com/categories/command-line">Heroku <span class="caps">CLI</span></a> has changed to reflect the new possibilites that come with the Cedar stack. Since Cedar introduces a new <a href="http://devcenter.heroku.com/articles/process-model">way of handling processes on Heroku</a>, most of the commands are now streamlined with this:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># old</span>
heroku console
heroku rake db:migrate
<span style="color: #666666; font-style: italic;"># new </span>
heroku run console
heroku run rake db:migrate
&nbsp;
<span style="color: #666666; font-style: italic;"># have a look at running processes</span>
heroku <span style="color: #c20cb9; font-weight: bold;">ps</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># look at logs of different processes and tail the output</span>
heroku logs <span style="color: #660033;">--ps</span> web <span style="color: #660033;">-t</span></pre></div></div>




<h3>Preparing the Migration</h3>

<p>I started by cloning my current app from Heroku into another directory and creating a new Cedar app on Heroku:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>heroku.com:hamburg-on-ruby.git legacy
<span style="color: #7a0874; font-weight: bold;">cd</span> legacy
heroku create <span style="color: #660033;">--stack</span> cedar</pre></div></div>




<h3>Adapting Cedar changes</h3>

<p>The <a href="http://devcenter.heroku.com/articles/rails3">docs for creating a Rails 3 app on Cedar</a> reflect some of the changes that have been introduced with Cedar.</p>

<p>One of those is that PostgreSQL is now recommended for local development and you need to have the <a href="https://rubygems.org/gems/pg">pg-gem</a> in your Gemfile. Otherwise you will get errors while running rake commands:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku run rake db:migrate
&nbsp;
  Running rake db:migrate attached to terminal... up, run.1
  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  rake aborted<span style="color: #000000; font-weight: bold;">!</span>
  no such <span style="color: #c20cb9; font-weight: bold;">file</span> to load <span style="color: #660033;">--</span> pg</pre></div></div>




<p>Since I developed my app with <span class="caps">SQL</span>ite3 and I don&#8217;t want to learn, install and manage <span class="caps">ANOTHER</span> Database I split up the database stuff for development, test and production:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Gemfile</span>
group <span style="color:#ff3333; font-weight:bold;">:production</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">&quot;pg&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">&quot;sqlite3-ruby&quot;</span>, :<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;sqlite3&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>and exclude production dependencies from my local environment:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># put this into your .profile</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">bd</span>=<span style="color: #ff0000;">&quot;bundle --without=production&quot;</span></pre></div></div>




<p>It&#8217;s also recommended to serve Rails through <a href="https://rubygems.org/gems/thin">thin webserver</a> and manage the application with <a href="https://rubygems.org/gems/foreman">the Procfile manager foreman</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Gemfile</span>
gem <span style="color:#996600;">&quot;foreman&quot;</span>
gem <span style="color:#996600;">&quot;thin&quot;</span></pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Procfile</span>
web: bundle <span style="color: #7a0874; font-weight: bold;">exec</span> rails server thin <span style="color: #660033;">-p</span> <span style="color: #007800;">$PORT</span></pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">foreman start</pre></div></div>




<p>After going through those chages you should be able to see your application on localhost:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">open http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">5000</span></pre></div></div>




<h2>The migration process</h2>

<p>If the application is running on your development machine you can start the core migration process by putting your legacy application into maintenance mode, so that no database changes will be made:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku maintenance:on
<span style="color: #666666; font-style: italic;"># stop worker, crons or whatever might be changing the db</span></pre></div></div>




<h3>Database Migration</h3>

<p>After you completely halted everything on your dyno, you can start dumping the database to your development machine (I thought it would be neat to do a direct migration from the legacy database to the new Cedar database, but I did not get it working). You need to install the <a href="http://devcenter.heroku.com/articles/taps">taps-gem</a> in order to do any dumping. Taps will dump the database into your development database unless you provide an connection string to another database:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># use sqlite for dumping and do it into a separate file</span>
heroku db:pull sqlite:<span style="color: #000000; font-weight: bold;">//</span>dump.db
&nbsp;
<span style="color: #666666; font-style: italic;"># mv the file to your Cedar application and push it</span>
heroku db:push sqlite:<span style="color: #000000; font-weight: bold;">//</span>dump.db</pre></div></div>




<h3>Config variables</h3>

<p>If you have custom config variables in your application it&#8217;s pretty easy to move them into the new environment:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># list all config values of the legacy app in console format</span>
heroku config <span style="color: #660033;">-s</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># replace the newlines with whitespaces and</span>
<span style="color: #666666; font-style: italic;"># append all the configuration variables of </span>
<span style="color: #666666; font-style: italic;"># your new Cedar app at the end or remove the</span>
<span style="color: #666666; font-style: italic;"># ones that you do not want to migrate!</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># add the list of values to your Cedar app</span>
heroku config:add <span style="color: #007800;">KEY</span>=VALUE <span style="color: #007800;">KEY2</span>=VALUE2 <span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>




<h3>Installing addons</h3>

<p>It&#8217;s also most likely that you want to use the same addons than in your legacy application:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># list your addons in the legacy app</span>
heroku addons
&nbsp;
<span style="color: #666666; font-style: italic;"># install all addons separately in the Cedar app</span>
heroku addons:add apigee:basic
heroku addons:add cron:daily
<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>




<h4>Sendgrid</h4>

<p>If you are using <a href="http://devcenter.heroku.com/articles/smtp#sending_email_from_rails">the Sendgrid Addon</a> you should be aware that the automatic configuration is not working anymore the Cedar Stack! You need to <a href="http://devcenter.heroku.com/articles/smtp">configure it in your app</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># config/environments/production.rb</span>
  config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">raise_delivery_errors</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
  config.<span style="color:#9900CC;">action_mailer</span>.<span style="color:#9900CC;">smtp_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:address</span>        <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;smtp.sendgrid.net&quot;</span>,
    <span style="color:#ff3333; font-weight:bold;">:port</span>           <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;25&quot;</span>,
    <span style="color:#ff3333; font-weight:bold;">:authentication</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:plain</span>,
    <span style="color:#ff3333; font-weight:bold;">:user_name</span>      <span style="color:#006600; font-weight:bold;">=&gt;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'SENDGRID_USERNAME'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
    <span style="color:#ff3333; font-weight:bold;">:password</span>       <span style="color:#006600; font-weight:bold;">=&gt;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'SENDGRID_PASSWORD'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
    <span style="color:#ff3333; font-weight:bold;">:domain</span>         <span style="color:#006600; font-weight:bold;">=&gt;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'SENDGRID_DOMAIN'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>




<h3>Switching domains</h3>

<p>Before you do the last step, you should have a look if everything is up and running:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku open</pre></div></div>




<p>If everything is fine, you can move all the domains from the legacy application to your new and shiny Cedar Stack application:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># list domains in legacy app</span>
heroku domains
&nbsp;
<span style="color: #666666; font-style: italic;"># and remove them</span>
heroku domains:remove hamburg.onruby.de
heroku domains:remove onruby.de
<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># re-add them to Cedar application</span>
heroku domains:add hamburg.onruby.de
heroku domains:add onruby.de
<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>




<p>Looking at <a href="http://onruby.de">the result</a> is quite disappointing, because nothing has changed for the user, but everything is new and shiny from the inside!</p>

<p>If you have any other pointers of what you need to do for migrating your application please feel free to add a comment!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/9WwyuG-InCc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2011/06/migrating-an-existing-app-to-heroku-celadon-cedar-stack/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2011/06/migrating-an-existing-app-to-heroku-celadon-cedar-stack/</feedburner:origLink></item>
		<item>
		<title>Developing ANDROID sucks!</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/LUwEJZhPrEE/</link>
		<comments>http://blog.nofail.de/2011/06/developing-android-sucks/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 09:57:54 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[DZone]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=495</guid>
		<description><![CDATA[DISCLAIMER: you guessed it, this is a rant! I am very interested in doing mobile development as a hobby. I started iOS development about a year ago but i stopped after publishing my first iPhone app dzone mobile because i thought that all those AppStore&#8482; and iTunes Connect&#8482; stuff was a pain in the ass [...]]]></description>
			<content:encoded><![CDATA[<h2><span class="caps">DISCLAIMER</span>: you guessed it, this is a rant!</h2>

<p>I am very interested in doing mobile development as a hobby. I started iOS development about a year ago but i stopped after publishing <a href="http://dzone.nofail.de/">my first iPhone app dzone mobile</a> because i thought that all those AppStore&#8482; and iTunes Connect&#8482; stuff was a pain in the ass and distracting me from beeing productive.</p>

<p>So I began developing this same app for the Android platform, in order to get a feeling for it. I&#8217;ve been doing Java for about 7 years now, so developing on Android should be rather familiar to me instead of learning all this verbose Objective-C nerdy pointer stuff. I am very well known to Eclipse, so working with the Android Plugin should be easy, right?</p>

<p>I started the app in November of 2010, when I had some spare time between jobs, but somehow I stopped in the middle of the project and just recently started all over. I was wandering why I had not worked on the app for about half a year?</p>

<p>The answer is simple: Developing <span class="caps">ANDROID </span>sucks!</p>

<h2>Eclipse</h2>

<p>I stopped working with Java in the middle of last year, switching to Ruby development with TextMate and MacVim. Coming back to Eclipse is like getting hit by a truck! This <span class="caps">IDE </span>is so overwhelming, but instead of giving you what you need it hides <a href="http://stackoverflow.com/questions/3175035/eclipse-find-in-project">the most common features, so that you have to search for it on stackoverflow</a>.</p>

<p>Is it really necessary for me to do Open-Clean-Refresh-Close-Open-Refresh cycles on my project to let Eclipse realize that everything is fine besides Eclipse itself?</p>

<p>Why do people, building Eclipse plugins, make the same errors again and again? Swallow errors, so that you need to have the Error Log View open all the time? Show build failures without any hints? Are you serious about that LogCat stuff? <span class="caps">WTF</span>?</p>

<p>I am using the debugger all the time when I am new to some Framework in order to better understand what is going on. But this is not very usefull unless you can see the source code of where you currently are&#8230; Guess what, it&#8217;s <a href="http://android.opensourceror.org/2010/01/18/android-source/">reeeeally hard to get it going</a>!</p>

<h2>Emulator</h2>

<p>The android Emulator is really slow on the Mac. I don&#8217;t know if it&#8217;s much faster on other systems, but i think it sucks. The startup time takes even more than eclipse, you need to <a href="http://stackoverflow.com/questions/2359895/android-emulator-screen-too-tall">fiddle around with runtime settings in order to adjust it to your needs</a> and why is it so difficult to put all the options you have in the menu bar instead of <a href="https://sites.google.com/site/androidhowto/how-to-1/rotate-mac-emulator">hiding it somewhere in the function keys</a>?</p>

<p>But the best thing is, that the <a href="http://stackoverflow.com/questions/3557996/android-httprequest-java-net-unknownhostexception">emulator is just not working right in the beginning</a>.</p>

<p>It does not properly respond to mouse gestures or the keyboard and ah yeah, I forgott, it&#8217;s ugly:</p>

<p><a href="http://blog.nofail.de/wp-content/uploads/2011/06/Bildschirmfoto-2011-06-24-um-11.25.47.png"><img src="http://blog.nofail.de/wp-content/uploads/2011/06/Bildschirmfoto-2011-06-24-um-11.25.47-300x277.png" alt="" title="android emulator" width="300" height="277" class="aligncenter size-medium wp-image-499" /></a></p>

<h2>Desing-Flaws</h2>

<p>Developing for iOS is a tough choice if one is coming from a language like Java that has a decent Runtime with garbage collection. I spent most of my development time with allocation/deallocation problems. This is something you really need to get into if you want to have fun working with Objective-C even though they <a href="http://stackoverflow.com/questions/6368600/some-questions-about-automatic-reference-counting-in-ios5-sdk">just released <span class="caps">ARC </span>(automatic reference counting) on iOS 5</a>.<br />
Besides that, I really think that iOS does a better job in designing an architecture that is developer friendly.</p>

<p>The thing that I just can&#8217;t get over on Android devices is that the application (the activity to be precise) is going to be reloaded if you rotate your device and you need to take care of a lot of things in order to let your app respond to that interaction. Just have a look at <a href="http://developer.android.com/resources/articles/faster-screen-orientation-change.html"><em>your future self</em></a> &#8230;</p>

<p>It&#8217;s really sad to me, that the Android designers decided to repeat the bad design decisions that had been established in Java Enterprise&#8482; all over again! It took the Java community about a decade to step back and come to frameworks where developer productivity is <span class="caps">THE </span>thing to focus on. All the rookies that start their &#8220;Java career&#8221; with android will be doomed to go through this same process again! Poor bastards&#8230;</p>

<h2><span class="caps">XML</span></h2>

<p>Finally! Let&#8217;s define everything in <span class="caps">XML</span>! I am getting bored at bashing on <span class="caps">XML&#8230;</span></p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dzone_android±master✓$ <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.xml&quot;</span>
.<span style="color: #000000; font-weight: bold;">/</span>AndroidManifest.xml
.<span style="color: #000000; font-weight: bold;">/</span>res<span style="color: #000000; font-weight: bold;">/</span>layout<span style="color: #000000; font-weight: bold;">/</span>details.xml
.<span style="color: #000000; font-weight: bold;">/</span>res<span style="color: #000000; font-weight: bold;">/</span>menu<span style="color: #000000; font-weight: bold;">/</span>options.xml
.<span style="color: #000000; font-weight: bold;">/</span>res<span style="color: #000000; font-weight: bold;">/</span>values<span style="color: #000000; font-weight: bold;">/</span>strings.xml
.<span style="color: #000000; font-weight: bold;">/</span>res<span style="color: #000000; font-weight: bold;">/</span>xml<span style="color: #000000; font-weight: bold;">/</span>preferences.xml</pre></div></div>




<p>iOS is also using <span class="caps">XML </span>for their interfaces, but they hide all that shit behind a really decent <a href="http://developer.apple.com/tools/interfacebuilder/">InterfaceBuilder</a>!</p>

<p>The Builder and <span class="caps">XML</span> Tools in the Eclipse Plugin are so ugly that i rather write the whole shit by hand, bitches!</p>

<h2>Tight coupling</h2>

<p>Why, for gods sake, did they come up with the idea to use inheritance for everything in Android? It&#8217;s even worse than in <span class="caps">J2EE </span>because you are not bound to Interfaces but Classes! Hello dear Android designers, there is no such thing as Mixins or Multi-Inheritance in Java?! How am I supposed to write clean code with that? Answer: You are not going to write clean code anyway, because you have to do premature optimization on your code so that it can run on all the shitty Android devices! <span class="caps">YEAH</span>!</p>

<p>Just forget everything you learned form state of the art frameworks like <span class="caps">MVC </span>or <span class="caps">DI.</span> It&#8217;s just not possible! BY <span class="caps">DESIGN</span>!</p>

<p>Just put state, lifecycle, business and view logic in one class; also helps reducing your package size, hooray!</p>

<h2>Checked Exceptions</h2>

<p>Do we really need more Checked Exceptions? Really?</p>

<h2>Testing</h2>

<p>Writing tests for iOS was nearly impossible at the time I was doing it. Even the guys at the Cocoaheads Hamburg did not know how to get it running. But this situation has improved over the last months. Special thanks to <span class="caps">XING </span>for doing a lot of research there and presenting it on the Usergroup!</p>

<p>I thought that testing for Android would be really cool, because the Java community has a really strong background on <span class="caps">TDD </span>and <a href="http://developer.android.com/guide/topics/testing/index.html">Testing is even a Topic on the Dev Guide</a>, even though it is the <span class="caps">LAST </span>one&#8230;</p>

<p>Let me make it clear to you: Testing Android sucks!</p>

<p>Because of all the tight coupling and multithreaded environment it is nearly impossible to test something. Even simple tasks like testing your Utility-Methods needs to be done in the Emulator! Just have a look at this <a href="http://mobile.tutsplus.com/tutorials/android/android-sdk-junit-testing/">multiscreen setup guide of how to get it running with JUnit</a> (Hello?! JUnit 3 is deprecated for <span class="caps">YEARS</span>!).</p>

<p>Despite all this crap, I finally did it! So please test <a href="https://github.com/phoet/dzone_android">my dzone application</a>, because I do not own an Android phone myself&#8230;</p>

<p><a href="http://github.com/phoet/dzone_android"><img src="http://f.cl.ly/items/3U0C3f3y271L2G0B0R1f/dzone_android.png" alt="dzone Feed" height="800" width="480" /></a></p><img src="http://feeds.feedburner.com/~r/nofail/~4/LUwEJZhPrEE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2011/06/developing-android-sucks/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2011/06/developing-android-sucks/</feedburner:origLink></item>
		<item>
		<title>AWS cart operations support in ASIN</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/5z828enCavQ/</link>
		<comments>http://blog.nofail.de/2011/04/aws-cart-operations-support-in-asin/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 11:54:04 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ASIN]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=477</guid>
		<description><![CDATA[It has been a little silent in here lately. This is probably due to my new freelance work as a Rails developer at Qype.com in Hamburg&#8230; Nevertheless, I am proud to announce, that, thx to Rehanift&#8217;s fork, ASIN now support AWS cart operations: #just require require 'asin' &#160; # create an ASIN client client = [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a little silent in here lately. This is probably due to my new freelance work as a Rails developer at <a href="http://qype.com">Qype.com</a> in Hamburg&#8230;</p>

<p>Nevertheless, I am proud to announce, that, thx to <a href="https://github.com/rehanift/asin">Rehanift&#8217;s fork</a>, <span class="caps">ASIN </span>now support <span class="caps">AWS </span>cart operations:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;">#just require</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'asin'</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># create an ASIN client</span>
  client = ASIN.<span style="color:#9900CC;">client</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># create a cart with an item</span>
  cart = client.<span style="color:#9900CC;">create_cart</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:asin <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1430218150'</span>, <span style="color:#ff3333; font-weight:bold;">:quantity</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  cart.<span style="color:#9900CC;">items</span>
  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&lt;</span><span style="color:#008000; font-style:italic;">#Hashie::Mash ASIN=&quot;1430218150&quot; CartItemId=&quot;U3G241HVLLB8N6&quot; ... &gt;]</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># get an already existing cart from a CartId and HMAC</span>
  cart = client.<span style="color:#9900CC;">get_cart</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'176-9182855-2326919'</span>, <span style="color:#996600;">'KgeVCA0YJTbuN/7Ibakrk/KnHWA='</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  cart.<span style="color:#9900CC;">empty</span>?
  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># clear everything from the cart</span>
  cart = client.<span style="color:#9900CC;">clear_cart</span><span style="color:#006600; font-weight:bold;">&#40;</span>cart<span style="color:#006600; font-weight:bold;">&#41;</span>
  cart.<span style="color:#9900CC;">empty</span>?
  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># add items to the cart</span>
  cart = client.<span style="color:#9900CC;">add_items</span><span style="color:#006600; font-weight:bold;">&#40;</span>cart, <span style="color:#006600; font-weight:bold;">&#123;</span>:asin <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1430216263'</span>, <span style="color:#ff3333; font-weight:bold;">:quantity</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  cart.<span style="color:#9900CC;">empty</span>?
  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># update items in the cart</span>
  cart = client.<span style="color:#9900CC;">update_items</span><span style="color:#006600; font-weight:bold;">&#40;</span>cart, <span style="color:#006600; font-weight:bold;">&#123;</span>:cart_item_id <span style="color:#006600; font-weight:bold;">=&gt;</span> cart.<span style="color:#9900CC;">items</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">CartItemId</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:SaveForLater</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:cart_item_id <span style="color:#006600; font-weight:bold;">=&gt;</span> cart.<span style="color:#9900CC;">items</span>.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">CartItemId</span>, <span style="color:#ff3333; font-weight:bold;">:quantity</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  cart.<span style="color:#9900CC;">saved_items</span>
  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&lt;</span><span style="color:#008000; font-style:italic;">#Hashie::Mash ASIN=&quot;1430218150&quot; CartItemId=&quot;U3G241HVLLB8N6&quot; ... &gt;]</span></pre></div></div>




<p>You can use the latest source from <a href="https://github.com/phoet/asin/">GitHub development branch</a> or download the <a href="https://rubygems.org/gems/asin/versions/0.4.0.beta1">beta version of the gem from RubyGems</a>. No easter eggs included <img src='http://blog.nofail.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p>Happy shopping(cart)!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/5z828enCavQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2011/04/aws-cart-operations-support-in-asin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2011/04/aws-cart-operations-support-in-asin/</feedburner:origLink></item>
		<item>
		<title>Gem Best Practice</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/tXWIN6ldIbg/</link>
		<comments>http://blog.nofail.de/2010/11/gem-best-practice/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 18:51:04 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=443</guid>
		<description><![CDATA[One thing that I like most about Ruby is the ease of contributing to OpenSource. You want to share code? Just create a gem and upload it to Rubygems. The problem is, there are a lot of implicit rules that make it hard to do it right in the first place. Enabling Rubygems Since Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that I like most about Ruby is the ease of contributing to OpenSource. You want to share code? Just create a gem and upload it to <a href="http://rubygems.org">Rubygems</a>. The problem is, there are a lot of implicit rules that make it hard to do it right in the first place.</p>

<h2>Enabling Rubygems</h2>

<p><a href="http://docs.rubygems.org/read/chapter/3#page70">Since Ruby 1.9 Rubygems is bundled</a> with every Ruby distribution. If you are using <a href="http://rvm.beginrescueend.com/"><span class="caps">RVM</span></a> you get Rubygems with the older versions too. <a href="https://gist.github.com/54177">Setting the <span class="caps">RUBYOPT </span>environment variable</a> will enforce it even for 1.8 versions:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># no need for 'require &quot;rubygems&quot;' in your code</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">RUBYOPT</span>=rubygems</pre></div></div>




<h2>The Gem command</h2>

<p>Since the <a href="http://ruby.dzone.com/articles/new-rubygemsorg-gemcutter-and">merge of Gemcutter and Rubygems</a> there have been a lot of improvements to the gem shell command. Sharing your code is now as easy as:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># create a gem from your local source configured in your gemspec</span>
gem build your.gemspec
<span style="color: #666666; font-style: italic;"># upload the created gem </span>
gem push your-0.0.1.gem</pre></div></div>




<p>There are some more new commands that handle the <a href="http://rubygems.org/pages/api_docs">Rubygems <span class="caps">API</span></a> communication, which are very well <a href="http://rubygems.org/pages/gem_docs">documented on RubyGems.org</a>. <br />
It is also worth taking some time to get an overview of the <a href="http://docs.rubygems.org/read/chapter/10">old command reference</a>. Commands like <em>which</em> or <em>cleanup</em> come in handy if you know them!</p>

<p>I use <a href="http://rvm.beginrescueend.com/"><span class="caps">RVM</span></a> and <a href="http://rvm.beginrescueend.com/gemsets/">Gemsets</a> extensively and I do not want to have all that duplicated RDoc and RI on disc (I&#8217;d rather search the web instead of using local generated doc), so I <a href="http://stackoverflow.com/questions/1381725/how-to-make-no-ri-no-rdoc-default-for-gem-install">changed my <em>.gemrc</em> file</a> to skip generating the doc on <em>gem install</em>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># .gemrc</span>
<span style="color:#006600; font-weight:bold;">---</span> 
<span style="color:#ff3333; font-weight:bold;">:update_sources</span>: <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#ff3333; font-weight:bold;">:sources</span>: 
<span style="color:#006600; font-weight:bold;">-</span> http:<span style="color:#006600; font-weight:bold;">//</span>gems.<span style="color:#9900CC;">rubyforge</span>.<span style="color:#9900CC;">org</span><span style="color:#006600; font-weight:bold;">/</span>
<span style="color:#006600; font-weight:bold;">-</span> http:<span style="color:#006600; font-weight:bold;">//</span>gems.<span style="color:#9900CC;">github</span>.<span style="color:#9900CC;">com</span>
gem: <span style="color:#006600; font-weight:bold;">--</span>no<span style="color:#006600; font-weight:bold;">-</span>ri <span style="color:#006600; font-weight:bold;">--</span>no<span style="color:#006600; font-weight:bold;">-</span>rdoc
<span style="color:#ff3333; font-weight:bold;">:verbose</span>: <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#ff3333; font-weight:bold;">:bulk_threshold</span>: <span style="color:#006666;">1000</span>
<span style="color:#ff3333; font-weight:bold;">:backtrace</span>: <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#ff3333; font-weight:bold;">:benchmark</span>: <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>




<h2>Building a Gem</h2>

<p><a href="https://github.com/technicalpickles/jeweler">Jeweler</a> is a great tool for scaffolding and releasing new Gems. If you don&#8217;t care about getting to know the basics, just move right over to their documentation. The problem is, that it makes things more complicated than they really are&#8230;</p>

<h3>Naming and Versioning</h3>

<p>There are <a href="http://blog.segment7.net/articles/2010/11/15/how-to-name-gems">some simple rules</a> when it comes to naming:</p>


<ol>
<li>Use lowercase letters only! Users of case insensitive file systems will be thankfull.</li>
<li>Use <span class="caps">ASCII </span>characters only! You know, those US guys just don&#8217;t know there is <span class="caps">UTF</span>-8.</li>
<li>Use _ underscores for parts of the name and &#8211; dashes for extensions of existing Gems.</li>
<li>Name your Gem like the file to require in your code. If not, put a big, fat warning in your documentation!</li>
</ol>



<p>Choose the Gem name with care, because you know: <a href="http://laughingmeme.org/2005/12/23/there-are-only-two-hard-things-in-computer-science-cache-invalidation-and-naming-things/">naming is everything</a>!</p>

<p>It became popular lately to start the development cycle with a version 0.0.1 instead of 1.0.0. I think this is just a matter of taste. More importantly you should handle your <a href="http://en.wikipedia.org/wiki/Software_versioning"><span class="caps">MAJOR.MINOR.FIX </span>versions</a> carefully. Increment your <span class="caps">FIX </span>version on bugfixes or additions to the <span class="caps">API </span>that won&#8217;t brake any existing code. Increment your <span class="caps">MINOR </span>version if you added features with an noticable impact to the <span class="caps">API </span>or it&#8217;s usage. Push a new <span class="caps">MAJOR </span>version if you changed your <span class="caps">API </span>completely or if you want to emphasize that the latest version is a major improvement or a new stable release. In an ideal world all those decisions and changes are documented in a <a href="https://github.com/phoet/gem_best_practice/blob/master/CHANGELOG"><span class="caps">CHANGELOG </span>file</a>.</p>

<p>In addition to these rules, Rubygems provides a mechanism to roll out beta versions of a Gem. In order to do this, just append a <em>.beta</em> etc. to the end of your version. These Gems can then be installed with the <em>&#8211;pre</em> flag:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails <span style="color: #660033;">--pre</span> <span style="color: #666666; font-style: italic;"># might install rails 3.1.0.beta some day</span></pre></div></div>




<h3>The Gemspec</h3>

<p>One thing that is essential for creating a Gem is the <a href="http://docs.rubygems.org/read/chapter/20"><em>.gemspec</em> file</a>. Put one in the root of your project folder and name it alike. The .gemspec file <a href="http://rubygems.rubyforge.org/rubygems-update/Gem/Specification.html">contains plain old Ruby</a> and simply specifies all important attributes for your Gem. For an example, have a look at the <a href="https://github.com/phoet/gem_best_practice/blob/master/gbp.gemspec">gem_best_practice.gemspec</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># coding: utf-8</span>
lib = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'../lib/'</span>, <span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>
$:.<span style="color:#9900CC;">unshift</span> lib <span style="color:#9966CC; font-weight:bold;">unless</span> $:.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>lib<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'gem_best_practice'</span>
&nbsp;
spec = <span style="color:#6666ff; font-weight:bold;">Gem::Specification</span>.<span style="color:#9900CC;">new</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>
  s.<span style="color:#9900CC;">name</span> = s.<span style="color:#9900CC;">rubyforge_project</span> = <span style="color:#996600;">'gem_best_practice'</span>
  s.<span style="color:#9900CC;">version</span> = <span style="color:#6666ff; font-weight:bold;">GemBestPractice::VERSION</span>
&nbsp;
  s.<span style="color:#9900CC;">author</span> = <span style="color:#996600;">'Peter Schröder'</span>
  s.<span style="color:#9900CC;">description</span> = <span style="color:#996600;">'A Gem that shows best practice for Gem creation.'</span>
  s.<span style="color:#9900CC;">email</span> = <span style="color:#996600;">'phoetmail@googlemail.com'</span>
  s.<span style="color:#9900CC;">homepage</span> = <span style="color:#996600;">'http://github.com/phoet/gem_best_practice'</span>
  s.<span style="color:#9900CC;">summary</span> = <span style="color:#996600;">'If you ever wondered how to create a Gem and what best practice should be applied, this project is for you.'</span>
&nbsp;
  s.<span style="color:#9900CC;">has_rdoc</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
  s.<span style="color:#9900CC;">rdoc_options</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'-a'</span>, <span style="color:#996600;">'--inline-source'</span>, <span style="color:#996600;">'--charset=UTF-8'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
  s.<span style="color:#9900CC;">files</span> = <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'lib/**/*.rb'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'bin/*'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>README.<span style="color:#9900CC;">rdoc</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  s.<span style="color:#9900CC;">test_files</span> = <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test/**/*.rb'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  s.<span style="color:#9900CC;">executables</span> = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>gbp<span style="color:#006600; font-weight:bold;">&#41;</span>
  s.<span style="color:#9900CC;">default_executable</span> = <span style="color:#996600;">'gbp'</span>
&nbsp;
  s.<span style="color:#9900CC;">add_dependency</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;erubis&quot;</span>, <span style="color:#996600;">&quot;~&gt; 2.6.0&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>After the <em>.gemspec</em> file is done, the Gem may be built via the <em>gem</em> command:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem build your.gemspec</pre></div></div>




<p>Or with a custom Rake task:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">spec = <span style="color:#CC0066; font-weight:bold;">eval</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;your.gemspec&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">readlines</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#6666ff; font-weight:bold;">Rake::GemPackageTask</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>spec<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>pkg<span style="color:#006600; font-weight:bold;">|</span>
  pkg.<span style="color:#9900CC;">need_zip</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
  pkg.<span style="color:#9900CC;">need_tar</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<h3>Folder Structure</h3>

<p>Ruby is an open language with very little restrictions. You can place your code anywhere, but there are some guidelines of how <a href="http://cookingandcoding.com/2009/06/04/creating-a-ruby-gem/">code should be structured</a> so that nobody has to mess <a href="http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices">with the <em>$LOAD_PATH</em></a> in order to use it. This is an example of standard Gem folders:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem_best_practice<span style="color: #000000; font-weight: bold;">/</span>
├── bin
├── example
├── lib
└── <span style="color: #7a0874; font-weight: bold;">test</span></pre></div></div>




<p>Your actual Ruby code should go under <em>lib</em> and subfolders. It&#8217;s a best practice to put just one file there and the other stuff right into another subfolder in order do avoid name clashes or the like. Extensions to the standard Ruby libraries should be separated out, so that they are easier to spot:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">├── lib
│   ├── gem_best_practice
│   │   ├── core_ext
│   │   │   └── kernel.rb
│   │   ├── core_ext.rb
│   │   └── gbp.rb
│   └── gem_best_practice.rb</pre></div></div>




<p>All the tests should go into the <em>test</em> folder ( <em>spec</em> / <em>feature</em> folder respectively). Make sure the Gem is well tested, otherwise chances are nobody will use the it nor contribute to the codebase. As an awesome Ruby developer, one would add some (working) examples in the <em>example</em> folder to demonstrate the <span class="caps">API </span>of your Gem in action. Additional executables for your Gem should be put into <em>bin</em> and don&#8217;t forget to add a proper shebang:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env ruby</span></pre></div></div>




<h3>Dependencies</h3>

<p>There are a lot of great libraries available for Ruby nowadays and one would be a fool not to use them. That&#8217;s why most of the Gems depend on other libraries. Different Gems may share common dependencies, so it&#8217;s elementary for a good Gem to be as loose about the own dependencies as possible to reduce versioning conflicts. Tools like <a href="http://gembundler.com/">Bundler</a> do a great job on resolving those conflicts and they depend on the versions that are wired in the <em>.gemspec</em> file of a Gem. You can easily <a href="http://gembundler.com/rubygems.html">tell Bundler to use your .gemspec</a> the main configuration source for your gems. A tradeoff between hard wiring Gem versions and providing no version restrictions at all, is to <a href="http://yehudakatz.com/2010/08/21/using-considered-harmful-or-whats-wrong-with/">use the ~&gt; range operator</a>, that will allow newer dependency versions within the same <span class="caps">MINOR </span>version:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  s.<span style="color:#9900CC;">add_dependency</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;erubis&quot;</span>, <span style="color:#996600;">&quot;~&gt; 2.6.0&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># &gt;= 2.6.0 and &lt; 2.7.0</span></pre></div></div>




<p>There is still one problem left. It&#8217;s currently <a href="http://ku1ik.com/blog/2010/07/03/thoughts-on-ruby-gem-dependencies.html">not possible to define optional dependencies</a> in your <em>.gemspec</em> file. This is a big problem for libraries that implement some kind of adapter pattern (Have a look at <a href="https://github.com/rubiii/httpi"><span class="caps">HTTPI</span></a> which provides an interface to different <span class="caps">HTTP </span>libraries) and don&#8217;t want to force the user to install <strong>all</strong> underlying implementations (This is <a href="http://yehudakatz.com/2010/04/17/ruby-require-order-problems/">also a problem for bundler</a>).</p>

<p>Until this problem is fixed in Rubygems, a simple approach to this problem is to programmatically rescue from LoadErrors:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># require optional dependency</span>
<span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'ap'</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">LoadError</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;awesome_print would be awesome, please 'gem install awesome_print'&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<h3>Documentation and Examples</h3>

<p>An awesome Gem deserves a decent documentation. If you are too lazy to document your code, you should at least bundle a <em><span class="caps">README</span></em> file with your source. <a href="http://github.com">GitHub</a> does a great job at pushing a project to provide a <em><span class="caps">README</span></em> (rdoc/textile/markdown/&#8230;), because this file will be prominently rendered on the projects start page. The <em><span class="caps">README</span></em> should at least include <strong>installation instructions</strong> and <strong>basic usage examples</strong>.</p>

<p>Using <a href="http://blog.firsthand.ca/2010/09/ruby-rdoc-example.html"><span class="caps">YARD</span></a> / <a href="http://rdoc.sourceforge.net/doc/index.html">RDoc</a> in the source code is another great way to help others understand the code, provide bugfixes or extend existing functionality. Even for yourself, having a good inline documentiont will save time when returning to a piece of code you did not had your hands on for month.</p>

<p>Generating the documentation can easily be done with <a href="http://rake.rubyforge.org/">Rake</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Rake::RDocTask</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:rdoc_dev</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>rd<span style="color:#006600; font-weight:bold;">|</span>
  rd.<span style="color:#9900CC;">rdoc_files</span>.<span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;lib/**/*.rb&quot;</span>, <span style="color:#996600;">&quot;README.rdoc&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  rd.<span style="color:#9900CC;">options</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'-a'</span>, <span style="color:#996600;">'--inline-source'</span>, <span style="color:#996600;">'--charset=UTF-8'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>If the project is hosted on GitHub, <a href="http://rdoc.info/">rdoc.info</a> may generate the documentation automatically from the source-repository. GitHub also provides a service-hook so that the documentation is updated on every push! A <em>.document</em> file in the project will give rdoc.info the right pointers which files to include in your docs:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">lib<span style="color:#006600; font-weight:bold;">/*</span>.<span style="color:#9900CC;">rb</span>
README.<span style="color:#9900CC;">rdoc</span></pre></div></div>




<p>Depending on the project, it might be a good idea to include some usage examples with the code. This might be the case if one can not put all the necessary information in the inline comments or the <span class="caps">README </span>file. Bye the way, (especially behavior driven) tests serve very well as executable examples.</p>

<p>Another thing that is overlooked quite often is the documentation of Ruby runtime compatibility. Does the Gem work with <span class="caps">MRI</span> 1.8 / 1.9 / JRuby / <span class="caps">REE </span>/ &#8230; ? Since <a href="http://rvm.beginrescueend.com/"><span class="caps">RVM</span></a> is a defacto standard in the Ruby environment, there is no good reason not to test at least Ruby 1.8.7 and 1.9.2.</p>

<h2>And then?</h2>

<p>After finishing the work on the first version of a Gem and pushing it to Rubygems, what comes next? </p>

<p>If you are just interested in the acceptence of the Gem you can have a look at <a href="http://rubygems.org/profiles/1055">the Rubygems user profile</a> or individual <a href="http://rubygems.org/gems/rails/stats">Gem stats</a>.</p>

<p>A good way to help the Gem gain acceptance is to make it OpenSource via <a href="http://github.com">GitHub</a> or <a href="http://rubyforge.org/">RubyForge</a>.</p>

<p>It&#8217;s not easy to reach a wide range of users, but if you want to promote your Gem over the interwebs there are a lot of services like <a href="http://dzone.com">DZone</a> or <a href="http://forrst.com/">Forrst</a> that allow you to post something about the Gem or to link to articles on your blog or Twitter posts. Another great resource for Ruby developers to discover new Gems is <a href="http://ruby-toolbox.com">The Ruby Toolbox</a>.</p>

<h2>The Gem Best Practice Gem</h2>

<p>I am currently putting all those Guidelines above into a <a href="https://github.com/phoet/gem_best_practice">Gem Best Practice Gem Project on GitHub</a> which is inspired by <a href="http://gembundler.com/rubygems.html">bundler&#8217;s <em>bundle gem</em> command</a>.</p>

<p>More best practice, less fail!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/tXWIN6ldIbg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/11/gem-best-practice/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/11/gem-best-practice/</feedburner:origLink></item>
		<item>
		<title>Updating Savon Handsoap Shootout</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/8F0SODOkYB4/</link>
		<comments>http://blog.nofail.de/2010/11/updating-savon-handsoap-shootout/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 15:43:01 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Savon]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=432</guid>
		<description><![CDATA[Since my initial series of blog posts about Savon and Handsoap a lot has been done on the Savon side. About a week ago rubiii has released the first beta of Savon 0.8. A lot of bugfixes, improvement and API changes have been addressed in the latest version. If you want to get used to [...]]]></description>
			<content:encoded><![CDATA[<p>Since my <a href="http://blog.nofail.de/tag/savon/">initial series of blog posts</a> about <a href="https://github.com/rubiii/savon">Savon</a> and <a href="https://github.com/troelskn/handsoap">Handsoap</a> a lot has been done on the Savon side.</p>

<p>About a week ago <a href="http://rubiii.com/">rubiii</a> has released the <a href="http://rubygems.org/gems/savon/versions/0.8.0.beta.1">first beta</a> of <a href="https://github.com/rubiii/savon/tree/eight">Savon 0.8</a>. A lot of bugfixes, improvement and <span class="caps">API </span>changes have been addressed in the latest version. If you want to get used to the new <span class="caps">API </span>a good starting point is the <a href="http://rubiii.github.com/savon/">Savon Guide</a>.</p>

<p>One thing that should be noted right away, is that Savon 0.8 is not downwards compatible. Most code parts have been rewritten and Savon now offers an improved error handling, support for local wsdl documents and more flexibility on request methods. See the <a href="http://github.com/rubiii/savon/blob/eight/CHANGELOG.md">changelog</a> for more information.</p>

<h2>Shootout update</h2>

<p>I have updated <a href="https://github.com/phoet/savon_handsoap_shootout">the examples used for the shootout</a> to reflect the latest changes for Savon 0.8.beta3, Handsoap 1.1.7 and <span class="caps">SOAP4R.</span> I restructured the examples, removed dead services and added <a href="http://gembundler.com/">Bundler</a> for gem dependencies. The examples run on <span class="caps">MRI</span> 1.8.7 and JRuby 1.5.2.</p>

<h2>More Savon infrastructure</h2>

<p>Some effort has been taken to make the day to day work with Savon even more pleasant. If you are working with RSpec, you can now test using <a href="https://github.com/rubiii/savon_spec">Savon Spec</a>.</p>

<p>If you are used to work with ActiveRecord models <a href="https://github.com/rubiii/savon_model">Savon Model</a> will help integrating <span class="caps">SOAP </span>into your Rails projects.</p>

<p><span class="caps">SOAP </span>without fail!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/8F0SODOkYB4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/11/updating-savon-handsoap-shootout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/11/updating-savon-handsoap-shootout/</feedburner:origLink></item>
		<item>
		<title>Generating PDF from HTML using DocRaptor on Heroku</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/KMwgtZRohsQ/</link>
		<comments>http://blog.nofail.de/2010/10/generating-pdf-from-html-using-docraptor-on-heroku/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 18:40:05 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[DocRaptor]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=416</guid>
		<description><![CDATA[There comes a time one has to create PDFs for a Rails application. Searching the web will most likely bring you to libraries like PDF Kit and Wicket PDF that use wkhtmltopdf as a driver. If your app is hosted on Heroku you wonder weather wkhtmltopdf is available so that you can use one of [...]]]></description>
			<content:encoded><![CDATA[<p>There comes a time one has to create <span class="caps">PDF</span>s for a Rails application. Searching the web will most likely bring you to libraries like <a href="http://github.com/jdpace/PDFKit/"><span class="caps">PDF</span> Kit</a> and <a href="http://github.com/mileszs/wicked_pdf/">Wicket <span class="caps">PDF</span></a> that use <a href="http://code.google.com/p/wkhtmltopdf/">wkhtmltopdf</a> as a driver.</p>

<p>If your app is hosted on <a href="http://heroku.com">Heroku</a> you wonder weather wkhtmltopdf is available so that you can use one of these awesome libraries. <a href="http://docs.heroku.com/search?q=pdf">Searching the Heroku docs</a>, you will probably come to same conclusion: nothing on there!</p>

As the Heroku support states:<br />
<blockquote>
You&#8217;re correct that there&#8217;s no official documentation. Most of our customers seem to be using wkhtmltopdf, generally with pdfkit. I do hope to document this usage soon.

<p>http://github.com/jdpace/PDFKit<br />

http://code.google.com/p/wkhtmltopdf/</p>

<p>If you want us to offer a Prince add-on, I encourage you to write them inviting them to check out our Add-on Provider Programme: http://addons.heroku.com/provider</p>

Of course, you can always purchase your own license and run it on <span class="caps">EC2 </span>or another server of your choosing.<br />
</blockquote>

<h2>PrinceXML</h2>

<p>One of the libraries that were used at <a href="http://www.blaulabs.de/">my last job</a> was <a href="http://princexml.com">PrinceXML</a>, which did a great jog generating <span class="caps">PDF</span>s from <span class="caps">HTML </span>pages. It <a href="http://princexml.com/doc/7.0/">supports most of the <span class="caps">HTML </span>and <span class="caps">CSS</span></a> stuff, passing the <a href="http://princexml.com/samples/acid2/"><span class="caps">ACID2 </span>test</a>. PrinceXML has <a href="http://princexml.com/doc/7.0/page-size/">some additional <span class="caps">CSS </span>attributes</a> that enable you to configure additional <span class="caps">PDF </span>specific layout settings.</p>

<h2>DocRaptor</h2>

<p>Since PrinceXML is a commercial product, Heroku won&#8217;t support it and I did not find anything on the web, that would offer <span class="caps">PDF </span>generation as a service. Asking the <a href="http://www.princexml.com/bb/viewtopic.php?f=3&amp;t=3820&amp;sid=cbbae46520b98f82e259f53e350d650d">PrinceXML Forum</a> I found out about <a href="http://docraptor.com/">DocRaptor</a>. These guys provide a service to convert <span class="caps">HTML </span>to <span class="caps">XLS </span>or <span class="caps">PDF </span>over a webservice interface, extactly what I was looking for. As an additional bonus, they <a href="http://rubygems.org/gems/doc_raptor">just implemented a gem</a> for supporting the Heroku Add-on interface. Mail to <a href="mailto:%73%75%70%70%6F%72%74%40%65%78%70%65%63%74%65%64%62%65%68%61%76%69%6F%72%2E%63%6F%6D">Expected Behavior Support</a> if you want to participate in the private beta.</p>

<h3>Improvements</h3>

<p>DocRaptor offers a great service, but they are still in early development. There were some Issues that were resolved recently. If you are a user of PrinceXML you probably know the <em>&#8211;baseurl</em> option that allows usage of relative paths for images and stylesheets. DocRaptor <a href="http://docraptor.com/documentation#pdf_options">adds support for command line options</a> just yet. The feature for <a href="http://docraptor.com/documentation#api_document_url">generating a <span class="caps">PDF </span>from a given <span class="caps">URL</span></a> is even better!</p>

<h3>Using DocRaptor from Rails</h3>

<p>The latest <a href="http://doc-raptor-docs.heroku.com/">DocRaptor documentation for the Heroku Add-on</a> is decent and it provides <a href="http://docraptor.com/examples">some nice examples</a>. </p>

<h4><span class="caps">PDF </span>from raw <span class="caps">HTML</span></h4>

<p>Here is what I did to get it running on <a href="http://phoet.de">my Rails 3 project</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Gemfile</span>
gem <span style="color:#996600;">&quot;doc_raptor&quot;</span>, <span style="color:#996600;">&quot;0.1.1&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># mime_types.rb</span>
<span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">Mime::Type</span></span>.<span style="color:#9900CC;">register_alias</span> <span style="color:#996600;">&quot;application/pdf&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:pdf</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># your_controller.rb</span>
<span style="color:#9966CC; font-weight:bold;">def</span> your_pdf_action
  respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">pdf</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      data = DocRaptor.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'DocRaptor.pdf'</span>, <span style="color:#ff3333; font-weight:bold;">:document_content</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> render_to_string, <span style="color:#ff3333; font-weight:bold;">:document_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;pdf&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:prince_options</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:baseurl <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'http://nofail.de'</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      send_data data, <span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'application/pdf'</span>, <span style="color:#ff3333; font-weight:bold;">:filename</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'DocRaptor.pdf'</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></div></div>




<p>If you registered the pdf mime-type you will have to provide an additional layout for this. I added some PrinceXML specific parameters to the styles to make it a fullscreen <span class="caps">PDF.</span> One thing that is essential for making the stylesheets work is the <em>media =&gt; &#8216;screen, print&#8217;</em> settings:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">//</span> application.<span style="color:#9900CC;">pdf</span>.<span style="color:#9900CC;">haml</span>
= stylesheet_link_tag <span style="color:#996600;">'style'</span>, <span style="color:#ff3333; font-weight:bold;">:media</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'screen, print'</span>
<span style="color:#006600; font-weight:bold;">//</span> you can provide a base tag <span style="color:#9966CC; font-weight:bold;">for</span> images <span style="color:#9966CC; font-weight:bold;">and</span> stylesheets
<span style="color:#006600; font-weight:bold;">//</span> <span style="color:#006600; font-weight:bold;">%</span>base<span style="color:#006600; font-weight:bold;">&#123;</span>:url<span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'http://blog.nofail.de'</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">%</span>style
  <span style="color:#0066ff; font-weight:bold;">@page</span> <span style="color:#006600; font-weight:bold;">&#123;</span> size: A4 <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#0066ff; font-weight:bold;">@page</span> <span style="color:#006600; font-weight:bold;">&#123;</span> margin: 0px <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#0066ff; font-weight:bold;">@page</span> <span style="color:#006600; font-weight:bold;">&#123;</span> border: none <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#0066ff; font-weight:bold;">@page</span> <span style="color:#006600; font-weight:bold;">&#123;</span> padding: 0px <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#0066ff; font-weight:bold;">@page</span> <span style="color:#006600; font-weight:bold;">&#123;</span> prince<span style="color:#006600; font-weight:bold;">-</span>shrink<span style="color:#006600; font-weight:bold;">-</span>to<span style="color:#006600; font-weight:bold;">-</span>fit: auto <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>




<h4><span class="caps">PDF</span>s from an <span class="caps">URL</span></h4>

<p>The simplest solution for generating a <span class="caps">PDF </span>is to send an url to the service, so you can re-use all your view logic:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">data = DocRaptor.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;DocRaptor.pdf&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:document_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://blog.nofail.de&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:document_type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;pdf&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
send_data data, <span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'application/pdf'</span>, <span style="color:#ff3333; font-weight:bold;">:filename</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;DocRaptor.pdf&quot;</span></pre></div></div>




<p>One caveat though, you got to have at least two <a href="http://docs.heroku.com/dynos">dynos</a> to serve the additional request from DocRaptor!</p>

<p>See a <a href="http://www.phoet.de/interest/curriculum/curriculum_table.pdf">working example on my homepage</a>.</p>

<p>Generating <span class="caps">PDF </span>form <span class="caps">HTML </span>without the hassle, thanks to DocRaptor!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/KMwgtZRohsQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/10/generating-pdf-from-html-using-docraptor-on-heroku/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/10/generating-pdf-from-html-using-docraptor-on-heroku/</feedburner:origLink></item>
		<item>
		<title>Rails, getting started without the hassle</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/keuJtzVBpM0/</link>
		<comments>http://blog.nofail.de/2010/09/rails-getting-started-without-the-hassle/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 18:25:56 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[RVM]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=402</guid>
		<description><![CDATA[I just changed jobs and am now a Rails developer at tolingo.com, which is an online translation broker. When I started out working on my new desk, I had to setup my iMac development environment. There are tons of articles of how to compile/install/run stuff like MySQL, to get you started on OS X, but [...]]]></description>
			<content:encoded><![CDATA[<p>I just changed jobs and am now a Rails developer at <a href="http://tolingo.com">tolingo.com</a>, which is an online translation broker. When I started out working on my new desk, I had to setup my iMac development environment. There are tons of articles of <a href="http://hivelogic.com/articles/ruby-rails-leopard">how to compile/install/run stuff like MySQL</a>, to get you started on OS X, but I think all one really needs is <a href="http://mxcl.github.com/homebrew/">Homebrew</a> and <a href="http://rvm.beginrescueend.com/"><span class="caps">RVM</span></a>.</p>

<h2>Homebrew</h2>

<p>Homebrew is a Ruby based packaging tool for Mac and once you start using it, you immediately hate yourself for having wasted time on <a href="http://www.macports.org/">MacPorts</a>&#8230;</p>

<blockquote>
&#8220;Homebrew is the easiest and most flexible way to install the <span class="caps">UNIX </span>tools Apple didn&#8217;t include with OS X.&#8221;<br />
</blockquote>

<p>This quote is from the official website and I guess they are absolutely right!</p>

<h3>Formula</h3>

<p>Homebrew is build around formulas. They describe how a package should be loaded from the web and installed on your system. It also cares about package dependencies, paths and all the other ugly stuff:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'formula'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Wget <span style="color:#006600; font-weight:bold;">&lt;</span> Formula
  homepage <span style="color:#996600;">'http://www.gnu.org/wget/'</span>
  url <span style="color:#996600;">'http://ftp.gnu.org/wget-1.12.tar.gz'</span>
  md5 <span style="color:#996600;">'308a5476fc096a8a525d07279a6f6aa3'</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> install
    <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;./configure --prefix=#{prefix}&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">'make install'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>You can easily install packages from the shell with <em>brew</em>:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">brew <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">wget</span></pre></div></div>




<p>Homebrew puts all the packages into <em>&#8216;/usr/local&#8217;</em>, so that it won&#8217;t interfer with other components of your system. To get your packages working, you need to include it into your <em>$PATH</em>. If you have any problems running something, Homebrew comes with the <em>doctor</em> command, that scans for problems in your setup!</p>

<h3>Installation</h3>

<p>Just download Homebrew to your system and update once a while:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># install homebrew via curl</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> <span style="color: #007800;">$USER</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> curl <span style="color: #660033;">-Lsf</span> http:<span style="color: #000000; font-weight: bold;">//</span>bit.ly<span style="color: #000000; font-weight: bold;">/</span>9H4NXH <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> xvz -C<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #660033;">--strip</span> <span style="color: #000000;">1</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># update homebrew</span>
brew update</pre></div></div>




<h3>Git, MySQL, Sphinx and more</h3>

<p>What else do you need? Just <em>search</em> for it or get more infos with <em>info</em>!</p>

<p>These are the packages that I needed for development:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># install mysql and set it up</span>
brew <span style="color: #c20cb9; font-weight: bold;">install</span> mysql
mysql_install_db
<span style="color: #666666; font-style: italic;"># add mysqld as launch agent</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span><span style="color: #666666; font-style: italic;">#{MYSQL_VERSION}/com.mysql.mysqld.plist ~/Library/LaunchAgents</span>
launchctl load <span style="color: #660033;">-w</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchAgents<span style="color: #000000; font-weight: bold;">/</span>com.mysql.mysqld.plist
&nbsp;
<span style="color: #666666; font-style: italic;"># install git</span>
brew <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">git</span> git-flow
&nbsp;
<span style="color: #666666; font-style: italic;"># add git bash completion (find path to your git with 'brew info git')</span>
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span><span style="color: #666666; font-style: italic;">#{GIT_VERSION}/etc/bash_completion.d/git-completion.bash ~/.git-completion.bash</span>
<span style="color: #7a0874; font-weight: bold;">source</span> .git-completion.bash
&nbsp;
<span style="color: #666666; font-style: italic;"># install sphinx search-deamon</span>
brew <span style="color: #c20cb9; font-weight: bold;">install</span> sphinx
&nbsp;
<span style="color: #666666; font-style: italic;"># aspell with all spellings</span>
brew <span style="color: #c20cb9; font-weight: bold;">install</span> aspell <span style="color: #660033;">--all</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># libxml and imagemagick for sprites</span>
brew <span style="color: #c20cb9; font-weight: bold;">install</span> libxml2 imagemagick</pre></div></div>




<h2><span class="caps">RVM </span>the Ruby Version Manager</h2>

<p><span class="caps">RVM </span>is a command line tool for managing your local Ruby environments, you can get some more information on the <a href="http://rvm.beginrescueend.com/"><span class="caps">RVM </span>homepage</a> and in <a href="http://blog.nofail.de/tag/rvm/">earlier articles</a>.</p>

<p>Quick start with installing <span class="caps">RVM </span>to your machine:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># install rvm via curl !!! FOLLOW RVM INSTRUCTIONS !!!</span>
<span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> curl http:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>rvm-install-head <span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># download and compile latest 1.8.7</span>
rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.8.7
&nbsp;
<span style="color: #666666; font-style: italic;"># create a .rvmrc file in your app's base directory</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;rvm use 1.8.7@#{YOUR_APP} --create&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #666666; font-style: italic;">#{YOUR_APP}/.rvmrc</span>
<span style="color: #666666; font-style: italic;"># execute it by cd-ing to your app's directory</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #666666; font-style: italic;">#{YOUR_APP}</span></pre></div></div>




<p>Now you can work on your app with a custom gem environment. Unless you are using <a href="http://gembundler.com/">Bundler</a>, this is probably what you want for installing and removing gems painlessly.</p>

<h3>Cucumber with Celerity</h3>

<p>Behavior driven development with <a href="http://cukes.info/">Cucumber</a> works nicely with <a href="http://celerity.rubyforge.org/">Celerity, a JRuby implementation of a headless browser using HtmlUnit</a> and it&#8217;s companion a Ruby wrapper called <a href="http://github.com/langalex/culerity">Culerity</a>. Culerity has recently been updated with some configuration points for registering your local JRuby environment:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># jruby config für culerity (from http://rvm.beginrescueend.com/integration/culerity/)</span>
rvm <span style="color: #c20cb9; font-weight: bold;">install</span> jruby
rvm use jruby<span style="color: #000000; font-weight: bold;">@</span>celerity <span style="color: #660033;">--create</span>
gem <span style="color: #c20cb9; font-weight: bold;">install</span> celerity
rvm wrapper jruby<span style="color: #000000; font-weight: bold;">@</span>celerity celerity jruby
<span style="color: #666666; font-style: italic;"># add to .profile</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">JRUBY_INVOCATION</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(readlink &quot;$(which celerity_jruby)</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #ff0000;">&quot;</span></pre></div></div>




<p>If you are experiencing any weird <em>Broken Pipe</em> errors (like me), have a look at <a href="http://github.com/langalex/culerity/issues/#issue/29">this issue</a>.</p>

<p>This is just an example of how you can setup your Rails development environment. Comments on this topic are appreciated!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/keuJtzVBpM0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/09/rails-getting-started-without-the-hassle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/09/rails-getting-started-without-the-hassle/</feedburner:origLink></item>
		<item>
		<title>DZone API and iPhone app</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/yDLIVsSteuo/</link>
		<comments>http://blog.nofail.de/2010/09/dzone-api-and-iphone-app/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 09:12:40 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[DZone]]></category>
		<category><![CDATA[Heroku]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=395</guid>
		<description><![CDATA[As I already mentioned, I am currently getting my hands dirty with Objective-C and iPhone application development. The biggest problem with getting started was that I had no idea what application I could write for that device that could become somewhat usable. As I am a passionate tech reader, I consume a lot of articles [...]]]></description>
			<content:encoded><![CDATA[<p>As <a href="http://blog.nofail.de/2010/08/using-blocks-in-objective-c/">I already mentioned</a>, I am currently getting my hands dirty with Objective-C and iPhone application development. </p>

<p>The biggest problem with getting started was that I had no idea what application I could write for that device that <a href="http://www.dzone.com/links/we_want_a_mobile_dzone.html">could become somewhat usable</a>. As I am a passionate tech reader, I consume a lot of articles posted on <a href="http://dzone.com">DZone</a>. Usually I use a feed reader like <a href="http://netnewswireapp.com/">NetNewsWire</a> for that, which works very well for my MacBook but is nearly useless on the iPhone, because the DZone site is not very mobile friendly&#8230;</p>

<h2>Problems</h2>

<p>Since there was no <a href="http://github.com/phoet/dzone">DZone iPhone application</a> on the marked I started working on it. Parsing DZone feeds was easy, even though the buildin <span class="caps">XML </span>support on iOS sucks. There were <a href="http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project">some nice libraries</a> that made my life easier.</p>

<h3>No deeplink</h3>

<p>The DZone <span class="caps">RSS </span>feed does not provide a deeplink to the actual linked article, so one would still land on the DZone page&#8230; Since <a href="http://meta.dzone.com/questions/66/dzone-api">DZone does not provide an <span class="caps">API </span>currently</a>, I started working on my own Rails application hosted on Heroku. Spidering the <span class="caps">RSS, </span>calling the page and extracting the link to the article is fragile, but it works (currently).</p>

<h3>No voting  </h3>

<p>One of my goals was to let the iPhone user vote for the article while reading it. The lack of an <span class="caps">API </span>forced me to do some more fragile login and posting stuff to the DZone page, but it works too (currently)!</p>

<p>You can read more about the <span class="caps">API</span> I created on the <a href="http://dzone-api.heroku.com/">actual page</a>.</p>

<h2>iPhone app</h2>

<p>The first version of the <strong>&#8220;dzone mobile&#8221;</strong> app has passed the iTunes store review process and is <a href="http://itunes.apple.com/app/dzone-mobile/id389511515">available through the app store</a>. A version with some minor bugfixes is currently beeing reviewed. Have a look at updates and documentation <a href="http://blog.nofail.de/dzone/">here</a> or <a href="http://github.com/phoet/dzone">here</a>.</p>

<h3>voting</h3>

<p>You have got to provide your DZone login credentials if you want to use the voting feature. Go to the iPhone Settings &gt; DZone and add your username and password. I want you to know that there is NO <span class="caps">SSL, </span>so your credentials will be submitted <span class="caps">UNSECURE</span>!</p>

<h3>more Features</h3>

<p>If you are interested in pushing this further, you can <a href="http://github.com/phoet/dzone/issues">add bug reports or feature requests on GitHub</a>.</p>

<p><img src="http://dl.dropbox.com/u/153067/dzone_screens.png" alt="screenshots" height="843" width="602" /></p>

<p>DZone iPhone sugar!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/yDLIVsSteuo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/09/dzone-api-and-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/09/dzone-api-and-iphone-app/</feedburner:origLink></item>
		<item>
		<title>Using the Redis addon on Heroku</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/dTMPJ0JqckM/</link>
		<comments>http://blog.nofail.de/2010/08/using-the-redis-addon-on-heroku/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:25:08 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[noSQL]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Redis]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=378</guid>
		<description><![CDATA[I am always playing around with new addons offered by Heroku. My latest discovery was the Redis addon that is provided by Redistogo. The addon is probably in private beta (docs are still on beta), but since they put up a link to it on their site, I managed to install it to my personal [...]]]></description>
			<content:encoded><![CDATA[<p>I am always <a href="http://blog.nofail.de/2010/07/mongo-ruby-driver-mongoid-and-mongomapper/">playing around with new addons</a> offered by Heroku. My latest discovery was the <a href="http://addons.heroku.com/redistogo">Redis addon</a> that is provided by <a href="http://redistogo.com/">Redistogo</a>. The addon is probably in private beta (<a href="http://docs-beta.heroku.com/redistogo">docs</a> are still on beta), but since they put up a link to it on their site, I managed to install it to my <a href="http://www.phoet.de">personal website</a> that runs in the cloud. </p>

<p><a href="http://code.google.com/p/redis/">Redis</a> is &#8220;an advanced key-value store&#8221; and has some features that make it a perfect match for a cache! I use caching extensively on my site and keep on <a href="http://blog.nofail.de/2010/02/simple-db-caching-for-heroku/">trying out new ways to do it</a> to circumvent Heroku&#8217;s readonly filesystem.</p>

<p>Like <a href="http://memcached.org/">Memcache</a>, Redis provides the ability to set a time to live (ttl) on a key. This comes in handy, if you have data that expires in a short period of time, like 3rd party data from Twitter etc.</p>

<h2>Caching with Redis</h2>

<p>Accessing Redis is very simple, since it is a text based protocol. The <a href="http://code.google.com/p/redis/wiki/CommandReference">command reference</a> is straight forward and there is a <a href="http://github.com/ezmobius/redis-rb/">simple Ruby wrapper</a> available:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;redis&quot;</span>
redis = Redis.<span style="color:#9900CC;">new</span>
redis.<span style="color:#9900CC;">set</span> <span style="color:#996600;">&quot;foo&quot;</span>, <span style="color:#996600;">&quot;bar&quot;</span>
<span style="color:#008000; font-style:italic;"># =&gt; &quot;OK&quot;</span>
redis.<span style="color:#9900CC;">get</span> <span style="color:#996600;">&quot;foo&quot;</span>
<span style="color:#008000; font-style:italic;"># =&gt; &quot;bar&quot;</span></pre></div></div>




<p>The <a href="http://github.com/jodosha/redis-store">redis-store gem</a> already provides a Rails 3 compatible Cache Store implementation, but I needed some more configuration points, especially the ttl.</p>

<p>That&#8217;s why I wrote my own <a href="http://github.com/phoet/rails_redis_cache">Rails 3 Redis Cache</a>, also a great way to get used to the way of working with Redis and the Redistogo addon.</p>

<h2>Using Rails Redis Cache</h2>

<p>There is some configuration needed for Rails to pick up the new cache store. If you want to use different or no caching for test, development and production, you should put the config in your environment files:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># config/environemnts/production.rb</span>
config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">perform_caching</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
config.<span style="color:#9900CC;">cache_store</span> = <span style="color:#6666ff; font-weight:bold;">ActiveSupport::Cache::RailsRedisCache</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'REDISTOGO_URL'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>If there is a Redis server available in all environments, you can put it in your environment file:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># config/environment.rb</span>
<span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">cache_store</span> = <span style="color:#6666ff; font-weight:bold;">ActiveSupport::Cache::RailsRedisCache</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'REDISTOGO_URL'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>The caching parts are mostly in my controllers:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@tweets</span> = cache<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tweets&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:expires_in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">30</span>.<span style="color:#9900CC;">seconds</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Twitter::Search</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> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>




<p>The store is using the <a href="http://github.com/rails/rails/blob/v3.0.0.beta1/activesupport/lib/active_support/cache.rb#L104">basic Rails cache store implementation</a> which is broken in the Rails 3.0.0.beta1 version that runs on Heroku, so <a href="http://github.com/phoet/basement/blob/master/config/rails_cache_fix.rb">I added a monkey-patch</a> for that using edge Rails. </p>

<h2>Redis on localhost</h2>

<p>Installing and running Redis on Mac OS X is really simple:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">brew <span style="color: #c20cb9; font-weight: bold;">install</span> redis
redis-server</pre></div></div>


<p> </p>

<p>There is also a commandline client available for direct access:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">redis-cli
redis<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #ff0000;">&quot;foo&quot;</span> <span style="color: #ff0000;">&quot;bar&quot;</span>
OK
redis<span style="color: #000000; font-weight: bold;">&gt;</span> get <span style="color: #ff0000;">&quot;foo&quot;</span>
<span style="color: #ff0000;">&quot;bar&quot;</span></pre></div></div>




<p>It&#8217;s key value stores, stupid!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/dTMPJ0JqckM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/08/using-the-redis-addon-on-heroku/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/08/using-the-redis-addon-on-heroku/</feedburner:origLink></item>
		<item>
		<title>Using blocks in Objective-C</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/LHXTZ0fRY80/</link>
		<comments>http://blog.nofail.de/2010/08/using-blocks-in-objective-c/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 08:57:28 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=362</guid>
		<description><![CDATA[One of my pious intentions for the year 2010 is to start writing some application for the Mac. Apart from the hype about iPhone development, I think that starting out in that area is especially appealing, as it reduces the size of the API one has to learn. Getting to know the iOS libraries is [...]]]></description>
			<content:encoded><![CDATA[<p>One of my pious intentions for the year 2010 is to start writing some application for the Mac. Apart from the hype about iPhone development, I think that starting out in that area is especially appealing, as it reduces the size of the <span class="caps">API </span>one has to learn. Getting to know the iOS libraries is a lot easier than handling the endless amount of Cocoa frameworks.</p>

<p>One thing that I discovered recently is the <a href="http://developer.apple.com/mac/articles/cocoa/introblocksgcd.html">support of blocks</a>, that has been introduced with <span class="caps">OSX</span> 10.6 and iOS 4.0.</p>

<h2>the environment matters</h2>

<p>Consuming 3rd party data from the web is kind of a pain, especially compared to how easy it is in Ruby. So I was pleased to find <a href="http://github.com/probablycorey/seriously">Seriously</a>, a framework for async calls and <span class="caps">JSON</span>/XML parsing. The Seriously examples made use of blocks:</p>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">NSString <span style="color: #339933;">*</span>url <span style="color: #339933;">=</span> @<span style="color: #ff0000;">&quot;http://api.twitter.com/1/users/show.json?screen_name=probablycorey&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>Seriously get<span style="color: #339933;">:</span>url handler<span style="color: #339933;">:^</span><span style="color: #009900;">&#40;</span>id body<span style="color: #339933;">,</span> NSHTTPURLResponse <span style="color: #339933;">*</span>response<span style="color: #339933;">,</span> NSError <span style="color: #339933;">*</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;Error: %@&quot;</span><span style="color: #339933;">,</span> error<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;Look, JSON is parsed into a dictionary!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        NSLog<span style="color: #009900;">&#40;</span>@<span style="color: #ff0000;">&quot;%@&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>body objectForKey<span style="color: #339933;">:</span>@<span style="color: #ff0000;">&quot;profile_background_image_url&quot;</span><span style="color: #009900;">&#93;</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: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>




<p>Executing this example in my app code <a href="http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg47163.html">raised an error</a>, that I could not easily understand:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #ff0000;">&quot;__NSConcreteGlobalBlock&quot;</span>, referenced from: ___block_holder_tmp_1.1207 <span style="color: #000000; font-weight: bold;">in</span> DZoneController.o
<span style="color: #c20cb9; font-weight: bold;">ld</span>: symbol<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span> not found
collect2: <span style="color: #c20cb9; font-weight: bold;">ld</span> returned <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">exit</span> status</pre></div></div>




<p>The problem was, that XCode set my execution environment to <span class="caps">OSX</span> 10.5 which does not have support for blocks. To fix this, one has to update the <em><span class="caps">MACOSX</span>_DEPLOYMENT_TARGET</em> build variable.</p>

<p>Right Clicking on the XCode project in the &#8220;Groups &amp; Files&#8221; view will bring up a context menu with &#8220;Get Info&#8221; (or pressing <span class="caps">CMD</span>+I while project is selected). The info pane has a &#8220;General&#8221; tab that lets you select the &#8220;Base <span class="caps">SDK </span>for All Configurations&#8221;, which I set that to iOS 4.0.<br />
An other option is to search for &#8220;MACOSX_DEPLOYMENT_TARGET&#8221; in the &#8220;Build&#8221; tab and changing that value accordingly. Make sure &#8220;Show&#8221; is set to &#8220;All Settings&#8221;.</p>

<p>At least some Objective-C sugar!</p>

<p><a href="http://blog.nofail.de/wp-content/uploads/2010/08/Bildschirmfoto-2010-08-05-um-10.03.27.png"><img src="http://blog.nofail.de/wp-content/uploads/2010/08/Bildschirmfoto-2010-08-05-um-10.03.27.png" alt="" title="Bildschirmfoto 2010-08-05 um 10.03.27" width="437" height="406" class="aligncenter size-full wp-image-364" /></a></p>

<p><a href="http://blog.nofail.de/wp-content/uploads/2010/08/Bildschirmfoto-2010-08-05-um-10.52.44.png"><img src="http://blog.nofail.de/wp-content/uploads/2010/08/Bildschirmfoto-2010-08-05-um-10.52.44.png" alt="" title="Bildschirmfoto 2010-08-05 um 10.52.44" width="437" height="537" class="aligncenter size-full wp-image-369" /></a></p><img src="http://feeds.feedburner.com/~r/nofail/~4/LHXTZ0fRY80" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/08/using-blocks-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/08/using-blocks-in-objective-c/</feedburner:origLink></item>
		<item>
		<title>Mongo Ruby Driver, Mongoid and MongoMapper</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/2mZKbMQBMUw/</link>
		<comments>http://blog.nofail.de/2010/07/mongo-ruby-driver-mongoid-and-mongomapper/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 19:53:13 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=352</guid>
		<description><![CDATA[================================================================= ================================================================= Update Aug. 2010 On Whyday, I created a live demo of the examples, that is running on Heroku. =============================================================== =============================================================== I am constantly looking around for different storage mechanisms on Heroku that can be used for caching 3rd party data. A recent update of their platform offered an MongoDB addon to access the [...]]]></description>
			<content:encoded><![CDATA[================================================================= =================================================================



<p>Update Aug. 2010</p>

<p>On <a href="http://whyday.org">Whyday</a>, I created a live demo of the examples, <a href="http://mongodb-examples.heroku.com/">that is running on Heroku</a>.</p>

<p>=============================================================== =============================================================== </p>

<p>I am constantly looking around for different storage mechanisms on <a href="http://docs.heroku.com">Heroku</a> that can be used for caching 3rd party data. <a href="http://blog.heroku.com/archives/2010/4/30/mongohq_add_on_public_beta/">A recent update</a> of their platform offered <a href="http://addons.heroku.com/mongohq">an MongoDB addon</a> to access the <a href="https://mongohq.com/">MongoHQ service</a> that drew my attention, so I started to evaluate this noSQL document database&#8230;</p>

<h2>MongoDB on OS X</h2>

<p>It&#8217;s always a good starting point to have a local installation of a technology, <a href="http://www.mongodb.org/display/DOCS/Quickstart+OS+X">here is how you get it running</a> on your Mac with <a href="http://mxcl.github.com/homebrew/">Homebrew</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">brew <span style="color: #c20cb9; font-weight: bold;">install</span> mongodb
<span style="color: #666666; font-style: italic;"># create a place for MongoDB to store the data</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>db
<span style="color: #666666; font-style: italic;"># run server with default config (adapt to the right version)</span>
mongod run <span style="color: #660033;">--config</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>mongodb<span style="color: #000000; font-weight: bold;">/</span>1.4.4-x86_64<span style="color: #000000; font-weight: bold;">/</span>mongod.conf</pre></div></div>




<p>Using MongoHQ requires a user-authentication, so it&#8217;s nice to have the same credentials on your local MongoDB instance:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># start the client</span>
mongo
<span style="color: #000000; font-weight: bold;">&gt;</span> use <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> db.addUser<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;test&quot;</span>, <span style="color: #ff0000;">&quot;test&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>




<h2>evaluating different <span class="caps">API</span>s</h2>

<p>A very basic approach, that basically wraps the MongoDB <span class="caps">API </span>into Ruby code is the <a href="http://api.mongodb.org/">Mongo Ruby Driver</a>, but there are two higher level <span class="caps">API</span>s close to ActiveRecord called <a href="http://mongoid.org/">Mongoid</a> and <a href="http://mongomapper.com/">MongoMapper</a>.</p>

<h3>Mongo Ruby Driver</h3>

<p>It&#8217;s pretty easy to connect to your MongoDB with the right connection string:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">conn = <span style="color:#6666ff; font-weight:bold;">Mongo::Connection</span>.<span style="color:#9900CC;">from_uri</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;mongodb://user:pass@host:port/db&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
db = conn.<span style="color:#9900CC;">db</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;db&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>The Mongo Ruby Driver is very simple and close to the <a href="http://www.mongodb.org/display/DOCS/Mongo+Query+Language">MongoDB <span class="caps">API</span></a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">coll = db.<span style="color:#9900CC;">collection</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
coll.<span style="color:#9900CC;">insert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'a'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
coll.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>row<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">p</span> row <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>




<h3>MongoMapper</h3>

<p>MongoMapper can also be accessed with a connection string:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Mongo::Connection</span>.<span style="color:#9900CC;">from_uri</span><span style="color:#006600; font-weight:bold;">&#40;</span>MONGO_URL<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>Instead of using ActiveRecord::Base MongoMapper provides the MongoMapper::Document module to handle the object document mapping. Since the structure of a document in MongoDB is open and not static like in a <span class="caps">SQL </span>database, you have to define the structure in code, so MongoMapper knows how to map the document to your Ruby objects:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Person
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">MongoMapper::Document</span>
&nbsp;
  key <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#CC0066; font-weight:bold;">String</span>
  key <span style="color:#ff3333; font-weight:bold;">:age</span>, <span style="color:#CC0066; font-weight:bold;">Integer</span>
  key <span style="color:#ff3333; font-weight:bold;">:born_at</span>, <span style="color:#CC00FF; font-weight:bold;">Time</span>
  key <span style="color:#ff3333; font-weight:bold;">:active</span>, Boolean
  key <span style="color:#ff3333; font-weight:bold;">:fav_colors</span>, <span style="color:#CC0066; font-weight:bold;">Array</span>
&nbsp;
  connection <span style="color:#6666ff; font-weight:bold;">Mongo::Connection</span>.<span style="color:#9900CC;">from_uri</span><span style="color:#006600; font-weight:bold;">&#40;</span>MONGO_URL<span style="color:#006600; font-weight:bold;">&#41;</span>
  set_database_name <span style="color:#996600;">'basement'</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
person = Person.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Nunemaker'</span>,
  <span style="color:#ff3333; font-weight:bold;">:age</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">27</span>,
  <span style="color:#ff3333; font-weight:bold;">:born_at</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">mktime</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1981</span>, <span style="color:#006666;">11</span>, <span style="color:#006666;">25</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">30</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
  <span style="color:#ff3333; font-weight:bold;">:active</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>,
  <span style="color:#ff3333; font-weight:bold;">:fav_colors</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>red green blue<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
person.<span style="color:#9900CC;">save</span>
&nbsp;
Person.<span style="color:#9900CC;">all</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>p<span style="color:#006600; font-weight:bold;">|</span>
  ...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<h3>Mongoid</h3>

<p>Configuring Mongoid is somewhat different but easy:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Mongoid.<span style="color:#9900CC;">database</span> = <span style="color:#6666ff; font-weight:bold;">Mongo::Connection</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>host, port<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">db</span><span style="color:#006600; font-weight:bold;">&#40;</span>db<span style="color:#006600; font-weight:bold;">&#41;</span>
Mongoid.<span style="color:#9900CC;">database</span>.<span style="color:#9900CC;">authenticate</span><span style="color:#006600; font-weight:bold;">&#40;</span>user, pass<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>The <span class="caps">DSL </span>for defining Mongoid Documents is similar to MongoMapper and works mostly the same way. <a href="http://mongoid.org/docs/querying/">Querying the database</a> is also similar to the <span class="caps">API </span>provided by ActiveRecord:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Tweeter 
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Mongoid::Document</span> 
  field <span style="color:#ff3333; font-weight:bold;">:user</span> 
  embeds_many <span style="color:#ff3333; font-weight:bold;">:tweets</span> 
<span style="color:#9966CC; font-weight:bold;">end</span> 
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Tweet 
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Mongoid::Document</span> 
  field <span style="color:#ff3333; font-weight:bold;">:status</span>, <span style="color:#ff3333; font-weight:bold;">:type</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">String</span> 
&nbsp;
  embedded_in <span style="color:#ff3333; font-weight:bold;">:tweeter</span>, <span style="color:#ff3333; font-weight:bold;">:inverse_of</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:tweets</span> 
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
tweet = Tweet.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;This is a tweet!&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
tweet.<span style="color:#9900CC;">tweeter</span> = Tweeter.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'ted'</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
tweet.<span style="color:#9900CC;">save</span>
&nbsp;
Tweeter.<span style="color:#9900CC;">all</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tweeter<span style="color:#006600; font-weight:bold;">|</span> 
  ...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>You can get the complete code and some more links from the <a href="http://github.com/phoet/mongodb_examples/">GitHub project</a> created for testing.</p>

<p>MongoDB is a great way to store document focused data and it&#8217;s simple to use with these great libraries!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/2mZKbMQBMUw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/07/mongo-ruby-driver-mongoid-and-mongomapper/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/07/mongo-ruby-driver-mongoid-and-mongomapper/</feedburner:origLink></item>
		<item>
		<title>ASIN vs ruby-aaws</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/x4v5GDxk2K4/</link>
		<comments>http://blog.nofail.de/2010/07/asin-vs-ruby-aaws/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 10:49:40 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ASIN]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[ruby-aaws]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=343</guid>
		<description><![CDATA[I recently wrote about using ruby-aaws on Heroku. I used it for creating a virtual bookshelf on my website, so anybody interested in what I read can have a look at the ISBN, price, description and some reviews (in german). Since this is a trivial scenario it covers only a fragment of features that ruby-aaws [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wrote about using <a href="http://blog.nofail.de/2010/01/heroku-with-ruby-aaws/">ruby-aaws on Heroku</a>. I used it for creating a <a href="http://www.phoet.de/work/bookshelf">virtual bookshelf</a> on my website, so anybody interested in what I read can have a look at the <span class="caps">ISBN, </span>price, description and some reviews (in german). Since this is a trivial scenario it covers only a fragment of features that ruby-aaws offers. </p>

<p>I always felt that using ruby-aaws was way too complicated! This is how you call Amazon for the title of a book:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;amazon&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;amazon/aws&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;amazon/aws/search&quot;</span>
il = <span style="color:#6666ff; font-weight:bold;">Amazon::AWS::ItemLookup</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'ASIN'</span>, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'ItemId'</span><span style="color:#006600; font-weight:bold;">=&gt;</span>asin <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
rg = <span style="color:#6666ff; font-weight:bold;">Amazon::AWS::ResponseGroup</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Medium'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
req = <span style="color:#6666ff; font-weight:bold;">Amazon::AWS::Search::Request</span>.<span style="color:#9900CC;">new</span>
resp = req.<span style="color:#9900CC;">search</span><span style="color:#006600; font-weight:bold;">&#40;</span>il, rg<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> resp.<span style="color:#9900CC;">item_lookup_response</span>.<span style="color:#9900CC;">items</span><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:#9900CC;">item</span>.<span style="color:#9900CC;">item_attributes</span>.<span style="color:#9900CC;">title</span>.<span style="color:#9900CC;">to_s</span></pre></div></div>




<p>I also had to monkeypatch some stuff to get it working with Heroku the first time:</p>


<ul>
<li>allow .amazonrc to be on a different location that can be used on Heroku</li>
<li>remove restriction to Ruby 1.8.7 and patch related Stuff</li>
</ul>



<p>If you look into the source and documentation of ruby-aaws you will see that it is no fun to patch anything in there&#8230; I think I would not have done it without the help of <a href="http://caliban.org">Ian Macdonald</a>.</p>

<p>Another thing was, that I could not use the builtin caching facility of ruby-aaws, cause it simply does not work on Heroku&#8217;s readonly file-system.</p>

<h2>simplicity with <span class="caps">ASIN</span></h2>

<p>Given these restrictions, I decided to build a <a href="http://rubygems.org/gems/asin">minimum featureset gem</a> tailored for my requirements:</p>


<ul>
<li>provide access to the Amazon-E-Commerce-API via <span class="caps">REST</span></li>
<li>simple configuration points</li>
<li>minimum amount of code to write for a request</li>
<li>maximum flexibility</li>
</ul>



<p>If you have a look into the <a href="http://docs.amazonwebservices.com/AWSEcommerceService/4-0/">Amazon documentation</a> you see that it is quite easy to call the <span class="caps">API </span>via <span class="caps">REST.</span> Just append some query parameters to your desired endpoint (f.e. webservices.amazon.com) and as a result you get the desired information from Amazon. The tricky thing is, that since recently you have to sign your request with your <span class="caps">AWS </span>credentials. I did not find any specs on how to do that on the documentation, but <a href="http://cloudcarpenters.com/blog/amazon_products_api_request_signing/">Cloud Carpenters had a nice example using Python</a> that I <a href="http://github.com/phoet/asin/blob/master/lib/asin.rb#L119">adapted for Ruby</a>.<br />
There is also the nice <a href="http://apisigning.com/service.html">Amazon <span class="caps">API </span>signing service</a> that frees you from self signing your requests. The reason I did not use it, is that it supports the amazon.com endpoint only (I need amazon.de).</p>

<h2>requests with <span class="caps">ASIN</span></h2>

<p>Using <span class="caps">ASIN </span>is simple. You just have to provide your credentials to the configuration method, the rest is covered with sensible defaults that you can override if you wish:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'asin'</span>
<span style="color:#9966CC; font-weight:bold;">include</span> ASIN
&nbsp;
<span style="color:#008000; font-style:italic;"># use the configure method to setup your api credentials</span>
configure <span style="color:#ff3333; font-weight:bold;">:secret</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'your-secret'</span>, <span style="color:#ff3333; font-weight:bold;">:key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'your-key'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># you can override the api endpoint if you wish</span>
configure <span style="color:#ff3333; font-weight:bold;">:secret</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'your-secret'</span>, <span style="color:#ff3333; font-weight:bold;">:key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'your-key'</span>, <span style="color:#ff3333; font-weight:bold;">:host</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'webservices.amazon.de'</span></pre></div></div>




<p>After this setup you can call the <a href="http://docs.amazonwebservices.com/AWSEcommerceService/4-0/ApiReference/ItemLookupOperation.html#SampleRequest"><span class="caps">REST </span>api via the lookup</a> method:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># lookup an item with the amazon standard identification number (asin)</span>
item = lookup <span style="color:#996600;">'1430218150'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># have a look at the title of the item</span>
item.<span style="color:#9900CC;">title</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> Learn Objective<span style="color:#006600; font-weight:bold;">-</span>C on the Mac <span style="color:#006600; font-weight:bold;">&#40;</span>Learn Series<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># provide additional configuration options like the response group</span>
lookup<span style="color:#006600; font-weight:bold;">&#40;</span>asin, <span style="color:#ff3333; font-weight:bold;">:ResponseGroup</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:Medium</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>Title is currently the only attribute that is directly supported from the Item class, but this is no restriction. <span class="caps">ASIN </span>uses <a href="http://github.com/intridea/hashie">Hashie::Mash</a> for the internal data representation of the Amazon <span class="caps">REST XML </span>response. The Item class stores the response in a raw attribute that can be accessed for read:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># access the internal data representation (Hashie::Mash)</span>
item.<span style="color:#9900CC;">raw</span>.<span style="color:#9900CC;">ItemAttributes</span>.<span style="color:#9900CC;">ListPrice</span>.<span style="color:#9900CC;">FormattedPrice</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> $<span style="color:#006666;">39.99</span></pre></div></div>




<p>You can tailor the Item class to your needs by opening up the class and provide the methods you like or doing something entirely different with the raw attribute. </p>

<p><span class="caps">OR, </span>just <a href="http://github.com/phoet/asin/">fork me on GitHub</a>!</p>

<p>Maximum flexibility with some syntactic sugar!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/x4v5GDxk2K4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/07/asin-vs-ruby-aaws/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/07/asin-vs-ruby-aaws/</feedburner:origLink></item>
		<item>
		<title>Distinguish Ruby Runtimes with WhichRuby</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/kHhW9bRa6PA/</link>
		<comments>http://blog.nofail.de/2010/06/distinguish-ruby-runtimes-with-whichruby/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 16:47:46 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[RVM]]></category>
		<category><![CDATA[which_ruby]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=333</guid>
		<description><![CDATA[Nowadays there are several decent Ruby runtimes available besides MRI ranging from alpha-versions to production-ready status. Using RVM these different interpreters become more and more interchangeable. current problems Since switching between runtimes became as easy rvm use x more care has to be taken to support a wide range of interpreters and versions. This is [...]]]></description>
			<content:encoded><![CDATA[<p>Nowadays there are <a href="http://rvm.beginrescueend.com/interpreters/">several decent Ruby runtimes available</a> besides <a href="http://www.ruby-lang.org/"><span class="caps">MRI</span></a> ranging from alpha-versions to production-ready status. Using <a href="http://blog.nofail.de/tag/rvm/"><span class="caps">RVM</span></a> these different interpreters become more and more interchangeable. </p>

<h2>current problems</h2>

<p>Since switching between runtimes became as easy <em>rvm use x</em> more care has to be taken to support a wide range of interpreters and versions. This is especially true for shared code like <a href="http://rubygems.org/">gems</a>.</p>

<p>Some engines like <a href="http://jruby.org/">JRuby</a> have <a href="http://kenai.com/projects/jruby/pages/DifferencesBetweenMriAndJruby">limitations</a> that prevent the usage of some Ruby features. In most cases it&#8217;s possible to work around these limitations and provide a different solution that works, but might be somewhat less performant.</p>

<h2>checking runtimes</h2>

<p>Ruby is great at <a href="http://railsapi.com/doc/ruby-v1.9/#Object">introspection</a>, but especially 1.8 misses some key information like <em><span class="caps">RUBY</span>_ENGINE</em> to determine the current interpreter at runtime and one has to extract it from the <em><span class="caps">RUBY</span>_DESCRIPTION</em> constant. </p>

<p><a href="http://github.com/phoet/which_ruby">WhichRuby</a> aims at simplifying this tedious task and providing a simple <span class="caps">API</span>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># irb@jruby</span>
jruby<span style="color:#006600; font-weight:bold;">-</span>1.4.0 <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'which_ruby'</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> 
jruby<span style="color:#006600; font-weight:bold;">-</span>1.4.0 <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#9966CC; font-weight:bold;">include</span> WhichRuby
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Object</span> 
jruby<span style="color:#006600; font-weight:bold;">-</span>1.4.0 <span style="color:#006600; font-weight:bold;">&gt;</span> jruby?
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>




<p>Executing different code fragments becomes as easy as defining a scope:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ruby_scope<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:jruby</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#008000; font-style:italic;"># custom jruby code here</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>This comes in very handy for stuff like <a href="http://blog.nofail.de/2010/04/ruby-in-java-java-in-ruby-jruby-or-ruby-java-bridge/">accessing Java code</a> natively via JRuby instead of using <span class="caps">RJB.</span></p>

<p>I don&#8217;t like Rubbae &#8211; I love it!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/kHhW9bRa6PA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/06/distinguish-ruby-runtimes-with-whichruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/06/distinguish-ruby-runtimes-with-whichruby/</feedburner:origLink></item>
		<item>
		<title>Ruby in Java, Java in Ruby, JRuby or Ruby Java Bridge?</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/nEyxkuDk60o/</link>
		<comments>http://blog.nofail.de/2010/04/ruby-in-java-java-in-ruby-jruby-or-ruby-java-bridge/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 11:37:44 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Buildr]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[RVM]]></category>
		<category><![CDATA[which_ruby]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=315</guid>
		<description><![CDATA[Hosting (J)Rails applications on a high availability Java infrastructure with clusters, loadbalancers and all that shit stuff is great, if you already have it in place. But does running an app on the JRE make it a JRuby application by default? Do you really want to be stuck on JRuby? I really like the idea [...]]]></description>
			<content:encoded><![CDATA[<p>Hosting (J)Rails applications on a high availability Java infrastructure with clusters, loadbalancers and all that <del>shit</del> stuff is great, if you already have it in place. </p>

<p>But does running an app on the <a href="http://java.com/de/"><span class="caps">JRE</span></a> make it a <a href="http://jruby.org/">JRuby</a> application by default? Do you really want to be <em>stuck</em> on JRuby?</p>

<p>I really like the idea of running code with the most appropriate runtime available, that is why I use <a href="http://rvm.beginrescueend.com/"><span class="caps">RVM</span></a> all the time. JRuby is still very slow on startup and tools like <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">autotest/autospec</a> take minutes for just a handfull of tests&#8230;</p>

<p>So I would like to host Rails applications on a <a href="http://tomcat.apache.org/">Tomcat</a>, but on the other hand I want the tests to be executed with <a href="http://en.wikipedia.org/wiki/Ruby_MRI"><span class="caps">MRI</span></a>! This should not be a problem as long as you don&#8217;t want to share a common codebase within Ruby and Java.</p>

<h2>Integration</h2>

<p>Is there a best practice for combining Java and Ruby? </p>

<p>Since every project is different, I think that you&#8217;ve got to evaluate the possible solutions to pick the one that fits best.</p>

<p>The next sections cover some approaches on integration of Java and Ruby code. Make sure to <a href="http://blog.nofail.de/2010/01/xruby-on-the-mac/">have <span class="caps">RVM </span>installed</a> if you want to execute the <a href="http://github.com/phoet/ruby-java-jruby-rjb/">provided example code</a>. I assume that a <span class="caps">JRE </span>is provided with every OS nowadays&#8230;</p>

<h3>Java in Ruby</h3>

<p>There are two common solutions for embeding Java into a Ruby application. The first and obvious one is via JRuby, which can only be run with the JRuby runtime:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'java'</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;access java.util.UUID via JRuby&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> java.<span style="color:#9900CC;">util</span>.<span style="color:#9900CC;">UUID</span>.<span style="color:#9900CC;">randomUUID</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toString</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm use jruby 
=<span style="color: #000000; font-weight: bold;">&gt;</span> Using jruby 1.5.0.RC1
&nbsp;
jruby lib<span style="color: #000000; font-weight: bold;">/</span>jruby.rb 
=<span style="color: #000000; font-weight: bold;">&gt;</span> access java.util.UUID via JRuby
=<span style="color: #000000; font-weight: bold;">&gt;</span> a16fda6a-c57d-43b9-<span style="color: #000000;">8376</span>-801e48fe56b3</pre></div></div>




<p>The same thing is possible using the <a href="http://rjb.rubyforge.org/" title="RJB">Ruby Java Bridge</a> from <span class="caps">MRI</span>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rjb'</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;access java.util.UUID via RJB&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> Rjb::import<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'java.util.UUID'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">randomUUID</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toString</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm use 1.8.7
=<span style="color: #000000; font-weight: bold;">&gt;</span> Using ruby 1.8.7 p249
&nbsp;
ruby lib<span style="color: #000000; font-weight: bold;">/</span>rjb.rb 
=<span style="color: #000000; font-weight: bold;">&gt;</span> access java.util.UUID via RJB
=<span style="color: #000000; font-weight: bold;">&gt;</span> 1db8298c-<span style="color: #000000;">5486</span>-<span style="color: #000000;">4933</span>-be00-cdb180388e38</pre></div></div>




<p>But it is also possible to do it the other way around!</p>

<h3>Ruby in Java</h3>

<p>Evaluating Ruby code in Java is dead simple with help of the JRuby library. You just need to set up a <a href="http://github.com/phoet/ruby-java-jruby-rjb/blob/master/src/test/java/de/nofail/jruby/JRubyTest.java">scripting container</a> that executes your scripts:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  @Test
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute_jruby_scriptlet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">new</span> ScriptingContainer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">runScriptlet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;puts 'hello jruby world'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>




<p>A more advanced example is to wire a Ruby class as a <a href="http://springsource.org">Spring bean</a>. You need to provide <a href="http://github.com/phoet/ruby-java-jruby-rjb/blob/master/src/test/resources/applicationContext.xml">some configuration</a> and <a href="http://github.com/phoet/ruby-java-jruby-rjb/blob/master/src/test/java/de/nofail/Identifier.java">a Java interface</a> that can be used as the basis for the bean:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- applicationContext.xml --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lang:jruby</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;identifier&quot;</span> <span style="color: #000066;">script-interfaces</span>=<span style="color: #ff0000;">&quot;de.nofail.Identifier&quot;</span> <span style="color: #000066;">script-source</span>=<span style="color: #ff0000;">&quot;classpath:/ruby/identifier.rb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lang:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;uuid&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{ T(java.util.UUID).randomUUID().toString() }&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lang:jruby<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># identifier.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> Identifier
  <span style="color:#9966CC; font-weight:bold;">def</span> setUuid<span style="color:#006600; font-weight:bold;">&#40;</span>uuid<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@uuid</span> = uuid
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> getUuid<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@uuid</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> to_s<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#996600;">&quot;Identifier[#{@uuid}]&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;"># don't forget to return an instance as a bean</span>
Identifier.<span style="color:#9900CC;">new</span></pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Identifier.java</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Identifier <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">String</span> getUuid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// SpringJRubyBeanTest.java</span>
@RunWith<span style="color: #009900;">&#40;</span>SpringJUnit4ClassRunner.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
@ContextConfiguration<span style="color: #009900;">&#40;</span>locations <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/applicationContext.xml&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SpringJRubyBeanTest <span style="color: #009900;">&#123;</span>
&nbsp;
  @Resource<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;identifier&quot;</span><span style="color: #009900;">&#41;</span>
  Identifier identifier<span style="color: #339933;">;</span>
&nbsp;
  @Test
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> generateUuid_success<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;uuid: &quot;</span> <span style="color: #339933;">+</span> identifier<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>




<p>The code is <a href="http://jira.codehaus.org/browse/JRUBY-4737">currently not running with JRuby 1.5.0.RC1</a> so you need the latest stable release for testing.</p>

<h2>checking Ruby enginges</h2>

<p>It is even possible to mix and match all those approches! You just need to keep track of the Ruby engine that is evaluating your code. I created a little helper called <a href="http://github.com/phoet/which_ruby">which_ruby</a> (available on <a href="http://rubygems.org/gems/which_ruby">rubygems</a>) as a sidekick for this article, but more on that in the next week.</p>

<p>Some Ruby sugar in your cup of Java!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/nEyxkuDk60o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/04/ruby-in-java-java-in-ruby-jruby-or-ruby-java-bridge/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/04/ruby-in-java-java-in-ruby-jruby-or-ruby-java-bridge/</feedburner:origLink></item>
		<item>
		<title>taming webapp logging with log4j</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/saS_OTNlenw/</link>
		<comments>http://blog.nofail.de/2010/04/taming-webapp-logging-with-log4j/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 18:39:25 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[log4j]]></category>
		<category><![CDATA[Logging]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=283</guid>
		<description><![CDATA[Logging is an aspect of programming that should follow some simple rules. If I should describe logging for a dictionary it would be something like: &#8220;Providing essential information with object introspection at a decent level of output that enables you to look into a running application or providing runtime information for debugging.&#8221; But even the [...]]]></description>
			<content:encoded><![CDATA[<p>Logging is an aspect of programming that should follow some simple rules. If I should describe logging for a dictionary it would be something like: &#8220;Providing essential information with object introspection at a decent level of output that enables you to look into a running application or providing runtime information for debugging.&#8221;</p>

<p>But even the simplest thing can be complicated if you use Java&#8230; </p>

<p>There are different logging frameworks like <a href="http://logging.apache.org/log4j/1.2/manual.html">log4j</a>, <a href="http://commons.apache.org/logging/">commons logging</a> or <a href="http://logback.qos.ch/">logback</a> even though Java includes it&#8217;s own <a href="http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/">java.util.logging</a> <span class="caps">API.</span> To make it even worse, the Java community came up with a <a href="http://www.slf4j.org/">simple logging facade</a> so one can use the logging framework of choice but implement against the facade &#8211; <span class="caps">WTF</span>?!</p>

<h2>a standard that sucks</h2>

<p>I would guess that 99% of Java code is written against log4j. Nobody really want&#8217;s to switch a logging framework during implementation and most developers I know see log4j as a technical standard.</p>

<p>I won&#8217;t recommend using log4j to anyone. The log4j documentation is crap! There is <a href="http://www.amazon.de/Pro-Apache-Log4j-Samudra-Gupta/dp/1590594991/ref=sr_1_1?ie=UTF8&amp;s=books-intl-de&amp;qid=1270486062&amp;sr=8-1">no usefull literature</a> either (I never thought that one would have to buy a book for logging&#8230;). The framework misses essential things like pattern matching filters (you will have to use <a href="http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/filter/ExpressionFilter.html">log4j companions</a>) and it is difficult to configure, especially on a <a href="http://tomcat.apache.org/tomcat-5.5-doc/logging.html">tomcat</a>.</p>

<p>Log4j is a bitch when it comes to deployment. One has to be careful where to put the log4j jar(s) and xml or plain text configuration files. If you do it wrong you end up with broken logging behavior; webapps log to the wrong log file, spit out stuff to the system out or stop logging at all.</p>

<h2>this is how we do it</h2>

<p>Our Java infrastructure is service oriented. We have a bunch of webservices hosted on serveral distributed tomcats and all wars depend on log4j for logging. We want to reload the logging configuration files at runtime (why is <a href="http://www.jboss.com/products/platforms/application/">jboss</a> able to do it and tomcat is not?!) and manipulate it via <a href="http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/"><span class="caps">JMX</span></a>. </p>

<h3>additional log4j configuration</h3>

<p>To achieve this, we have to put some additional configuration into every webapp. Log4j comes with a watchdog that looks for changes in the configuration files. The functionality can be enabled by using the <a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/DOMConfigurator.html#configureAndWatch%28java.lang.String%29">configureAndWatch() method</a>. There is a precanned <a href="http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/util/Log4jConfigListener.html">Spring solution</a> for this, but it has configuration overhead and environmental restrictions. So the best place to implement it ourselves is in a custom context listener:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- web.xml --&gt;</span>
   [...]
	<span style="color: #808080; font-style: italic;">&lt;!-- listener for configuring the log4j watchdog --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>de.nofail.TomcatLoggingListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   [...]</pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">   <span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> contextInitialized<span style="color: #009900;">&#40;</span>ServletContextEvent sce<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		ServletContext servletContext <span style="color: #339933;">=</span> sce.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">String</span> log4jFile <span style="color: #339933;">=</span> <span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%s-log4j.xml&quot;</span>, servletContext.<span style="color: #006633;">getContextPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> configFilename <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>log4jFile<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toURI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAbsolutePath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			DOMConfigurator.<span style="color: #006633;">configureAndWatch</span><span style="color: #009900;">&#40;</span>configFilename, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error resolving log4j configuration file for context=&quot;</span> <span style="color: #339933;">+</span> servletContext, e<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: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span></pre></div></div>




<p>This listener will use a config file named <em><span class="caps">WEBAPP</span>-log4j.xml</em> lying in the root directory. The goal is, that every webapp has it&#8217;s own logging context. Every war should include a log4j.jar so that logging won&#8217;t be affected by other apps, the <a href="http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html">classloader hierarchie</a> will ensure this. The different xml configuration files can than be placed in a <a href="http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html">shared tomcat directory</a> for easy access of an operations team (which is probably yourself).</p>

<p>Using different configuration files has the advantage that you don&#8217;t have to mess around with appenders based on packages. That&#8217;s how one can configure different log levels for the same packages in each application, very usefull if you release a new application!</p>

<h3>Java Management Extension</h3>

<p>There are different ways to integrate <span class="caps">JMX </span>functionality into a webapp. The simplest approach is to use another servlet listener for propagating an mbean:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- web.xml --&gt;</span>
   [...]
	<span style="color: #808080; font-style: italic;">&lt;!-- listener for configuring JMX --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>de.nofail.JMXListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   [...]</pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">   <span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> contextInitialized<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ServletContextEvent sce<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			TomcatLogging mbean <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TomcatLogging<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			ObjectName clutter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectName<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;de.nofail:type=TomcatLogging&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			ManagementFactory.<span style="color: #006633;">getPlatformMBeanServer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">registerMBean</span><span style="color: #009900;">&#40;</span>mbean, clutter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalStateException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not create JMX context: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, e<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: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span></pre></div></div>




<p>If you are using <a href="http://www.springsource.com/">Spring</a> it&#8217;s easy to add <a href="http://static.springsource.org/spring/docs/2.0.x/reference/jmx.html"><span class="caps">JMX </span>support via annotations</a>.</p>

<p>Now you can access your running webapp via jconsole:</p>

<p><img src="http://blog.nofail.de/wp-content/uploads/2010/04/Bildschirmfoto-2010-04-06-um-19.36.00.png" width="585" class="aligncenter size-medium wp-image-292" /></p>

<h2>more information?</h2>

<p>You can have a look at a <a href="http://github.com/phoet/tomcat-logging">working example</a> <a href="http://blog.nofail.de/2010/03/creating-a-maven-webapp-from-scratch/">based on Maven</a> on github.</p>

<p>Drink a cup of Java&#8482;&#169;&#174;, but don&#8217;t forget the sugar!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/saS_OTNlenw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/04/taming-webapp-logging-with-log4j/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/04/taming-webapp-logging-with-log4j/</feedburner:origLink></item>
		<item>
		<title>Creating a Maven webapp from scratch</title>
		<link>http://feedproxy.google.com/~r/nofail/~3/5BN9luGy0aQ/</link>
		<comments>http://blog.nofail.de/2010/03/creating-a-maven-webapp-from-scratch/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 18:46:10 +0000</pubDate>
		<dc:creator>phoet</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://blog.nofail.de/?p=262</guid>
		<description><![CDATA[Doing a little research for an article about log4j configuration in Java webapps, I decided to use Maven as a sidekick. I already pointed out earlier that my favourite build tool is buildr. The reason I chose Maven is that it has archetypes and that there is a deprecated guide for using such an archetype [...]]]></description>
			<content:encoded><![CDATA[<p>Doing a little research for an article about <a href="http://logging.apache.org/log4j/">log4j</a> configuration in Java webapps, I decided to use <a href="http://maven.apache.org/">Maven</a> as a sidekick. <a href="http://blog.nofail.de/2010/01/buildr-the-build-system-that-doesnt-suck/">I already pointed out earlier</a> that my favourite build tool is <a href="http://buildr.apache.org/">buildr</a>. The reason I chose Maven is that it has <a href="http://maven.apache.org/guides/introduction/introduction-to-archetypes.html">archetypes</a> and that there is <del>a deprecated</del> guide for using such an archetype <a href="http://maven.apache.org/guides/mini/guide-webapp.html">to create a blank webapp</a> that would be valuable for me.</p>

<h2>installing Maven on OS X</h2>

<p>The Maven <a href="http://maven.apache.org/documentation">documentation</a> in general and the <a href="http://maven.apache.org/download.html#Installation">installation instructions</a> in particular <strong><span class="caps">SUCK</span></strong>. They lack essential information as most Java documentation does. So here is a step by step guide for OS X:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># go to the place you want to install Maven to</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library
<span style="color: #666666; font-style: italic;"># download latest Maven version</span>
curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>apache.autinity.de<span style="color: #000000; font-weight: bold;">/</span>maven<span style="color: #000000; font-weight: bold;">/</span>binaries<span style="color: #000000; font-weight: bold;">/</span>apache-maven-2.2.1-bin.zip
<span style="color: #666666; font-style: italic;"># unzip the archive</span>
<span style="color: #c20cb9; font-weight: bold;">unzip</span> apache-maven-2.2.1-bin.zip
<span style="color: #666666; font-style: italic;"># add a symlink for convenience</span>
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> apache-maven-2.2.1 maven
<span style="color: #666666; font-style: italic;"># add executables to the PATH</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;~/Library/maven/bin&quot;</span>:\<span style="color: #007800;">$PATH</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.profile
&nbsp;
<span style="color: #666666; font-style: italic;"># open a new bash and check Maven is running</span>
mvn <span style="color: #660033;">--version</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> Apache Maven 2.2.1 <span style="color: #7a0874; font-weight: bold;">&#40;</span>r801777; <span style="color: #000000;">2009</span>-08-06 <span style="color: #000000;">21</span>:<span style="color: #000000;">16</span>:01+0200<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>




<h2>creating the webapp</h2>

<p>If Maven is running on the system, you can use the archetype to create a blank webapp:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># go to the workspace</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #666666; font-style: italic;"># let Maven create a webapp</span>
mvn archetype:generate \ 
   <span style="color: #660033;">-DgroupId</span>=de.nofail \
   <span style="color: #660033;">-DartifactId</span>=tomcat-logging \
   <span style="color: #660033;">-Dversion</span>=1.0.0-SNAPSHOT \
   <span style="color: #660033;">-DarchetypeArtifactId</span>=maven-archetype-webapp</pre></div></div>




<p>This takes several minutes, as it requires <del>a thousand</del> some <del>broken</del> dependencies for whatever is necessary to create some files and folders! But after that, you have a fresh, apache conform webapp at hand:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># go to the webapp</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> tomcat-logging<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #666666; font-style: italic;"># let Maven create a distributable war</span>
mvn clean package</pre></div></div>




<p>This is very nice for a Java application! Zero configuration and you get a running webapp that you can start <del>after another two thousand downloads</del> instantly from the command line:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mvn jetty:run <span style="color: #000000; font-weight: bold;">&amp;</span>
open http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>tomcat-logging<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>




<h2>all by myself</h2>

<p>There is just one big problem with this so far: it won&#8217;t work bejond that! Maven lacks sensible defaults everywhere! Examples? Here you go:</p>

<h3>Java compiler</h3>

<p>Maven uses Java 1.4 as the default compliance level for the Java compiler. So if you start adding some <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html">Annotations</a> or <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html">Generics</a> to your code, which are Java 1.5 features, your build will fail until configuring the compiler plugin properly:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	[...]
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			[...]
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-compiler-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.0.2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			[...]
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	[...]</pre></div></div>




<p>This should be a top level configuration!</p>

<h3>Jetty plugin</h3>

<p>Making changes to the code won&#8217;t change anything in the webapp run by the <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin">Jetty plugin</a>. You need to configure the plugin in order to pick up changes. Since the plugin can not do any hot code replacement, it has to restart the context after every change. A no-go for most webapps:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	[...]
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			[...]
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.mortbay.jetty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-jetty-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>6.1.10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scanIntervalSeconds<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scanIntervalSeconds<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			[...]
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	[...]</pre></div></div>




<p>Why is this soooo much <span class="caps">XML</span>?</p>

<h2>Eclipse integration</h2>

<p>Maven has support for integrating a project into <a href="http://eclipse.org/">Eclipse</a> via the <a href="http://maven.apache.org/plugins/maven-eclipse-plugin/">Maven-Eclipse-Plugin</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># configure your workspace (do not use ~ to point to your home!)</span>
mvn eclipse:configure-workspace -Declipse.workspace=..<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #666666; font-style: italic;"># create Eclipse files</span>
mvn eclipse:eclipse</pre></div></div>




<p>These tasks add a M2_REPO classpath variable to your Eclipse environment that points to your local Maven repository and creates a <em>.project</em> and <em>.classpath</em> file from the existing pom. Just import the project with <em>Import &gt; General &gt; Existing Projects into Workspace</em> and your done.</p>

<h3>better with Eclipse plugins</h3>

<p>Since there are mature Eclipse plugins for Maven and Jetty, you should consider installing these from their update sites:</p>


<ul>
<li><a href="http://m2eclipse.sonatype.org/sites/m2e">m2eclipse</a></li>
<li><a href="http://run-jetty-run.googlecode.com/svn/trunk/updatesite">run jetty run</a></li>
</ul>



<p>It&#8217;s never easy doing stuff from scratch, but Maven should help flatten the rocky path to Java projects. Instead it piles up another Mount Everest of complexity to climb for a Java developer&#8230;</p>

<h2>additional information</h2>

<p>Check out my github profile for <a href="http://github.com/phoet/tomcat-logging">a working example project</a> that was created using these steps.</p>

<p>Maven &#8211; development <del>for morons</del> made easy!</p><img src="http://feeds.feedburner.com/~r/nofail/~4/5BN9luGy0aQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.nofail.de/2010/03/creating-a-maven-webapp-from-scratch/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.nofail.de/2010/03/creating-a-maven-webapp-from-scratch/</feedburner:origLink></item>
	</channel>
</rss>

