<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Roman&#039;s tech blog &#187; Ruby</title>
	<atom:link href="http://blog.gugl.org/archives/category/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.gugl.org</link>
	<description>ruby, perl and other stuff</description>
	<lastBuildDate>Sat, 25 Jun 2011 20:33:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Monit and Phusion Passenger</title>
		<link>http://blog.gugl.org/archives/120</link>
		<comments>http://blog.gugl.org/archives/120#comments</comments>
		<pubDate>Fri, 29 Apr 2011 22:21:24 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[integration]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[passenger]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=120</guid>
		<description><![CDATA[While there&#8217;re multiple tools available for monitoring, ranging from Dan Bernshtein&#8217;s daemontools to God, I found that Monit is a pretty balanced solution. On one hand, it&#8217;s quite powerful, and on the other &#8211; it&#8217;s not resource hungry. The only drawback that I found, is that for monitoring a process, the process must have a [...]]]></description>
			<content:encoded><![CDATA[<p>While there&#8217;re multiple tools available for monitoring, ranging from Dan Bernshtein&#8217;s <a href="http://cr.yp.to/daemontools.html">daemontools</a> to <a href="http://god.rubyforge.org/">God</a>, I found that <a href="http://mmonit.com/monit/">Monit</a> is a pretty balanced solution. On one hand, it&#8217;s quite powerful, and on the other &#8211; it&#8217;s not resource hungry. The only drawback that I found, is that for monitoring a process, the process must have a pid-file saved somewhere. The Monit FAQ states that the programs which don&#8217;t have pid-file support should be run with some wrapper which will create it on their behalf.</p>
<p>I wanted to use Monit to monitor Rails&#8217; instances, so if they grow too fat, Monit will take care of that. The problem is that the pid file that the <a href="http://www.modrails.com/">Passenger</a> creates a) doesn&#8217;t have a predictable location (there&#8217;s something called &#8220;generation&#8221; or something like that), and b) doesn&#8217;t have children, as those processes are detached.</p>
<p>Of course there exists a possibility of patching Passenger for providing such pid files. But, luckily, Passenger provides extension points in form of callbacks which are fired when the application instance is created and when it&#8217;s taken down.</p>
<p>It was trivial to use this API to provide pid-file managing. The result of this work was the &#8220;passenger_monit&#8221; plugin.</p>
<p>So, go ahead, add &#8216;gem &#8220;passenger_monit&#8221;&#8216; to your Gemfile and give it a try!</p>
<p>The source is available from:<br />
<a href="https://github.com/romanbsd/passenger_monit">https://github.com/romanbsd/passenger_monit</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/120/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>http://blog.gugl.org/archives/114</link>
		<comments>http://blog.gugl.org/archives/114#comments</comments>
		<pubDate>Tue, 05 Apr 2011 09:46:54 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=114</guid>
		<description><![CDATA[Logging line numbers in Ruby Logger can be done with a simple decorator: class LoggerDecorator def initialize&#40;logger&#41; @logger = logger end &#160; %w&#123;debug info warn error fatal&#125;.each do &#124;method&#124; eval&#40;&#60;&#60;-eomethod&#41; def #{method}(msg) @logger.#{method}(position) {msg} end eomethod end &#160; private def position caller.at&#40;1&#41;.sub&#40;%r&#123;.*/&#125;,''&#41;.sub&#40;%r&#123;:in\s.*&#125;,''&#41; end end]]></description>
			<content:encoded><![CDATA[<p>Logging line numbers in Ruby Logger can be done with a simple decorator:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">class</span> LoggerDecorator
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>logger<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@logger</span> = logger
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>debug info warn error fatal<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>method<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#CC0066; font-weight:bold;">eval</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>eomethod<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#008000; font-style:italic;">#{method}(msg)</span>
          <span style="color:#0066ff; font-weight:bold;">@logger</span>.<span style="color:#008000; font-style:italic;">#{method}(position) {msg}</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      eomethod
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    private
    <span style="color:#9966CC; font-weight:bold;">def</span> position
      <span style="color:#CC0066; font-weight:bold;">caller</span>.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>.<span style="color:#006600; font-weight:bold;">*/</span><span style="color:#006600; font-weight:bold;">&#125;</span>,<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>:<span style="color:#9966CC; font-weight:bold;">in</span>\s.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#125;</span>,<span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/114/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExtJS with Rails 3</title>
		<link>http://blog.gugl.org/archives/106</link>
		<comments>http://blog.gugl.org/archives/106#comments</comments>
		<pubDate>Sun, 06 Mar 2011 10:37:41 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[extjs]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=106</guid>
		<description><![CDATA[In order to make ExtJS play nicely with Rails, the following tweaks are needed: On the ExtJS javascript side, the following things are needed: 1. Ask server to server JSON: Ext.Ajax.defaultHeaders = &#123;'Accept': 'application/json'&#125;; 2. RailsJsonStore: Ext.data.RailsJsonStore = Ext.extend&#40;Ext.data.JsonStore, &#123; constructor: function&#40;config&#41; &#123; Ext.data.RailsJsonStore.superclass.constructor.call&#40;this, Ext.applyIf&#40;config, &#123; messageProperty: 'message', //for store.reader.getMessage() restful: true, url: '/'+ config&#91;'root'&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>In order to make ExtJS play nicely with Rails, the following tweaks are needed:</p>
<p>On the ExtJS javascript side, the following things are needed:</p>
<p>1. Ask server to server JSON:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">Ajax</span>.<span style="color: #660066;">defaultHeaders</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'Accept'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'application/json'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>2. RailsJsonStore:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">RailsJsonStore</span> <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">JsonStore</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    constructor<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">RailsJsonStore</span>.<span style="color: #660066;">superclass</span>.<span style="color: #660066;">constructor</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">applyIf</span><span style="color: #009900;">&#40;</span>config<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            messageProperty<span style="color: #339933;">:</span> <span style="color: #3366CC;">'message'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//for store.reader.getMessage()</span>
            restful<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/'</span><span style="color: #339933;">+</span> config<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'root'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'s'</span><span style="color: #339933;">,</span>
            writer<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>encode<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ext.<span style="color: #660066;">reg</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'railsjsonstore'</span><span style="color: #339933;">,</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">RailsJsonStore</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>3. XSRF protection:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">Ajax</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'beforerequest'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> csrf <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;meta[name='csrf-token']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>csrf<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                o.<span style="color: #660066;">defaultHeaders</span> <span style="color: #339933;">=</span> Ext.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">defaultHeaders</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'X-CSRF-Token'</span><span style="color: #339933;">:</span> csrf.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'content'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</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;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>On Rails side:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">active_record</span>.<span style="color:#9900CC;">include_root_in_json</span> = <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/106/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Livejournal ruby gem</title>
		<link>http://blog.gugl.org/archives/102</link>
		<comments>http://blog.gugl.org/archives/102#comments</comments>
		<pubDate>Mon, 22 Nov 2010 23:18:07 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[livejournal]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=102</guid>
		<description><![CDATA[I forked the livejournal ruby gem (http://neugierig.org/software/livejournal/ruby/) which seems to be abandoned. It fixes the well known errors like: livejournal/entry.rb:174:in `load_prop': unknown prop which are due to new properties. It also has some new functionality. The fork can be found here. I tried to contact the author, but haven&#8217;t heard from him yet.]]></description>
			<content:encoded><![CDATA[<p>I forked the livejournal ruby gem (<a href="http://neugierig.org/software/livejournal/ruby/">http://neugierig.org/software/livejournal/ruby/</a>) which seems to be abandoned.<br />
It fixes the well known errors like:</p>
<pre>livejournal/entry.rb:174:in `load_prop': unknown prop</pre>
<p>which are due to new properties.<br />
It also has some new functionality.<br />
The fork can be found <a href="https://github.com/romanbsd/livejournal">here</a>.<br />
I tried to contact the author, but haven&#8217;t heard from him yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/102/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using curb with open-uri</title>
		<link>http://blog.gugl.org/archives/89</link>
		<comments>http://blog.gugl.org/archives/89#comments</comments>
		<pubDate>Wed, 18 Feb 2009 11:43:28 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[curb]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[libcurl]]></category>
		<category><![CDATA[open-uri]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=89</guid>
		<description><![CDATA[Simple, but nice replacement for open-uri library (which uses rather slow Net::HTTP library) which uses libcurl (via curb). It&#8217;s easy to swap the original one just by replacing &#8216;require open-uri&#8217; with &#8216;require curb-openuri&#8217;. Should work as the original, even with better defaults (which, of course, can be changed). http://github.com/romanbsd/curb-openuri/tree]]></description>
			<content:encoded><![CDATA[<p>Simple, but nice replacement for open-uri library (which uses rather slow Net::HTTP library) which uses libcurl (via curb).<br />
It&#8217;s easy to swap the original one just by replacing &#8216;require open-uri&#8217; with &#8216;require curb-openuri&#8217;. Should work as the original, even with better defaults (which, of course, can be changed).</p>
<p><a href="http://github.com/romanbsd/curb-openuri/tree">http://github.com/romanbsd/curb-openuri/tree</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/89/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Non-negative Matrix Factorization for Ruby</title>
		<link>http://blog.gugl.org/archives/82</link>
		<comments>http://blog.gugl.org/archives/82#comments</comments>
		<pubDate>Mon, 09 Feb 2009 18:04:54 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gsl]]></category>
		<category><![CDATA[matrices]]></category>
		<category><![CDATA[nmf]]></category>
		<category><![CDATA[non-negative matrix factorization]]></category>
		<category><![CDATA[rb-gsl]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=82</guid>
		<description><![CDATA[Several months back I needed to compute NMF of some relatively larges matrices. Since the native Ruby code was painfully slow, and for some reason even failed to work for some matrices, I decided to write a C implementation which will leverage the GNU Scientific Library (GSL) and then wrap it for using in Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>Several months back I needed to compute NMF of some relatively larges matrices.<br />
Since the native Ruby code was painfully slow, and for some reason even failed to work for some matrices, I decided to write a C implementation which will leverage the GNU Scientific Library (GSL) and then wrap it for using in Ruby application.<br />
It was a neat add-on to the rb-gsl ruby library. What it does is adding NMF module under the GSL::Matrix, and there you have a method nmf which receives a GSL::Matrix and number of columns as a parameter and then returns two matrices.<br />
Since this is an iterative algorithm, the number of runs is limited to 1000, and the desired difference cost metric is set to 10<sup>-6</sup>.<br />
I tried to contact the author and even posted my code in the issue tracker, but haven&#8217;t received any response at the time of writing.<br />
So I decided to create a git-svn mirror on Github and add my changes there.<br />
<a href='http://github.com/romanbsd/rb-gsl/tree/master'>http://github.com/romanbsd/rb-gsl</a></p>
<p>You can install the gem using this command:</p>
<pre>
  $ gem sources -a http://gems.github.com/ # (you only have to do this once)
  $ gem install romanbsd-gsl
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/82/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>I18n support for validates_date_time</title>
		<link>http://blog.gugl.org/archives/77</link>
		<comments>http://blog.gugl.org/archives/77#comments</comments>
		<pubDate>Sun, 08 Feb 2009 10:39:29 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[i18n]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=77</guid>
		<description><![CDATA[This simple fix uses the fact, that if the second argument to the &#8216;add&#8217; method is a symbol, then a generate_message is called, which does all the voodoo of Rails 2.2 I18n. I tried to contact the original author to no avail, therefore I&#8217;ll post it here, hoping that if anyone needs it, it&#8217;ll surface [...]]]></description>
			<content:encoded><![CDATA[<p>This simple fix uses the fact, that if the second argument to the &#8216;add&#8217; method is a symbol, then a generate_message is called, which does all the voodoo of Rails 2.2 I18n.<br />
I tried to contact the original author to no avail, therefore I&#8217;ll post it here, hoping that if anyone needs it, it&#8217;ll surface on a Google search.<br />
The fix itself is quite simple:</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">Index: lib/validates_date_time.rb
===================================================================
<span style="color: #888822;">--- lib/validates_date_time.rb  <span style="">&#40;</span>revision 403<span style="">&#41;</span></span>
<span style="color: #888822;">+++ lib/validates_date_time.rb  <span style="">&#40;</span>working copy<span style="">&#41;</span></span>
<span style="color: #440088;">@@ -114,7 +114,7 @@</span>
       if options<span style="">&#91;</span>:before<span style="">&#93;</span>
         options<span style="">&#91;</span>:before<span style="">&#93;</span>.each do |r|
           if r.value<span style="">&#40;</span>record<span style="">&#41;</span> and value &gt;= r.last_value
<span style="color: #991111;">-            record.errors.add<span style="">&#40;</span>attr_name, options<span style="">&#91;</span>:before_message<span style="">&#93;</span> % r<span style="">&#41;</span></span>
<span style="color: #00b000;">+            record.errors.add<span style="">&#40;</span>attr_name, :before, :default =&gt; options<span style="">&#91;</span>:before_message<span style="">&#93;</span> % r<span style="">&#41;</span></span>
             break
           end
         end
<span style="color: #440088;">@@ -123,7 +123,7 @@</span>
       if options<span style="">&#91;</span>:after<span style="">&#93;</span>
         options<span style="">&#91;</span>:after<span style="">&#93;</span>.each do |r|
           if r.value<span style="">&#40;</span>record<span style="">&#41;</span> and value &lt;= r.last_value
<span style="color: #991111;">-            record.errors.add<span style="">&#40;</span>attr_name, options<span style="">&#91;</span>:after_message<span style="">&#93;</span> % r<span style="">&#41;</span></span>
<span style="color: #00b000;">+            record.errors.add<span style="">&#40;</span>attr_name, :after, :default =&gt; options<span style="">&#91;</span>:after_message<span style="">&#93;</span> % r<span style="">&#41;</span></span>
             break
           end
         end</pre></div></div>

<p>I&#8217;ve a fork of the git-svn mirror here:<br />
<a href='http://github.com/romanbsd/validates_date_time/tree/master'>http://github.com/romanbsd/validates_date_time/tree/master</a></p>
<p>Then, for using it, you&#8217;ll just need to have the following path in your locale yml files (for example):</p>
<pre>
  activerecord:
    errors:
      models:
        user:
          attributes:
            birth_date:
              before: 'is wrong'
              after: 'is wrong'
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/77/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Displaying recaptcha inside ModalBox</title>
		<link>http://blog.gugl.org/archives/72</link>
		<comments>http://blog.gugl.org/archives/72#comments</comments>
		<pubDate>Fri, 30 Jan 2009 13:22:45 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[modalbox]]></category>
		<category><![CDATA[recaptcha]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=72</guid>
		<description><![CDATA[I just wanted to display reCAPTCHA inside a ModalBox. This simple task turned out to be quite complicated. After playing with innerHTML, creating &#60;script&#62; nodes manually and attaching them and other voodoo and black magic and failing to accomplish the desired effect, I settled with displaying the recaptcha inside iframe inside ModalBox. Modalbox.show&#40;'&#60;iframe src=&#34;' + [...]]]></description>
			<content:encoded><![CDATA[<p>I just wanted to display <a href='http://www.recaptcha.net/'>reCAPTCHA</a> inside a <a href='http://www.wildbit.com/labs/modalbox/'>ModalBox</a>.<br />
This simple task turned out to be quite complicated.<br />
After playing with innerHTML, creating &lt;script&gt; nodes manually and attaching them and other voodoo and black magic and failing to accomplish the desired effect, I settled with displaying the recaptcha inside iframe inside ModalBox.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> Modalbox.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;iframe src=&quot;'</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'?iframe=1&quot;&gt;&lt;/iframe&gt;'</span><span style="color: #339933;">,</span> 
  <span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">title</span><span style="color: #339933;">,</span> width<span style="color: #339933;">:</span> <span style="color: #CC0000;">600</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(The iframe parameter helps to select another layout).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/72/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expire cache item in Rails ActiveSupport::Cache::FileStore</title>
		<link>http://blog.gugl.org/archives/65</link>
		<comments>http://blog.gugl.org/archives/65#comments</comments>
		<pubDate>Fri, 30 Jan 2009 13:11:51 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[activesupport]]></category>
		<category><![CDATA[caching]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=65</guid>
		<description><![CDATA[Wouldn&#8217;t it be nice to cache some item (e.g. action) for some amount of time, before expiring it? For example, if you&#8217;re displaying some page that parts of it change very often, but you don&#8217;t want to expire cache every time, since you prefer to serve stale information instead of expiring the page? The answer [...]]]></description>
			<content:encoded><![CDATA[<p>Wouldn&#8217;t it be nice to cache some item (e.g. action) for some amount of time, before expiring it? For example, if you&#8217;re displaying some page that parts of it change very often, but you don&#8217;t want to expire cache every time, since you prefer to serve stale information instead of expiring the page?<br />
The answer is the options[:expires_in] which is supported by the Rails&#8217; ActiveSupport::Cache::MemCacheStore.<br />
The current implementation of ActiveSupport::Cache::FileStore, however, lacks such feature, despite the fact that it&#8217;s really easy to implement.</p>
<p>This is the fix accompanied by a unit-test.<br />
<a href='http://blog.gugl.org/wp-content/uploads/2009/01/cache_fix.diff'>cache_fix</a></p>
<p>And then you can happily add a line like this in your controllers:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">caches_action <span style="color:#ff3333; font-weight:bold;">:find</span>, <span style="color:#ff3333; font-weight:bold;">:expires_in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span>.<span style="color:#9900CC;">minute</span></pre></div></div>

<p>The check, by the way, adds about 7usec to cache read request, which IMHO is negligible.</p>
<p>The Rails core team <a href='http://rails.lighthouseapp.com/projects/8994/tickets/1693'>doesn&#8217;t seem to be interested</a> in this patch, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/65/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I18n support for recaptcha</title>
		<link>http://blog.gugl.org/archives/58</link>
		<comments>http://blog.gugl.org/archives/58#comments</comments>
		<pubDate>Thu, 22 Jan 2009 22:46:13 +0000</pubDate>
		<dc:creator>Roman</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[recaptcha]]></category>

		<guid isPermaLink="false">http://blog.gugl.org/?p=58</guid>
		<description><![CDATA[There&#8217;s a nice plugin which adds helper for the reCAPTCHA. The downside is that it doesn&#8217;t support I18n at the moment. This is a straight forward approach patch that adds this functionality. (I don&#8217;t know what will be the fate of I18n in Rails 3, thus the simple check for version). The error message path [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a nice <a href='http://ambethia.com/recaptcha/'>plugin</a> which adds helper for the reCAPTCHA. The downside is that it doesn&#8217;t support I18n at the moment.<br />
This is a straight forward approach patch that adds this functionality. (I don&#8217;t know what will be the fate of I18n in Rails 3, thus the simple check for version).<br />
The error message path then will be:<br />
activerecord.errors.models.<i>model_name</i>.captcha</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">diff --git a/lib/recaptcha.rb b/lib/recaptcha.rb
index <span style="color: #440088;">87c26</span>e9..44413bc <span style="">100644</span>
<span style="color: #888822;">--- a/lib/recaptcha.rb</span>
<span style="color: #888822;">+++ b/lib/recaptcha.rb</span>
<span style="color: #440088;">@@ -65,7 +65,11 @@ module Ambethia</span>
             session<span style="">&#91;</span>:recaptcha_error<span style="">&#93;</span> = error
             if model = options<span style="">&#91;</span>:model<span style="">&#93;</span>
               model.valid?
<span style="color: #991111;">-              model.errors.add_to_base &quot;Captcha response is incorrect, please try again.&quot;</span>
<span style="color: #00b000;">+              if Rails::VERSION::MAJOR &gt;= 2 and Rails::VERSION::MINOR &gt;= 2</span>
<span style="color: #00b000;">+                model.errors.add_to_base I18n.translate<span style="">&#40;</span>&quot;#<span style="">&#123;</span>model.class.name.underscore<span style="">&#125;</span>.captcha&quot;, :scope =&gt; %w<span style="">&#40;</span>activerecord errors models<span style="">&#41;</span>, :default =&gt; &quot;Captcha response is incorrect, please try again.&quot;<span style="">&#41;</span></span>
<span style="color: #00b000;">+              else</span>
<span style="color: #00b000;">+                model.errors.add_to_base &quot;Captcha response is incorrect, please try again.&quot;</span>
<span style="color: #00b000;">+              end</span>
             end
             return false
           else</pre></div></div>

<p>I wonder if this is the proper way of adding I18n support&#8230;<br />
P.S. I reported this <a href='http://ambethia.lighthouseapp.com/projects/11072-recaptcha/tickets/7'>on lighthouse.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gugl.org/archives/58/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

