<?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>Dark Liquid &#187; Ruby</title>
	<atom:link href="http://darkliquid.co.uk/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://darkliquid.co.uk</link>
	<description>Rainy Days</description>
	<lastBuildDate>Sun, 01 Aug 2010 06:33:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dynamically Defined Targets for Remote Tasks in Vlad</title>
		<link>http://darkliquid.co.uk/2009/10/01/dynamically-defined-targets-for-remote-tasks-in-vlad/</link>
		<comments>http://darkliquid.co.uk/2009/10/01/dynamically-defined-targets-for-remote-tasks-in-vlad/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 10:47:05 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Howto/Tutorial]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[useful]]></category>
		<category><![CDATA[vlad]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/?p=274</guid>
		<description><![CDATA[Typically things like Vlad and Capistrano make the assumption you already know where you want to run your tasks. They assume you already have some servers somewhere ticking over just fine and you want to do stuff on them according to some predetermined pattern. However, what happens when you want to write some tasks you [...]]]></description>
			<content:encoded><![CDATA[<p>Typically things like Vlad and Capistrano make the assumption you already know where you want to run your tasks. They assume you already have some servers somewhere ticking over just fine and you want to do stuff on them according to some predetermined pattern.</p>
<p>However, what happens when you want to write some tasks you can run on <em>any</em> remote server? What happens if you don&#8217;t have any servers and you want to build some dynamically and then run some remote tasks on them?</p>
<p>Well, I&#8217;ve been asking these questions and I found an answer that helped me out and thought I&#8217;d share it here.</p>
<p>Using the dependency system of rake and the lazy role evaluation of vlad along with the fact that it provides some very useful public class methods (so they are presumably safe, rather than hacking into the internals with send or the like) I wrote the following simple test script:</p>
<pre><code lang="ruby">
require 'rubygems'
require 'highline'
require 'vlad'
task :server_config do
  ssh_string = HighLine.new.ask 'Enter the SSH details of the server you want to connect to: '
  Rake::RemoteTask.role :server, ssh_string
end

desc 'Run stuff on a server'
remote_task :server, :roles => :server do
  run "echo 'hello i am a server'"
end
task :server => :server_config
</code></pre>
<p>What&#8217;s going on here is that I have a remote task using a role server which as of yet <em>I haven&#8217;t defined</em>. When I run <code>rake server</code> that runs the server task. The server task is dependent on the server_config task which sets up a role &#8216;server&#8217; with the given string (ideally something like user@server.com). The remote task then executes, evaluating the value of the role, which is now set to the users input, and connects to the server you&#8217;ve set at run time. How awesome is that?</p>
<p>Of course, this is a contrived example, you could use a system to setup roles automatically from other things rather than pulling in user input but the lesson to take away here is that is is possible to use vlad tasks on dynamically defined targets <em>easily</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2009/10/01/dynamically-defined-targets-for-remote-tasks-in-vlad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stuff</title>
		<link>http://darkliquid.co.uk/2009/05/06/stuff/</link>
		<comments>http://darkliquid.co.uk/2009/05/06/stuff/#comments</comments>
		<pubDate>Wed, 06 May 2009 09:20:56 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[meetups]]></category>
		<category><![CDATA[social networking]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/?p=227</guid>
		<description><![CDATA[Wow, things have been a little crazy recently. Work has been ish and we&#8217;re down to just me and the boss for the time being which is pretty sad. Hopefully thing&#8217;s will pick up again soon and we&#8217;re taking this as an opportunity for a company reboot so we&#8217;ll see. My WiiFit exercise regime isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, things have been a little crazy recently. Work has been ish and we&#8217;re down to just me and the boss for the time being which is pretty sad. Hopefully thing&#8217;s will pick up again soon and we&#8217;re taking this as an opportunity for a company reboot so we&#8217;ll see.</p>
<p>My WiiFit exercise regime isn&#8217;t happening. I&#8217;m always busy with something it seems so I never get time. I&#8217;ve not actually used it for exercise in about 3 weeks now. Terrible I know. At least my body seems to be pretty happy hovering around 15.5st rather than still ramping up the pounds of fat <img src='http://darkliquid.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;ve still been trying to write as much as possible and have managed to get Dru to start contributing more to protagonize <a title="The Protagonize Blog - Meet Your Moderators" href="http://blog.protagonize.com/2009/05/05/meet-your-moderators/">which I am now a moderator of</a>! So now I get to <span style="text-decoration: line-through;">ab</span>use my power for <span style="text-decoration: line-through;">evil</span> good. Woohoo!</p>
<p>I&#8217;ve been trying to keep the <a href="http://bournemouthrb.org.uk">Bournemouth.rb Ruby Group</a> up and running recently. So far we&#8217;re only small, but we&#8217;ve managed to run a few meetups so far. Currently we&#8217;re trying to find some projects to hack on together &#8211; if you have any ideas post them up on the <a href="http://bournemouthrb.org.uk">Bournemouth.rb wiki</a>. I&#8217;m quite enjoying this whole community lark. Let&#8217;s hope it lasts! If you are a rubyist in Bournemouth or if you&#8217;re just interested in the Ruby programming language and looking to get into it then try coming along, signup on the <a href="http://lists.bournemouthrb.org.uk/mailman/listinfo/list">Bournemouth.rb mailing list</a> for more info.</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2009/05/06/stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing Context in Liquid Drops</title>
		<link>http://darkliquid.co.uk/2009/02/24/accessing-context-in-liquid-drops/</link>
		<comments>http://darkliquid.co.uk/2009/02/24/accessing-context-in-liquid-drops/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 17:34:26 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[liquid]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/?p=203</guid>
		<description><![CDATA[Have you ever thought it would be nice to be able to access the context from within a custom Liquid::Drop when using the Liquid template system? Turns out, you can. On Drops there is a method &#8216;context=&#8217; which gets set by the parser when it comes across a Drop object. From within the drop, all [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever thought it would be nice to be able to access the context from within a custom Liquid::Drop when using the Liquid template system?</p>
<p>Turns out, you can.</p>
<p>On Drops there is a method &#8216;context=&#8217; which gets set by the parser when it comes across a Drop object. From within the drop, all you need to do is access the @context variable and you&#8217;re away.</p>
<p>Why this isn&#8217;t advertised more is beyond me, or maybe I&#8217;m just an idiot and missed it, but I couldn&#8217;t see how to do this at all until I decided to sit down and essentially try and write it myself and delved into the code in Liquid that deals with processing variables. Turns out it&#8217;s already there and it works a charm. Nice for writing Drops that behave differently in different contexts, depending on register settings and the like.</p>
<p>Anyway, I thought it was useful, hope this helps someone else before they pull all their hair out.</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2009/02/24/accessing-context-in-liquid-drops/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Git tracking</title>
		<link>http://darkliquid.co.uk/2008/11/05/git-tracking/</link>
		<comments>http://darkliquid.co.uk/2008/11/05/git-tracking/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 07:49:12 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[scm]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/?p=174</guid>
		<description><![CDATA[We&#8217;ve been switching to git recently and something mildly annoys me about it not to mention certain colleagues of mine have a dread fear of editing configuration files. In most git tutorials I&#8217;ve seen, once you have created your git project and then want to set up tracking of your master branch against a remote [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve been switching to git recently and something mildly annoys me about it not to mention certain colleagues of mine have a dread fear of editing configuration files. In most git tutorials I&#8217;ve seen, once you have created your git project and then want to set up tracking of your master branch against a remote server you are required to edit config files. Git has so many nice little tools for doing everything else, why not something for this? So, for swift justice, we decided to remedy the situation with some bash-fu.</p>
<pre><code lang="bash">
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}

function git-track {
  CURRENT_BRANCH=$(parse_git_branch)
  git-config branch.$CURRENT_BRANCH.remote $1
  git-config branch.$CURRENT_BRANCH.merge refs/heads/$CURRENT_BRANCH
}
</code></pre>
<p>With the above snippet in your bash conf (yes, I recognise the irony of editing a config file to give you a command to avoid editing a config file) you can just type:</p>
<pre><code lang="bash">
git-track [remote name]
</code></pre>
<p>to track the branch you are currently in against the same branch in that remote. Simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2008/11/05/git-tracking/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Office 2007 Excel file to CSV hack</title>
		<link>http://darkliquid.co.uk/2008/10/31/simple-office-2007-excel-file-to-csv-hack/</link>
		<comments>http://darkliquid.co.uk/2008/10/31/simple-office-2007-excel-file-to-csv-hack/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 10:55:31 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[office 2007]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/?p=171</guid>
		<description><![CDATA[I needed to convert a very simple Office 2007 Excel file into a CSV. I don&#8217;t have Office 2007 so I hacked up some Ruby goodness to convert it. require 'rubygems' require 'hpricot' doc = open('office2007.xls') { &#124;f&#124; Hpricot(f) } csv = '' doc.search('//row').each do &#124;row&#124; (row/'cell/data').each do &#124;data&#124; csv < < "\"#{data.to_plain_text}\"," if data [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to convert a very simple Office 2007 Excel file into a CSV. I don&#8217;t have Office 2007 so I hacked up some Ruby goodness to convert it.</p>
<pre>
<code lang="ruby">
require 'rubygems'
require 'hpricot'
doc = open('office2007.xls') { |f| Hpricot(f) }
csv = ''
doc.search('//row').each do |row|
(row/'cell/data').each do |data|
csv < < "\"#{data.to_plain_text}\"," if data
end
csv.chomp!(',')
csv << "\n"
end
File.open("output_file_name", 'w') {|f| f.write(csv) }
</code>
</code></pre>
<p>Hope someone finds this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2008/10/31/simple-office-2007-excel-file-to-csv-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Legacy Capistrano Issues</title>
		<link>http://darkliquid.co.uk/2008/10/13/legacy-capistrano-issues/</link>
		<comments>http://darkliquid.co.uk/2008/10/13/legacy-capistrano-issues/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 08:47:16 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/?p=159</guid>
		<description><![CDATA[I have some apps deployed with older versions of capistrano but I still want to be able to use the latest capistrano on newer projects. Ideally I&#8217;d update the older apps to use the newer capistrano, but sometimes that requires a lot of work for not much benefit when I have a perfectly good copy [...]]]></description>
			<content:encoded><![CDATA[<p>I have some apps deployed with older versions of capistrano but I still want to be able to use the latest capistrano on newer projects. Ideally I&#8217;d update the older apps to use the newer capistrano, but sometimes that requires a lot of work for not much benefit when I have a perfectly good copy of the old capistrano laying around to run those old deploy scripts with.</p>
<p>However, by perfectly good, I mean broken. It breaks because it doesn&#8217;t specifically require the correct versions of other gems but this you can fix. This is how I fixed it for my particular use case. I&#8217;m assuming you have a recent version of rubygems where you can use the gem method for specifying require&#8217;s gem versions.</p>
<p>Open up your old cap program, mine was here:<br />
/usr/local/lib/ruby/gems/1.8/gems/capistrano-1.4.1/bin/cap</p>
<p>Before the &#8220;require &#8216;capistrano/cli&#8217;&#8221; line add the following:</p>
<pre><code lang="ruby">gem 'net-ssh', '=1.0.10'
gem 'net-sftp', '=1.1.0'
gem 'capistrano', '=1.4.1'</code></pre>
<p>I also edited my lib/tasks/capistrano.rake file to have the following code in it.</p>
<pre><code lang="ruby">def cap(*parameters)
  begin
    require 'rubygems'
  rescue LoadError
    # no rubygems to load, so we fail silently
  end

  gem 'net-ssh', '=1.0.10'
  gem 'net-sftp', '=1.1.0'
  gem 'capistrano', '= 1.4.1'
  require 'capistrano/cli'

  Capistrano::CLI.new(parameters.map { |param| param.to_s }).execute!
end</code></pre>
<p>Then I created a new symlink.</p>
<pre><code lang="bash">ln -s /usr/local/lib/ruby/gems/1.8/gems/capistrano-1.4.1/bin/cap /usr/local/bin/old_cap</code></pre>
<p>Now I can run my old stuff and I have my old cap program as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2008/10/13/legacy-capistrano-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing without the database</title>
		<link>http://darkliquid.co.uk/2007/09/17/testing-without-the-database/</link>
		<comments>http://darkliquid.co.uk/2007/09/17/testing-without-the-database/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 11:04:00 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/index.php/2007/09/17/testing-without-the-database/</guid>
		<description><![CDATA[We’ve been embracing the whole testing without the database for our unit tests, making use of unit_record. However, with a recent update I found a lot of my tests failing. I eventually narrowed it down to something to do with query caching. Well, apparently query caching only gets activated if there are ActiveRecord configurations, so, [...]]]></description>
			<content:encoded><![CDATA[<p>We’ve been embracing the whole testing without the database for our unit tests, making use of <code>unit_record</code>. However, with a recent update I found a lot of my tests failing. I eventually narrowed it down to something to do with query caching. Well, apparently query caching only gets activated if there are ActiveRecord configurations, so, since we aren’t using the database anyway, it should be okay to clear the configuration for our unit tests &#8211; right?</p>
<p>Well, it was, and this is what I put in my <code>unit_test_helper</code> file:</p>
<pre><code class='ruby'># Clears active record configurations since we don't need them
# (and they cause query cache problems)
ActiveRecord::Base.configurations.clear</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2007/09/17/testing-without-the-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I just released my first Ruby Gem!</title>
		<link>http://darkliquid.co.uk/2007/03/25/i-just-released-my-first-ruby-gem/</link>
		<comments>http://darkliquid.co.uk/2007/03/25/i-just-released-my-first-ruby-gem/#comments</comments>
		<pubDate>Sun, 25 Mar 2007 11:49:00 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/index.php/2007/03/25/i-just-released-my-first-ruby-gem/</guid>
		<description><![CDATA[Just a few minutes ago I released my first rubygem &#8211; tuxdroid an api for interfacing with the tuxdroid robot from kysoh. It’s sweet being able to just do: require 'rubygems' require 'tuxdroid' tux = TuxDroid::Tux.new tux.mouth pen Of course, you’ll need ruby-usb installed as well, which isn’t a gem as of yet so you’ll [...]]]></description>
			<content:encoded><![CDATA[<p>Just a few minutes ago I released my first rubygem &#8211; <a href='http://rubyforge.org/projects/tuxdroid/'>tuxdroid</a> an api for interfacing with the <a href='http://www.tuxisalive.com'>tuxdroid robot</a> from <a href='http://www.kysoh.com/'>kysoh</a>.</p>
<p>It’s sweet being able to just do:</p>
<pre><code>require 'rubygems'
require 'tuxdroid'
tux = TuxDroid::Tux.new
tux.mouth <img src='http://darkliquid.co.uk/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> pen</code></pre>
<p>Of course, you’ll need ruby-usb installed as well, which isn’t a gem as of yet so you’ll have to compile that manually.</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2007/03/25/i-just-released-my-first-ruby-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where are the Rubyists in Bournemouth?</title>
		<link>http://darkliquid.co.uk/2007/03/08/where-are-the-rubyists-in-bournemouth/</link>
		<comments>http://darkliquid.co.uk/2007/03/08/where-are-the-rubyists-in-bournemouth/#comments</comments>
		<pubDate>Thu, 08 Mar 2007 13:18:00 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/index.php/2007/03/08/where-are-the-rubyists-in-bournemouth/</guid>
		<description><![CDATA[Hello? Is anyone out there? I’m looking for other Rubyists in the Bournemouth area. There doesn’t seem to be a local Ruby User Group and so I’ve created a basic entry for one for Bournemouth at RubyHolic. Are there any other ruby guys or girls anywhere near me? I’d love to meet you. I’m not [...]]]></description>
			<content:encoded><![CDATA[<p>Hello? Is anyone out there?</p>
<p>I’m looking for other Rubyists in the Bournemouth area. There doesn’t seem to be a local Ruby User Group and so I’ve created a basic entry for one for <a href='http://rubyholic.com/groups/show/401'>Bournemouth at RubyHolic</a>. Are there any other ruby guys or girls anywhere near me? I’d love to meet you.</p>
<p>I’m not very good at this whole organising groups thing, so be gentle when it comes to arranging a meet up <img src='http://darkliquid.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Since I didn’t see an option to add personal member details at <a href='http://rubyholic.com'>rubyholic</a> I’ll introduce myself here:</p>
<p>I’ve been using Ruby since 2+ years ago when I started using Rails. I work with it professionally as web developer and sysadmin for a local Bournemouth web design/development company called <a href='http://ww.soniciq.com'>SonicIQ</a> (<a href='http://jobs.37signals.com/jobs/1203'>SonicIQ are hiring</a> by the way). I’m interested in all things Ruby and am currently working on a simple Ruby/SDL-based tile engine in my spare time among other various projects. I’m mostly a Linux guy and try to attend the <a href='http://www.dorset.lug.org.uk'>local LUG</a> with some kind of regularity but I also love my MacBook. </p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2007/03/08/where-are-the-rubyists-in-bournemouth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Exchange &#8211; Part 2</title>
		<link>http://darkliquid.co.uk/2007/02/11/ruby-on-rails-exchange-part-2/</link>
		<comments>http://darkliquid.co.uk/2007/02/11/ruby-on-rails-exchange-part-2/#comments</comments>
		<pubDate>Sun, 11 Feb 2007 11:01:00 +0000</pubDate>
		<dc:creator>Dark Liquid</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://darkliquid.co.uk/index.php/2007/02/11/ruby-on-rails-exchange-part-2/</guid>
		<description><![CDATA[In my last post I wrote up the first half of my attendance of the RoR eXchange hosted by skillsmatter up in London. Now I’m going to cover the talks by James Cox, Damien Tanner, Ben Griffiths, Eleanor McHugh and the after-show party. (&#8230;)]]></description>
			<content:encoded><![CDATA[<p><a href='http://darkliquid.co.uk/2007/2/10/ruby-on-rails-exchange'>In my last post</a> I wrote up the first half of my attendance of the RoR eXchange hosted by skillsmatter up in London.</p>
<p>Now I’m going to cover the talks by James Cox, Damien Tanner, Ben Griffiths, Eleanor McHugh and the after-show party.</p>
<p> (&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://darkliquid.co.uk/2007/02/11/ruby-on-rails-exchange-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
