<?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>LolocoJr &#187; ruby</title>
	<atom:link href="http://www.railsguru.com/articles/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsguru.com</link>
	<description>Andy Lo-A-Foe&#039;s blog</description>
	<lastBuildDate>Fri, 09 Jul 2010 12:08:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ruby En Rails 2007 Conference</title>
		<link>http://www.railsguru.com/articles/2007/05/23/ruby-en-rails-2007-conference/</link>
		<comments>http://www.railsguru.com/articles/2007/05/23/ruby-en-rails-2007-conference/#comments</comments>
		<pubDate>Wed, 23 May 2007 08:00:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2007/07/14/ruby-en-rails-2007-conference</guid>
		<description><![CDATA[<p>On June 7th the Ruby En Rails 2007 Conference will be held here in Amsterdam. I&#8217;m really looking forward to meeting up with the dutch Rails crowd. I&#8217;ll be giving a lighting talk on Mongrel clustering and will share my experience with this in use on a busy site. Also looking forward to some of [...]]]></description>
			<content:encoded><![CDATA[<p>On June 7th the <a href="http://2007.rubyenrails.nl/">Ruby En Rails 2007 Conference</a> will be held here in Amsterdam. I&#8217;m really looking forward to meeting up with the dutch Rails crowd. I&#8217;ll be giving a lighting talk on <a href="http://2007.rubyenrails.nl/sprekers/tracks">Mongrel clustering</a> and will share my experience with this in use on a <a href="http://www.filmpjes.nl">busy</a> site. Also looking forward to some of the talks, especially the opening keynote. Hope to see you there!!</p>
<p>
<strong>Update:</strong> I just read there are no more seats left, so hope you got in!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2007/05/23/ruby-en-rails-2007-conference/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using MPlayer identify with Ruby</title>
		<link>http://www.railsguru.com/articles/2006/07/12/using-mplayer-identify-with-ruby/</link>
		<comments>http://www.railsguru.com/articles/2006/07/12/using-mplayer-identify-with-ruby/#comments</comments>
		<pubDate>Wed, 12 Jul 2006 12:13:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[mplayer]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2007/07/30/using-mplayer-identify-with-ruby</guid>
		<description><![CDATA[<p>For a project I need to fetch some metadata from WAV recordings. Mplayer can extract this information nicely with the -identify command. I&#8217;m using Ruby Sessions for executing the external mplayer command, although a simple IO.POpen() might do fine too. The code wrapper class looks like this:</p>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25



require 'rubygems'
require_gem 'session'

class MediafileInfo
      [...]]]></description>
			<content:encoded><![CDATA[<p>For a project I need to fetch some metadata from <span class="caps">WAV</span> recordings. Mplayer can extract this information nicely with the -identify command. I&#8217;m using <a href="http://raa.ruby-lang.org/project/session/">Ruby Sessions</a> for executing the external mplayer command, although a simple IO.POpen() might do fine too. The code wrapper class looks like this:<br/></p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">require <span class="s"><span class="dl">'</span><span class="k">rubygems</span><span class="dl">'</span></span><tt>
</tt>require_gem <span class="s"><span class="dl">'</span><span class="k">session</span><span class="dl">'</span></span><tt>
</tt><tt>
</tt><span class="r">class</span> <span class="cl">MediafileInfo</span><tt>
</tt>        <span class="co">MPLAYER_BINARY</span> = <span class="s"><span class="dl">&quot;</span><span class="k">mplayer</span><span class="dl">&quot;</span></span><tt>
</tt>        <span class="co">MPLAYER_IDENTIFY</span> = <span class="s"><span class="dl">&quot;</span><span class="k">-identify -vo null -ao null -frames 0</span><span class="dl">&quot;</span></span><tt>
</tt><tt>
</tt>        <span class="r">def</span> <span class="fu">initialize</span>(filename)<tt>
</tt>                stdout, stderr = <span class="s"><span class="dl">'</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="dl">'</span></span><tt>
</tt>                shell = <span class="co">Session</span>::<span class="co">Shell</span>.new<tt>
</tt>                shell.execute <span class="s"><span class="dl">&quot;</span><span class="il"><span class="dl">#{</span><span class="co">MPLAYER_BINARY</span><span class="dl">}</span></span><span class="k"> </span><span class="il"><span class="dl">#{</span><span class="co">MPLAYER_IDENTIFY</span><span class="dl">}</span></span><span class="k"> </span><span class="il"><span class="dl">#{</span>filename<span class="dl">}</span></span><span class="dl">&quot;</span></span>, <span class="sy">:stdout</span> =&gt; stdout, <span class="sy">:stderr</span> =&gt; stderr<tt>
</tt><tt>
</tt>                vars = (stdout.split(<span class="rx"><span class="dl">/</span><span class="ch">\n</span><span class="dl">/</span></span>).collect! { |o| o <span class="r">if</span> o =~ <span class="rx"><span class="dl">/</span><span class="k">^ID_</span><span class="dl">/</span></span> } ).compact!<tt>
</tt><tt>
</tt>                vars.each { |v|<tt>
</tt>                        a, b = v.split(<span class="s"><span class="dl">&quot;</span><span class="k">=</span><span class="dl">&quot;</span></span>)<tt>
</tt>                        eval <span class="s"><span class="dl">&quot;</span><span class="k">@</span><span class="il"><span class="dl">#{</span>a.to_s.downcase<span class="dl">}</span></span><span class="k"> = </span><span class="ch">\&quot;</span><span class="il"><span class="dl">#{</span>b<span class="dl">}</span></span><span class="ch">\&quot;</span><span class="dl">&quot;</span></span><tt>
</tt>                }<tt>
</tt>        <span class="r">end</span><tt>
</tt><tt>
</tt>        <span class="c"># Intercept calls</span><tt>
</tt>        <span class="r">def</span> <span class="fu">method_missing</span>(method_name, *args)<tt>
</tt>                value = eval <span class="s"><span class="dl">&quot;</span><span class="k">@id_</span><span class="il"><span class="dl">#{</span>method_name.to_s.downcase<span class="dl">}</span></span><span class="dl">&quot;</span></span><tt>
</tt>        <span class="r">end</span><tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p><br/><br />
All ID_* lines that mplayer spits out will now be method calls (and instance variables) of your MediafileInfo object. The method_missing call is there to do proper value defaulting if the variable doesn&#8217;t exist, but I&#8217;m not using it as such right now. To get the playing time of every type of mediafile that mplayer understands you simply do someting like:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">info = <span class="co">MediafileInfo</span>.new(<span class="s"><span class="dl">&quot;</span><span class="k">voicemail.wav</span><span class="dl">&quot;</span></span>)<tt>
</tt><tt>
</tt>puts <span class="s"><span class="dl">&quot;</span><span class="k">Voicemail playtime: </span><span class="il"><span class="dl">#{</span>info.length.to_i<span class="dl">}</span></span><span class="k"> seconds</span><span class="dl">&quot;</span></span></pre>
</td>
</tr>
</table>
<p>Ruby 0wnz! <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <br/><br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2006/07/12/using-mplayer-identify-with-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails&#8217; end_of_month</title>
		<link>http://www.railsguru.com/articles/2006/02/20/rails-end_of_month/</link>
		<comments>http://www.railsguru.com/articles/2006/02/20/rails-end_of_month/#comments</comments>
		<pubDate>Mon, 20 Feb 2006 00:30:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2007/05/31/rails-end_of_month</guid>
		<description><![CDATA[<p>Whilst building the payment module for one of my Rails apps I used the very convenient  Rails&#8217; Time extension method end_of_month  returns the last day of the month. However it sets the time to 00:00:00, which is quite unexpected IMHO! Technically the end of the month is still 86400 seconds away. This behaviour [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst building the payment module for one of my Rails apps I used the very convenient  Rails&#8217; Time extension method <a href="http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Calculations.html#M000221">end_of_month</a>  returns the last day of the month. However it sets the time to 00:00:00, which is quite unexpected <span class="caps">IMHO</span>! Technically the end of the month is still 86400 seconds away. This behaviour is documented, but if you haven&#8217;t actually read the whole <span class="caps">API</span> it might cause some nasty surprises. I fixed it by simply adding 86399 seconds to end_of_time. That still leaves 999 usecs, but I can live with that <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2006/02/20/rails-end_of_month/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ActiveRecord InvalidStatement</title>
		<link>http://www.railsguru.com/articles/2005/12/07/activerecord-invalidstatement/</link>
		<comments>http://www.railsguru.com/articles/2005/12/07/activerecord-invalidstatement/#comments</comments>
		<pubDate>Wed, 07 Dec 2005 17:10:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2007/04/13/activerecord-invalidstatement</guid>
		<description><![CDATA[<p>It seems that ActiveRecord cannot return sane errors when some constraint on a database operation is not met, for instance if you forget to set an attribute which has a &#8220;NOT NULL&#8221; constraint. If this happens AR simply throws an InvalidStatement exception. You would have to actually search your database logs for the error message. [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that ActiveRecord cannot return sane errors when some constraint on a database operation is not met, for instance if you forget to set an attribute which has a &#8220;NOT <span class="caps">NULL</span>&#8221; constraint. If this happens AR simply throws an InvalidStatement exception. You would have to actually search your database logs for the error message. This really sucks! Also check out <a href="http://substantiality.net/articles/2005/11/10/activerecord-has-got-issues">this blog post on the same topic</a>. Oh well, perhaps I should try and fix this issue instead of griping, it&#8217;s open source after all. You can of course also argue that the model file in the Rails app was not complete (:allow_nil =&gt; false)..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2005/12/07/activerecord-invalidstatement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
