<?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>Mark Gandolfo</title>
	<atom:link href="http://markgandolfo.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://markgandolfo.com</link>
	<description>A technologists blog</description>
	<lastBuildDate>Sun, 05 May 2013 05:22:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Cups &amp; HP-Lib on raspberry Pi to create a new paperless life</title>
		<link>http://markgandolfo.com/?p=70</link>
		<comments>http://markgandolfo.com/?p=70#comments</comments>
		<pubDate>Sat, 08 Dec 2012 02:44:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[raspberry pi]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=70</guid>
		<description><![CDATA[I tend to hoard paper. It&#8217;s not something I like doing, but I have a hard time differentiating the important bills from the non important, so I tend to keep everything which usually piles up until it falls over and I spend a day going through it, throwing out most things. There must be a [...]]]></description>
				<content:encoded><![CDATA[<p>I tend to hoard paper. It&#8217;s not something I like doing, but I have a hard time differentiating the important bills from the non important, so I tend to keep everything which usually piles up until it falls over and I spend a day going through it, throwing out most things. </p>
<p>There must be a solution to push all of these documents in a digital format to one of the many services online (read dropbox/google drive). Although I&#8217;m aware doxie exists, about this time I bought a raspberry Pi, and have had a ball making LED&#8217;s flash, but I couldn&#8217;t help thinking that there must be a better use for it. </p>
<p>So, I think you all know where I&#8217;m going with this. My plan:</p>
<p>Raspberry Pi to be connected to my HP coloursmart c7280 all-in-one device (of which the printer no longer works, so it&#8217;s only use is now a scanner).<br />
I&#8217;ll wire up (via breadboard) a number of switches &#038; buttons. </p>
<p>6 switch, dip Switch will determine document type (it&#8217;ll light a specific LED &#8211; I&#8217;ll have printed labels next to the LED&#8217;s)</p>
<p>The Button will initiate the process which will:</p>
<ul>
<li>Start the scan</li>
<li>Rename the document (This part is still needs to be solved)</li>
<li>Upload the document</li>
<li>Clean up</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=70</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capybara, RSpec, Swinger and a dash of awesome</title>
		<link>http://markgandolfo.com/?p=67</link>
		<comments>http://markgandolfo.com/?p=67#comments</comments>
		<pubDate>Thu, 09 Jun 2011 12:30:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=67</guid>
		<description><![CDATA[When trying to get Capybara-rspec working I went googling first, to see how others have done it&#8230; People suck and generally over complicate the simplest tasks&#8230; Heres how I got it all working! # Gemfile &#160; gem 'rspec-rails' gem 'capybara' gem 'swinger' Add rspec rails, capybara and swinger, then install your gems and generate rspec [...]]]></description>
				<content:encoded><![CDATA[<p>When trying to get Capybara-rspec working I went googling first, to see how others have done it&#8230; People suck and generally over complicate the simplest tasks&#8230; Heres how I got it all working!</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Gemfile</span>
&nbsp;
  gem <span style="color:#996600;">'rspec-rails'</span>
  gem <span style="color:#996600;">'capybara'</span>
  gem <span style="color:#996600;">'swinger'</span></pre></div></div>

<p>Add rspec rails, capybara and swinger, then install your gems and generate rspec skeleton files</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bundle <span style="color: #c20cb9; font-weight: bold;">install</span>
rails g rspec:<span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>In your spec/spec_helper.rb file require your gems.. a quick note, I force spec to use &#8220;test&#8221; env, why wouldn&#8217;t it do this by default? I&#8217;m sure theres an answer, but it doesn&#8217;t feel write, and everything works just fine like this!</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># spec/spec_helper.rb</span>
&nbsp;
ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;RAILS_ENV&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'test'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;../../config/environment&quot;</span>, <span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rspec/rails'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'capybara/rspec'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'swinger'</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span>Rails.<span style="color:#9900CC;">root</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;spec/support/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">require</span> f<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
RSpec.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">mock_with</span> <span style="color:#ff3333; font-weight:bold;">:rspec</span>
  config.<span style="color:#9900CC;">fixture_path</span> = <span style="color:#996600;">&quot;#{::Rails.root}/spec/fixtures&quot;</span>
  config.<span style="color:#9900CC;">use_transactional_fixtures</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I really like the idea of my integration tests living in a directory called &#8220;spec/integration&#8221;, so I create it, and put some tests in there.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># /spec/integration/user_integration.rb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;spec_helper&quot;</span>
&nbsp;
describe <span style="color:#996600;">'A user session'</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  it <span style="color:#996600;">'should allow a user to login'</span>, <span style="color:#ff3333; font-weight:bold;">:driver</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:selenium</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    visit <span style="color:#996600;">'/'</span>
    click_link <span style="color:#996600;">'Login'</span>
    fill_in <span style="color:#996600;">'Email'</span>, <span style="color:#ff3333; font-weight:bold;">:with</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;user@markyg.com&quot;</span>
    fill_in <span style="color:#996600;">'Password'</span>, <span style="color:#ff3333; font-weight:bold;">:with</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;password&quot;</span>
    click_button <span style="color:#996600;">'Sign in'</span>
    find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'Signed in successfully'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>A quick note, swinger allows us to add :driver => :selenium, or :driver => :culerity to our specs, this is how we can easily switch drivers.. if you leave this out, it&#8217;ll use rack. </p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=67</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Raw Output Of Html In Rails3</title>
		<link>http://markgandolfo.com/?p=63</link>
		<comments>http://markgandolfo.com/?p=63#comments</comments>
		<pubDate>Sat, 11 Sep 2010 06:33:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=63</guid>
		<description><![CDATA[As of rails3 the]]></description>
				<content:encoded><![CDATA[<p>As of rails3 the <%=h tag is now applied by default to all of your <%= @content</p>
<p>So for instance in a message:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;">## Controller</span>
  <span style="color:#0066ff; font-weight:bold;">@message</span> = <span style="color:#996600;">&quot;Unfortunately an error occurred: Sorry, this product is no longer available, if you think you received this in error, please &lt;a href='/contact/us'&gt;contact us&lt;/a&gt;&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;">## View</span>
  = <span style="color:#0066ff; font-weight:bold;">@message</span></pre></div></div>

<p>would result in<br />
<code><br />
Unfortunately an error occurred: Sorry, this product is no longer available, if you think you received this in error, please &lt;a href='/contact/us'&gt;contact us&lt;/a&gt;<br />
</code></p>
<p>To remove htmlentities being sanitized you can use the raw() method helper</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;">## Controller</span>
  <span style="color:#0066ff; font-weight:bold;">@message</span> = <span style="color:#996600;">&quot;Unfortunately an error occurred: Sorry, this product is no longer available, if you think you received this in error, please &lt;a href='/contact/us'&gt;contact us&lt;/a&gt;&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;">## View</span>
  =raw <span style="color:#0066ff; font-weight:bold;">@message</span></pre></div></div>

<p>would result in</p>
<p><code><br />
Unfortunately an error occurred: Sorry, this product is no longer available, if you think you received this in error, please <a href='/contact/us'>contact us</a><br />
</code><br />
Be careful how you use this, if @message was set from user input, than they could inject some nasty javascript or flash in your page.</p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=63</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails3: Undefined Method Includes Values</title>
		<link>http://markgandolfo.com/?p=61</link>
		<comments>http://markgandolfo.com/?p=61#comments</comments>
		<pubDate>Thu, 09 Sep 2010 06:31:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=61</guid>
		<description><![CDATA[I can across an error in Rails3 today when I was trying to implement a scope. scope :latest, order&#40;&#34;created_at asc&#34;&#41;.first When trying to run that Scope I&#8217;d get undefined method 'includes_values' for It had me scratching my head since the trace showed me nothing. So I went through the activerecord codebase, and sure enough it [...]]]></description>
				<content:encoded><![CDATA[<p>I can across an error in Rails3 today when I was trying to implement a scope.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">scope <span style="color:#ff3333; font-weight:bold;">:latest</span>, order<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;created_at asc&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span></pre></div></div>

<p>When trying to run that Scope I&#8217;d get</p>
<p><code>undefined method 'includes_values' for <#Product:rarrarrar></code></p>
<p>It had me scratching my head since the trace showed me nothing. So I went through the activerecord codebase, and sure enough it was something stupid that I did.</p>
<p>The scope should return an ActiveRecord object, and not a result set. So simply removing the .first off my scope resulting in a working scope</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> scope <span style="color:#ff3333; font-weight:bold;">:latest</span>, order<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;created_at asc&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Its a simple fix, but googling came up with nothing. So I hope this helps someone else who comes across this error.</p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=61</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How To: Install Node Js And Roll Out Your First Project</title>
		<link>http://markgandolfo.com/?p=55</link>
		<comments>http://markgandolfo.com/?p=55#comments</comments>
		<pubDate>Fri, 03 Sep 2010 06:24:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[NodeJS]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=55</guid>
		<description><![CDATA[So after NodeKnockout I have to say I learnt a lot about the simplicity that comes with developing a nodeJs app! A few people have asked me about how easy it is to roll out their own app, and I&#8217;ve walked a few people though it, and finally decided it warranted a blog post! You&#8217;ll be [...]]]></description>
				<content:encoded><![CDATA[<p>So after <a href="http://nodeknockout.com/">NodeKnockout</a> I have to say I learnt a lot about the simplicity that comes with developing a nodeJs app! A few people have asked me about how easy it is to roll out their own app, and I&#8217;ve walked a few people though it, and finally decided it warranted a blog post!</p>
<p>You&#8217;ll be walked through how to set up:</p>
<ul>
<li>Install <a href="http://nodejs.org/">NodeJS</a></li>
<li>Install <a href="http://npmjs.org/">Node Package Manager (npm)</a></li>
<li>Install the <a href="http://github.com/visionmedia/express">Express</a> framework, and a few other packages</li>
</ul>
<h3>Quick Note</h3>
<p>I&#8217;m doing this on a mac, but it should be the same on any posix system (linux, bsd, etc) (sorry windows, but if you want to be a serious developer, and .Net isn&#8217;t doing it for you, then change your OS)</p>
<p>So lets get this started!</p>
<h2>Install NodeJS</h2>
<p>Visit the <a href="http://nodejs.org/">NodeJS</a> website and download the latest node package. It&#8217;ll come in tar.gz format. At the time of writing this, its node-v0.2.0.tar.gz. So I&#8217;ll pull it down, and install it!</p>
<p>On the console do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>nodejs.org<span style="color: #000000; font-weight: bold;">/</span>dist<span style="color: #000000; font-weight: bold;">/</span>node-v0.2.0.tar.gz
  <span style="color: #c20cb9; font-weight: bold;">tar</span> xvf node-v0.2.0.tar.gz
  <span style="color: #7a0874; font-weight: bold;">cd</span> node-v0.2.0
  .<span style="color: #000000; font-weight: bold;">/</span>configure
  <span style="color: #c20cb9; font-weight: bold;">make</span>
  <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>The sudo is required as node installs /usr/local/lib/</p>
<p>Once thats done, check to make sure you have it installed</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  node <span style="color: #660033;">--version</span> =<span style="color: #000000; font-weight: bold;">&gt;</span> 0.2.0</pre></div></div>

<h2>Install NPM</h2>
<p>Visit the <a href="http://npmjs.org/">NPM</a> site. There is a link to the github repo that has some extra info not on the site. I recommend visiting it and reading the readme..</p>
<p>After you&#8217;ve done that, to install:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  curl http:<span style="color: #000000; font-weight: bold;">//</span>npmjs.org<span style="color: #000000; font-weight: bold;">/</span>install.sh <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sh</span></pre></div></div>

<p>And then check if its installed</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  npm <span style="color: #660033;">--version</span> =<span style="color: #000000; font-weight: bold;">&gt;</span> 0.1.27-<span style="color: #000000;">11</span></pre></div></div>

<p>You might have a later version, again this was the latest at time of writing.</p>
<h2>Express</h2>
<p>Express is a sinatra like framework that wraps nodejs. It looks pretty sexy! It uses <a href="http://github.com/visionmedia/jade">Jade</a> by default, which is a HAML like templating language. Very sexy indeed.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #c20cb9; font-weight: bold;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;">install</span> express
  <span style="color: #c20cb9; font-weight: bold;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;">install</span> jade</pre></div></div>

<h2>Rolling out a new nodejs app!</h2>
<p>Express has a few generators, which makes life easier for all involved.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  express my_new_project</pre></div></div>

<p>Go through the project and have a look at the directories/files. The important one there is the app.js file. This file is used to run your new project!</p>
<p>To run your node server run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  node app.js</pre></div></div>

<p>You can then point the browser at http://localhost:3000 and bingo!</p>
<h3>Where to find packages?</h3>
<p>There is a good list of hosted <a href="http://github.com/ry/node/wiki/modules">Addons &amp; Modules</a>. Or just a bit of googling will come up with a few extras.</p>
<p>In further articles I&#8217;ll write a little bit more about how to modify the app, add extra actions, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=55</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Node.Js Knockout Retrospective &amp; Dns Bot App</title>
		<link>http://markgandolfo.com/?p=53</link>
		<comments>http://markgandolfo.com/?p=53#comments</comments>
		<pubDate>Sat, 28 Aug 2010 06:22:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[NodeJS]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=53</guid>
		<description><![CDATA[It was a crazy 48 hours! My team members @coenhyde and @nathanhoad and myself had little knowledge of node.js and really didn&#8217;t know how to even start a project. But we investigated a bunch of frameworks and decided on: ExpressJS as our main framework. Jade as our template language (which was integrated into express) Less for our [...]]]></description>
				<content:encoded><![CDATA[<p>It was a crazy 48 hours! My team members <a href="http://twitter.com/coenhyde">@coenhyde</a> and <a href="http://twitter.com/nathanhoad">@nathanhoad</a> and myself had little knowledge of node.js and really didn&#8217;t know how to even start a project. But we investigated a bunch of frameworks and decided on:</p>
<p><a href="http://expressjs.com/">ExpressJS</a> as our main framework.<br />
<a href="http://jade-lang.com/">Jade</a> as our template language (which was integrated into express)<br />
<a href="http://github.com/cloudhead/less.js.git">Less</a> for our stylesheets<br />
<a href="http://www.mongodb.org/">MongoDB</a> for our database server</p>
<p>It all started with a mad rush to understand what the hell was happening within node, and more importantly how we could implement our idea! The event based architecture that node is built around made for an interesting adventure since our whole team is mainly PHP and Ruby on Rails developers.</p>
<p>The first day was spent finding our feet, given the massive amount of nodeJs plugins and frameworks, but by the end of the day we had a good idea of the scope of the technology and more importantly a good idea of how much code we could cut within the remaining 24 hours.</p>
<p>We decided to ditch our original idea and move more towards a simple tool that every technologist has been craving! We called it <a href="http://dnsbotapp.com/">DNS Bot App</a> and its primary purpose is to assist you in the propagation of a domain.</p>
<p>It works by pinging a variety of root servers all around the globe and building a picture of where your domain is resolving. for this first iteration it will show you A records, but stay tuned for more to come!</p>
<p>All in all, Node Knockout was in my opinion a complete success, the goal of the competition was to get a few more people involved in Node and more importantly build some buzz around it. Personally my goals going into the competition was simply to learn a new language, and although I&#8217;m nowhere near an expert, I really feel I&#8217;ve crossed that first hurdle that exists when learning a new language!</p>
<p>So if you think that <a href="http://dnsbotapp.com/">DNS Bot App</a> may be useful for you now or in the future, please show some support and <a href="http://nodeknockout.com/teams/cronify">Vote for us</a>!</p>
<p>So a big shoutout to the node.js team, node knockout crew and of course my team members. It was a cool beer filled and sleep deprived ride, but one I&#8217;m looking forward to doing again!</p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=53</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordcountr.com</title>
		<link>http://markgandolfo.com/?p=51</link>
		<comments>http://markgandolfo.com/?p=51#comments</comments>
		<pubDate>Fri, 27 Aug 2010 06:21:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=51</guid>
		<description><![CDATA[I just wrote a simple rails app to count words in a block of text! You can find it at http://wordcountr.com/. I built it mainly to play around with rails3 but also I hated the fact there wasn&#8217;t an easy way to count words in a document. So I&#8217;ve created this. I hope to implement [...]]]></description>
				<content:encoded><![CDATA[<p>I just wrote a simple rails app to count words in a block of text!</p>
<p>You can find it at <a href="http://wordcountr.com/">http://wordcountr.com/</a>. I built it mainly to play around with rails3 but also I hated the fact there wasn&#8217;t an easy way to count words in a document.</p>
<p>So I&#8217;ve created this. I hope to implement some Natural Language Processing in the future to give more details about the block of text a user submits!</p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=51</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails3 With Cucumber, Rspec</title>
		<link>http://markgandolfo.com/?p=49</link>
		<comments>http://markgandolfo.com/?p=49#comments</comments>
		<pubDate>Sun, 22 Aug 2010 06:20:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=49</guid>
		<description><![CDATA[Initially I had a few problems getting rspec and cucumber (especially gherkin) working with rails3 beta and ruby 1.9.2! Mainly these problems I ran into seemed to deal with bundler. So easy enough, to get cucumber and rspec working, add the following to your Gemfile group :test do gem 'webrat' gem 'rspec' gem 'capybara' gem [...]]]></description>
				<content:encoded><![CDATA[<p>Initially I had a few problems getting rspec and cucumber (especially gherkin) working with rails3 beta and ruby 1.9.2! Mainly these problems I ran into seemed to deal with bundler.</p>
<p>So easy enough, to get cucumber and rspec working, add the following to your Gemfile</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'webrat'</span>
  gem <span style="color:#996600;">'rspec'</span>
  gem <span style="color:#996600;">'capybara'</span>
  gem <span style="color:#996600;">'database_cleaner'</span>
  gem <span style="color:#996600;">'cucumber-rails'</span>
  gem <span style="color:#996600;">'cucumber'</span>
  gem <span style="color:#996600;">'rspec-rails'</span>
  gem <span style="color:#996600;">'spork'</span>
  gem <span style="color:#996600;">'launchy'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>then run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bundle <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>chances are the first time you try to run your tests (especially if you&#8217;re using rvm) you&#8217;ll have segfaults displayed. To fix this manually remove the natively compiled gets and reinstall them using the gem command.</p>
<p>i.e.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem uninstall gherkin nokogiri 
gem <span style="color: #c20cb9; font-weight: bold;">install</span> gherkin <span style="color: #660033;">-v</span>=2.1.5
gem <span style="color: #c20cb9; font-weight: bold;">install</span> nokogiri <span style="color: #660033;">-v</span>=1.4.3.1</pre></div></div>

<p>Do this for each of your segfaulting gems and things should start to work!</p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=49</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hudson Ci Server Running Selenium/Webdriver Cucumber In Headless Mode Xvfb</title>
		<link>http://markgandolfo.com/?p=47</link>
		<comments>http://markgandolfo.com/?p=47#comments</comments>
		<pubDate>Thu, 01 Jul 2010 06:15:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=47</guid>
		<description><![CDATA[I was determined to get our CI server running cucumber features in headless mode. I ran into a few webdriver problems which resulting in a small monkey patch (capybara patch being written and submitted) for capybara. This is how I got it running on a fedora 12 server (and some tips on getting it working [...]]]></description>
				<content:encoded><![CDATA[<p>I was determined to get our CI server running cucumber features in headless mode. I ran into a few webdriver problems which resulting in a small monkey patch (capybara patch being written and submitted) for capybara.</p>
<p>This is how I got it running on a fedora 12 server (and some tips on getting it working on an ubuntu server).</p>
<h2>Install Xvfb</h2>
<p>On fedora</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> xorg-x11-server-Xvfb</pre></div></div>

<p>on ubuntu</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> xvfb</pre></div></div>

<h3>Running Xvfb</h3>
<p>To run Xvfb, in console simply type, then set a environment variable to bind all X requests from the command line to go to the new virtual deskspace</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  Xvfb <span style="color: #660033;">-ac</span> :<span style="color: #000000;">99</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">99</span></pre></div></div>

<p>This will launch a new virtual display bound to display 99.</p>
<h3>Install X11VNC to see whats happening!!</h3>
<p>This is very cool. You can actually set up a vnc server and bind it to the virtual display to see what is happening!!!</p>
<p>On Fedora</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #c20cb9; font-weight: bold;">sudo</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> x11vnc</pre></div></div>

<p>On ubuntu</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> x11vnc<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<h3>To run</h3>
<p>Simple run the following command! And point your VNC client to the installation server!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> x11vnc <span style="color: #660033;">-display</span> :<span style="color: #000000;">99</span></pre></div></div>

<p>Test it by going to the command line and typing something like <code>xterm</code> or <code>firefox</code>!</p>
<h2>Hudson</h2>
<p>Install the hudson gem</p>
<p>The hudson gem is in the gems repo, but for docmentation go http://github.com/cowboyd/hudson.rb. I generally do this as the user &#8220;hudson&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  gem <span style="color: #c20cb9; font-weight: bold;">install</span> term-ansicolor
  gem <span style="color: #c20cb9; font-weight: bold;">install</span> yajl-ruby
  gem <span style="color: #c20cb9; font-weight: bold;">install</span> httparty <span style="color: #660033;">-v</span>=0.5.2
  gem <span style="color: #c20cb9; font-weight: bold;">install</span> builder <span style="color: #660033;">-v</span>=2.1.2
  gem <span style="color: #c20cb9; font-weight: bold;">install</span> thor <span style="color: #660033;">-v</span>=0.13.6
  gem <span style="color: #c20cb9; font-weight: bold;">install</span> hpricot 
  gem <span style="color: #c20cb9; font-weight: bold;">install</span> hudson <span style="color: #660033;">--pre</span></pre></div></div>

<h3>Install hudson</h3>
<p>On the command line just type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> hudson server</pre></div></div>

<p>this will install hudson, and save configuration to the ~/.hudson directory</p>
<h3>Checkout your application to this box</h3>
<p>First thing is to ensure you have set up a git user and email in the global config</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> user.name <span style="color: #ff0000;">&quot;hudson&quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">git</span> config <span style="color: #660033;">--global</span> user.email <span style="color: #ff0000;">&quot;hudson@myserver.com&quot;</span></pre></div></div>

<p>Then clone your app down, install all associated gems and create your testing database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>github.com:username<span style="color: #000000; font-weight: bold;">/</span>mygitrepo.git
  rake gems:<span style="color: #c20cb9; font-weight: bold;">install</span>
  rake db:create:all
  <span style="color: #007800;">RAILS_ENV</span>=<span style="color: #7a0874; font-weight: bold;">test</span> rake db:schema:load</pre></div></div>

<h3>Test cucumber/webdriver runs</h3>
<p>Type <code>cucumber</code> in your apps directory</p>
<h3>Create a new Hudson Project</h3>
<p>Thanks to the hudson gem, you can set up the inital project skeleton via the command line (isn&#8217;t technology great) Here we can use the hudson create command and tell hudson to use the current directory, and that hudson is installed on localhost:3001</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #666666; font-style: italic;">#{to_your_rails_app}</span>
  hudson create . <span style="color: #660033;">--host</span> localhost <span style="color: #660033;">--port</span> <span style="color: #000000;">3001</span></pre></div></div>

<h3>Set up the hudson project</h3>
<p>Log into the project, if its on your local computer, point your browser to http://localhost:3001 and click on your project, also skip this next section.</p>
<p>If you&#8217;re installing hudson on a remote server you&#8217;ll need to ssh port forward since hudson at this point is only listening on localhost.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-L</span> <span style="color: #000000;">8123</span>:localhost:<span style="color: #000000;">3001</span> hudson<span style="color: #000000; font-weight: bold;">@</span>mytestserver.com</pre></div></div>

<p>Then open a browser and point it to http://localhost:8123 and click on your project</p>
<h3>Set up the build</h3>
<ol>
<li>Remove all defined build sets.</li>
<li>Add a new build step &#8220;Execute Shell&#8221; with the command &#8220;cp config/database.tests.yml config/database.yml&#8221;</li>
<li>Add a new build step &#8220;Exceute Shell&#8221; with the command &#8220;RAILS_ENV=test rake gems:install&#8221;</li>
<li>Add a new build step &#8220;Execute Shell&#8221; with the command &#8220;RAILS_ENV=test rake db:migrate&#8221;</li>
<li>Add a new build step &#8220;Execute shell&#8221; with the command &#8220;spec spec&#8221; # if you have specs</li>
<li>Add a new build step &#8220;Execute shell&#8221; with the command &#8220;DISPLAY=:99 cucumber&#8221; # with cucumber</li>
</ol>
<p>Press the save button.</p>
<h2>If webdriver doesn&#8217;t append to your virtual display</h2>
<p>If webdriver doesn&#8217;t append to your Xvfb then you can put this script in /features/support/capybara_webdriver_patch.rb</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Added profile support for capybara, so we can run our tests in headless mode</span>
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Capybara::Driver::Selenium</span> <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Capybara::Driver::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">driver</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@driver</span>
      profile = <span style="color:#6666ff; font-weight:bold;">Selenium::WebDriver::Firefox::Profile</span>.<span style="color:#9900CC;">new</span>
      profile.<span style="color:#9900CC;">load_no_focus_lib</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
      <span style="color:#0066ff; font-weight:bold;">@driver</span> = <span style="color:#6666ff; font-weight:bold;">Selenium::WebDriver</span>.<span style="color:#9966CC; font-weight:bold;">for</span> <span style="color:#ff3333; font-weight:bold;">:firefox</span>, <span style="color:#ff3333; font-weight:bold;">:profile</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; profile
      <span style="color:#CC0066; font-weight:bold;">at_exit</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        <span style="color:#0066ff; font-weight:bold;">@driver</span>.<span style="color:#9900CC;">quit</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0066ff; font-weight:bold;">@driver</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Some after thoughts</h3>
<p>Some extras you should set up before you think your finished. They&#8217;re outside of the scope of this document but there are plenty of docs out there on the interwebs who can give you all the information you need to rock and roll.</p>
<ul>
<li>At the moment its open to everyone, go to global configuration and set up ACL&#8217;s</li>
<li>Your builds aren&#8217;t very continuous yet, you can schedule builds periodically by going into the project configuration area, or I believe you can tie it into githubs callback mechanisms</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=47</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Observers In Rails</title>
		<link>http://markgandolfo.com/?p=45</link>
		<comments>http://markgandolfo.com/?p=45#comments</comments>
		<pubDate>Mon, 21 Jun 2010 06:13:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://markgandolfo.com/?p=45</guid>
		<description><![CDATA[In an effort to reduce the clutter of before and after callbacks in your Rails models an Observer can be used. In a simple use case, you may want to give the user 500 credits in your online store when they signup. Without an observer your User model would look something similar to class User [...]]]></description>
				<content:encoded><![CDATA[<p>In an effort to reduce the clutter of before and after callbacks in your Rails models an Observer can be used. In a simple use case, you may want to give the user 500 credits in your online store when they signup.</p>
<p>Without an observer your User model would look something similar to</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> before_create
     <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">credits</span> = <span style="color:#006666;">500</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Which is fine, if thats all that is in your model. But once your model starts to grow its generally a good idea to keep the callbacks in a different location! Observers to the rescue! With a Rails Observer your code would look similar to</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># models/user.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># models/user_observer.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> UserObserver <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Observer</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> before_create<span style="color:#006600; font-weight:bold;">&#40;</span>user<span style="color:#006600; font-weight:bold;">&#41;</span>
     user.<span style="color:#9900CC;">credits</span> = <span style="color:#006666;">500</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now tell Rails that you want your observer to be included</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># config/environment.rb </span>
<span style="color:#6666ff; font-weight:bold;">Rails::Initializer</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">active_record</span>.<span style="color:#9900CC;">observers</span> = <span style="color:#ff3333; font-weight:bold;">:user_observer</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Rails will automatically understand that this observer is for the user class based on the name (convention over configuration to the rescue). Although you can also have an observer where the model can&#8217;t be inferred by the name, in this case you can explicitly define the models the observer should be observing.</p>
<p>For instance, lets say we have an Audit observer, for a number of models.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">class</span> AuditObserver <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Observer</span>
    observe <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#ff3333; font-weight:bold;">:item</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> after_update<span style="color:#006600; font-weight:bold;">&#40;</span>record<span style="color:#006600; font-weight:bold;">&#41;</span>
      AuditTrail.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>record, <span style="color:#996600;">&quot;UPDATED&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This will observe the user model and on an observed update will create a new audit trail record. Sexy huh?</p>
<p>So no excuses, clean your code up, use observers! Its a sexy design pattern which I feel is completely underused!</p>
]]></content:encoded>
			<wfw:commentRss>http://markgandolfo.com/?feed=rss2&#038;p=45</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
