<?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>Nicholas' Blog</title>
	<atom:link href="http://www.ozmox.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ozmox.com</link>
	<description>adventures in Ruby and Ruby on Rails programming</description>
	<lastBuildDate>Thu, 11 Feb 2010 12:17:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fixing Rails 3 Beta &#8216;Invalid .gemspec format&#8217; Errors</title>
		<link>http://www.ozmox.com/2010/02/07/fixing-rails-3-beta-invalid-gemspec-format-errors/</link>
		<comments>http://www.ozmox.com/2010/02/07/fixing-rails-3-beta-invalid-gemspec-format-errors/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 14:51:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=450</guid>
		<description><![CDATA[If you&#8217;ve tried out Rails 3 on Ruby 1.9.1 (like myself) you might of noticed that a lot of errors are being sent to stderr, it&#8217;ll look something like this:

Ozawa Sakuro has posted a fix for this on GitHub.  You can see the original thread here, or simply follow the directions below to quickly fix [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve tried out Rails 3 on Ruby 1.9.1 (like myself) you might of noticed that a lot of errors are being sent to stderr, it&#8217;ll look something like this:</p>
<p><a style="text-decoration: none;" href="http://www.ozmox.com/wp-content/uploads/2010/02/Screen-shot-2010-02-07-at-8.38.52-AM.png"><img class="aligncenter size-medium wp-image-451" title="Rails 3 .gemspec warnings printing to stderr" src="http://www.ozmox.com/wp-content/uploads/2010/02/Screen-shot-2010-02-07-at-8.38.52-AM-300x190.png" alt="" width="300" height="190" /></a></p>
<p><a href="http://github.com/sakuro" target="_blank">Ozawa Sakuro</a> has posted a fix for this on GitHub.  You can see the <a href="http://github.com/carlhuda/bundler/issues/issue/24" target="_blank">original thread</a> here, or simply follow the directions below to quickly fix it without trolling through the entire discussion:</p>
<p>1.  Edit <strong>lib/bundler.rb</strong>:</p>
<pre>4: require 'bundler/rubygems-ext'  # originally 'bundler/rubygems'</pre>
<p>2. Next rename <strong>lib/bundler/rubygems.rb</strong> to <strong>rubygems-ext.rb</strong> and then edit the file and wrap the require in a control structure as shown below:</p>
<pre>1: unless defined? Gem
2:   require 'rubygems'
3:   require 'rubygems/specification'
4: end</pre>
<p>I&#8217;ve tested this fix and it works with Bundler 0.9.3.  Version 0.9.4 resolves the issue (thanks for the update Christian).  In any event I hope this little nugget of information helps reduce the hair pulling.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2010/02/07/fixing-rails-3-beta-invalid-gemspec-format-errors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Know What You&#8217;re Eating?</title>
		<link>http://www.ozmox.com/2010/01/03/know-what-youre-eating/</link>
		<comments>http://www.ozmox.com/2010/01/03/know-what-youre-eating/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 21:17:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cooking]]></category>
		<category><![CDATA[Off-topic]]></category>
		<category><![CDATA[food industry]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=437</guid>
		<description><![CDATA[A lot of us take on new year&#8217;s resolutions to exercise and try to be more healthy. You might be better off saving the money on the gym membership that statistically you&#8217;ll lose money on (and believe me they all know it and bank on it). Try instead to take a look at what you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of us take on new year&#8217;s resolutions to exercise and try to be more healthy. You might be better off saving the money on the gym membership that statistically you&#8217;ll lose money on (and believe me they all know it and bank on it). Try instead to take a look at what you&#8217;re eating&#8230;</p>
<p>I&#8217;m as guilty as anyone keeping a stash of Chili Fritos (a favorite here in Texas) corn chips in my desk at work. This year I&#8217;m going to try and be more conscience as to what I&#8217;m eating though. I&#8217;ve come to understand over the last part of 2009 (especially due to Michael Pollan&#8217;s book &#8216;In Defense of Food&#8217; and the recession, people losing their livelihoods because of corrupt politicians and businessmen). You choice of food doesn&#8217;t only affect your health, but it affects your local economy and the livelihoods of people worldwide.</p>
<p>Would you eat something with the following ingredients?</p>
<div id="_mcePaste"><strong>Rice flour, corn, sunflower oil with vitamin-e and anti-oxidents, salt, corn starch, cheddar and blue cheese (cured milk, salt, enzymes, yellow-orange food additive), dense oil (similar to saturated fat)*, butter (cream, salt), MSG (a flavor enhancer), preservative, anti-caking agent, anti-caking agent, preservative, edible glue, lab-created flavors, yellow-orange food additive.</strong></div>
<div><strong><br />
</strong></div>
<div><strong><span style="font-weight: normal;">Ok, what if I told you that the above were actual ingredients from Quaker&#8217;s Quakes Rice Snacks, only not in the way they list them:</span></strong></div>
<div><strong><span style="font-weight: normal;"><br />
</span></strong></div>
<pre>Rice flour, corn, sunflower oil with natural tocopherols added, whey, 
salt, maltodextrin, cheddar and blue cheese (cured milk, salt, enzymes,
annatto extract), partially hydrogenated soybean and cottenseed oil*,
butter (cream, salt), monosodium glutamate, lactic acid, disodium
phosphate, tricalcium phosphate, citric acid, gum arabic, 
natural flavors, annatto extract. *Adds a dietary insignificant
amount of trans fat.</pre>
<p>Eating is more than just about your health.  Food isn&#8217;t just to provide nutrients.  Food should be eaten for pleasure, community and identity.  It should engage you with the natural world and make you appreciate and respect life.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2010/01/03/know-what-youre-eating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a Cucumber Feature</title>
		<link>http://www.ozmox.com/2010/01/02/writing-a-cucumber-feature/</link>
		<comments>http://www.ozmox.com/2010/01/02/writing-a-cucumber-feature/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 17:19:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[story-writing]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=422</guid>
		<description><![CDATA[This is the second post about Cucumber, where we&#8217;ll be exploring the creation of a feature. Cucumber centers on testing the expected behavior of your application, rather than the expected behavior of a method. I had someone explain to me once, &#8220;unit tests/specs are the methods/implementation you wish you had, Cucumber tests are the application [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second post about Cucumber, where we&#8217;ll be exploring the creation of a feature. Cucumber centers on testing the expected behavior of your application, rather than the expected behavior of a method. I had someone explain to me once, &#8220;unit tests/specs are the methods/implementation you wish you had, Cucumber tests are the application you wish you had.&#8221;</p>
<h2>User Stories</h2>
<p>When thinking about a Cucumber feature you will want to relate it to a user story. If you&#8217;re familiar with Agile development stories are nothing new.  For those who are not though it&#8217;s not too complicated. A story is simply an expression of value generally in the form of:  &#8221;As {a role} I want/need {to do some function} so that {business value}.&#8221; Generally the business value is best expressed in terms of: revenue generation, revenue protection, operational efficiency (cost savings).</p>
<p>For the example we&#8217;ll be using this story:</p>
<p><strong><em>As a workshop co-ordinator I need to manage contact information so I can easily reference individuals and start communications with them.</em></strong></p>
<p>You&#8217;ll notice that this story doesn&#8217;t imply implementation.  You generally never want to imply implementation in a story.  Also you&#8217;ll notice that the story is simple and comprehensible by pretty much anyone (business user, developer, average Joe Public).</p>
<h2>Starting a Feature File</h2>
<p>In our Rails application we&#8217;ll want to go inside our <strong>/features</strong> folder.  Create a new file called <strong>manage_contact.feature</strong>.  At the top of the file type in the following:</p>
<pre>Feature:  Manage Contact
  In order to easily reference individuals and start communications with them
  As a workshop co-ordinator
  I want to manage contact information</pre>
<p>Now we have our first feature.  The next step is to define some scenarios.  Scenarios express various actions the user might take in relation to the feature.  Below are some of the scenarios we came up with for this feature (these go below your feature entry &#8211; indented to be even to the &#8220;In order, As a, I want&#8221; section).  You don&#8217;t need to, but I like listing the scenarios in order of priority, this way a developer working on the feature can just start on top and work downwards:</p>
<pre>Scenario: View list of contacts

Scenario: Add a new contact

Scenario: Email a contact from the list

Scenario: Remove an existing contact

Scenario: Update an existing contact

Scenario: Start an IM conversation with a contact from the list</pre>
<p>Your finished feature file should look something like this <a href="http://gist.github.com/267564" target="_blank">gist</a>. In the next post we&#8217;ll start to look at building out our scenario&#8217;s with step definitions, that is define what behavior we expect to happen with each scenario we have defined.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2010/01/02/writing-a-cucumber-feature/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Cucumber to Your Salad</title>
		<link>http://www.ozmox.com/2010/01/02/adding-cucumber-to-your-salad/</link>
		<comments>http://www.ozmox.com/2010/01/02/adding-cucumber-to-your-salad/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 15:17:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=420</guid>
		<description><![CDATA[Cucumber has come a long way since I&#8217;ve first started to use it.  My two posts about getting started with BDD have been the most visited pages of my blog.  So it seems only fitting to address the new features and update the material.  I&#8217;ll be creating a series of blog posts (so it doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Cucumber has come a long way since I&#8217;ve first started to use it.  My two posts about getting started with BDD have been the most visited pages of my blog.  So it seems only fitting to address the new features and update the material.  I&#8217;ll be creating a series of blog posts (so it doesn&#8217;t end up being one giant scrolling page) addressing a real-life situation of creating a contact management feature.  We&#8217;ll build it from the ground up using Cucumber and RSpec.</p>
<h2>Installing Cucumber / RSpec</h2>
<p>The first step to using Cucumber (and RSpec) is to install the necessary gems.  This is very straightforward and probably familiar to most people:</p>
<pre>sudo gem install rspec rspec-rails cucumber cucumber-rails webrat ZenTest database_cleaner</pre>
<p>If you are using Ruby &gt; 1.9 you will also need to install the test-unit gem (or RSpec will not load properly).</p>
<pre>sudo gem install test-unit -v=1.2.3</pre>
<p>Now if you run into errors installing webrat, know that it requires nokogiri (an awesome XML parser, see <a href="http://www.ozmox.com/2009/11/15/nokogiri-cut-with-precision/" target="_blank">my blog post about nokogiri</a>).  In order to build nokogiri though you need to have a few libraries installed ahead of time.  If you run into any errors installing webrat (likely because it couldn&#8217;t install the dependency nokogiri gem) try the following (I&#8217;m using a Debian -Kbuntu- flavor of Linux, so your specific command might vary):</p>
<pre>sudo aptitude install libxml2-dev libxslt1-dev</pre>
<p>Once you have installed the two developer libraries for libxml2 and libxslt you can try to reinstall webrat (sudo gem install webrat) and it should properly build.</p>
<h2>Adding RSpec and Cucumber to a Rails Project</h2>
<p>Having the gems installed is the first step.  To use Cucumber in your Rails project you need to run a few generation scripts which prime your application and make a few config updates. Run the following commands from inside your Rails application root:</p>
<pre>script/generate rspec
script/generate cucumber</pre>
<p>These scripts create new rake tasks, a spec and feature folder, as well as modify your database.yml (adding a new cucumber environment).  You&#8217;ll also notice a new cucumber environment file added to your environments folder already completed with all the necessary config.gem entries, nice.</p>
<p>That&#8217;s all there is to it for getting started.  Next post I will talk about outside-in development and starting your first feature!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2010/01/02/adding-cucumber-to-your-salad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails on Windows with JRuby</title>
		<link>http://www.ozmox.com/2009/12/12/rails-on-windows-with-jruby/</link>
		<comments>http://www.ozmox.com/2009/12/12/rails-on-windows-with-jruby/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 15:10:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=406</guid>
		<description><![CDATA[Getting a working Rails stack on Windows can be a frustrating experience.  Rails was born in the Linux/Unix world so there are many libraries assumed to be on your system, but are not part of a regular Windows OS installation.  Below I share my own personal experience with getting up and running with Ruby and [...]]]></description>
			<content:encoded><![CDATA[<p>Getting a working Rails stack on Windows can be a frustrating experience.  Rails was born in the Linux/Unix world so there are many libraries assumed to be on your system, but are not part of a regular Windows OS installation.  Below I share my own personal experience with getting up and running with Ruby and Rails using JRuby, which for me was the best way to go.</p>
<h3>Requirements</h3>
<ul>
<li><a href="http://java.sun.com/javase/downloads/widget/jdk6.jsp" target="_blank">Sun Java JDK </a></li>
<li><a href="http://jruby.kenai.com/downloads/1.4.0/jruby_windows_1_4_0.exe">JRuby 1.4.0 Windows Installer</a></li>
<li><a href="http://www.postgresql.org/download/windows" target="_blank">Postgres SQL server</a></li>
</ul>
<p><em>Note the links above might move or change so you can visit (<a href="http://java.sun.com" target="_blank">java.sun.com</a>, <a href="http://www.jruby.org" target="_blank">www.jruby.org</a>, <a href="http://www.postgresql.org/download/windows">www.postgres.com</a>) and poke around to find them.</em></p>
<h3><em><span style="font-style: normal;">Installing Java and JRuby</span></em></h3>
<p><em><span style="font-style: normal;">This part is very easy.  Just double click the Java installer and follow the directions.  It will install Java to a location in your C:\Program Files (or the location you specify).  Do the same with JRuby.  I like to have JRuby live right under C:\jruby-1.4.0 so it is easy for me to get to (by default it will also go under C:\Program Files).</span></em></p>
<p><em><span style="font-style: normal;">Now we need to edit our Windows environment and make sure that JRuby and Java can be seen on the path.  You&#8217;ll want to go to your <strong>Start &gt; Co</strong><strong>ntrol Panel &gt; System &gt; Advanced system</strong> <strong>settings</strong> and click the <strong>Environment Variables</strong> button.</span></em></p>
<p><em><span style="font-style: normal;"><a href="http://www.ozmox.com/wp-content/uploads/2009/12/env_vars_jruby_java.jpg"><img class="alignright size-medium wp-image-407" style="margin: 8px;" title="Windows Environment Variables" src="http://www.ozmox.com/wp-content/uploads/2009/12/env_vars_jruby_java-272x300.jpg" alt="Windows Environment Variables" width="272" height="300" /></a>You might already see a JAVA_HOME value under User variables (and that&#8217;s ok).  You might even see one for JRUBY too.  I like to have the environment variables for Java and JRuby available at the system level however.</span></em></p>
<p><em><span style="font-style: normal;">Click <strong>New</strong> under the </span><span style="font-style: normal;">System variables</span><span style="font-style: normal;"> section and add entries for <strong>JDK_HOME</strong> and <strong>JRUBY_HOME</strong> as you see in the example on the right.  Click OK when you&#8217;re done.</span></em></p>
<p>Now open a command prompt window (Start &gt; Accessories &gt; Command prompt) and type in <strong>echo %JDK_HOME%</strong> and hit enter.  You should see the value you set, do this for <strong>(</strong><strong>echo</strong> <strong>%JRUBY_HOME%)</strong> as well. Both should return the values you set previously in the Environment Variables window.  The last thing to do is add these values to your PATH.</p>
<p>Return to the Environment Variables window and edit the PATH value under system variables by selecting it and hitting Edit.  Entries are separated by a semi-colon (;) so make sure you add one to the front of the entries you&#8217;re adding unless there is one already there:</p>
<pre>;%JDK_HOME%;%JRUBY_HOME%</pre>
<p>Now after that&#8217;s done close and reopen your command prompt window (so that the new values are loaded).  Type<strong> echo %PATH%</strong> and you should see the two paths at the end of the results:</p>
<pre>&gt;&gt; echo %PATH%
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files(x86)\Git\cmd;
C:\Program Files\Java\jdk1.6.0_17;C:\jruby-1.4.0\bin</pre>
<p>Now that all our paths seem in order we can further verify everything is working right:</p>
<pre>&gt;&gt; java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)</pre>
<pre>&gt;&gt; jruby -v
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02) (Java HotSpot(TM) 64-Bit)</pre>
<h3>Welcome to JRuby</h3>
<p>At this stage you should have a working copy of JRuby.  JRuby is just like Ruby, except it uses Java and not the MRI/YARV interpreter.  Most of the commands you might be used to on a regular Ruby stack work the same in JRuby, except often you use <strong>jruby -S</strong> to run your commands rather than ruby.  Let&#8217;s start installing a few of my favorite gems:</p>
<pre>jruby -S gem install rails haml nokogiri shoulda factory_girl cucumber webrat ^
rspec rspec-rails will_paginate ZenTest redgreen fastercsv RedCloth paperclip ^ 
nifty-generators jruby-openssl</pre>
<p>That should be plenty to get you going on most any Rails/Ruby project.  Watch the output as the gems are installed, rarely should you run into trouble.  If a gem is complaining about installing you can add the &#8211;platform=java flag to the end to try and force it to install under the Java platform (for example):</p>
<pre>&gt;&gt; jruby -S gem install grumpy_gem --platform=java</pre>
<h3>Connecting to Postgres</h3>
<p><img class="alignright" style="margin: 8px;" src="http://www.ozmox.com/wp-content/uploads/2009/12/Untitled-300x204.jpg" alt="" width="300" height="204" />You probably can use any Rails supported database, but I prefer Postgres.  It&#8217;s a free database that is available on a variety of platforms (much like MySQL) but a little more powerful.  I also find it easier to work with on JRuby so it&#8217;s the one I&#8217;ll use here.</p>
<p>Run the PostgreSQL installer.  Follow the on-screen directions.  During the installation, however it is important to make sure you install the optional JDBC drivers, don&#8217;t forget this step (if you do you will have to run the Postgres Stackbuilder application later and install them).</p>
<p>The installer is going to add a &#8216;postgres&#8217; user onto your system and require you to restart at some point.  Once the installation is completely finished you can open your command prompt and install the Rubygem for connecting to Postgres:</p>
<pre>&gt;&gt; jruby -S gem install activerecord-jdbcpostgresql-adapter</pre>
<p>I am not going to go into details about how to set-up users, etc. in Postgres.  You hopefully are familiar enough with database software to know how to do there is plenty of information on the Web to figure this out, just Google it.  Postgres comes with some nice GUI tools that make it easy to do and it is pretty straight forward.</p>
<p>Now there is one caveat with the Postgres ActiveRecord adapters and JRuby.  There&#8217;s a <a href="http://blog.nicksieger.com/articles/2009/10/12/fresh-0-9-2-activerecord-jdbc-adapter-release">known issue</a> with creating and dropping databases in Rails.  So in order to get things like <strong>rake db:create:all</strong> to work you need to type inside your Rails application root:</p>
<pre>&gt;&gt; jruby -S script/generate jdbc</pre>
<p>That is pretty much all there is to getting a full stack up and running on Windows.  I have started developing in the past week using JRuby on Windows along with <a href="http://www.jetbrains.com/ruby/" target="_blank">Rubymine</a> as my editor and <a href="http://www.git-scm.com/" target="_blank">GIT</a> as my source control.  I&#8217;ve been pretty happy with it thus far.  I still enjoy developing most on my MacBook Pro &#8211; but it was a fun experience exploring JRuby (I&#8217;ve been playing with JRuby and Ant working together).</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 651px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">4-Bit Server VM 1.6.0_17) [amd64-java]C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Wind</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 651px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">owsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 651px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">(x86)\Git\cmd;C:\Program Files\Java\jdk1.6.0_17;C:\jruby-1.4.0\C:\Users\Nicholas&gt;echo %PATH%</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 651px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Wind</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 651px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">owsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 651px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">(x86)\Git\cmd;C:\Program Files\Java\jdk1.6.0_17;C:\jruby-1.4.0\bin</div>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2009/12/12/rails-on-windows-with-jruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nokogiri &#8211; Cut with Precision</title>
		<link>http://www.ozmox.com/2009/11/15/nokogiri-cut-with-precision/</link>
		<comments>http://www.ozmox.com/2009/11/15/nokogiri-cut-with-precision/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 15:59:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ActiveResource]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=395</guid>
		<description><![CDATA[Many times we as developers have to deal with complex data, be it an ActiveResource result set or a HTML/XML document.  Trying to parse data out of these using for each and nesting loops within loops can be cumbersome.  A more elegant solution is to use nokogiri and xpath.
Nokogiri is a type of Japanese saw, [...]]]></description>
			<content:encoded><![CDATA[<p>Many times we as developers have to deal with complex data, be it an ActiveResource result set or a HTML/XML document.  Trying to parse data out of these using for each and nesting loops within loops can be cumbersome.  A more elegant solution is to use nokogiri and xpath.</p>
<p>Nokogiri is a type of Japanese saw, it also is a gem in Ruby that you can use to easily deal with XML or HTML documents.  (hint, ActiveRecord and ActiveResource objects both have to_xml methods).  You can easily install nokogiri (make sure you have libxml2 development packages installed, as the gem requires these to be properly built).</p>
<p>$ sudo gem install nokogiri</p>
<p>Now consider the following XML document: <a title="foods.xml" href="http://gist.github.com/235268" target="_blank">foods.xml</a></p>
<p>Before we can work with our data we need to read XML into Nokogiri.  This is easy to accomplish:</p>
<pre>&gt; require 'rubygems'
&gt; require 'nokogiri'
&gt; doc = Nokogiri::XML.parse(File.read('foods.xml'))
=&gt; #&lt;Nokogiri::XML::Document:0x3f930c9db884 ...</pre>
<p>What we are returned is a Nokogiri document which is a collection of Nokogiri elements and text objects.  The document supports seaching (selecting a subset of nodes, or nokogiri nodeset) by both CSS selectors or XPath notation.  These are returned as an array of elements and text objects.</p>
<p>So for example if we wanted to know all the names of the food items in our document we simply say:</p>
<pre>&gt; doc.xpath("//name").collect(&amp;:text)
=&gt; ["carrot", "tomato", "corn", "grapes", "orange", "pear", "apple"]</pre>
<p>If we were interested in the entire node we could leave off the .collect(&amp;:text). What if we wanted to select all the names of food items that were best baked?  This requires us to use what&#8217;s called an axis &#8211; we will first need to find the element &#8220;baked&#8221; but then go back up our XML elements to find which food the item is inside.</p>
<pre>&gt; doc.xpath("//tag[text()='baked']/ancestor::node()/name").collect(&amp;:text)
=&gt; ["pear", "apple"]</pre>
<p>What if we were only interested in vegetables that were good for roasting?  Just add //veggies:</p>
<pre>&gt; doc.xpath("//veggies//tag[text()='roasted']/ancestor::node()/name").collect(&amp;:text)
=&gt; ["carrot", "tomato"]</pre>
<p>What about if we wanted to know all the tags &#8216;corn&#8217; had?  Again this is very easy:</p>
<pre>&gt; doc.xpath("//name[text()='corn']/../tags/tag").collect(&amp;:text)
=&gt; ["raw", "boiled", "grilled"]</pre>
<p>We can even do searches matching the first character.  Let&#8217;s say we wanted to know all the food items that started with the letter &#8216;c&#8217;:</p>
<pre>&gt; doc.xpath("//name[starts-with(text(),'c')]").collect(&amp;:text)
=&gt; ["carrot", "corn"]</pre>
<p>You have to admit this is pretty cool stuff.  You could also use <strong>[contains(text(),'rot']<em> </em></strong>and get back just carrot, useful when you want to do a partial match.  Axis combined with selectors give you a wide variety of options for parsing your dataset.  You can also match using operations.  See the links below for resources on the variety of options available.</p>
<h3>Xpath is Powerful</h3>
<p>Xpath lets us select XML elements, attributes and text without having to write cumbersome recursive, nested loops. Below are  links to online resources and tutorials.  The next time you have to dig through an XML document or ActiveResource result, don&#8217;t use recursive, nested loops; instead, consider a Japanese saw &#8211; nokogiri.</p>
<p><strong>Learn More</strong></p>
<ul>
<li><a href="http://www.zvon.org/xxl/XPathTutorial/General/examples.html">A good XPath tutorial using examples (by Miloslav Nic)</a></li>
<li><a href="http://www.w3schools.com/XPath/xpath_syntax.asp">W3Schools Xpath Syntax tutorial</a></li>
<li><a href="http://nokogiri.rubyforge.org/nokogiri/">Nokogiri Docs</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2009/11/15/nokogiri-cut-with-precision/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Writing Stories with True Value</title>
		<link>http://www.ozmox.com/2009/11/05/writing-stories-with-true-value/</link>
		<comments>http://www.ozmox.com/2009/11/05/writing-stories-with-true-value/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 12:54:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Scrum]]></category>
		<category><![CDATA[story-writing]]></category>
		<category><![CDATA[tasks]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=393</guid>
		<description><![CDATA[A lot of folks who dive into the world of Agile (be it Scrum or XP) will need to learn how to write stories.  Stories are an expression of a feature which provides value.  They typically take the format of &#8220;As a {user-role} I need/want to {some functionality} so that {value}.&#8221;  I coach people to [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of folks who dive into the world of Agile (be it Scrum or XP) will need to learn how to write stories.  Stories are an expression of a feature which provides value.  They typically take the format of &#8220;As a<em> {user-role}</em> I need/want to <em>{some functionality}</em> so that <em>{value}</em>.&#8221;  I coach people to use what I call the 3Ws:  Who is the user, what is it they want to do, and why do they want to do that?  Any well written story should be able to answer those three questions.</p>
<p>The following is an example story that isn&#8217;t written well:</p>
<p><em><strong>&#8220;As a manager I want documentation produced so that the software can be understood by people.&#8221;</strong></em></p>
<p>Who&#8217;s the user here, the manager &#8211; really?  It doesn&#8217;t sound like he&#8217;s the one using the documentation, &#8220;people&#8221; are (whomever that is).  &#8221;Documentation produced&#8221; also is a task &#8211; not an expression of functionality.  The value statement is also dubious &#8220;so that software can be understood,&#8221; but why is that valuable for &#8220;the people?&#8221;  Reading this story leaves you with too many unanswered questions and is overly vague.  You can quickly see this story fails to answer our 3Ws.</p>
<p>Instead, a better approach, is to make documentation part of the done criteria (or acceptance) of the actual feature the story should be addressing.  Remember with stories we want to end with a demonstrable unit of work.  If the feature was to add the ability to send e-mail after someone comments on a blog post, for example, you might have something like this:</p>
<p><strong><em>&#8220;As a user who&#8217;s commented on a blog post I want to receive a notification anytime additional comments are added so that I keep up with the conversation.&#8221;</em></strong></p>
<p>This story is much better.  We know that we&#8217;re talking about people who have posted a comment on a blog post.  We know that they want to receive a notification anytime new comments are added.  They want this because it helps them keep up with the conversation.  Anyone could read this story and understand what needs to happen. What&#8217;s even better is it doesn&#8217;t imply implementation.  It doesn&#8217;t say I should receive an SMS message, and e-mail or a letter in the mail.  Those details will be discussed when this story is planned.</p>
<p>In order to complete this work the whole vertical slice has to be addressed:  code business logic, design e-mail template/layout, test feature, write documentation.  There isn&#8217;t a need to have a separate story for this &#8212; I&#8217;d advise against it, because your feature really isn&#8217;t done if documentation is a requirement.  When you finish a feature you want it to be done, done.</p>
<h3>Bad Smells</h3>
<ul>
<li>Story not addressing a vertical slice typically have &#8220;developer&#8221; or &#8220;manager&#8221; as the user-role.</li>
<li>Story doesn&#8217;t express business value or functionality, but instead expresses a task.</li>
<li>Story has dependencies on other stories being done first.</li>
<li>Story talks about implementation.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2009/11/05/writing-stories-with-true-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enjoy Working with Models using Hirb</title>
		<link>http://www.ozmox.com/2009/11/01/enjoy-working-with-models-using-hirb/</link>
		<comments>http://www.ozmox.com/2009/11/01/enjoy-working-with-models-using-hirb/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 14:11:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=389</guid>
		<description><![CDATA[Hirb is a simple gem that lets you view objects as table (with their attributes as columns and their data as rows).  Collections are shown as a table.  Installing the gem is easy sudo gem install hirb.  The easiest way to handle including it into IRB is to add it to your .irbrc file in [...]]]></description>
			<content:encoded><![CDATA[<p>Hirb is a simple gem that lets you view objects as table (with their attributes as columns and their data as rows).  Collections are shown as a table.  Installing the gem is easy <strong><em>sudo gem install hirb</em><span style="font-weight: normal;">.  The easiest way to handle including it into IRB is to add it to your .irbrc file in your home directory:</span></strong></p>
<pre>require 'rubygems'
require 'hirb'

Hirb::View.enable</pre>
<p>Or you can leave off the last line, which will require you to type that into your console whenever you want it to turn on.  (This is the setting I use, because I am not always working with large data sets, but when I do I turn it on).</p>
<p>Another neat trick is to output your ActiveRecord SQL right into your console.  This is a nice if you&#8217;re wanting to optimize queries or you just are curious as to what ActiveRecord is really doing.  You could view the logs, but this puts everything into context.  Also if you don&#8217;t see a query happening you know that you&#8217;re still working with an in-memory object.  Type the below into your Rails console whenever you want to see SQL queries in-line with your ActiveRecord calls:</p>
<p>&gt;&gt; ActiveRecord::Base.logger = Logger.new(STDOUT)</p>
<p>You&#8217;ll end up with a console that looks like the image below.  Pretty nice if you have a lot of model work or just want to better visualize ActiveRecord calls and objects.</p>
<div id="attachment_390" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.ozmox.com/wp-content/uploads/2009/11/hirb_console.png"><img class="size-medium wp-image-390" title="hirb_console" src="http://www.ozmox.com/wp-content/uploads/2009/11/hirb_console-300x276.png" alt="Rails console using Hirb and inline logger" width="300" height="276" /></a><p class="wp-caption-text">Rails console using Hirb and inline logger</p></div>
<p><strong>Learn More</strong></p>
<p><a href="http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html">http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2009/11/01/enjoy-working-with-models-using-hirb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Your Own Gems</title>
		<link>http://www.ozmox.com/2009/10/26/creating-your-own-gems/</link>
		<comments>http://www.ozmox.com/2009/10/26/creating-your-own-gems/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 11:51:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=381</guid>
		<description><![CDATA[Plugins have fallen out of style in the Rails world.  Gems are a better choice because they can be easily versioned and shared across projects.  Using Echoe you can easily package, install and deploy gems.  You can also checkout www.gemcutter.org, a next generation gem repository to host your gems.
Installing Echoe is easy, type &#8216;sudo gem [...]]]></description>
			<content:encoded><![CDATA[<p>Plugins have fallen out of style in the Rails world.  Gems are a better choice because they can be easily versioned and shared across projects.  Using Echoe you can easily package, install and deploy gems.  You can also checkout <a href="www.gemcutter.org">www.gemcutter.org</a>, a next generation gem repository to host your gems.</p>
<p>Installing Echoe is easy, type &#8216;<strong>sudo gem install echoe</strong>&#8216; at your command prompt.  Echoe provides rake tasks and simplifies the creation of a gem.</p>
<p>You can create a project with the standard directory layout:</p>
<pre>/mygem
../lib
../test
..Rakefile
..README.rdoc
..LICENSE
..CHANGELOG</pre>
<p>You can optionally include a /bin or /ext if you have executables or extensions.  Just make sure at a minimum you have a Rakefile and lib folder.  You will also want to probably include a readme, license and changelog &#8212; it&#8217;s just the good citizen thing to do.</p>
<p>Next open your Rakefile and add the following template.  If you want to understand these options or add additional configurations you can reference <a href="http://blog.evanweaver.com/files/doc/fauna/echoe/classes/Echoe.html">Echoe&#8217;s documentation</a>.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">require &#8216;rubygems&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">require &#8216;rake&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">require &#8216;echoe&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Echoe.new(&#8216;vowels&#8217;, &#8216;0.0.1&#8242;) do |p|</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">p.description = &#8216;Tell whether or not a string starts with a vowel&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">p.url = &#8216;http://www.ozmox.com/&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">p.author = &#8216;Nicholas Cancelliere&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">p.email = &#8216;ncancelliere@gmail.com&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">p.ignore_pattern = ['tmp/*', 'script/*']</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">p.development_dependencies = []  # by default echoe adds itself as a dependency, we override this</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">end</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 367px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext</div>
<pre>require 'rubygems'
require 'rake'
require 'echoe'

Echoe.new('vowels', '0.0.1') do |p|
  p.description = 'Tell whether or not a string starts with a vowel'
  p.url = 'http://www.ozmox.com/'
  p.author = 'John Doe'
  p.email = 'jdoe@gmail.com'
  p.ignore_pattern = ['tmp/*', 'script/*']
  p.development_dependencies = []
end

Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }</pre>
<p>The configuration is pretty self-explanitory.  Once you have added this template to your Rakefile you can run &#8216;<strong>rake manifest</strong>&#8216; to generate a file manifest automatically.  The manifest is a list of all the files in your gem.</p>
<p>If you plan for people to use your gem you&#8217;ll want to write your own tests.  Many folks shy away from poorly tested gems.  Below is a simple module that adds both a class method and instance method.  It isn&#8217;t necessarily useful for a real-life situation, but I wanted to demonstrate especially how you create class-methods (since it isn&#8217;t as simple as adding self.method).</p>
<pre># lib/vowels.rb
module Vowels</pre>
<pre>  def self.included(base)
    base.extend ClassMethods
  end</pre>
<pre>  module ClassMethods
    def is_vowel?(str)
      ['a','e','i','o','u'].include?(str.slice(0,1).downcase)
    end
  end</pre>
<pre>  def is_vowel?
    "Sorry Vanna White doesn't live here."
  end</pre>
<pre>end</pre>
<p>When this gem is installed, any class that includes Vowels will gain two methods: a class method <em>is_vowel?</em> and an instance method <em>is_vowel?</em>.  We create the class method by adding a module ClassMethods and using a little know-how of the Ruby object lifecycle.</p>
<p>Now that we have our gem written we need to update our manifest, generate a package and install it (build will both update your manifest and package in one action):</p>
<pre>rake build
rake install</pre>
<p>Now we should be able to utilize our new gem!</p>
<pre># config/environment.rb
config.gem "vowels", :lib =&gt; "vowels"

# app/models/contact
class Contact &lt; ActiveRecord::Base
  include Vowels
end

$ contact = Contact.first
=&gt; #&lt;Contact id: 1, name: "Abby Smith"&gt;
$ contact.is_vowel?
=&gt; "Sorry Vanna White doesn't live here!"
$ Contact.is_vowel?(contact.name)
=&gt; true</pre>
<p>As you can see from the above demonstration, we have successfully created both a class and instance method.  Because our Vowels module is provided by a gem we can use it anywhere as long as we require rubygems and vowels.</p>
<p>That is all there is to creating gems!  Now go create something awesome&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2009/10/26/creating-your-own-gems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safely Handling Data in Ruby</title>
		<link>http://www.ozmox.com/2009/10/17/safely-handling-data-in-ruby/</link>
		<comments>http://www.ozmox.com/2009/10/17/safely-handling-data-in-ruby/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 13:48:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ozmox.com/?p=376</guid>
		<description><![CDATA[Are you Tainted?
Ruby has a special method that you can call on an object called tainted?, and it will return a boolean based on whether the data comes from an external source or not.  Values that come from the network, a file on disk, command line, etc. will be considered tainted.  A value that is [...]]]></description>
			<content:encoded><![CDATA[<h2>Are you Tainted?</h2>
<p>Ruby has a special method that you can call on an object called <em>tainted?</em>, and it will return a boolean based on whether the data comes from an external source or not.  Values that come from the network, a file on disk, command line, etc. will be considered tainted.  A value that is derived from inside your Ruby code will not.</p>
<pre>irb&gt; z = 20 + 50
=&gt; 70
irb&gt; z.tainted?
=&gt; false</pre>
<pre>irb&gt; b = File.open("sample.txt").readlines.first
=&gt; "This is an example text file.\n"
irb&gt; b.tainted?
=&gt; true</pre>
<p>Even when you combine data from inside Ruby with tainted data you&#8217;ll still get something that&#8217;s tainted&#8230;</p>
<pre>irb&gt; n = b + " More text."
=&gt; "This is an example text file.\n More text."
irb&gt; n.tainted?
=&gt; true</pre>
<p>One thing to note, and this is important, is that datastructures themselves may not be tainted, but the data they contain are.  You cannot know this without inspecting each individual piece of data (the array below has two pieces of tainted data):</p>
<pre>irb&gt; y = [n, z, b]
=&gt; ["More text. This is an example text file.\n", 40, "This is an example text file.\n"]
irb&gt; y.tainted?
=&gt; false</pre>
<p>You can also force data to be considered untainted by using the <em>untainted</em> method.  And likewise you can force data to be tainted by using the <em>tainted</em> method.</p>
<pre>irb&gt; safe = n.untaint
=&gt; "This is an example text file.\n More text."
irb&gt; safe.tainted?
=&gt; false</pre>
<h2>$SAFE (Safe Levels)</h2>
<p>Another feature in Ruby are Safe Levels.  This is represented by a special variable $SAFE.  The default in Ruby is 0, which really provides no safety.  You can increase the $SAFE level in your program by setting the value of $SAFE to be higher, but once you do so you cannot lower it (this is for security purposes).  Below is a brief description of the different safety levels.</p>
<ul>
<li>0 &#8211; No restrictions. (This is the default value.)</li>
<li>1 &#8211; Potentially unsafe methods can not use tainted data.  Current directory is not added to Ruby&#8217;s search path for loading libs.</li>
<li>2 &#8211; Ruby will not load any external files from globally writeable locations on the filesystem.  File#chmod, Kernel#fork, and Process::setpriority methods are also disabled.  All restrictions from 1 included.</li>
<li>3 &#8211; Any newly created objects, even those from within the program, are considered tainted automatically.  You also cannot untaint objects.  All restrictions for 1 and 2 included.</li>
<li>4 &#8211; Non-tainted objects created prior to the safe level being set cannot be modified.  All restrictions from 1, 2 and 3 included.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ozmox.com/2009/10/17/safely-handling-data-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
