<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
  <title>self.works_with_ruby? - Home</title>
  <id>tag:workswithruby.com,2012:mephisto/</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  
  <link href="http://workswithruby.com/" rel="alternate" type="text/html" />
  <updated>2012-05-14T08:46:12Z</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/works_with_ruby" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="works_with_ruby" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2010-10-15:11072</id>
    <published>2010-10-15T19:49:00Z</published>
    <updated>2012-05-14T08:46:12Z</updated>
    <category term="openminds" />
    <category term="ruby" />
    <category term="sumocoders" />
    <link href="http://workswithruby.com/2010/10/the-big-leap" rel="alternate" type="text/html" />
    <title>The Big Leap</title>
<content type="html">
            &lt;p&gt;Today was my last day at Openminds!&lt;/p&gt;

&lt;p&gt;As some of you know I’ve been working with Openminds, a Belgian hosting and development company, for about 4 years now. I was their first employee, when the business was still vested in a small condo, and I’ve grown with it while the company moved 2 times to bigger locations, and only got bigger and better. I already knew my way around computers, but during my time at Openminds I learned a whole lot more about servers and hosting. I also met Ruby and Rails there, I got to learn it, and I can say I’ve become a professional Ruby programmer now. I’ve also enjoyed working with the colleagues there, who are all the best at what they do.&lt;/p&gt;

&lt;p&gt;But now it’s time to take the big leap, and no longer take the safe bet of being an employee. From now on I’m an Entrepreneur! A few months ago my colleague Jens asked me and Tijs to start a new business with him, and after some days I was sure now was the moment!&lt;/p&gt;

&lt;p&gt;We’ll be doing what we’re good at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consultancy in web-applications, from starting a new app to rescuing a dying one and optimizing an existing one.&lt;/li&gt;
&lt;li&gt;Convert good idea’s into full fledged web applications&lt;/li&gt;
&lt;li&gt;Give regular web applications an awesome mobile interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I will be responsible for the Ruby-department of this story, with Ruby consultancy and Ruby development. I’ll also share my expertise in server-setups with our customers.&lt;/p&gt;

&lt;p&gt;The first weeks of this plan we were known as Unnamed BVBA, but as of today we’ll be known as &lt;strong&gt;SumoCoders&lt;/strong&gt;, where we’ll wrestle applications and code like real rikishi (wrestlers, “literally men of power”)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sumocoders.be" title="SumoCoders"&gt;&lt;img src="http://www.defv.be/sumocoders.png" /&gt;&lt;/a&gt;&lt;br /&gt;
More info (in dutch) on &lt;a href="http://www.sumocoders.be"&gt;our website&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2010-09-27:11008</id>
    <published>2010-09-27T08:44:00Z</published>
    <updated>2012-05-14T08:46:10Z</updated>
    <link href="http://workswithruby.com/2010/9/make-javascript-docs-googl-able" rel="alternate" type="text/html" />
    <title>Make javascript docs googl'able</title>
<content type="html">
            &lt;p&gt;&lt;a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function" title="JavaScript JS Documentation: JS Function arity, JavaScript Function arity, JS Function .arity, JavaScript Function .arity"&gt;&lt;img src="http://static.jsconf.us/promotejshs.png" height="150" alt="JavaScript JS Documentation: JS Function arity, JavaScript Function arity, JS Function .arity, JavaScript Function .arity" width="180" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://promotejs.com/"&gt;You can make Javascript docs better too!&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2010-08-02:10851</id>
    <published>2010-08-02T17:01:00Z</published>
    <updated>2012-05-14T08:46:09Z</updated>
    <category term="appstore" />
    <category term="developers" />
    <category term="ipad" />
    <link href="http://workswithruby.com/2010/8/ipad-appstore-disillusion" rel="alternate" type="text/html" />
    <title>iPad AppStore disillusion</title>
<content type="html">
            &lt;p&gt;A few weeks ago Apple launched the iPad in 9 more countries, including Belgium. Ever since they first came out and the first reviews appeared I have been wanting one, and I had placed a pre-order from the moment it was possible. So the friday it launched, I got an e-mail from the local Apple Reseller saying they had one in reservation for me. I picked it up and have been happy with it ever since.&lt;/p&gt;

&lt;p&gt;First thing I did when I got it was copy over all the applications I use and love on my iPhone. From what I knew from Apple I figured most apps would have been made iPhone and iPad compatible, but to my surprise not a lot of them were. When I looked into it in detail I saw a (to me) shocking trend: Most apps I have bought on the iPhone do have an iPad version, they’re just new apps.&lt;/p&gt;

&lt;h4&gt;iPhone version&lt;/h4&gt;

&lt;p&gt;&lt;img src="http://farm5.static.flickr.com/4116/4853361481_2e4fc235e5_o.jpg" alt="iPhone App" /&gt;&lt;/p&gt;

&lt;h4&gt;iPad version&lt;/h4&gt;

&lt;p&gt;&lt;img src="http://farm5.static.flickr.com/4095/4853359855_d84ebcfff4_o.jpg" alt="iPad App" /&gt;&lt;/p&gt;

&lt;p&gt;If you look in the store you’ll find a bunch of these “appName” - “appName HD” pairs. I’d be fine with that if HD versions came with new features, new modes, … But most of the time, it is just a graphic update, changing the resolution from iPhone to iPad size.&lt;/p&gt;

&lt;p&gt;I had expected most of the developers to make their applications iPhone and iPad compatible, to give an “as good as it gets” experience to the users, but apparently the developers are going for the easy buck, trying to squeeze some more money out of the same app.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2010-07-08:10808</id>
    <published>2010-07-08T13:25:00Z</published>
    <updated>2012-05-14T08:46:08Z</updated>
    <category term="actionmailer" />
    <category term="css" />
    <category term="rails3" />
    <category term="tamtam" />
    <link href="http://workswithruby.com/2010/7/inlining-css-in-actionmailer-3-rails-3-0" rel="alternate" type="text/html" />
    <title>Inlining CSS in ActionMailer 3 (Rails 3.0)</title>
<content type="html">
            &lt;p&gt;As most of you already know, a bunch of online mail readers (like Hotmail, Gmail, …) don’t handle stylesheets very well, they prefer inline styling (&lt;p /&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This code sees if I am working with a template and if that template has a HTML MIME-type, it inline’s it with TamTam.&lt;/p&gt;

&lt;p&gt;In my mailers I just include it. If you want to have this in all mailers, just add an initializer that includes InlineCss in ActionMailer::Base, and it should work&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2010-05-12:10692</id>
    <published>2010-05-12T13:50:00Z</published>
    <updated>2012-05-14T08:46:06Z</updated>
    <category term="arrrrcamp" />
    <category term="rails3" />
    <category term="railties" />
    <link href="http://workswithruby.com/2010/5/railties-talk" rel="alternate" type="text/html" />
    <title>Railties Talk</title>
<content type="html">
            &lt;p&gt;Last &lt;a href="http://arrrrcamp.be"&gt;ArrrrCamp&lt;/a&gt; I gave a talk about Railties and Engines.&lt;/p&gt;

&lt;div&gt;
&amp;lt;object height="355" width="425"&gt;&amp;lt;param /&gt;&amp;lt;param /&gt;&amp;lt;param /&gt;&amp;lt;embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=railtiesforexport-100512085225-phpapp02&amp;amp;stripped_title=railties" height="355" width="425"&gt;&amp;lt;/embed&gt;&amp;lt;/object&gt;&lt;/div&gt;

&lt;p&gt;You can get the PDF with my presenter notes on &lt;a href="http://www.defv.be/railties.pdf"&gt;http://www.defv.be/railties.pdf&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2010-03-01:10558</id>
    <published>2010-03-01T14:20:00Z</published>
    <updated>2012-05-14T08:46:04Z</updated>
    <category term="git" />
    <category term="gitignore" />
    <category term="rails" />
    <link href="http://workswithruby.com/2010/3/environment-specific-files-and-git" rel="alternate" type="text/html" />
    <title>Environment specific files and gitignore</title>
<content type="html">
            &lt;p&gt;I love my Mac for doing development! Textmate and Passenger make it my all-time favorite environment to develop Ruby / Rails in. It does have some very specific “junk” files I don’t want in my git, though.&lt;/p&gt;

&lt;p&gt;In the beginning I would include all those files in every project’s &lt;code&gt;.gitignore&lt;/code&gt; file. This worked since all my colleagues also work on a Mac with Passenger &amp;amp; TextMate. Recently I’ve come across people with different setups, which made the project’s .gitignore look like this:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
.DS_Store
Thumbs.db
tmp/restart.txt
.idea
.todo
.bundle
.rake_tasks~
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;After some searching I found you can easily setup a global .gitignore which ignores your environment specific files. Doing so is easy:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
# ~/.gitignore
.DS_Store
tmp/restart.txt
.rake_tasks~
.idea
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And added this to my global git config&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
git config --global core.excludesfile ~/.gitignore 
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This all makes your .gitignore file much cleaner and more relevant for the project itself.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2010-01-14:10502</id>
    <published>2010-01-14T15:56:00Z</published>
    <updated>2012-05-14T08:46:01Z</updated>
    <category term="debian" />
    <category term="dpkg" />
    <category term="mongodb" />
    <category term="nosql" />
    <link href="http://workswithruby.com/2010/1/compiling-mongodb-stable-as-a-debian-lenny-package" rel="alternate" type="text/html" />
    <title>Compiling mongodb 'stable' as a debian lenny package</title>
<content type="html">
            &lt;p&gt;Today I had the pleasure of having to install MongoDb on one of our production servers. Pleasure because MongoDb is an awesome document database, and I also like new things.&lt;/p&gt;

&lt;p&gt;Most of our production servers run Debian, and we try to keep all installed packages up to date with apt. Since Debian Lenny didn’t have a mongodb package (it does have a lot of other packages Mongolian language packs) I had to make my own. Luckily the &lt;a href="http://github.com/mongodb/mongo"&gt;mongodb git repository&lt;/a&gt; comes with a ‘debian’ folder, so making a .deb package should be easy as pie.&lt;/p&gt;

&lt;p&gt;There are quite a few gotchas to get it to build, though. This is what you’ll need to do:&lt;/p&gt;

&lt;p&gt;Get last mongodb ‘stable’ source&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;git clone git://github.com/mongodb/mongo.git
cd mongo
git checkout r1.2.1
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;debian/control&lt;/strong&gt; file lists all deps including one we can’t fulfill on Lenny, &lt;code&gt;xulrunner-1.9-dev&lt;/code&gt;. We only have &lt;code&gt;xulrunner-dev&lt;/code&gt;. So change the &lt;strong&gt;debian/control&lt;/strong&gt; file:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
# the Build-Depends line
-Build-Depends: debhelper (&amp;gt;= 7), libboost-dev, libpcre3, libpcre3-dev, scons, xulrunner-1.9-dev, libboost-thread-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-date-time-dev
+Build-Depends: debhelper (&amp;gt;= 7), libboost-dev, libpcre3, libpcre3-dev, scons, xulrunner-dev, libboost-thread-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-date-time-dev

# the Depends line
-Depends: ${shlibs:Depends}, ${misc:Depends}, xulrunner-1.9-dev
+Depends: ${shlibs:Depends}, ${misc:Depends}, xulrunner-dev
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Also, be sure to install all these build-deps&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
apt-get install debhelper libboost-dev libpcre3 libpcre3-dev scons xulrunner-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-date-time-dev
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Next up, we’ll need to change a script (&lt;strong&gt;buildscripts/hacks_ubuntu.py&lt;/strong&gt;) which sets old-xulrunner-compatibility. Apparently the bug I encountered was already fixed but didn’t work on my system. I just deleted the condition since I was sure I needed the old-compatability mode.&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
diff --git a/buildscripts/hacks_ubuntu.py b/buildscripts/hacks_ubuntu.py
index 67c5d78..baebfe6 100644
--- a/buildscripts/hacks_ubuntu.py
+++ b/buildscripts/hacks_ubuntu.py
@@ -42,6 +42,5 @@ def foundxulrunner( env , options ):
                            incroot + &amp;quot;unstable/&amp;quot; ] )

     env.Append( CPPDEFINES=[ &amp;quot;XULRUNNER&amp;quot; , &amp;quot;OLDJS&amp;quot; ] )
-    if best.find( &amp;quot;1.9.0&amp;quot; ) &amp;gt;= 0:
-        env.Append( CPPDEFINES=[ &amp;quot;XULRUNNER190&amp;quot; ] )
+    env.Append( CPPDEFINES=[ &amp;quot;XULRUNNER190&amp;quot; ] )
     return True
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;That’s all changes needed to get it to compile. Next step is running &lt;code&gt;dpkg-buildpackage&lt;/code&gt; and installing the package!&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;dpkg-buildpackage -rfakeroot -b
# &amp;lt;it builds..&amp;gt;
dpkg -i ../mongodb_1.2.1*.deb
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-10-08:10421</id>
    <published>2009-10-08T14:34:00Z</published>
    <updated>2012-05-14T08:45:59Z</updated>
    <category term="presentation" />
    <category term="rails" />
    <category term="ruby" />
    <link href="http://workswithruby.com/2009/10/ruby-and-rails-beginner-talk" rel="alternate" type="text/html" />
    <title>Ruby and Rails beginner talk</title>
<content type="html">
            &lt;p&gt;Last night I gave a talk for &lt;a href="http://zeus.ugent.be"&gt;Zeus&lt;/a&gt; about Ruby and Rails, talking about Ruby fundamentals and a short intro to the Rails philosophy and MVC.&lt;/p&gt;

&lt;p&gt;I don’t know if you’ll be much with the slides without hearing the talk, but you can find them on &lt;a href="http://defv.be/ruby.and.rails.pdf"&gt;http://defv.be/ruby.and.rails.pdf&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want to see the entire presentation you should come to &lt;a href="http://arrrrcamp.be"&gt;ArrrrCamp&lt;/a&gt;, where I’ll be giving it again.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-09-28:10416</id>
    <published>2009-09-28T15:32:00Z</published>
    <updated>2012-05-14T08:45:58Z</updated>
    <category term="hash" />
    <category term="ruby" />
    <category term="tip" />
    <link href="http://workswithruby.com/2009/9/ruby-hash-coolness" rel="alternate" type="text/html" />
    <title>Ruby Hash coolness</title>
<content type="html">
            &lt;p&gt;Don’t shoot me if you already use this every day, but this is new to me.&lt;/p&gt;

&lt;p&gt;In the past I’ve often had code like this&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
&lt;span class="iv"&gt;@hosts&lt;/span&gt; = {}

&lt;span class="iv"&gt;@accounts&lt;/span&gt;.each &lt;span class="r"&gt;do&lt;/span&gt; |account|
  &lt;span class="iv"&gt;@hosts&lt;/span&gt;[account[&lt;span class="sy"&gt;:host&lt;/span&gt;]] ||= []
  &lt;span class="iv"&gt;@hosts&lt;/span&gt;[account[&lt;span class="sy"&gt;:host&lt;/span&gt;]] &amp;lt;&amp;lt; account
&lt;span class="r"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;But why do this hen you can just add some initializer code to your hash.&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
&lt;span class="iv"&gt;@hosts&lt;/span&gt; = &lt;span class="co"&gt;Hash&lt;/span&gt;.new { |h, k| h[k] = [] }

&lt;span class="iv"&gt;@accounts&lt;/span&gt;.each &lt;span class="r"&gt;do&lt;/span&gt; |account|
  &lt;span class="iv"&gt;@hosts&lt;/span&gt;[account[&lt;span class="sy"&gt;:host&lt;/span&gt;]] &amp;lt;&amp;lt; account
&lt;span class="r"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Where Hash automatically invokes the block when an unknown hash key is called. Great!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-08-05:10376</id>
    <published>2009-08-05T09:15:00Z</published>
    <updated>2012-05-14T08:45:58Z</updated>
    <category term="jquery" />
    <category term="rails" />
    <link href="http://workswithruby.com/2009/8/autoload-jquery-plugins" rel="alternate" type="text/html" />
    <title>Autoload JQuery Plugins</title>
<content type="html">
            &lt;p&gt;Rails has the convenient helper &lt;code&gt;javascript_include_tag&lt;/code&gt; where you can give up &lt;code&gt;:default&lt;/code&gt;, which automatically loads prototype / effects, or with the &lt;a href="http://ennerchi.com/projects/jrails"&gt;jrails plugin&lt;/a&gt; adds jquery, jquery-ui and jrails. &lt;/p&gt;

&lt;p&gt;But when using jQuery you want to use more than those files, you want to use jQuery plugins, or write your own, all in small .&lt;/p&gt;

&lt;p&gt;Loading this can be a pain in the ass. Thats why I wrote this little initializer which adds everything in public/javascripts/jquery/*.js to the defaults.&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&lt;span class="c"&gt;# config/initializers/add_jquery_to_defaults.rb&lt;/span&gt;
&lt;span class="co"&gt;Dir&lt;/span&gt;[&lt;span class="co"&gt;File&lt;/span&gt;.join(&lt;span class="co"&gt;ActionView&lt;/span&gt;::&lt;span class="co"&gt;Helpers&lt;/span&gt;::&lt;span class="co"&gt;AssetTagHelper&lt;/span&gt;::&lt;span class="co"&gt;JAVASCRIPTS_DIR&lt;/span&gt;,&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;jquery&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;*.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;)].each &lt;span class="r"&gt;do&lt;/span&gt; |js|
  &lt;span class="co"&gt;ActionView&lt;/span&gt;::&lt;span class="co"&gt;Helpers&lt;/span&gt;::&lt;span class="co"&gt;AssetTagHelper&lt;/span&gt;.register_javascript_include_default &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;jquery/&lt;/span&gt;&lt;span class="il"&gt;&lt;span class="dl"&gt;#{&lt;/span&gt;&lt;span class="co"&gt;File&lt;/span&gt;.basename(js)&lt;span class="dl"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class="r"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-07-15:10363</id>
    <published>2009-07-15T15:28:00Z</published>
    <updated>2012-05-14T08:45:57Z</updated>
    <category term="bug" />
    <category term="cache" />
    <category term="fcgi" />
    <category term="lighttpd" />
    <category term="rack" />
    <link href="http://workswithruby.com/2009/7/rack-cache-and-lighttpd-fcgi" rel="alternate" type="text/html" />
    <title>Rack::Cache and Lighttpd+FCGI</title>
<content type="html">
            &lt;p&gt;On some of the Openminds shared hosting servers we run a Lighttpd+FCGI stack for Ruby/Rails applications. This week we got a complaint from a user saying they had a problem with the latest Radiant 0.8. Every page he loaded was the same as the first page he opened since the last server restart.&lt;/p&gt;

&lt;p&gt;When digging into the problem it was clear that it was a problem with Rack::Cache, which only created 1 meta-store entry and served that from there on. On investigation Rack::Cache::Key.call(@request) always returned http://example.com:80/dispatch.fcgi?. Apparently the last part of the key gets created by script&lt;em&gt;name and path&lt;/em&gt;info:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
..snip..
      parts &amp;lt;&amp;lt; &lt;span class="iv"&gt;@request&lt;/span&gt;.script_name
      parts &amp;lt;&amp;lt; &lt;span class="iv"&gt;@request&lt;/span&gt;.path_info
..snip..
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;When looking at the request it seems Lighttpd+FCGI doesn’t fill in the env[‘PATH_INFO’], which results in always having the same cache key, thus the same page.&lt;/p&gt;

&lt;p&gt;To solve this problem I’ve created a small Rack middleware that sets PATH&lt;em&gt;INFO from REQUEST&lt;/em&gt;URI (Like Passenger does with Nginx)&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
&lt;span class="r"&gt;module&lt;/span&gt; ::&lt;span class="co"&gt;Rack&lt;/span&gt;
  &lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;LighttpdFix&lt;/span&gt;
    &lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;initialize&lt;/span&gt;(app)
      &lt;span class="iv"&gt;@app&lt;/span&gt; = app
    &lt;span class="r"&gt;end&lt;/span&gt;     

    &lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;call&lt;/span&gt;(env)
      env[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;PATH_INFO&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;] = env[&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;REQUEST_URI&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;].split(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="i"&gt;2&lt;/span&gt;).first
      &lt;span class="iv"&gt;@app&lt;/span&gt;.call(env)
    &lt;span class="r"&gt;end&lt;/span&gt;     
  &lt;span class="r"&gt;end&lt;/span&gt;
&lt;span class="r"&gt;end&lt;/span&gt;

&lt;span class="c"&gt;# in production.rb&lt;/span&gt;
config.middleware.insert_before ::&lt;span class="co"&gt;Rack&lt;/span&gt;::&lt;span class="co"&gt;Cache&lt;/span&gt;, ::&lt;span class="co"&gt;Rack&lt;/span&gt;::&lt;span class="co"&gt;LighttpdFix&lt;/span&gt;

&lt;span class="c"&gt;# or for Radiant&lt;/span&gt;
config.middleware.insert_before ::&lt;span class="co"&gt;Radiant&lt;/span&gt;::&lt;span class="co"&gt;Cache&lt;/span&gt;, ::&lt;span class="co"&gt;Rack&lt;/span&gt;::&lt;span class="co"&gt;LighttpdFix&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&amp;lt;s&gt;I’ll make a gem out of this tomorrow.&amp;lt;/s&gt;I made a gem out of this, you can find it on &lt;a href="http://github.com/DefV/rack_lighttpd_fix/"&gt;GitHub&lt;/a&gt; and install it using RubyGems.&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;sudo gem install DefV-rack_lighttpd_fix&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-05-12:10344</id>
    <published>2009-05-12T19:20:00Z</published>
    <updated>2012-05-14T08:45:56Z</updated>
    <category term="hashing" />
    <category term="mysql" />
    <category term="password" />
    <category term="ruby" />
    <link href="http://workswithruby.com/2009/5/mysql-password-hashing-in-ruby" rel="alternate" type="text/html" />
    <title>MySQL password hashing in Ruby</title>
<content type="html">
            &lt;p&gt;An old database used MySQL’s PASSWORD() hashing functionality for storing user credentials. We’re creating a Ruby app now to interface with that database, and wanted to hash the password in ruby. After looking at the code it looked like they just SHA1 hash the password twice and prepend a *. Implementation in Ruby is easy:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;require &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;digest/sha1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

&lt;span class="r"&gt;def&lt;/span&gt; &lt;span class="fu"&gt;hash_mysql_password&lt;/span&gt; pass
  &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; + &lt;span class="co"&gt;Digest&lt;/span&gt;::&lt;span class="co"&gt;SHA1&lt;/span&gt;.hexdigest(&lt;span class="co"&gt;Digest&lt;/span&gt;::&lt;span class="co"&gt;SHA1&lt;/span&gt;.digest(pass)).upcase
&lt;span class="r"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Which gives us in MySQL&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;mysql&amp;gt; SELECT PASSWORD('foo');
+-------------------------------------------+
| PASSWORD('foo')                           |
+-------------------------------------------+
| *F3A2A51A9B0F2BE2468926B4132313728C250DBF | 
+-------------------------------------------+
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And in Ruby&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;&amp;gt;&amp;gt; hash_mysql_password 'foo'
=&amp;gt; &amp;quot;*F3A2A51A9B0F2BE2468926B4132313728C250DBF&amp;quot;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-04-27:10336</id>
    <published>2009-04-27T13:44:00Z</published>
    <updated>2012-05-14T08:45:56Z</updated>
    <category term="activerecord" />
    <category term="rails" />
    <category term="ruby" />
    <category term="timestamps" />
    <link href="http://workswithruby.com/2009/4/custom-activerecord-timestamps" rel="alternate" type="text/html" />
    <title>Custom ActiveRecord timestamps</title>
<content type="html">
            &lt;p&gt;Some legacy databases have already defined their own &lt;code&gt;created_at&lt;/code&gt; or &lt;code&gt;updated_at&lt;/code&gt; fields. They can be easily filled in with ActiveRecord &lt;code&gt;before_save&lt;/code&gt; filters, but after implementing this behaviour a few times the urge arose to write something reusable, so I created the &lt;code&gt;custom_timestamps&lt;/code&gt; plugin.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;custom_timestamps&lt;/code&gt; you can easily define the columns you want to be updated on creation/change&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
&lt;span class="r"&gt;class&lt;/span&gt; &lt;span class="cl"&gt;LegacyModel&lt;/span&gt; &amp;lt; &lt;span class="co"&gt;ActiveRecord&lt;/span&gt;::&lt;span class="co"&gt;Base&lt;/span&gt;
  set_create_column &lt;span class="sy"&gt;:creation_time&lt;/span&gt;
  set_update_column &lt;span class="sy"&gt;:change_time&lt;/span&gt;
&lt;span class="r"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The plugin can be found on &lt;a href="http://github.com/DefV/custom_timestamps/tree/master"&gt;github&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-04-02:10316</id>
    <published>2009-04-02T15:31:00Z</published>
    <updated>2012-05-14T08:45:55Z</updated>
    <category term="conference" />
    <category term="radiant" />
    <category term="rails" />
    <category term="ruby" />
    <category term="rum" />
    <link href="http://workswithruby.com/2009/4/arrrrcamp-belgium" rel="alternate" type="text/html" />
    <title>ArrrrCamp Belgium</title>
<content type="html">
            &lt;p&gt;&lt;a href="http://www.openminds.be"&gt;We&lt;/a&gt; have been talking between ourselves about hosting a Belgian Ruby conference since the last Railsconf Europe, and we have finally decided to proceed with the idea. Colleague Joren put things in motion and today we’re proud to announce &lt;a href="http://arrrrcamp.be"&gt;Arrrrcamp&lt;/a&gt;, which stands for “About Ruby, Rails, Radiant and Rum Camp”.&lt;/p&gt;

&lt;p&gt;The event will take place on friday, May 8th, in Ghent, Belgium. The idea is to have a barcamp-like organisation of talks, where everybody is encouraged to participate by either doing talks, taking pictures, do some hacking, … You can read all about the event on the &lt;a href="http://arrrrcamp.be"&gt;website&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://workswithruby.com/">
    <author>
      <name>jan</name>
    </author>
    <id>tag:workswithruby.com,2009-03-13:10292</id>
    <published>2009-03-13T16:41:00Z</published>
    <updated>2012-05-14T08:45:54Z</updated>
    <category term="bug" />
    <category term="radiant" />
    <category term="ruby" />
    <link href="http://workswithruby.com/2009/3/radiant-0-7-x-and-ruby-1-8-4" rel="alternate" type="text/html" />
    <title>Radiant 0.7.x and Ruby 1.8.4</title>
<content type="html">
            &lt;p&gt;A client of ours complained that Radiant 0.7.1 was not working out of the box on one of our shared servers. When running the radiant command he got an error:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
/usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/vendor/rails/railties/lib/initializer.rb:199:in `set_load_path': undefined method `load_paths' for nil:NilClass (NoMethodError)
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/vendor/rails/railties/lib/initializer.rb:97:in `run'
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/lib/radiant/initializer.rb:101:in `run'
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/bin/../config/boot.rb:72:in `load_initializer'
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/bin/../config/boot.rb:90:in `load_initializer'
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/bin/../config/boot.rb:61:in `run'
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/bin/../config/boot.rb:19:in `boot!'
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/bin/../config/boot.rb:161
  from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
  from /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/bin/radiant:3
  from /usr/bin/radiant:19
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;It worked fine on our other servers, as well as on our local machines, the only thing that was different was the ruby version, which was 1.8.4 on that specific server. Apparently that version handles super a bit different. The solution was to change 1 line in /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/lib/radiant/initializer.rb:&lt;/p&gt;

&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;
&lt;span class="c"&gt;# In /usr/lib/ruby/gems/1.8/gems/radiant-0.7.1/lib/radiant/initializer.rb line 101:&lt;/span&gt;
-     &lt;span class="r"&gt;super&lt;/span&gt;
+     &lt;span class="r"&gt;super&lt;/span&gt;(command, configuration)
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
          </content>  </entry>
</feed>

