<?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>My stuff &#187; Ruby/Ruby on Rails</title>
	<atom:link href="http://michelhollands.net/blog/index.php/category/rubyruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://michelhollands.net/blog</link>
	<description>Tech and travel tidbits</description>
	<lastBuildDate>Tue, 13 Dec 2011 09:59:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Using Oracle with Ruby on Rails</title>
		<link>http://michelhollands.net/blog/2007/03/14/using-oracle-with-ruby-on-rails/</link>
		<comments>http://michelhollands.net/blog/2007/03/14/using-oracle-with-ruby-on-rails/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 19:00:44 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://michelhollands.net/blog/2007/03/14/using-oracle-with-ruby-on-rails/</guid>
		<description><![CDATA[If you want to use the Ruby Oracle OCI driver with Ruby on Rails, you might run into problems with the configuration. In the database.yml file, the following should be used to specify the host : host: localhost/mydatabase The mydatabase part is the the name of your database. For the adapter &#8216;oci&#8217; should be specified. [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to use the <a href="http://ruby-oci8.rubyforge.org/en/">Ruby Oracle OCI</a> driver with <a href="http://www.rubyonrails.org/">Ruby on Rails</a>, you might run into problems with the configuration. In the database.yml file, the following should be used to specify the host :</p>
<pre>
   host: localhost/mydatabase
</pre>
<p>The mydatabase part is the the name of your database. For the adapter &#8216;oci&#8217; should be specified. The database, username and password fields should be filled in as usual.</p>
<p>Thanks to <a href="http://duanesbrain.blogspot.com/2006/10/ruby-on-rails-with-oracle-express.html">Duane&#8217;s Brain</a> for pointing that out.</p>
]]></content:encoded>
			<wfw:commentRss>http://michelhollands.net/blog/2007/03/14/using-oracle-with-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Little Ruby script for generating passwords</title>
		<link>http://michelhollands.net/blog/2007/03/14/little-ruby-script-for-generating-passwords/</link>
		<comments>http://michelhollands.net/blog/2007/03/14/little-ruby-script-for-generating-passwords/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 17:33:44 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://michelhollands.net/blog/2007/03/14/little-ruby-script-for-generating-passwords/</guid>
		<description><![CDATA[Ruby is a scripting language, in the same league as Perl and Python. It is fully object-oriented, and comes batteries includes like Python, which means it comes with a full library installed by default. It is receiving a lot of attention these days due to the Ruby on Rails web application framework, which is indeed [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby is a scripting language, in the same league as Perl and Python. It is fully object-oriented, and comes batteries includes like Python, which means it comes with a full library installed by default. It is receiving a lot of attention these days due to the Ruby on Rails web application framework, which is indeed a very capable and surprisingly easy to use framework (probably more on this in a later article). Here I&#8217;ll show you a small script used to generate a (pseudo-)random password, showing a very small subset of the capabilities of Ruby for scripting.</p>
<p>This is the script :</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">   letters = <span style="color:#996600;">&quot;&quot;</span>
   <span style="color:#996600;">&quot;a&quot;</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;z&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> letters = letters <span style="color:#006600; font-weight:bold;">+</span> s<span style="color:#006600; font-weight:bold;">&#125;</span>
   <span style="color:#996600;">&quot;A&quot;</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Z&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> letters = letters <span style="color:#006600; font-weight:bold;">+</span> s<span style="color:#006600; font-weight:bold;">&#125;</span>
   <span style="color:#996600;">&quot;0&quot;</span>.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;9&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span> letters = letters <span style="color:#006600; font-weight:bold;">+</span> s<span style="color:#006600; font-weight:bold;">&#125;</span>
   password = <span style="color:#996600;">&quot;&quot;</span>
   <span style="color:#006666;">8</span>.<span style="color:#9900CC;">times</span> <span style="color:#006600; font-weight:bold;">&#123;</span> password <span style="color:#006600; font-weight:bold;">+</span>= letters<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0066; font-weight:bold;">rand</span><span style="color:#006600; font-weight:bold;">&#40;</span>letters.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
   <span style="color:#CC0066; font-weight:bold;">print</span> password</pre></div></div>

<p>First an empty string called letters is created. Then we get a taste of Ruby&#8217;s full object orientedness. The string &#8220;a&#8221; is an object, and it has a method called upto(), which generates all the characters upto the one given as a parameter. This upto() method can take a block, which is a series of instructions that is executed for each character generated. This character is passed<br />
as a parameter to the block, using the |s| construct. In the block, the char is then added to the<br />
letters string. The same is done for the uppercase letters and digits.</p>
<p>Then an empty password string is generated. We then loop 8 times, using the times() method of the 8 object. Yes indeed, literal numbers have methods as well in Ruby. A block is given to the times method, which will then get executed the specified number of times. In the block, we select a random letter from the letters string, by calling the default rand method, which takes as parameters the upper bound of the random interval. This is set to the length of the letters string here. We then select a character from the letters string by selecting a range of chars starting at the random position and of length 1. Lastly the password is printed.</p>
<p>The script is run as follows, with the output shown as well :</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">C:\scripts\ruby<span style="color: #33cc33;">&gt;</span>ruby random_password.rb
9XhsZa1K</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://michelhollands.net/blog/2007/03/14/little-ruby-script-for-generating-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.569 seconds -->

