<?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>Richard O&#039;Neill &#187; Ruby</title>
	<atom:link href="http://richardoneill.com.au/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://richardoneill.com.au</link>
	<description>Design, Develepment and Photography</description>
	<lastBuildDate>Thu, 29 Dec 2011 09:05:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Regular Expressions in Ruby and PHP</title>
		<link>http://richardoneill.com.au/2007/06/regular-expressions-in-ruby-and-php/</link>
		<comments>http://richardoneill.com.au/2007/06/regular-expressions-in-ruby-and-php/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 14:39:17 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Here is a short comparison between Ruby and PHP. The task was to print the location of all HTML links in a webpage using regular expressions. If anyone knows of a cleaner or more efficient way to do this in Ruby or PHP, please post it in the comments! Ruby require 'net/http' #connect and get [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="/tags/ruby"><img src="/img/articles/ruby.jpg" style="border: 0px; float: left;" alt="Ruby" /></a>
<p>Here is a short comparison between Ruby and PHP. The task was to print the location of all HTML links in a webpage using regular expressions. </p>
<p>If anyone knows of a cleaner or more efficient way to do this in Ruby or PHP, please post it in the comments!</p>
<p>
<h3>Ruby</h3>
</p>
<p><code>require 'net/http'</p>
<p>#connect and get the webpage<br />
host = Net::HTTP.new('www.site.com.au', 80)<br />
body = host.get('/index.php', nil ).body</p>
<p>puts "Links found..."</p>
<p>#find link URIs<br />
links = body.scan(/&lt;a(.*?)href="(.*?)"(.*?)&gt;(.*?)&lt;/a&gt;/)</p>
<p>#print all link URIs<br />
links.each {|id,uri| puts uri}</code><br />
<h3>PHP</h3>
</p>
<p><code>&lt;?php</p>
<p>	$page = file_get_contents('http://www.site.com.au/index.php');</p>
<p>	// find links</p>
<p>	preg_match_all('/&lt;a(.*?)href="(.*?)"(.*?)&gt;(.*?)&lt;/a&gt;/', $page, $links);	</p>
<p>	// links found</p>
<p>	foreach($links[2] as $link)<br />
	{<br />
		&nbsp;&nbsp;&nbsp;print "$linkn";<br />
	}</p>
<p>?&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://richardoneill.com.au/2007/06/regular-expressions-in-ruby-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why&#8217;s (Poignant) Guide to Ruby</title>
		<link>http://richardoneill.com.au/2007/06/whys-poignant-guide-to-ruby/</link>
		<comments>http://richardoneill.com.au/2007/06/whys-poignant-guide-to-ruby/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 16:49:09 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I&#8217;ve just started reading Why&#8217;s (Poignant) guide to Ruby. The writing style is a little different to most technical books but that&#8217;s what makes it interesting. Here&#8217;s an example from chapter 1&#8230; One day I was walking down one of those busy roads covered with car dealerships (this was shortly after my wedding was called [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve just started reading <a href="http://poignantguide.net/ruby/">Why&#8217;s (Poignant) guide to Ruby.</a> </p>
<p>The writing style is a little different to most technical books but that&#8217;s what makes it interesting. </p>
<p><a href="http://poignantguide.net/ruby/"><img src="/img/articles/poignant.jpg" style="border: 0px;" alt="Why's (Poignant) guide to Ruby." /></a>
<p>Here&#8217;s an example from chapter 1&#8230;</p>
<p><code>One day I was walking down one of those busy roads covered with car dealerships (this was shortly after my wedding was called off) and I found an orphaned dog on the road. A wooly, black dog with greenish red eyes. I was kind of feeling like an orphan myself, so I took a couple balloons that were tied to a pole at the dealership and I relocated them to the dogâ€™s collar. Then, I decided he would be my dog. I named him Bigelow. We set off to get some Milkbones for Bigelow and, afterwards, head over to my place, where we could sit in recliners and listen to Gorkyâ€™s Zygotic Mynci. Oh, and weâ€™d also need to stop by a thrift store and get Bigelow his own recliner.</code>
<p>I thought the author (Why) did a great job of explaining global variables to beginners&#8230;</p>
<p><code>Some parts of your program are like little houses. You walk in and they have their own variables. In one house, you may have a dad that represents Archie, a travelling salesman and skeleton collector. In another house, dad could represent Peter, a lion tamer with a great love for flannel. Each house has its own meaning for dad.<br />
With global variables, you can be guaranteed that the variable is the same in every little house.</code></p>
]]></content:encoded>
			<wfw:commentRss>http://richardoneill.com.au/2007/06/whys-poignant-guide-to-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Task</title>
		<link>http://richardoneill.com.au/2007/05/ruby-task/</link>
		<comments>http://richardoneill.com.au/2007/05/ruby-task/#comments</comments>
		<pubDate>Wed, 30 May 2007 17:17:13 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Since I&#8217;m fairly new to Ruby, I thought it would be a good idea to give myself a trivial programming task. I decided to create a simple script to generate a star field typical of the DOS gaming era. To make things a little more challenging, I used a grid to make sure stars were [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img src="/img/articles/ruby.jpg" style="float: left;" alt="Ruby Star Field" />
<p>Since I&#8217;m fairly new to Ruby, I thought it would be a good idea to give myself a trivial programming task.</p>
<p>I decided to create a simple script to generate a star field typical of the DOS gaming era. </p>
<p>To make things a little more challenging, I used a grid to make sure stars were evenly spaced and covered the whole image.</p>
<p>Here&#8217;s the code:</p>
<p><code>	require 'rubygems'<br />
	require 'RMagick'</p>
<p>	include Magick</p>
<p>	#create the sky<br />
	$sky = Image.new(200,200){ self.background_color = "black" }</p>
<p>	#define possible star colours<br />
	$colours = [white, grey, blue, pink, yellow]</p>
<p>	#define the create star function<br />
	def draw_star(x, y)<br />
		$sky.pixel_color(x, y, $colours[rand($colours.length)])<br />
	end</p>
<p>	#define starting coordinates<br />
	x = 0<br />
	y = 0</p>
<p>	#define starting block<br />
	block = 0</p>
<p>	while block < 100</p>
<p>		  #define random coordinates for the star in the block<br />
		  rand_x = x + rand(20)<br />
		  rand_y = y + rand(20)</p>
<p>		  #draw the star<br />
		  draw_star(rand_x, rand_y)</p>
<p>		  #move the x coodinate position to the next block<br />
		  x += 20</p>
<p>		  #check if its the last block on the row<br />
		  if block % 10 == 0<br />
			    y += 20<br />
			    x = 0<br />
		  end</p>
<p>		  #next block<br />
		  block += 1</p>
<p>	end</p>
<p>	#create the image<br />
	$sky.write("sky.jpg")</code>
<p>And here is the output:</p>
<p><img src="/img/articles/rubysky.jpg" alt="Ruby Sky" /></p>
]]></content:encoded>
			<wfw:commentRss>http://richardoneill.com.au/2007/05/ruby-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beast Forum</title>
		<link>http://richardoneill.com.au/2007/05/beast-forum/</link>
		<comments>http://richardoneill.com.au/2007/05/beast-forum/#comments</comments>
		<pubDate>Thu, 10 May 2007 14:12:10 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Beast is a new light-weight forum built with Ruby on Rails. The simple design is great, and let&#8217;s the user discussions take center stage unlike most forums. Take a look at Beast&#8217;s thread view page compared to vbulletin&#8217;s. Vbulletin&#8217;s thread view page is bloated with useless features, while Beast&#8217;s is clean and easy to read. [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://beast.caboo.se">Beast</a> is a new light-weight forum built with <a href="http://www.rubyonrails.com/">Ruby on Rails</a>. </p>
<p>The simple design is great, and let&#8217;s the user discussions take center stage unlike most forums. </p>
<p>Take a look at Beast&#8217;s thread view page compared to <a href="http://www.vbulletin.com">vbulletin&#8217;s</a>.</p>
<p><img src="/img/articles/threadview.jpg" alt="Thread view" />
<p>Vbulletin&#8217;s thread view page is bloated with useless features, while Beast&#8217;s is clean and easy to read. I wish more forums were designed this way, like the good old days of <a href="http://en.wikipedia.org/wiki/YaBB">Yabb</a> and <a href="http://en.wikipedia.org/wiki/Ikonboard">Ikonboard</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardoneill.com.au/2007/05/beast-forum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with mod_ruby</title>
		<link>http://richardoneill.com.au/2007/04/working-with-modruby/</link>
		<comments>http://richardoneill.com.au/2007/04/working-with-modruby/#comments</comments>
		<pubDate>Wed, 11 Apr 2007 15:08:41 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[While working with mod_ruby over the past week, I put together a small list of tips which might help other beginners like me&#8230; 403 Forbidden Error After successfully installing mod_ruby, I would get a &#8220;403 Forbidden&#8221; error when attempting to run a ruby script. My apache log file showed.. [Wed Apr 11 10:32:13 2007] [error] [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img src="/img/articles/ruby.jpg" style="float: left; margin-right: 5px;" alt="Ruby">
<p>While working with mod_ruby over the past week, I put together a small list of tips which might help other beginners like me&#8230;</p>
<p><strong>403 Forbidden Error</strong></p>
<p>After successfully installing mod_ruby, I would get a &#8220;403 Forbidden&#8221; error when attempting to run a ruby script. My apache log file showed..</p>
<p><code>[Wed Apr 11 10:32:13 2007] [error] access to /var/www/ruby/ruby.rb failed for (null), reason: Options ExecCGI is off in this directory</code>
<p>I simply added &#8220;Options +ExecCGI&#8221; to my httpd.conf file like so&#8230;</p>
<p><code>&#60;Files *.rb&#62;<br />
	Options +ExecCGI<br />
	SetHandler ruby-object<br />
	RubyHandler Apache::RubyRun.instance<br />
&#60;/Files&#62;</code>
<p>I was still getting a 403 error when running the script, but my apache logs were now reporting that the file permissions were incorrect. Easy fix, I chmod&#8217;d the file to 777, and the test script worked perfectly.</p>
<p><strong>Incorrect HTTP Headers</strong></p>
<p>I found that I could change the content type from text/plain to text/html by using this code&#8230;</p>
<p><code>r = Apache.request<br />
r.content_type = 'text/html'<br />
r.send_http_header<br />
exit(Apache::OK) if r.header_only?<code
<p>There are other <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/94545">solutions to this problem</a>.</p>
<p><strong>Changes in included files not taking effect</strong></p>
<p>mod_ruby caches scripts included using 'require'. Using 'load' instead will force mod_ruby to reload the included script.</p>
<p><strong>Fetching GET variables</strong></p>
<p><code>variable = Apache.request.paramtable['variable']</code></p>
]]></content:encoded>
			<wfw:commentRss>http://richardoneill.com.au/2007/04/working-with-modruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby First Impressions</title>
		<link>http://richardoneill.com.au/2007/04/ruby-first-impressions/</link>
		<comments>http://richardoneill.com.au/2007/04/ruby-first-impressions/#comments</comments>
		<pubDate>Wed, 04 Apr 2007 17:35:37 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I&#8217;ve been trying to make an effort to learn Ruby for a few months now. Finally, the other night I decided I would start writing a small project in Ruby to see what everyone is talking about. Fortunately Ruby comes prepackaged with CentOS, but the ruby-mysql module was not installed. This was my first minor [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img src="/img/articles/ruby.jpg" style="float: left; margin-right: 5px;" alt="Ruby">
<p>I&#8217;ve been trying to make  an effort to learn <a href="http://www.ruby-lang.org">Ruby</a> for a few months now. Finally, the other night I decided I would start writing a small project in Ruby to see what everyone is talking about.</p>
<p>Fortunately Ruby comes prepackaged with CentOS, but the ruby-mysql module was not installed. This was my first minor problem. Attempting to install the mysql module, resulted in Make errors. I finally located the mysql-ruby RPM in the <a href="http://dev.centos.org/centos/4.2/testing/i386/RPMS/">CentOS testing repo</a>. Problem solved.</p>
<p>I admit, I underestimated Ruby. It&#8217;s more challenging than I expected, but it definitely brought the &#8220;fun&#8221; back into programming. </p>
<p>I&#8217;m still not sure about the best way to structure a Ruby application. I&#8217;ve had a look around some other open source apps though, and it&#8217;s slowly starting to make more sense to me. If anyone could point me in the direction of a good tutorial that would be much appreciated.</p>
<p>I&#8217;m having fun learning though, and I&#8217;m sure all my questions will be answered soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://richardoneill.com.au/2007/04/ruby-first-impressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

