<?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>Jamie&#039;s Weblog</title>
	<atom:link href="http://jamie.ideasasylum.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamie.ideasasylum.com</link>
	<description>Procrastination and utter drivel since 2001!</description>
	<lastBuildDate>Wed, 17 Apr 2013 16:17:54 +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>Geeking out about Water (Containers)</title>
		<link>http://jamie.ideasasylum.com/2013/04/geeking-out-about-water/</link>
		<comments>http://jamie.ideasasylum.com/2013/04/geeking-out-about-water/#comments</comments>
		<pubDate>Wed, 17 Apr 2013 16:06:10 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Reviews]]></category>
		<category><![CDATA[bottles]]></category>
		<category><![CDATA[punc]]></category>
		<category><![CDATA[vapur]]></category>
		<category><![CDATA[water]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1526</guid>
		<description><![CDATA[I&#8217;m a freak: a computer programmer that doesn&#8217;t drink coffee. I don&#8217;t drink tea either. Or hot chocolate (unless I&#8217;ve just been swimming with dolphins in the seas off New Zealand and hypothermia is a possible concern). I like ice cold drinks: Fruit juice, orange squash, Coke or 7UP, and mostly just water. One of [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m a freak: a computer programmer that doesn&#8217;t drink coffee. I don&#8217;t drink tea either. Or hot chocolate (unless I&#8217;ve just been swimming with dolphins in the seas off New Zealand and hypothermia is a possible concern). I like ice cold drinks: Fruit juice, orange squash, Coke or 7UP, and mostly just water.</p>
<p>One of the highlights of last Friday were my two experiences drinking water. Here&#8217;s why…</p>
<h2>Vapur</h2>
<p><a href="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/web-5l_reflex_0005s_0001_vapur_reflex-cool_grey-front-72dpi_1.jpg"><img src="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/web-5l_reflex_0005s_0001_vapur_reflex-cool_grey-front-72dpi_1-300x300.jpg" alt="web-5l_reflex_0005s_0001_vapur_reflex-cool_grey-front-72dpi_1" width="300" height="300" class="alignright size-medium wp-image-1529" /></a> I was a Cork Meet – a large networking event – and like most conferences it caters mostly for the engage-brain-with-coffee crowd. Luckily I found a water dispenser in the corner and I could fill up my <a href="http://vapur.us/shop/reflex/reflex">Vapur Reflex</a> which I&#8217;d received at Christmas but had yet to use.</p>
<p>It&#8217;s perfect! It folds flat when you&#8217;re carrying it, stands up when it&#8217;s full, has a good solid nozzle which doesn&#8217;t leak, and a caribiner for attaching to a bag. It is now a permanent addition to my laptop bag and I may get a second for my camera bag.</p>
<p>The only downside is that the bag lacks structure and tends to droop down when you&#8217;re drinking it. It can also look like you&#8217;re drinking from an IV bag.</p>
<h2>PUNC</h2>
<p>I was so thrilled with my experiences with the Vapur bag in the morning that I was excitedly telling everyone I met… and then I met John, inventor of PUNC bottles who told me I was doing it all wrong.</p>
<p><a href="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/500ml-stainless-steel-bottles-red-punc.jpg"><img src="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/500ml-stainless-steel-bottles-red-punc-e1366214128920-300x300.jpg" alt="500ml-stainless-steel-bottles-red-punc" width="300" height="300" class="alignleft size-medium wp-image-1528" /></a>John was giving a presentation at the <a href="http://selr8r.com">Selr8r</a> open day and started by telling us that plastic bottles are bad. He&#8217;s probably right, although I&#8217;ll be honest and say that I have bigger fish to fry in terms of healthy living. The <a href="http://en.wikipedia.org/wiki/Bisphenol_A#Health_effects">BPA scandal</a> has made everyone a bit more aware of the health risks of plastics and I have no doubt that there will be more health problems discovered in the future. But I don&#8217;t think that&#8217;s the main selling point. After all, your drinking water in the office is almost certainly delivered in a large plastic bottle.</p>
<p><a href="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/green_water.jpg"><img src="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/green_water-113x300.jpg" alt="green_water" width="113" height="300" class="alignright size-medium wp-image-1527" /></a>The first thing you notice about the PUNC bottle is the packaging. The bottle comes nestled in a bright, bold poster tube and that alone marks it out as something special. This is an object of design. The bottles themselves are made of thin stainless steel and are incredibly light (nothing like the old aluminium bottle I had for hiking). The stainless steel is the same stuff used for food preparation and, since some of my limbs are already held together by this material, I think we can trust it! The bottles are curved in the middle, which really helps with holding them, particularly when you get condensation forming on an ice cold bottle. It gives the bottle a softer look and they come in a range of playful metallic colours.</p>
<p>The bottles have a range of caps too. I have the sports cap which provides the familiar exercise bottle valve. The only downside to this is there&#8217;s no air-hole which limits the amount of water you can take in (and you can&#8217;t squeeze the bottle either). There&#8217;s also an easy flip-up straw lid and regular screw on lids. I tend to leave the lid off at my desk and just drink from the wide mouth (big enough to put ice cubes in). PUNC bottles come in various sizes (0.5L, 0.75L and 1L) and there is also a selection insulated bottles (stays cold for 24hrs!)</p>
<p>John was gracious enough to give me the Red 1L bottle he&#8217;d brought in for the presentation. Or perhaps he took pity on me when I told him that I would buy a 1litre bottle of Volvic and just reuse the plastic bottle for a few months! Yeah, that doesn&#8217;t sound too hygenic now that I mention it.</p>
<h2>Which bottle should I buy?</h2>
<p>Trick question. Buy both!</p>
<p>If you drink water then having a Vapur in your laptop bag or camera bag is just a no-brainer. They&#8217;re perfect for travelling light.</p>
<p>The PUNC bottles are my choice for drinking water just about anywhere else. I use mine at my desk and I plan on getting a small one for my daughter&#8217;s lunchbox, and maybe another for the car. You can <a href="http://puncbottles.com/stockists/">find local stockists on the PUNC site</a> or <a href="http://westerngreen.ie/23-stainless-steel-water-bottles-">buy online</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/04/geeking-out-about-water/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s the money, stupid!</title>
		<link>http://jamie.ideasasylum.com/2013/03/its-the-money-stupid/</link>
		<comments>http://jamie.ideasasylum.com/2013/03/its-the-money-stupid/#comments</comments>
		<pubDate>Thu, 28 Mar 2013 22:31:36 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[rant]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[formspring]]></category>
		<category><![CDATA[startups]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1520</guid>
		<description><![CDATA[I just read this daft &#8220;postmortem&#8221; about FormSpring (a social ask-me-anything Q&#38;A site which is shutting down after $14m of funding but it had &#8220;been challenging to sustain the resources needed to keep the lights on.&#8220;). Ok, I lie. I gave up reading and just did a Ctrl-F for the phrases &#8220;profit&#8221;, &#8220;revenue&#8221;, &#8220;business model&#8221;, [...]]]></description>
				<content:encoded><![CDATA[<p>I just read <a href="http://blog.capwatkins.com/formspring-a-postmortem">this daft &#8220;postmortem&#8221; about FormSpring</a> (a social ask-me-anything Q&amp;A site which is shutting down after $14m of funding but it had &#8220;<a href="http://formspring.wordpress.com/2013/03/15/formspring-is-shutting-down/">been challenging to sustain the resources needed to keep the lights on.</a>&#8220;). Ok, I lie. I gave up reading and just did a Ctrl-F for the phrases &#8220;profit&#8221;, &#8220;revenue&#8221;, &#8220;business model&#8221;, and &#8220;money&#8221;. 0 of 0. <strong>That&#8217;s the <em>fucking</em> problem!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/03/its-the-money-stupid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Startup Pubbish-ness</title>
		<link>http://jamie.ideasasylum.com/2013/03/startup-pubbish-ness/</link>
		<comments>http://jamie.ideasasylum.com/2013/03/startup-pubbish-ness/#comments</comments>
		<pubDate>Wed, 27 Mar 2013 13:56:42 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[rant]]></category>
		<category><![CDATA[cork]]></category>
		<category><![CDATA[corkpubsummit]]></category>
		<category><![CDATA[pitches]]></category>
		<category><![CDATA[pubsummit]]></category>
		<category><![CDATA[startups]]></category>
		<category><![CDATA[websummit]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1512</guid>
		<description><![CDATA[I might be about to commit professional hari-kiri here but I wanted to push back on all the startup love I&#8217;ve been hearing. I attended the Cork Pub Summit event yesterday evening, organised like a local mini-Web Summit to provide a place the tech community to meet and local startups to pitch their ideas. It [...]]]></description>
				<content:encoded><![CDATA[<p>I might be about to commit professional hari-kiri here but I wanted to push back on all the startup love I&#8217;ve been hearing. I attended the Cork Pub Summit event yesterday evening, organised like a local mini-Web Summit to provide a place the tech community to meet and local startups to pitch their ideas. It was good fun.</p>
<p>First, let&#8217;s get this out of the way: total respect to everyone who pitched last night. It takes guts to get up in front of 300 people and talk about your baby. Not everyone can do it.</p>
<p>But. We have to stop cheering every pitch without even a modicum of criticism. We&#8217;re not headless startup cheerleaders, rar-rar&#8217;ing each pitch onwards without expressing our own opinions. As a professional consultant, I have more than my fair share of opinions, and I need them: I only want to work with businesses where I know I can help them succeed. I hate seeing people wasting their time on a doomed startup. These people have passed up other opportunities to work on their idea and it&#8217;s our duty to ask some searching questions, not for the sake of being mean but because we want them to succeed (though, perhaps not with this idea).</p>
<p>So, here are some of my (rough) notes…</p>
<h3><a href="http://popdeem.com/">Popdeem</a></h3>
<p>Social media analytics (AGAIN! — sorry, saw too many in this space at Web Summit). Major problems: convincing a company to convince their customers to download your app with the Popdeem branding. And then to get those customers to post to Facebook. And after all that you can&#8217;t even tell what the effect was on the business. That&#8217;s never going to fly. We need much better proof that this sort of paid-social-media-postings really drives sustainable revenue for the businesses. I would trust a real, enthusiastic Instagram over a rewarded-by-free-burrito Facebook posting.</p>
<h3><a href="http://www.uryearbook.com/">URYearBook</a></h3>
<p>Yearbooks. I didn&#8217;t realise that they were a thing outside of U.S. high schools (or, at least, the TV dramatisation of same). <em>Yearbooks</em> are annual, so what will you live off for the other 11months? Also, your target market are cheap (but as a once-off special thing perhaps they will stump up enough). Who does the curation? Social media volumes would be too great to capture it all in the yearbook. And how do you know what&#8217;s relevant to the class? It actually sounds like a nice small business but very very seasonal. Perhaps you could licence directly to online printers? Also, be careful with the digital version. Don&#8217;t give this away for free or a lower price point. It will decimate sales of the physical book (unless you can price it to make as much/more profit than the physical version).</p>
<h3><a href="http://liveduel.com/">LiveDuel</a></h3>
<p>WTF. He wants 100k to go to SF and complete this accelerator program?! It also seems like he&#8217;s heading away from his target market (Asia?) and it wasn&#8217;t entirely clear who his customers would be. Initially he talked about monitising sports communities/forums but now it seems like it&#8217;s a licensable technology for other games companies? I found the pitch confusing.</p>
<h3><a href="http://www.click4classes.com/">Click4Classes</a></h3>
<p>Two-sided market problem. Must convince both class providers and students to use the site. Furthermore, it&#8217;s not good for businesses to be listed like this. Where&#8217;s the opportunity to stand out, for brand recognition or word-of-mouth recommendation? It also introduces an admin headache for class providers if only some of their student paid through the site.</p>
<h3><a href="http://www.vconnecta.com/">Vconnecta</a></h3>
<p>This is only guy who knew how to pitch. There were strong visuals about carrying around electoral registers, in the rain, with a clipboard and then trying to compile together all the reactions etc. I can see some <em>real</em> pain there. Furthermore, the target market are rich (politicians!), easily found (public information) and reachable (public emails, office hours etc). They&#8217;re also desperate to have more information at election time when they feel very vulnerable. Only downside: elections are usually only every 4-5 years but I think there would be enough local/council/city/mayoral/by- elections each year that the service would be well-used. And that’s without considering general activism campaigning. There should also be a natural pricing tier based on area (local councillors canvasing a small town would pay less than a senator canvasing a state who would pay less again that a national political party). I see <em>easy</em> six figure revenues here. The data analytics alone would be worth it to many parties. One word of caution: that Romney app crashed when they most needed it — the infrastructure needs to be reliable and able to cope with large surges in activity.</p>
<p>One other annoyance was that every pitch &amp; question time seemed to overrun, which led the crowd to become noisy, which led to other people <em>shushing</em> the crowd like naughty school-children. To be honest, you’re going to lose the crowd if your pitch is over 4mins to a room full of smart, interested, beer-drinking people — at that stage we’ve heard enough to form an opinion which we want to discuss with our neighbours. Instead of shushing us, perhaps the Pub Summit should have <em>involved</em> the crowd? Give us tokens to “invest” in the best pitch. Or take questions from the floor instead of the panel (trust me: everyone in the audience had an opinion!). I think the Pub Summit format should encourage the informal, rowdy, “pubbish-ness”</p>
<p>I throughly enjoyed the Pub Summit last night. Thanks to <a href="https://twitter.com/donal_cahalane">Donal Cahalane</a> for doing the heavy lifting in bringing this to Cork. I chatted to friends I hadn’t seen in years, met some new people and generally enjoyed myself.</p>
<p><em>Addendum:</em> I met the guys behind Click4Classes at a <a href="http://www.selr8r.com/">Selr8r</a> event recently and got to put some of my points to them. I still maintain that these are potential problems with the business but it was great to hear that they have considered them and are planning some features to help good businesses stand out (themes, student ratings etc). If anything, it just reinforces that a good pitch event shouldn&#8217;t leave these questions unanswered in anyone&#8217;s mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/03/startup-pubbish-ness/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Configuring Guard notifications with Vagrant</title>
		<link>http://jamie.ideasasylum.com/2013/03/configuring-guard-notifications-with-vagrant/</link>
		<comments>http://jamie.ideasasylum.com/2013/03/configuring-guard-notifications-with-vagrant/#comments</comments>
		<pubDate>Tue, 12 Mar 2013 09:35:15 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[guard]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1507</guid>
		<description><![CDATA[One problem when running everything in a headless Vagrant instance is that you lose the ability to see Guard Rspec notifications. Actually, you don&#8217;t lose it but it&#8217;s not immediately obvious how to configure Guard. Since Guard is running inside Vagrant, it can&#8217;t display the Growl notifications on the guest operating system. However, you can [...]]]></description>
				<content:encoded><![CDATA[<p>One problem when running everything in a headless Vagrant instance is that you lose the ability to see Guard Rspec notifications. Actually, you don&#8217;t lose it but it&#8217;s not immediately obvious how to configure Guard. Since Guard is running inside Vagrant, it can&#8217;t display the Growl notifications on the guest operating system. However, you can specify a server to send those notifications to:</p>
<p><img src="http://i.imgur.com/wYdw0Uw.png" alt="Configure Growl to accept network notifications (and set a password!)" /></p>
<p>Then, at the top of your <code>Guardfile</code>, add the following line:</p>
<pre><code class="language-ruby">notification :gntp, :sticky => false, :host => '10.0.2.2', :password => 'yourstrongpassword'</code></pre>
<p>The key was discovering that <code>10.0.2.2</code> was the correct address to use on a guest operating system to communicate with the host operating system. This might change with your Vagrant configuration but <a href="http://superuser.com/questions/310697/connect-to-the-host-machine-from-a-virtualbox-guest-os">this post explains how to get the correct address</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/03/configuring-guard-notifications-with-vagrant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing the stupid mistakes, like committing focus:true</title>
		<link>http://jamie.ideasasylum.com/2013/02/preventing-the-stupid-mistakes-like-committing-focustrue/</link>
		<comments>http://jamie.ideasasylum.com/2013/02/preventing-the-stupid-mistakes-like-committing-focustrue/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 13:20:11 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Useful]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1499</guid>
		<description><![CDATA[I frequently use focus: true in my specs when I&#8217;m working in a particular area of the code. I also frequently forget to remove this tag and subsequently commit the spec to Git, resulting in most of the test suite not running. Duh! &#8220;Removing focus:true&#8221; is my most frequent commit message :-/ The solution is [...]]]></description>
				<content:encoded><![CDATA[<p>I frequently use <code>focus: true</code> in my specs when I&#8217;m working in a particular area of the code. I also frequently forget to remove this tag and subsequently commit the spec to Git, resulting in most of the test suite not running. Duh! &#8220;Removing focus:true&#8221; is my most frequent commit message :-/</p>
<p>The solution is to write a pre-commit hook for Git. Or, in my case, find someone who has done it and tweak <a href="http://devblog.springest.com/using-git-hooks-to-prevent-committing-focus-true-and-other-bad-stuff">their solution</a> until it actually works (grep -P isn&#8217;t supported on a Mac, for example).</p>
<p>So, here&#8217;s my pre-commit hook. Simply copy this script into <code>.git/hooks/pre-commit</code> and make sure it&#8217;s executable.</p>
<pre><code class="language-ruby">#!/usr/bin/env ruby
spec_hits = []

# Find the names of all the filenames that have been (A)dded (C)opied or (M)odified
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("n")

filenames.each do |filename|
  # Perform special checks for _spec filenames (rspec tests)
  if filename.match /_spec.rb$/
    # Filter all the additions to this file, find if they contain `focus: true` and store these lines without the initial `+` and spaces
    results = `git diff --cached  #{filename} | grep "^+[^+]" | grep "focus:[:space:]*true"`.split("n").map { |r| r.sub(/^+[st]*/, '') }

    if $? == 0
      # Add the relevant change with line number to the spec_hits array
      results.each{ |r| spec_hits.push "#{filename}:" + `grep -n '#{r}' #{filename}`.sub(/:s+/, ' ').chomp }
    end
  end
end

if spec_hits.any?
  puts "e[33m>>> Please remove your `focus: true` from the following tests before committinge[0m"
  puts spec_hits.join("n")
end

exit 1 if spec_hits.any?</code></pre>
<p>You might need to edit the regex if you use the hashrocket syntax</p>
<p><strong>Update:</strong> I've modified the script to prevent <code>debugger</code>, <code>binding.pry</code> and make it easily configurable:</p>
<pre><code class="language-ruby ">#!/usr/bin/env          

ruby spec_hits = []

checks = {
            '_spec.rb$' => ['focus:[:space:]*true'],
            '.rb$' => ['binding.pry', 'debugger']
         }

# Find the names of all the filenames that have been (A)dded (C)opied or (M)odified
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("n")

filenames.each do |filename|
  # Perform special checks for _spec filenames (rspec tests)
  checks.each do |filename_pattern, patterns|
    if filename.match filename_pattern
      patterns.each do |contents_pattern|
        results = `git diff --cached  #{filename} | grep "^+[^+]" | grep "#{contents_pattern}"`.split("n").map { |r| r.sub(/^+[st]*/, '') }
        if $? == 0
          # Add the relevant change with line number to the spec_hits array
          results.each{ |r|
            spec_hits.push "#{filename}:" + `grep -n '#{r}' #{filename}`.sub(/:s+/, ' ').chomp
          }
        end
      end
    end
  end
end

if spec_hits.any?
  puts "e[33m>>> Please remove the following problems from these files before committinge[0m"
  puts spec_hits.join("n")
end

exit 1 if spec_hits.any?</code></pre>
<p><a href="https://gist.github.com/ideasasylum/5112128">Download the Gist</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/02/preventing-the-stupid-mistakes-like-committing-focustrue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to backup a Linux server with Tarsnap</title>
		<link>http://jamie.ideasasylum.com/2013/02/how-to-backup-a-linux-server-with-tarsnap/</link>
		<comments>http://jamie.ideasasylum.com/2013/02/how-to-backup-a-linux-server-with-tarsnap/#comments</comments>
		<pubDate>Fri, 01 Feb 2013 22:16:19 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Useful]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[tarsnap]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1484</guid>
		<description><![CDATA[I picked up a dedicated server just before Christmas from OVH. It&#8217;s a nice little &#8216;Kimsufi&#8217; 4GB Atom server which is more than enough for a couple of WordPress blogs and some personal projects. As it&#8217;s a bare-bones dedicated server I really want a decent backup service to make sure I don&#8217;t lose 11years of [...]]]></description>
				<content:encoded><![CDATA[<p>I picked up a dedicated server just before Christmas from OVH. It&#8217;s a nice little <a href="http://www.ovh.ie/dedicated_servers/kimsufi.xml">&#8216;Kimsufi&#8217; 4GB Atom server</a> which is more than enough for a couple of WordPress blogs and some personal projects. As it&#8217;s a bare-bones dedicated server I really want a decent backup service to make sure I don&#8217;t lose 11years of blog posts. The ideal solution is to store those backups in a cloud service like Amazon.</p>
<p>I asked for suggestions twitter and <a href="http://twitter.com/conoro">Conor</a> suggested <a href="http://duplicity.nongnu.org/">Duplicity</a>. It looks like a good solution but it did mean I&#8217;d have to remember my AWS account details (I think I have three account, with two different email addresses). Then <a href="http://twitter.com/atomicules">Simon</a> suggested <a href="https://www.tarsnap.com/">Tarsnap</a>, which I had bookmarked months ago but I wasn&#8217;t sure how complicate the &#8220;paranoid security&#8221; would make it. Actually, Tarsnap is much simpler because it uses Amazon S3 in the backend but it doesn&#8217;t require you to manage it.</p>
<h2>Tarsnap</h2>
<h3>Install Tarsnap</h3>
<p>I install and use Tarsnap as root so that it has access to all files on the server</p>
<pre><code>wget https://www.tarsnap.com/download/tarsnap-autoconf-1.0.33.tgz
apt-get install libssl-dev zlib1g-dev e2fslibs-dev
tar xzvf tarsnap-autoconf-1.0.33.tgz 
cd tarsnap-autoconf-1.0.33/
./configure 
make all install clean
</code></pre>
<h3>Configure Tarsnap</h3>
<pre><code>tarsnap-keygen --keyfile /root/tarsnap.key --user jamie@ideasasylum.com --machine ovh
mv /usr/local/etc/tarsnap.conf.sample /usr/local/etc/tarsnap.conf
vi /usr/local/etc/tarsnap.conf  
</code></pre>
<p>You don&#8217;t actually need to change any options in tarsnap.conf but double-check it anyway</p>
<h3>Create a backup</h3>
<pre><code>tarsnap -c -f my_backup_name my_important_directory
</code></pre>
<h3>List the backups</h3>
<pre><code>tarsnap --list-archives
</code></pre>
<h3>View the files in a backup</h3>
<pre><code>tarsnap -t -f my_backup_name
</code></pre>
<h2>Automating the Backups</h2>
<p>Well, that&#8217;s Tarsnap setup and working but I really want something automated. Enter <a href="https://github.com/Gestas/Tarsnap-generations">this delicious little script</a> which manages the Tarsnap backup process for you. Install the script as <code>root</code>:</p>
<h3>Install Tarsnap Generations</h3>
<pre><code>wget https://raw.github.com/Gestas/Tarsnap-generations/master/tarsnap-generations.sh
chmod ug+x tarsnap-generations.sh     
</code></pre>
<h3>Configure it</h3>
<p>Create a file with newline-seperated list of the folder you wish to backup (for me, that&#8217;s <code>/srv/www</code> and <code>/etc/nginx</code>)</p>
<pre><code>vi /root/tarsnap.folders
</code></pre>
<p>Now we need to setup cron</p>
<pre><code>crontab -e
</code></pre>
<p>and add the line</p>
<pre><code>30 23 * * * /root/tarsnap-generations.sh -f /root/tarsnap.folders -h 1 -d 10 -w 4 -m 12
</code></pre>
<p>This will run the backup process at 2330hrs every day, keep 10 daily backups, 4 weekly backups and 12 monthly backups.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/02/how-to-backup-a-linux-server-with-tarsnap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Curing the SAD</title>
		<link>http://jamie.ideasasylum.com/2013/01/sad/</link>
		<comments>http://jamie.ideasasylum.com/2013/01/sad/#comments</comments>
		<pubDate>Sat, 26 Jan 2013 18:06:23 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[depression]]></category>
		<category><![CDATA[health]]></category>
		<category><![CDATA[light]]></category>
		<category><![CDATA[sad]]></category>
		<category><![CDATA[seasonal affected disorder]]></category>
		<category><![CDATA[vitamins]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1469</guid>
		<description><![CDATA[About 2.5weeks ago I was ridiculously sleepy in the middle of the day, couldn&#8217;t think and was basically wiped out. It was like having the flu only without the fever or any actual sickness. I eventually realised that a lot of the symptoms pointed to Seasonal Affected Disorder. Yes folks, I haz the sad. After [...]]]></description>
				<content:encoded><![CDATA[<p>About 2.5weeks ago I was ridiculously sleepy in the middle of the day, couldn&#8217;t think and was basically wiped out. It was like having the flu only without the fever or any actual sickness. I eventually realised that a lot of the symptoms pointed to Seasonal Affected Disorder. Yes folks, I haz the sad.</p>
<p>After lots of great advice from my twitter friends, I tried two things: Berocca and an SAD light.</p>
<h2>Berocca</h2>
<p><img src="http://www.berocca.ie/static/media/images/upload/pack_performance.png" width="208" height="68" alt="Berocca Performance" class="alignleft size-medium wp-image-1470" /><a href="http://www.berocca.ie/en/home.php">Berocca</a> is basically Vitamin B, Vitamin C, magnesium, calcium, and zinc wrapped up in a little effervescent tablet which makes a passable orange drink. I think that without a doubt the Berocca has a <strong>huge</strong> effect on my mood and energy levels. I&#8217;ve been giggling for no apparent reason in the mornings and I&#8217;m much happier despite suffering through a cold this week. Highly recommended!</p>
<h2>Lumie Brightspark</h2>
<p><img src="http://cdn.shopify.com/s/files/1/0165/5660/products/Brightspark1_1024x1024.jpg?574" width="300" height="300" class="alignleft" />I bought a reconditioned <a href="http://www.lumie.com/collections/light-therapy-sad/products/brightspark">Lumie Brightspark</a> which has a fairly large light area but doesn&#8217;t take up much space on the desk because it stands vertically. First thing: this thing is <em>bright!</em>. It&#8217;s bright enough to scare little children <img src='http://jamie.ideasasylum.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  <img src="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/2013-01-16_1358359077-300x300.jpg" alt="2013-01-16_1358359077" width="300" height="300" class="alignright size-medium wp-image-1473" /></p>
<p>It&#8217;s bright enough that when you turn it on, it drowns out all other light sources including the main room light, an uplighter and the ambient window light… and that&#8217;s a problem. Although it is giving me the daylight I need for my brain to say &#8220;Morning! Time to wake up and hunt something!&#8221; it is highly reminiscent of coding at 2am by the singular glow of a desklamp.</p>
<p>Initially I had the lamp positioned in front of me at a 45° angle but this cast really strong shadows across the desk &amp; laptop. Then I moved it to be at a 90° angle to the laptop and just within my peripheral vision. This was much better although I noticed I&#8217;d subconsciously try to shield my eyes from it after a hour or so. One other thing: it&#8217;s worth turning up the brightness of your monitor to match to brightness of the lamp otherwise it&#8217;s like peering inside on a sunny day.</p>
<p>My next idea was to try to balance the light in the room (perhaps it&#8217;s because I&#8217;m a photographer but having the single light source and shadows began to annoy me). So I switched my office space around so the desk was facing the window. It&#8217;s not the brightest window (North-facing, in Ireland) but having the window at 45° left and the lamp at 45° right really helps to balance everything. The lamp is also now 6&#8243; above the desk so it throws more light down on the desk.<img src="http://jamie.ideasasylum.com/wordpress/wp-content/uploads/IMG_3979-300x300.jpg" alt="IMG_3979" width="300" height="300" class="alignleft size-medium wp-image-1470" /></p>
<p>It might sound like I&#8217;m a little disappointed by the lamp. I&#8217;m not. If I&#8217;ve been using it for a short while, I&#8217;m really reluctant to switch it off; and if I leave the room I feel like the landing is the deepest darkest cave in comparison (it has a skylight!). I feel an instant lift when I walk back into the office to the bright white light. It sounds daft and hippyish but I definitely feel happier with the light on. I&#8217;m not sure if the effects carry on through the rest of the day but I&#8217;ll definitely continue using it.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/01/sad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Picks of the week: Papertrail, rack-ssl-enforcer, WP-Markdown and Marked</title>
		<link>http://jamie.ideasasylum.com/2013/01/picks-of-the-week-papertrail-rack-ssl-enforcer-wp-markdown-and-marked/</link>
		<comments>http://jamie.ideasasylum.com/2013/01/picks-of-the-week-papertrail-rack-ssl-enforcer-wp-markdown-and-marked/#comments</comments>
		<pubDate>Mon, 21 Jan 2013 14:02:32 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Weekly Picks]]></category>
		<category><![CDATA[markdown]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1466</guid>
		<description><![CDATA[I recently set up PaperTrail on our production server and it’s extremely useful. It basically uploads the log files you configure, aggregates them and let’s you search them. That’s useful but what’s blow-me-away amazing is setting up saved searches and alerts. Now I can easily be notified when a particular user logs it, or when [...]]]></description>
				<content:encoded><![CDATA[<p>I recently set up <a href="http://papertrailapp.com">PaperTrail</a> on our production server and it’s extremely useful. It basically uploads the log files you configure, aggregates them and let’s you search them. That’s useful but what’s blow-me-away amazing is setting up saved searches and alerts. Now I can easily be notified when a particular user logs it, or when a particular action occurs, and all without needing to introduce specific code into my application. I’m very impressed so far.</p>
<p>I used <a href="https://github.com/tobmatth/rack-ssl-enforcer">rack-ssl-enforcer</a> to redirect all insecure connections over to the secure HTTPS versions, and it worked well. If you’re a Vagrant user, it has the advantage over the built-in Rails support because you can configure the secure and insecure ports.</p>
<p>And I’ve now stated writing all my blog posts in Markdown formatting. The <a href="http://wordpress.org/extend/plugins/wp-markdown/">WP-Markdown</a> plugin for WordPress lets you write plain Markdown in the Compose editor, renders this to HTML as a preview below (like Stackoverflow), and—most importantly—it saves both the markdown text and the rendered HTML. This means that you can disable the plugin and the rendered blog post will remain the same. It also has really good syntax highlighting support that makes writing technical posts a more pleasant experience.</p>
<p>Lastly, there’s <a href="http://markedapp.com">Marked</a>. If you find the WordPress editor a little restrictive for editing and prefer writing in your favourite text editor / writing tool (e.g. <a href="http://www.iawriter.com/">iAWriter</a> / <a href="http://bywordapp.com/">Byword</a>, then Marked if the perfect companion application. It monitors a markdown file and renders a preview (using a variety of styles) and lets you export the results as HTML, PDF etc. It’s a small thing but I found it useful</p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/01/picks-of-the-week-papertrail-rack-ssl-enforcer-wp-markdown-and-marked/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing your web application with Nginx, Rails 3 and Namecheap SSL certs</title>
		<link>http://jamie.ideasasylum.com/2013/01/securing-your-web-application-with-nginx-rails-3-and-namecheap-ssl-certs/</link>
		<comments>http://jamie.ideasasylum.com/2013/01/securing-your-web-application-with-nginx-rails-3-and-namecheap-ssl-certs/#comments</comments>
		<pubDate>Thu, 17 Jan 2013 16:53:46 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[namecheap]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rack-ssl-enforcer]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[vagrant]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1458</guid>
		<description><![CDATA[Securing your web application with an SSL certificate is the least your users will expect you to do. Once upon a time, HTTPS sites were rare and even then, only the &#8220;private&#8221; parts beyond a login dialog were encrypted. Those times died with Netscape and they aren&#8217;t coming back. Here I&#8217;ll show you how to [...]]]></description>
				<content:encoded><![CDATA[<p>Securing your web application with an SSL certificate is the least your users will expect you to do. Once upon a time, HTTPS sites were rare and even then, only the &#8220;private&#8221; parts beyond a login dialog were encrypted. Those times died with Netscape and they aren&#8217;t coming back.</p>
<p>Here I&#8217;ll show you how to secure your Rails 3 application, running on Nginx, with a NameCheap SSL certificate. The requirements of this application are:</p>
<ul>
<li>Must use HTTPS with a valid SSL certificate</li>
<li>All insecure HTTP links must redirect to their HTTPS versions</li>
<li>It must work across multiple subdomains (e.g. mycompany.yourdomain.com)</li>
<li>The marketing site running at www.yourdomain.com and yourdomain.com will not use HTTPS</li>
</ul>
<p>We&#8217;ll be using Nginx on Ubuntu 12.04, Vagrant, Rails 3.2.11, rack-ssl-enforcer and <a href="http://www.namecheap.com/?aff=44226">NameCheap</a></p>
<h2>In Development</h2>
<h3>Configuring Vagrant</h3>
<p>The first step is to make things work locally in our development environment. I&#8217;m using Vagrant here which has made my choices slightly different but if you&#8217;re developing locally on Mac OS X, then this <a href="http://railscasts.com/episodes/357-adding-ssl">Railscast</a> will be very useful to you. In my Vagrantfile I have</p>
<pre><code>config.vm.forward_port 80, 8080                   # http
</code></pre>
<p>So, if I go to <code>mycompany.lvh.me:8080</code> on my browser, I&#8217;ll be hitting the nginx instance running inside Vagrant (lvh.me is just a short wildcard domain name which points to 127.0.0.1 — essential for testing subdomains locally). We need to update Vagrant to forward the HTTPS traffic too.</p>
<pre><code>config.vm.forward_port 80, 8080                   # http
config.vm.forward_port 443, 8081                  # https
</code></pre>
<p>Now, restart our Vagrant instance and the local 8081 port will forward to the 443 port on the virtual machine. Easy.</p>
<h3>Configuring Nginx</h3>
<p>Now we need to configure our Nginx server to listen for HTTPS traffic on port 443. My simplified nginx.conf file looks like this (I&#8217;ve remove the basic http server instance for clarity but it&#8217;s basically the same as the https server)</p>
<pre><code>gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/html text/xml text/css text/comma-separated-values text/javascript application/x-javascript application/atom+xml;

# this can be any application server, not just Unicorn/Rainbows!
upstream app_server {
  # for UNIX domain socket setups:
  server unix:/tmp/unicorn.cognito.sock fail_timeout=0;
}
server {
  listen 443 default deferred ssl; # for Linux

  client_max_body_size 4G;
  server_name _;

  keepalive_timeout 5;

  root /vagrant/public;
  try_files $uri/index.html $uri.html $uri @app;

  ssl                  on;
  ssl_certificate      /vagrant/server.crt;
  ssl_certificate_key  /vagrant/server.key;

  ssl_session_timeout  5m;

  ssl_protocols  SSLv2 SSLv3 TLSv1;
  ssl_ciphers  HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers   on;

  location @app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app_server;
  }

  # Rails error pages
  error_page 500 502 503 504 /500.html;
  location = /500.html {
    root /vagrant/public;
  }
}
</code></pre>
<p>}</p>
<p>The most important lines to consider here are:</p>
<pre><code>ssl                  on;
ssl_certificate      /vagrant/server.crt;
ssl_certificate_key  /vagrant/server.key;

ssl_session_timeout  5m;

ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers   on;
</code></pre>
<p>which turns SSL on, points Nginx to the certificate and key files (more about that next) and configures the ssl options. We also need to set this line:</p>
<pre><code>proxy_set_header X-Forwarded-Proto $scheme;
</code></pre>
<p>so that http->https redirects will work correctly.</p>
<p>Finally, test that your configuration is valid and restart your nginx server</p>
<pre><code>sudo nginx -t
sudo service nginx restart
</code></pre>
<h3>Creating a Self-Signed Certificate</h3>
<p>You&#8217;ll have noticed the <code>server.key</code> and <code>server.crt</code> in nginx.conf. We need to create those</p>
<p>First, create a Certificate Signing Request:</p>
<pre><code>openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
</code></pre>
<p>Answer the questions with anything you like.</p>
<p>Next, use the .csr to generate a self-signed certificate:</p>
<pre><code>openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
</code></pre>
<p>That should give you your <code>server.key</code> and <code>server.crt</code> file. Copy them to an appropriate location as specified in your nginx.conf</p>
<h3>Configuring Rails</h3>
<p>In the simplest case, you can configure Rails to redirect all links to https using this option:</p>
<pre><code>config.force_ssl = true
</code></pre>
<p>This works fine in most cases but remember that our local http and https ports are 8080 and 8081 respectively. Rails doesn&#8217;t have the ability to specify custom HTTPS ports so I&#8217;ve used <a href="https://github.com/tobmatth/rack-ssl-enforcer">rack-ssl-enforcer</a> to do the same job. Place this in development.rb:</p>
<pre><code># Redirect all HTTP links to use HTTPS
config.middleware.use Rack::SslEnforcer, :http_port =&gt; 8080,
                                         :https_port =&gt; 8081,
                                         :hsts =&gt; true
</code></pre>
<p>That <code>hsts</code> option refers to <a href="http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security">HTTP Strict Transport Security</a> which is a method of using HTTP header to force the client to use a secure connection. <code>hsts</code> is enabled by default with Rails&#8217; force_ssl option but not with rack-ssl-enforcer.</p>
<p>Just a word about HSTS: It instructs the browser to always use a secure connection when visiting URLs at your domain. I was initially worried that using HSTS on a subdomain like mycompany.yourdomain.com would also force HTTPS on the naked domain which is just running the marketing site. Thankfully it does not. It operates on the level of the full domain name</p>
<p>Now, restart your Rails application and visiting an insecure URL like <code>http://mycompany.lvh.me:8080</code> should redirect you to <code>https://mycompany.lvh.me:8081</code>. The browser will display a scary warning about not trusting the certificate but that&#8217;s only because it&#8217;s self-signed.</p>
<h2>In Production</h2>
<p>Hopefully your development and production environments are similar enough that you can reuse the nginx.conf etc. In production.rb, there&#8217;s no need to specify the port for rack-ssl-enforcer though:</p>
<pre><code># Redirect all HTTP links to use HTTPS
config.middleware.use Rack::SslEnforcer, :hsts =&gt; true
</code></pre>
<h3>Obtaining your SSL Certificate</h3>
<p>I used <a href="http://www.namecheap.com/?aff=44226">NameCheap</a> because they sell a good (bewildering) selection of certificates, at a decent price, and I was quite impressed with their support staff (prompt, friendly, efficient and knowledgable).</p>
<p>I bought the <a href="http://www.namecheap.com/ssl-certificates/comodo/essential-ssl-wildcard-certificate.aspx?aff=44226">Comodo Essential SSL Wildcard</a> for $99 which is a pretty good deal compared to other suppliers. Your own requirements may vary but this worked for me.</p>
<p><strong>Before your start</strong>, make sure that you don&#8217;t have any privacy protection on your WHOIS domain information. This certificate is &#8220;domain validated&#8221; which means that they need to send an email to an address associated with the domain. Check with a WHOIS server or your domain registrar that a valid email address is publicly available and associated with your domain. Not doing this slowed up our purchase by a few days.</p>
<p>NameCheap uses a two-step purchasing process so you can buy the SSL cert with just the basic details and then activate it later using the information below.</p>
<p>On our server, we need to generate a Certificate Signing Request (just like we did with our self-signed key)</p>
<pre><code>openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
</code></pre>
<p>Fill in the details properly this time and use <code>*.yourdomain.com</code> as the Common Name value. It is very important to specify a wildcard domain here if you want it!</p>
<p><a href="https://manage.www.namecheap.com/myaccount/ssl-list.asp?from=listingleftnav">Activate your SSL certificate</a> by selecting <code>Apache + OpenSSL</code> and pasting in the contents of your server.csr (<em>not</em> your development one!)</p>
<p>Now select an email address to send the confirmation to. You can choose from either a predefined address (admin/administrator/postmaster/webmaster@yourdomain.com) or the address found in the domain&#8217;s WHOIS information. <strong>You cannot send this confirmation to any arbitrary address!</strong></p>
<p>Once you receive the email, paste the supplied code into the form at the url they give you and you should receive two emails shortly afterwards. One contains the &#8220;site seal&#8221; — a useless graphic designed only to promote the certificate authourity — and a zip file containing the certificates. Yes, multiple certificates.</p>
<p>Now, the tricky bit. You need to concatenate the certificate files together in the following order to form the certificate chain:</p>
<ol>
<li>Your certificate (STAR&#95;yourdomain&#95;com.crt)</li>
<li>EssentialSSLCA_2.crt</li>
<li>ComodoUTNSGCCA.crt</li>
<li>UTNAddTrustSGCCA.crt</li>
<li>AddTrustExternalCARoot.crt</li>
</ol>
<p>The easiest way to do this on Linux is</p>
<pre><code>unzip STAR_yourdomain_com.zip

cat STAR_yourdomain_com.crt EssentialSSLCA_2.crt ComodoUTNSGCCA.crt UTNAddTrustSGCCA.crt AddTrustExternalCARoot.crt &gt; yourdomain.com.crt
</code></pre>
<p>Now, put the resulting certificate <code>yourdomain.com.crt</code> and the <code>server.key</code> used to generate the CSR into a safe place.</p>
<pre><code>sudo mkdir /etc/nginx/certs
sudo cp server.key /etc/nginx/certs
sudo cp yourdomain.com.crt /etc/nginx/certs
</code></pre>
<p>In your production <code>nginx.conf</code>, use the paths <code>/etc/nginx/certs/server.key</code> and <code>/etc/nginx/certs/yourdomain.com.crt</code> for the key and certificate values respectively.</p>
<p>Restart your nginx server and you should be good to go!</p>
<p>Comodo has <a href="https://support.comodo.com/index.php?_m=knowledgebase&amp;_a=viewarticle&amp;kbarticleid=1365">some basic documentation on installing their certs on Nginx</a></p>
<h2>Bonus Points</h2>
<p><strong>Remember to add a reminder to your calendar to renew the certificate in a year!</strong> If the certificate expires then your customers will be presented with scary-looking warnings in their browser.</p>
<p>Extra bonus points if your write all this down because I guarantee you will not remember the process next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/01/securing-your-web-application-with-nginx-rails-3-and-namecheap-ssl-certs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making Apartment &amp; Delayed_Job play nicely</title>
		<link>http://jamie.ideasasylum.com/2013/01/making-apartment-delayed_job-play-nicely/</link>
		<comments>http://jamie.ideasasylum.com/2013/01/making-apartment-delayed_job-play-nicely/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 16:30:26 +0000</pubDate>
		<dc:creator>Jamie Lawrence</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apartment]]></category>
		<category><![CDATA[delayed_job]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jamie.ideasasylum.com/?p=1454</guid>
		<description><![CDATA[Background Delayed Job is a popular gem for running background tasks on Rails applications. Apartment is another useful gem for switching Postgresql schemas in response to particular subdomains (it means that visiting ibm.myapp.com will automatically switch to the &#8216;ibm&#8217; schema and select * from user will only return IBM users). What&#8217;s the problem? Getting these two [...]]]></description>
				<content:encoded><![CDATA[<h2>Background</h2>
<p><a title="Delayed Job on Github" href="https://github.com/collectiveidea/delayed_job" target="_blank">Delayed Job</a> is a popular gem for running background tasks on Rails applications. <a title="Apartment gem on Github" href="https://github.com/influitive/apartment" target="_blank">Apartment</a> is another useful gem for switching Postgresql schemas in response to particular subdomains (it means that visiting ibm.myapp.com will automatically switch to the &#8216;ibm&#8217; schema and select * from user will only return IBM users).</p>
<h2>What&#8217;s the problem?</h2>
<p>Getting these two gems to play well together can be a little difficult because DelayedJob  has no idea how to handle postgres schemas. In a nutshell, DelayedJob serialises the job and parameters as a YAML string in the database column. However, if one of these parameters (or the job) is an ActiveRecord object it will try to reload this from the database… but it will fall over because those objects are not in the same schema as the <code>delayed_jobs</code> table.</p>
<p>Luckily the Apartment gem has instructions for configuring it to work with DelayedJob. These instructions persist a new <code>database</code> attribute which is then used to switch schemas inside a DelayedJob hook. Unfortunately, it does require using the <code>syck</code> YAML parser and whilst this worked for me in development, I couldn&#8217;t get it working in production. Also, the default parser in Ruby 1.9.3 is <a title="Psych YAML parser on Github" href="https://github.com/tenderlove/psych" target="_blank">Psych</a> and I&#8217;d really rather keep it that way.</p>
<h2>What&#8217;s a possible the solution?</h2>
<p>You could spend a while trying to patch the Psych parser so that it will switch schema automatically as it is reconstructing the ActiveRecord objects from the database. Unfortunately, I wasn&#8217;t able to make this work reliably and it made me feel all icky anyway. But it did make me question why we were even persisting AR object inside a delayed_job…</p>
<h2>So, what&#8217;s the actual solution?</h2>
<p><strong>Don&#8217;t use ActiveRecord parameters in DelayedJobs.</strong></p>
<p>Just pass in basic scalar types (integer, strings, etc) and arrays, and  use these to search for the correct ActiveRecord. It all works considerably easier this way and is much simpler to understand. To be honest, this seems like good practice anyway and I&#8217;d prefer if DelayedJob didn&#8217;t try to serialise AR records at all. I still use the DelayedJob hooks provided by Apartment to automatically switch database schemas before and after job invocation though because <a href="https://github.com/influitive/apartment/blob/development/lib/apartment/delayed_job/hooks.rb" target="_blank">they are simple</a> and reliable.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamie.ideasasylum.com/2013/01/making-apartment-delayed_job-play-nicely/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
