<?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>footle &#187; ruby</title>
	<atom:link href="http://blog.footle.org/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.footle.org</link>
	<description>(intr.v.) 1. To waste time; trifle. 2. To talk nonsense. (n.) Nonsense; foolishness</description>
	<lastBuildDate>Fri, 30 Jul 2010 04:34:10 +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>Installing Ruby 1.9.2 via rvm on OS X</title>
		<link>http://blog.footle.org/2010/07/29/installing-ruby-1-9-2-via-rvm-on-os-x/</link>
		<comments>http://blog.footle.org/2010/07/29/installing-ruby-1-9-2-via-rvm-on-os-x/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 04:34:10 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.footle.org/?p=239</guid>
		<description><![CDATA[It took me a bit of digging to figure this out (it kept failing with readline errors, and then iconv went missing), so I thought I&#8217;d share: rvm package install readline rvm package install iconv rvm install 1.9.2 -C --enable-shared,--with-iconv-dir=$HOME/.rvm/usr,\ --with-readline-dir=$HOME/.rvm/usr,--build=x86_64-apple-darwin10]]></description>
			<content:encoded><![CDATA[<p>It took me a bit of digging to figure this out (it kept failing with readline errors, and then iconv went missing), so I thought I&#8217;d share:</p>
<p><code>
<pre>rvm package install readline
rvm package install iconv
rvm install 1.9.2 -C --enable-shared,--with-iconv-dir=$HOME/.rvm/usr,\
--with-readline-dir=$HOME/.rvm/usr,--build=x86_64-apple-darwin10</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.footle.org/2010/07/29/installing-ruby-1-9-2-via-rvm-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL-Style Output for the Rails Console</title>
		<link>http://blog.footle.org/2009/03/01/mysql-style-output-for-the-rails-console/</link>
		<comments>http://blog.footle.org/2009/03/01/mysql-style-output-for-the-rails-console/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 01:42:47 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.footle.org/?p=103</guid>
		<description><![CDATA[While poking around the database in my rails console, I often found myself jumping to the mysql console just so I could get an easier-to-digest view of the data. I finally had enough of this silliness and wrote up a quick function to dump of set of ActiveRecord objects in the mysql report format. >> [...]]]></description>
			<content:encoded><![CDATA[<p>While poking around the database in my rails console, I often found myself jumping to the mysql console just so I could get an easier-to-digest view of the data. I finally had enough of this silliness and wrote up a quick function to dump of set of ActiveRecord objects in the mysql report format.</p>
<p><code>
<pre>>> report(records, :id, :amount, :created_at)
+------+-----------+--------------------------------+
| id   | amount    | created_at                     |
+------+-----------+--------------------------------+
| 8301 | $12.40    | Sat Feb 28 09:20:47 -0800 2009 |
| 6060 | $39.62    | Sun Feb 15 14:45:38 -0800 2009 |
| 6061 | $167.52   | Sun Feb 15 14:45:38 -0800 2009 |
| 6067 | $12.00    | Sun Feb 15 14:45:40 -0800 2009 |
| 6059 | $1,000.00 | Sun Feb 15 14:45:38 -0800 2009 |
+------+-----------+--------------------------------+
5 rows in set</pre>
<p></code></p>
<p><a href="http://gist.github.com/72234">Grab it from GitHub</a> and stick it in your <code>.irbrc</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.footle.org/2009/03/01/mysql-style-output-for-the-rails-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking for STDIN in ruby</title>
		<link>http://blog.footle.org/2008/08/21/checking-for-stdin-inruby/</link>
		<comments>http://blog.footle.org/2008/08/21/checking-for-stdin-inruby/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 00:24:06 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.footle.org/?p=88</guid>
		<description><![CDATA[A colleague was asking today how he could see if there&#8217;s data waiting on STDIN in ruby (on Linux). On OS X, this is pretty straightforward: if $stdin.stat.size > 0 puts "got something: #{STDIN.read}" else puts "nada" end That doesn&#8217;t work in Linux, though. After some digging, I found this post, which lead to: require [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague was asking today how he could see if there&#8217;s data waiting on <code>STDIN</code> in ruby (on Linux). On OS X, this is pretty straightforward:</p>
<p><code>
<pre>
if $stdin.stat.size > 0
  puts "got something: #{STDIN.read}"
else
  puts "nada"
end
</pre>
<p></code></p>
<p>That doesn&#8217;t work in Linux, though. After some digging, I found <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/186313">this post</a>, which lead to:</p>
<p><code>
<pre>
require 'fcntl'

flags = STDIN.fcntl(Fcntl::F_GETFL, 0)
flags |= Fcntl::O_NONBLOCK
STDIN.fcntl(Fcntl::F_SETFL, flags)

begin
  puts "got something: #{STDIN.read}"
rescue Errno::EAGAIN
  puts "nada"
end
</pre>
<p></code></p>
<p>Which works on both platforms, but is (a) ugly (catching an exception), and (b) requires you to actually try to read from <code>STDIN</code>.</p>
<p>In playing around with that, though, I noticed that <code>STDIN.fcntl(Fcntl::F_GETFL, 0)</code> returned <code>0</code> if there was something on <code>STDIN</code>, and something non-zero (<code>2</code> in OSX and <code>32770</code> in Linux) if <code>STDIN</code> was empty. So now the code is simple again:</p>
<p><code>
<pre>
require 'fcntl'

if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
  puts "got something: #{STDIN.read}"
else
  puts "nada"
end</pre>
<p></code></p>
<p>I&#8217;m not sure how reliable that is on other platforms (it won&#8217;t work on Windows&mdash;fcntl is a Unix-y thing). If I&#8217;m understanding fcntl.h correctly, a return value of 2/32770 (0&#215;8002) seems to indicate that the io stream in question is open for writing. I&#8217;m not sure if that is intended or just a side-effect. Anyone know?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.footle.org/2008/08/21/checking-for-stdin-inruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ConditionsConstructor</title>
		<link>http://blog.footle.org/2008/02/27/conditionsconstructor/</link>
		<comments>http://blog.footle.org/2008/02/27/conditionsconstructor/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 15:04:59 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.footle.org/2008/02/27/conditionsconstructor/</guid>
		<description><![CDATA[I hadn&#8217;t posted this before because it seemed kind of trivial and silly, but I used it again the other day and decided maybe I should share the joy after all. Far too often I find myself jumping through hoops building ActiveRecord find conditions arrays dynamically depending on what arguments were passed in to the [...]]]></description>
			<content:encoded><![CDATA[<p>I hadn&#8217;t posted this before because it seemed kind of trivial and silly, but I used it again the other day and decided maybe I should share the joy after all.</p>
<p>Far too often I find myself jumping through hoops building ActiveRecord <code>find</code> conditions arrays dynamically depending on what arguments were passed in to the method. So I cooked up a simple little class to clean that up a bit:</p>
<p><code>
<pre>
# class to construct conditions for AR queries
# cc = ConditionsConstructor.new('foobar &gt; ?', 7)
# cc.add('blah is not null')
# cc.add('baz in (?)', [1,2,3])
# cc.conditions
# # => ["foobar &gt; ? and blah is not null and baz in (?)", 7, [1, 2, 3]]
class ConditionsConstructor
  def initialize(str = nil, *args)
    @conditions_strs = str ? [str] : []
    @conditions_args = args
  end

  def add(str, *args)
    @conditions_strs &lt;&lt; str
    @conditions_args += args
  end

  def conditions
    [@conditions_strs.join(' and ')] + @conditions_args
  end
end
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.footle.org/2008/02/27/conditionsconstructor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reloading Ruby Classes in Rails</title>
		<link>http://blog.footle.org/2007/05/13/reloading-ruby-classes-in-rails/</link>
		<comments>http://blog.footle.org/2007/05/13/reloading-ruby-classes-in-rails/#comments</comments>
		<pubDate>Mon, 14 May 2007 02:58:54 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.footle.org/2007/05/13/reloading-ruby-classes-in-rails/</guid>
		<description><![CDATA[I ran across a bug in Date::Format today, and after spending a few hours hacking away at a fix (the date/format.rb code is *uuuuugly* and *sloooow*&#8230;someone should really rewrite that. Better yet, rewrite it in C), I thought I&#8217;d submit a patch. So I grabbed the ruby_1_8 branch and lo and behold, my issue had [...]]]></description>
			<content:encoded><![CDATA[<p>I ran across a bug in Date::Format today, and after spending a few hours hacking away at a fix (the date/format.rb code is *uuuuugly* and *sloooow*&#8230;someone should really rewrite that. Better yet, rewrite it in C), I thought I&#8217;d submit a patch. So I grabbed the <a href="http://www.ruby-lang.org/en/community/ruby-core/">ruby_1_8 branch</a> and lo and behold, my issue had already been fixed!</p>
<p>So the question now was how to monkeypatch the entire Date::Format module? Simply <code>require</code>-ing it as a plugin doesn&#8217;t work, since Date::Format is already loaded at that point. The trick then is to use <code>load</code> instead of require.</p>
<p>First, I tried this:</p>
<pre><code>
load 'date/format.rb'
</code></pre>
<p>(note: load needs the actual filename; it doesn&#8217;t have the magic that require does) but that gave me an error:</p>
<pre><code>
in `load': wrong number of arguments (1 for 0) (ArgumentError)
</code></pre>
<p>Turns out Rails::Plugin::Loader defines its own <code>load</code>, so:</p>
<pre><code>
Kernel::load 'date/format.rb'
</code></pre>
<p>et voila!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.footle.org/2007/05/13/reloading-ruby-classes-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do Passwords Right With bcrypt-ruby</title>
		<link>http://blog.footle.org/2007/02/28/do-passwords-right-with-bcrypt-ruby/</link>
		<comments>http://blog.footle.org/2007/02/28/do-passwords-right-with-bcrypt-ruby/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 01:25:53 +0000</pubDate>
		<dc:creator>brad</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[privacy-and-security]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.footle.org/2007/02/28/do-passwords-right-with-bcrypt-ruby/</guid>
		<description><![CDATA[My colleague Coda Hale just released a sweet bcrypt-ruby gem that does password hashing right. It also provides for future-proofing by enabling you to assign a computational cost for generating a password hash and letting you version your password hashes. You have no more excuses.]]></description>
			<content:encoded><![CDATA[<p>My colleague Coda Hale just released a sweet <a href="http://blog.codahale.com/2007/02/28/bcrypt-ruby-secure-password-hashing/">bcrypt-ruby gem</a> that does password hashing right. It also provides for future-proofing by enabling you to assign a computational cost for generating a password hash and letting you version your password hashes. You have no more excuses.  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.footle.org/2007/02/28/do-passwords-right-with-bcrypt-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
