<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Jul's blog]]></title>
  <link href="http://js.hu/atom.xml" rel="self"/>
  <link href="http://js.hu/"/>
  <updated>2012-04-18T17:40:18+02:00</updated>
  <id>http://js.hu/</id>
  <author>
    <name><![CDATA[Balazs Nagy]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Testing woes]]></title>
    <link href="http://js.hu/blog/2012/04/18/testing-woes/"/>
    <updated>2012-04-18T15:53:00+02:00</updated>
    <id>http://js.hu/blog/2012/04/18/testing-woes</id>
    <content type="html"><![CDATA[<p>The newest drama club activities aim overtesting. DHH has placed his coin telling one should not try to have 100% coverage.</p>

<p>There are a lot of things in a standard rails app, which is nothing more but repetition. You don&#8217;t have to search too much to find a RESTful controller. It usually does the same as all the others. The same stuff gets copied over and over. Of course you think TDD just slows you down: you&#8217;ve already done that a thousandth time, why should you pretend this is something new?<!--more--></p>

<p>While this is totally understandable, we should not blame TDD. The problem is we&#8217;re writing copypaste code. Sure, we can add services and presenters to make our CRUD code a bit more interesting, but this is just another way to slow us down. No, the good solution is to move repetitive code to a single place. Use services and presenters when they add value (read: if your code doesn&#8217;t worth a dime, why do you want gold plating?).</p>

<p>ActiveRecord models are different. According to David, don&#8217;t test standard AR associations, validations, or scopes. What else a model contains, might I ask? Oh, come on, don&#8217;t bring up stuff you&#8217;ve moved from the controller, or are needed by views. Those belong to services and presenters. This basically says you should not test AR classes. This makes the decision much easier: is the model worth being tested? Do we really need this model after all?</p>

<p>Ah, and there&#8217;s cucumber. I&#8217;ve started with rspec + cucumber. RSpec just felt right, and Cucumber&#8230; well, it added BDD spice. Then I figured Cucumber is just a burden, an artifical layer over integration test, the end user usually just doesn&#8217;t care, and anyway, the whole stuff was just brittle.</p>

<p><span class='pullquote-right' data-pullquote='Running acceptance and unit tests at the same time is counterproductive. '>
I&#8217;ve switched to Steak, and then to Capybara, and it was good. Then, I even made my switch to MiniTest / MiniSpec, but then I had an epiphany. Running acceptance and unit tests at the same time is counterproductive. Now I&#8217;m using RSpec / Cucumber again.
</span></p>

<p>Take a BDD session. You describe your feature (don&#8217;t you?), you lay out your scenarios (tag them with @wip), and start implementing the first one. When it fails, you go to the inner TDD circle, and start implementing the first step which brings you closer to the goal: write a test, watch it fail, implement it. Then you can commit your code. You can switch back to the BDD circle to see whether your changes have made the first step pass. When you have finished with a scenario, remove the @wip tag.</p>

<p>You can see, TDD tests should always pass, but BDD should pass only when a scenario has been completed. Seeing errors in test run is discouraging, no matter they come from unfinished integration tests.</p>

<p>There is nothing wrong with Capybara, but you should run integration tests separately. In my case, returning to Cucumber was a late recognition I&#8217;ve been cuking it wrong. I have no problems describing the customer needs in a higher abstraction level.</p>

<p>All in all, DHH says you should not test your boring code. Take a step further: make your code interesting, and remove boring stuff. You might raise test coverage dramatically.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Revenge of the Standing desk]]></title>
    <link href="http://js.hu/blog/2011/11/11/standing-desk/"/>
    <updated>2011-11-11T21:09:00+01:00</updated>
    <id>http://js.hu/blog/2011/11/11/standing-desk</id>
    <content type="html"><![CDATA[<p>I spent most of my career in chairs. I sat beside various sizes of tables. One thing never changed though: their heights.</p>

<p>Recently I had to work from home for a week, and I decided my neck, back and bottom should be treated better. Fortunately my desk at home is an <a href="http://www.ikea.com/us/en/catalog/products/60111123/">IKEA Fredrik</a>, and I have a Dennis stool (you can see a picture of a similar one <a href="http://www.flickr.com/photos/diurys/3939257052">here</a>), which now has a successor in IKEA called <a href="http://www.ikea.com/us/en/catalog/products/40199211/">Franklin</a> (buying advice: choose the 29 1/8&#8221; or 74cm tall one).</p>

<p>My only problem is getting an anti-fatigue mat. I have flat feet, and standing is not one of my strengths. However, while a Genuine Joe&#8217;s Air Step is just a click away in the US for $20-30, this kind of stuff is completely unknown here. I&#8217;m testing a roll-up workout mat folded in half, with moderate success.</p>

<p>How fantastic, DIY, inexpensive, yadayadayada. I was curious, and I asked whether we can do the same at my workplace.</p>

<p>First off, I asked the local Ergo team whether they can help. They could: I got a mail a couple of days later from the furniture supplier company, telling that they can set me up a standing workstation for $2-3k, I just have to ask my manager for funding.</p>

<p>Of course we don&#8217;t have a budget for something like this, but if I make a case with a note from my doctor, we can push it through. Ookay, doctor&#8217;s recommendation, sounds reasonable.</p>

<p>Anyways, the supplier&#8217;s suggestion was a Steelcase Activa Lift 2 with gas struts (AFAICT <a href="http://www.steelcase.com/en/products/category/tables/adjustable/series5/pages/overview.aspx">Steelcase Series 5</a> is more or less the same), mentioning it&#8217;s cheaper than the electric motor version. They also mentioned gas struts can be set every day. How nice. Still, <a href="http://www.geekdesk.com/">GeekDesk</a> version 2.0 is $200 cheaper, and when you adjust its height, your cup of water will stay there.</p>

<p>Can be set every day&#8230; read: you have to put everything off of your table before operating. I&#8217;m sorry, but I already have a lot of stuff on my table when I arrive: a laptop with a stand, a keyboard and mouse, my coffee mug, my <a href="http://www.aeropress.com/">Aeropress</a>. Then I put other stuff on it, like my own laptop, a couple of USB drives, keys, wallet, badge, and the like. I want to sit whenever I&#8217;m tired, therefore I want to move the table up / down every single time.</p>

<p>At this point my unconscious interrupts. Why do I need all these stuff? Why I need a height-adjustable desk? I don&#8217;t! All I want is to raise my external monitor and my input devices. Raising a monitor is not a big deal, every furniture shop has adjustable VESA standard monitor stands. Raising my keyboard however is not something furniture designers figured out: they tend to forget good tilt and palmrest. My old natural keyboard had <strong>negative</strong> tilt and a wide palmrest, the way it should&#8217;ve always been.</p>

<p>My revenge will come on Monday: I&#8217;ll go to the closest DIY retailer, and I&#8217;ll buy a 11&#8221; x 32&#8221; x 1&#8221; ash board, and four 15&#8221; long table legs (eg. 30x80cm 2.5mm wide board, and 40cm table legs). It <strong>will</strong> beat the supplier&#8217;s $3000 setup.</p>

<p>News at 11.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Nested Forms Using Handlebars.js]]></title>
    <link href="http://js.hu/blog/2011/09/16/nested-forms-using-handlebars-js/"/>
    <updated>2011-09-16T22:47:00+02:00</updated>
    <id>http://js.hu/blog/2011/09/16/nested-forms-using-handlebars-js</id>
    <content type="html"><![CDATA[<p>I&#8217;ve already <a href="http://blog.js.hu/2009/06/15/add-form-fragments/">done that</a>. Everybody <a href="https://github.com/alloy/complex-form-examples">already</a> <a href="http://railscasts.com/episodes/197-nested-model-form-part-2">done</a> <a href="http://www.rubyflow.com/items/6464-awesome-nested-fields-for-rails">that</a>. What nested forms are? It&#8217;s something which adds a new entry row, or removes one from a form, by clicking on <code>+</code> or <code>-</code> buttons (sometimes <code>add</code> or <code>remove</code>, YMMV). This all awesome, but with some tricks, it&#8217;s very easy to reproduce.<!-- more --></p>

<p>I&#8217;ll write every user-faced webpage in <a href="http://www.sproutcore.com/">SproutCore</a> sooner or later, it&#8217;s inevitable. However, old habits die hard, I still want to use <a href="http://rubygems.org/gems/formtastic">Formtastic</a>, and stuff <a href="http://slim-lang.org/">Slim</a> gives to me.</p>

<p>The first common denominator is the template usage. All righty then, let&#8217;s start somehow.</p>

<p>Interestingly, building your own handlebars.js is the hardest part (and if you&#8217;re already used to it, you can imagine the rest). First off, you need <code>node.js</code> and <code>npm</code> installed:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>brew install node
</span><span class='line'>curl http://npmjs.org/install.sh | sudo sh
</span></code></pre></td></tr></table></div></figure>


<p>I really hope you already use <a href="http://mxcl.github.com/homebrew/">homebrew</a>.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">cd</span> /tmp
</span><span class='line'>curl https://nodeload.github.com/wycats/handlebars.js/tarball/master | tar zxvf -
</span><span class='line'><span class="nb">cd </span>wycats-handlebars*
</span><span class='line'><span class="c"># (at this point you might want to remove therubyracer gem from Gemfile)</span>
</span><span class='line'>bundle --path vendor --binstubs
</span><span class='line'>npm install jison
</span><span class='line'>bin/rake release
</span></code></pre></td></tr></table></div></figure>


<p>Now wipe the sweat off of our forehead, and grab the newly created <code>handlebars.js</code> and <code>handlebars.vm.js</code> files, and copy them to our project&#8217;s <code>lib/assets/javascripts</code> directory (some of you might want to put them to <code>vendor/assets/javascripts</code> rightfully, I&#8217;m just lazy).</p>

<p>I&#8217;m not about to go into the details how to implement nested forms. <strong>That</strong> part hasn&#8217;t changed after all. You can get a very good insight on what it is and how to implement it watching <a href="https://github.com/ryanb">Ryan Bates</a>&#8217; always amazing <a href="http://railscasts.com/episodes/196-nested-model-form-part-1">RailsCasts episode #196</a>, and the following <a href="http://railscasts.com/episodes/197-nested-model-form-part-2">RailsCasts episode #197</a>.</p>

<p>OK, 3rd party stuff is in place, let&#8217;s wire it into our app:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="c1">// app/assets/javascript/application.js</span>
</span><span class='line'><span class="c1">//= require jquery</span>
</span><span class='line'><span class="c1">//= require jquery_ujs</span>
</span><span class='line'><span class="c1">//= require handlebars</span>
</span><span class='line'><span class="c1">//= require_tree .</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now handlebars.js is picked up. Let&#8217;s create a view:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='haml'><span class='line'><span class="c">/ views/pages/_form.html.slim</span>
</span><span class='line'><span class="p">=</span> <span class="n">semantic_form_for</span> <span class="vi">@quote</span> <span class="k">do</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span>
</span><span class='line'>  script#add_form_fragment{type=&quot;text/x-handlebars-template&quot;}
</span><span class='line'>    <span class="p">=</span> <span class="n">f</span><span class="o">.</span><span class="n">semantic_fields_for</span><span class="p">(</span><span class="ss">:fragments</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="ss">:child_index</span> <span class="o">=&gt;</span> <span class="s2">&quot;{{new_id}}&quot;</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">builder</span><span class="o">|</span>
</span><span class='line'>      <span class="p">=</span> <span class="n">render</span><span class="p">(</span><span class="s2">&quot;fragment&quot;</span><span class="p">,</span> <span class="ss">:p</span> <span class="o">=&gt;</span> <span class="n">builder</span><span class="p">)</span>
</span><span class='line'>  <span class="p">=</span> <span class="n">f</span><span class="o">.</span><span class="n">inputs</span>
</span><span class='line'>  <span class="p">=</span> <span class="n">f</span><span class="o">.</span><span class="n">inputs</span> <span class="ss">:fragments</span> <span class="k">do</span>
</span><span class='line'>    <span class="p">=</span> <span class="n">f</span><span class="o">.</span><span class="n">semantic_fields_for</span> <span class="ss">:fragments</span> <span class="k">do</span> <span class="o">|</span><span class="nb">p</span><span class="o">|</span>
</span><span class='line'>      <span class="p">=</span> <span class="n">render</span> <span class="s1">&#39;fragment&#39;</span><span class="p">,</span> <span class="ss">:p</span> <span class="o">=&gt;</span> <span class="nb">p</span>
</span><span class='line'>    <span class="p">=</span> <span class="n">link_to</span> <span class="n">t</span><span class="p">(</span><span class="s1">&#39;.add_form_fragment_link&#39;</span><span class="p">),</span> <span class="s2">&quot;#&quot;</span><span class="p">,</span> <span class="nb">id</span><span class="p">:</span> <span class="s2">&quot;add_form_fragment_link&quot;</span>
</span><span class='line'>  <span class="p">=</span> <span class="n">f</span><span class="o">.</span><span class="n">buttons</span>
</span></code></pre></td></tr></table></div></figure>


<p><strong><em>UPDATE:</em></strong> It looks like I forgot to show you my fragment. Here you are:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='haml'><span class='line'><span class="c">/ views/pages/_fragment.html.slim</span>
</span><span class='line'><span class="p">=</span> <span class="nb">p</span><span class="o">.</span><span class="n">inputs</span> <span class="ss">:name</span> <span class="o">=&gt;</span> <span class="s1">&#39;fragment&#39;</span> <span class="k">do</span>
</span><span class='line'>  <span class="p">=</span> <span class="nb">p</span><span class="o">.</span><span class="n">input</span> <span class="ss">:param1</span>
</span><span class='line'>  <span class="p">=</span> <span class="nb">p</span><span class="o">.</span><span class="n">input</span> <span class="ss">:param2</span>
</span><span class='line'>  <span class="p">=</span> <span class="nb">p</span><span class="o">.</span><span class="n">input</span> <span class="ss">:_destroy</span><span class="p">,</span> <span class="ss">:as</span> <span class="o">=&gt;</span> <span class="ss">:boolean</span><span class="p">,</span> <span class="ss">:input_html</span> <span class="o">=&gt;</span> <span class="p">{</span> <span class="ss">:class</span> <span class="o">=&gt;</span> <span class="s1">&#39;destroy_fieldset&#39;</span> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>As you can see, we put a rendered <code>fields_for</code> + <code>render 'fragment'</code> into a script field, but with a child index which can be replaced by handlebars. Remove links are not handled here, that part hasn&#8217;t changed. I suppose we might want to place more fragments into a page, and in that case we can hook to more DOM events:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="c1"># app/assets/javascript/form_fragments.js.coffee</span>
</span><span class='line'><span class="nv">template = </span><span class="p">[]</span>
</span><span class='line'>
</span><span class='line'><span class="nv">add_fields = </span><span class="nf">(e, link, association)-&gt;</span>
</span><span class='line'>  <span class="nv">new_id = </span><span class="k">new</span> <span class="nb">Date</span><span class="p">().</span><span class="nx">getTime</span><span class="p">()</span>
</span><span class='line'>  <span class="nv">source = </span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#&quot;</span> <span class="o">+</span> <span class="nx">association</span><span class="p">).</span><span class="nx">html</span><span class="p">()</span>
</span><span class='line'>  <span class="nx">template</span><span class="p">[</span><span class="nx">association</span><span class="p">]</span> <span class="o">||=</span> <span class="nx">Handlebars</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">source</span><span class="p">)</span>
</span><span class='line'>  <span class="nx">$</span><span class="p">(</span><span class="nx">link</span><span class="p">).</span><span class="nx">before</span><span class="p">(</span><span class="nx">template</span><span class="p">[</span><span class="nx">association</span><span class="p">]({</span><span class="nv">new_id: </span><span class="nx">new_id</span><span class="p">}))</span>
</span><span class='line'>  <span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">()</span>
</span><span class='line'><span class="nx">$</span> <span class="o">-&gt;</span>
</span><span class='line'>  <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#add_form_fragment_link&quot;</span><span class="p">).</span><span class="nx">click</span> <span class="nf">(e)-&gt;</span>
</span><span class='line'>    <span class="nx">add_fields</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span> <span class="k">this</span><span class="p">,</span> <span class="s2">&quot;add_form_fragment&quot;</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>In this point if you look at the source it generates, you&#8217;ll see  <code>{{new_id}}</code>  gets replaced with <code>__new_id__</code> at a couple of places. It&#8217;s because Formtastic naming settings replace everything which is not a letter, number, and some punctuation marks like dash, colon, or period. Let&#8217;s fix it:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># config/initializers/formtastic.rb</span>
</span><span class='line'><span class="k">module</span> <span class="nn">Formtastic::Inputs::Base::Naming</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">sanitized_object_name</span>
</span><span class='line'>    <span class="n">object_name</span><span class="o">.</span><span class="n">to_s</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/\]\[|[^-a-zA-Z0-9:.{}]/</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="sr">/_$/</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>You can also fix in ActionView:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># config/initializers/actionview.rb</span>
</span><span class='line'><span class="k">class</span> <span class="nc">ActionView</span><span class="o">::</span><span class="no">Helpers</span><span class="o">::</span><span class="no">InstanceTag</span>
</span><span class='line'>  <span class="kp">private</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">sanitized_object_name</span>
</span><span class='line'>    <span class="vi">@sanitized_object_name</span> <span class="o">||=</span> <span class="vi">@object_name</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/\]\[|[^-a-zA-Z0-9:.{}]/</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="sr">/_$/</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p></p>

<p>You can always smooth off wrinkles, like hiding the add link if you don&#8217;t catch it:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="c">/* app/assets/stylesheets/form_fragment.css */</span>
</span><span class='line'><span class="nt">no-js</span> <span class="nf">#add_form_fragment_link</span> <span class="p">{</span> <span class="k">display</span><span class="o">:</span> <span class="k">none</span><span class="p">;</span> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>You use <a href="http://www.modernizr.com/">Modernizr</a>, don&#8217;t you?</p>

<p>That&#8217;s it, enjoy your new templates put into a <code>&lt;script&gt;</code> tag, instead of a long onclick event with full of escaping.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Rails nursery]]></title>
    <link href="http://js.hu/blog/2011/08/17/rails_nursery/"/>
    <updated>2011-08-17T13:33:00+02:00</updated>
    <id>http://js.hu/blog/2011/08/17/rails_nursery</id>
    <content type="html"><![CDATA[<p>I decided I give <a href="https://github.com/sstephenson/rbenv">rbenv</a> a shot. This change also means I have to find another way to separate rails gems from my standard ones. I&#8217;ll tell you why.<!-- more --></p>

<p>YMMV, but I have a couple of rails projects in my development directory. These are not necessarily on the same rails version. I have a 2.3, some 3.0, and some 3.1 rc used in my projects. Therefore I just can&#8217;t put all these gems into a single place. How my project selects the correct version of <code>rails</code> command? Hint: gem versioning is not a solution.</p>

<p>For my first problem, I found <a href="http://blog.js.hu/2011/05/18/vendoring-gems-with-style/">vendoring gems with style</a> pretty useful.</p>

<p>In my opinion, rbenv fits perfectly to Ryan McGeary&#8217;s <a href="http://ryan.mcgeary.org/2011/02/09/vendor-everything-still-applies/">solution</a>. Please put your project <code>.rbenv</code> file into source control.</p>

<p>Of course, from time to time I want to fire up a clean rails app for prototyping, and this is when I use gemsets. I could use <a href="https://github.com/jamis/rbenv-gemset">rbenv-gemset</a> from Jamis Buck too, but it&#8217;s just too much for my taste either.</p>

<p>My answer here is rails nursery (of course this applies to every ruby-related package, which requires some code generation):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'>gem install bundler
</span><span class='line'>mkdir ~/Code/rails-nursery-3.1.0.rc6
</span><span class='line'><span class="nb">cd</span> ~/Code/rails-nursery-3.1.0.rc6
</span><span class='line'>bundle init
</span><span class='line'><span class="nb">echo</span> <span class="s1">&#39;gem &quot;rails&quot;, &quot;3.1.0.rc6&quot;&#39;</span> &gt;&gt; Gemfile
</span><span class='line'>bundle install --path<span class="o">=</span>vendor --binstubs
</span></code></pre></td></tr></table></div></figure>


<p>That&#8217;s it. You switch to the nursery directory (in my case it&#8217;s <code>~/Code/rails-nursery-3.1.0.rc6</code>), and you&#8217;ll have the minimum requirements for creating a new 3.1.0rc6 rails app:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='sh'><span class='line'><span class="nb">cd</span> ~/Code/rails-nursery-3.1.0.rc6
</span><span class='line'>bin/rails new ~/Code/&lt;project&gt; --skip-bundle
</span><span class='line'><span class="nb">cd</span> ~/Code/&lt;project&gt;
</span><span class='line'><span class="nb">echo</span> <span class="s1">&#39;vendor/ruby&#39;</span> &gt;&gt; .gitignore
</span><span class='line'><span class="nb">echo</span> <span class="s1">&#39;vendor/rbx&#39;</span> &gt;&gt; .gitignore
</span><span class='line'>bundle install --path<span class="o">=</span>vendor --binstubs
</span></code></pre></td></tr></table></div></figure>


<p>Now you have a separate directory for all the gems you might not want in the future, and be honest: it&#8217;s much easier to get rid of this directory, than cherry-picking your installed gems.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stop the Octopress]]></title>
    <link href="http://js.hu/blog/2011/08/13/octopress/"/>
    <updated>2011-08-13T00:45:00+02:00</updated>
    <id>http://js.hu/blog/2011/08/13/octopress</id>
    <content type="html"><![CDATA[<p>Back to basics, you might think. When I started blogging, I wrote <a href="http://js.hu/package/blosxom.php/index.html">my own engine</a> in PHP. It was a breeze to use, it had modules and styles (called flavours), and blog posts could be written as files. However, it was not a content generator engine, since it picked up these text files on every hit.<!-- more --></p>

<p>It handled a database to store basic things like comments or indexes, but it was way before SQLite: I used db4 as a key-value store to do this.</p>

<p>Time passed, and every single PHP upgrade broke something in the code. I felt the whole system to be a burden. After a while I created a last flavour for Blosxom.PHP to export all blogposts and comments to Wordpress with a tailored rss feed.</p>

<p>Fast forward to now. I turned away from PHP and started writing Rails applications. My priorities have shifted. My cornerstones, however are still around: a good ol&#8217; zsh prompt and my TextMate (I fire up vim more often though). Now I feel WP is a burden.</p>

<p>Make no mistake, I believe Wordpress is a very good platform for personal blogging and even for a simple CMS, but it makes things difficult, and doesn&#8217;t allow the HTTP server where it excels: static page serving.</p>

<p>Most of a web page is static on a blog like this: archives, indexes, pages and syndication feeds can be generated, and only results should be put to document root. Moving parts can be deferred: comments, tweets, Google +1&#8217;s come from remote services. In fact, every local service can be replaced by some unobtrusive javascript magic, and a remote service.</p>

<p><span class='pullquote-right' data-pullquote='we should do better, with less resources, fewer database dependencies.'>
But why the fuss? I don&#8217;t think I&#8217;ll ever be <a href="http://fireballed.org/">fireballed</a>, but I strongly believe we should do better, with less resources, fewer database dependencies. I also don&#8217;t want to be a victim of an expired http session, crashed browser. Oh well, and I&#8217;ve fed up with web-based WYSIWYG editors.
</span></p>

<p>Thus, I move back to <a href="http://js.hu/">js.hu</a>, where I already have a ton of legacy stuff: some old Updike translations from a Hungarian magazine, even the first chapter of <a href="http://rickcooks.blogspot.com/">Rick Cook</a>&#8217;s <a href="http://www.baen.com/library/0671878468/0671878468__c_.htm">Wizards&#8217; Bane</a>. I led a guerrilla translation project of <a href="http://joelonsoftware.com/">Joel on Software</a>. I will keep serving these in their original (eg. ugly) format.</p>

<p>Therefore, expect new blog entries appearing here, mostly from my professional life.</p>
]]></content>
  </entry>
  
</feed>

