<?xml version='1.0' encoding='utf-8' ?>
<feed xmlns='http://www.w3.org/2005/Atom'>
  <title type='text'>Mocoso</title>
  <generator uri='http://effectif.com/nesta'>Nesta</generator>
  <id>tag:blog.mocoso.co.uk,2009:/</id>
  <link href='http://blog.mocoso.co.uk/articles.xml' rel='self' />
  <link href='http://blog.mocoso.co.uk' rel='alternate' />
  <subtitle type='text'>Joel Chippindale's occasional blog.</subtitle>
  <updated>2011-11-27T12:15:14+00:00</updated>
  <author>
    <name>Joel Chippindale</name>
    <uri>http://blog.mocoso.co.uk</uri>
  </author>
  <entry>
    <title>Vagrant bundler tools</title>
    <link href='http://blog.mocoso.co.uk/vagrant-bundler-tools' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2011-11-27:/vagrant-bundler-tools</id>
    <content type='html'>
            &lt;p&gt;We've been experimenting with using vagrant for to develop on Ubuntu virtual box instances running under OSX.&lt;/p&gt;
            
            &lt;p&gt;One of the things that bugged me about this was not being able open the bundled gem in Textmate by simply typing&lt;/p&gt;
            
            &lt;pre&gt;&lt;code&gt;bundle open &amp;lt;GEM_NAME&amp;gt;&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
            
            &lt;p&gt;Vagrant supports plugins so I've written one to solve this problem.&lt;/p&gt;
            
            &lt;h2&gt;Install&lt;/h2&gt;
            
            &lt;pre&gt;&lt;code&gt;gem install vagrant-bundler-tools&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
            
            &lt;h2&gt;Use&lt;/h2&gt;
            
            &lt;p&gt;It currently support bundler's &lt;em&gt;list&lt;/em&gt;, &lt;em&gt;show&lt;/em&gt; and &lt;em&gt;open&lt;/em&gt; commands. Simply prefix these commands with &lt;em&gt;vagrant&lt;/em&gt; to have them access the gems on your vagrant guest.&lt;/p&gt;
            
            &lt;pre&gt;&lt;code&gt;vagrant bundle list&amp;#x000A;vagrant bundle show &amp;lt;GEM_NAME&amp;gt;&amp;#x000A;vagrant bundle open &amp;lt;GEM_NAME&amp;gt;&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
            
            &lt;h2&gt;The code&lt;/h2&gt;
            
            &lt;p&gt;The code is &lt;a href=&quot;https://github.com/mocoso/vagrant-bundler-tools&quot;&gt;hosted on Github&lt;/a&gt;.&lt;/p&gt;
          </content>
    <published>2011-11-27T12:15:14+00:00</published>
    <updated>2011-11-27T12:15:14+00:00</updated>
  </entry>
  <entry>
    <title>Floating point arithmetic is going to kill you</title>
    <link href='http://blog.mocoso.co.uk/ruby-floats-are-going-to-let-you-down' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2010-10-30:/ruby-floats-are-going-to-let-you-down</id>
    <content type='html'>
              &lt;p&gt;We all &lt;em&gt;know&lt;/em&gt; that floating point arithmetic is imprecise but most of us pretend this isn't a problem until it reaches out and bites us.&lt;/p&gt;
              
              &lt;p&gt;I was using Ruby &lt;a href=&quot;http://ruby-doc.org/core/classes/Float.html&quot;&gt;Float&lt;/a&gt; to calculate &lt;a href=&quot;http://en.wikipedia.org/wiki/Value_added_tax&quot;&gt;VAT&lt;/a&gt; and, predictably, got bitten. The good news is that there is a simple solution.&lt;/p&gt;
              
              &lt;!--more--&gt;
              
              
              &lt;h2&gt;The problem&lt;/h2&gt;
              
              &lt;p&gt;The VAT rate in the UK is 17.5% (in Oct 2010) and so if we fire up the irb we can multiple by 0.175 (a Float in Ruby) to work out how much VAT to charge (in pence) on &amp;pound;105.00 as follows&lt;/p&gt;
              
              &lt;pre&gt;&lt;code&gt;&amp;gt; 10500 * 0.175&amp;#x000A;=&amp;gt; 1837.5&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
              
              &lt;p&gt;This all looks good, however we want to charge a whole number of pence and so let's do it again rounding the result to the nearest integer&lt;/p&gt;
              
              &lt;pre&gt;&lt;code&gt;&amp;gt; (10500 * 0.175).round&amp;#x000A;=&amp;gt; 1837&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
              
              &lt;p&gt;But wait 1837.5 should round up to 1838 shouldn't it?&lt;/p&gt;
              
              &lt;pre&gt;&lt;code&gt;&amp;gt; 10500 * 0.175&amp;#x000A;=&amp;gt; 1837.5&amp;#x000A;&amp;gt; (1837.5).round&amp;#x000A;=&amp;gt; 1838&amp;#x000A;&amp;gt; (10500 * 0.175).round&amp;#x000A;=&amp;gt; 1837&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
              
              &lt;p&gt;WTF! Lets look a little closer.&lt;/p&gt;
              
              &lt;pre&gt;&lt;code&gt;&amp;gt; 10500 * 0.175 == 1837.5&amp;#x000A;=&amp;gt; false&amp;#x000A;&amp;gt; sprintf('%.50f', 1837.5)&amp;#x000A;=&amp;gt; &quot;1837.50000000000000000000000000000000000000000000000000&quot;&amp;#x000A;&amp;gt; sprintf('%.50f', 10500 * 0.175)&amp;#x000A;=&amp;gt; &quot;1837.49999999999977262632455676794052124023437500000000&quot;&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
              
              &lt;p&gt;Aargh! So near and yet so far&lt;/p&gt;
              
              &lt;h2&gt;The solution&lt;/h2&gt;
              
              &lt;p&gt;Ruby has a neat solution for this.&lt;/p&gt;
              
              &lt;p&gt;Use a &lt;a href=&quot;http://ruby-doc.org/core/classes/Rational.html&quot;&gt;Rational&lt;/a&gt; instead of a Float to represent the percentage and get back to being precise.&lt;/p&gt;
              
              &lt;pre&gt;&lt;code&gt;&amp;gt; 10500 * Rational(175, 1000)&amp;#x000A;=&amp;gt; Rational(3675, 2)&amp;#x000A;&amp;gt; 10500 * Rational(175, 1000) == 1837.5&amp;#x000A;=&amp;gt; true&amp;#x000A;&amp;gt; sprintf('%.50f', 10500 * Rational(175, 1000))&amp;#x000A;=&amp;gt; &quot;1837.50000000000000000000000000000000000000000000000000&quot;&amp;#x000A;&amp;gt; (10500 * Rational(175, 1000)).round&amp;#x000A;=&amp;gt; 1838&amp;#x000A;&lt;/code&gt;&lt;/pre&gt;
              
              &lt;p&gt;Phew, all is well with the world again.&lt;/p&gt;
              
              &lt;p&gt;Now we can reliably use Ruby to calculate that 17.5% VAT on &amp;pound;105 is &amp;pound;18.38.&lt;/p&gt;
              
              &lt;p&gt;Thanks go to &lt;a href=&quot;http://twitter.com/tomstuart&quot;&gt;Tom&lt;/a&gt; for unravelling this knotted ball of string.&lt;/p&gt;
            </content>
    <published>2010-10-30T08:06:21+00:00</published>
    <updated>2010-10-30T08:06:21+00:00</updated>
  </entry>
  <entry>
    <title>Delete/put links break your Rails app</title>
    <link href='http://blog.mocoso.co.uk/deleteput-links-break-your-rails-app' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2009-12-12:/deleteput-links-break-your-rails-app</id>
    <content type='html'>
                &lt;p&gt;In Rails you can easily use the link_to helper in your templates to create links that will generate HTTP POST, PUT and DELETE requests when clicked. You can do this using simply setting the &lt;tt&gt;:method&lt;/tt&gt; option, but this ease of use hides a very real problem.&lt;/p&gt;
                
                &lt;h2&gt;The problem&lt;/h2&gt;
                
                &lt;p&gt;These links only work for users with javascript enabled.&lt;/p&gt;
                
                &lt;p&gt;Visitors without javascript enabled the links will actually take them to the show action of your controller (or a 404 if you con't have a show action), which won't be what you or they expect.&lt;/p&gt;
                
                &lt;p&gt;It's easy not to notice this behaviour since mostly you test your app with javascript enabled.&lt;/p&gt;
                
                &lt;p&gt;For example:&lt;/p&gt;
                
                &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;link_to &quot;Delete Image&quot;, @image, :method =&gt; :delete&lt;/code&gt;&lt;/pre&gt;
                
                
                &lt;p&gt;Generates&lt;/p&gt;
                
                &lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;a href=&quot;/images/9&quot; onclick=&quot;var f = document.createElement('form');&amp;#x000A;  f.style.display = 'none';&amp;#x000A;  this.parentNode.appendChild(f);&amp;#x000A;  f.method = 'POST';&amp;#x000A;  f.action = this.href;&amp;#x000A;  var m = document.createElement('input');&amp;#x000A;  m.setAttribute('type', 'hidden');&amp;#x000A;  m.setAttribute('name', '_method');&amp;#x000A;  m.setAttribute('value', 'delete');&amp;#x000A;  f.appendChild(m);f.submit();return false;&quot;&gt;Delete Image&amp;lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;
                
                
                &lt;p&gt;Take note of all the javascript gymnastics to make this work.&lt;/p&gt;
                
                &lt;h2&gt;The solution&lt;/h2&gt;
                
                &lt;p&gt;The easy fix is to use the button_to helper instead.&lt;/p&gt;
                
                &lt;p&gt;For example:&lt;/p&gt;
                
                &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;button_to &quot;Delete Image&quot;, @image, :method =&gt; :delete&lt;/code&gt;&lt;/pre&gt;
                
                
                &lt;p&gt;Generates&lt;/p&gt;
                
                &lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;form method=&quot;post&quot; action=&quot;/images/9&quot; class=&quot;button-to&quot;&gt;&amp;#x000A;  &amp;lt;input name=&quot;_method&quot; type=&quot;hidden&quot; value=&quot;put&quot; /&gt;&amp;#x000A;  &amp;lt;input type=&quot;submit&quot; value=&quot;Delete Image&quot; /&gt;&amp;#x000A;&amp;lt;/form&gt;&lt;/code&gt;&lt;/pre&gt;
                
                
                &lt;p&gt;A nice little submit button with no javascript and no pain.&lt;/p&gt;
                
                &lt;p&gt;This may even be a better user experience for all your users (with or without javascript) because the button will indicate to them that they are making a change (either updating or deleting something) rather than just visiting a link.&lt;/p&gt;
                
                &lt;h2&gt;The solution (part II)&lt;/h2&gt;
                
                &lt;p&gt;Of course perhaps you used the link_to helper because you wanted it to look like a standard link on the page (rather than a submit button).&lt;/p&gt;
                
                &lt;p&gt;One possible solution would be to use CSS but it's actually very difficult to use CSS to make a submit button look exactly like (rather than just similar to) your other links across a range of browsers.&lt;/p&gt;
                
                &lt;p&gt;Another is to use javascript to replace the form generated by the button_to helper with a link. Then javascript enabled visitors will see a link just like if you had used the link_to helper, and visitors without javascript enabled will see a button.&lt;/p&gt;
                
                &lt;p&gt;If you are using jQuery then this can be achieved by adding the following javascript to your site.&lt;/p&gt;
                
                &lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;jQuery.fn.convert_submit_button_to_link = function () {&amp;#x000A;  this.each( function () {&amp;#x000A;    var button = jQuery(this);&amp;#x000A;    button.&amp;#x000A;      hide().&amp;#x000A;      after(jQuery('&amp;lt;a href=&quot;#&quot;&gt;' + button.attr('value') + '&amp;lt;/a&gt;').attr('class', button.attr('class')).click(button.attr('onclick')));&amp;#x000A;  });&amp;#x000A;  return this;&amp;#x000A;};&amp;#x000A;&amp;#x000A;$(document).ready(function () {&amp;#x000A;  // Convert any input with the class 'submit-link' to a link&amp;#x000A;  $('input.submit-link').convert_submit_button_to_link();&amp;#x000A;};&lt;/code&gt;&lt;/pre&gt;
                
                
                &lt;p&gt;And then any submit button with the class 'submit-link' will be replaced by a link that will submit the form.&lt;/p&gt;
                
                &lt;p&gt;For example the submit button generated by the following would be converted to a link&lt;/p&gt;
                
                &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;button_to &quot;Delete Image&quot;, @image, :method =&gt; :delete, :class =&gt; 'submit-link'&lt;/code&gt;&lt;/pre&gt;
                
                
                &lt;p&gt;So there are no excuses for using link_to for destroy/update actions.&lt;/p&gt;
                
                &lt;p&gt;I will leave it as an exercise for the reader to convert this jQuery specific javascript to your favourite javascript library.&lt;/p&gt;
              </content>
    <published>2009-12-12T07:06:21+00:00</published>
    <updated>2009-12-12T07:06:21+00:00</updated>
  </entry>
  <entry>
    <title>Trigger Integrity builds with a cron job</title>
    <link href='http://blog.mocoso.co.uk/trigger-integrity-builds-of-your-projects-with-cron' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2009-11-27:/trigger-integrity-builds-of-your-projects-with-cron</id>
    <content type='html'>
                  &lt;p&gt;&lt;em&gt;&lt;strong&gt;Updated 21 Dec 2009:&lt;/strong&gt; modified code to work with integrity v. 0.2.9&lt;/em&gt;&lt;/p&gt;
                  
                  &lt;p&gt;&lt;a href=&quot;http://integrityapp.com/&quot;&gt;Integrity&lt;/a&gt; is a great little continuous integration server, even if it is a little rough around the edges.&lt;/p&gt;
                  
                  &lt;p&gt;Out of the box Integrity expects that you will trigger all your builds using &lt;a href=&quot;http://help.github.com/post-receive-hooks/&quot;&gt;github's post receive hooks&lt;/a&gt; - although you need to be aware of &lt;a href=&quot;http://github.com/integrity/integrity/issues#issue/14&quot;&gt;this bug&lt;/a&gt; which means you have to miss the .git of the end of the project's git repository URI when setting this up.&lt;/p&gt;
                  
                  &lt;p&gt;I however prefer to poll my project's repositories for changes so that they do not need to be aware of my Integrity server.&lt;/p&gt;
                  
                  &lt;!--more--&gt;
                  
                  
                  &lt;p&gt;If you are using Integrity v0.2.9 or greater then this can be achieved by adding the following rake task to the Rakefile in your Integrity installation.&lt;/p&gt;
                  
                  &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;desc &quot;Will build the latest commit for any project that has already been built and the latest commit has not already been built&quot;&amp;#x000A;task :build_new_commits do&amp;#x000A;  require &quot;init&quot;&amp;#x000A;  Integrity.log(&quot;Checking for new commits at #{Time.now}&quot;)&amp;#x000A;  Integrity::Project.all.each do |project|&amp;#x000A;    # Don't build if project is just being set up, or a build of 'HEAD' is already outstanding or the latest commit has already&amp;#x000A;    # been built.&amp;#x000A;    unless project.blank? ||&amp;#x000A;        project.last_build.commit.identifier == 'HEAD' ||&amp;#x000A;        (head = Integrity::Repository.new(project.uri, project.branch, 'HEAD').head) == project.last_build.commit.identifier&amp;#x000A;      project.build(head)&amp;#x000A;    end&amp;#x000A;  end&amp;#x000A;end&lt;/code&gt;&lt;/pre&gt;
                  
                  
                  &lt;p&gt;Then set up a cron job by adding the something like the following entry to your crontab. This will to automatically check every 2 minutes to see if there are any outstanding commits of your project to build. You will need to replace the /path/to/ section in each of the paths with appropriate values for your system.&lt;/p&gt;
                  
                  &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;*/2 * * * * cd /path/to/integrity &amp;&amp; /path/to/ruby ./bin/rake build_new_commits &gt;&gt; /path/to/cron.log 2&gt;$&lt;/code&gt;&lt;/pre&gt;
                  
                  
                  &lt;p&gt;Alternatively, if you are using for earlier versions of integrity&lt;/p&gt;
                  
                  &lt;ul&gt;
                  &lt;li&gt;0.2.0 or greater: use this &lt;a href=&quot;http://gist.github.com/261005&quot;&gt;rake task&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;0.1.1 or greater: use &lt;a href=&quot;http://github.com/bkoski/integrity-watcher&quot;&gt;bkoski's integrity-watcher&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
                  
                  
                  &lt;p&gt;Or, if you want to add build triggers to git repositories not on github then take a look at &lt;a href=&quot;http://morethanseven.net/2008/12/28/local-continuous-integration-integrity/&quot;&gt;morethanseven's post commit hook&lt;/a&gt;.&lt;/p&gt;
                </content>
    <published>2009-11-27T13:31:42+00:00</published>
    <updated>2009-11-27T13:31:42+00:00</updated>
  </entry>
  <entry>
    <title>Cucumber screenshot gem</title>
    <link href='http://blog.mocoso.co.uk/cucumber-screenshot-gem' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2009-11-04:/cucumber-screenshot-gem</id>
    <content type='html'>
                    &lt;p&gt;&lt;a href=&quot;http://cukes.info/&quot;&gt;Cucumber&lt;/a&gt; is great for integration testing but when a feature fails for a web application you just get the content of the page spewed out onto the console.&lt;/p&gt;
                    
                    &lt;p&gt;If only you could see a screenshot of the whole web page that produced the failure.&lt;/p&gt;
                    
                    &lt;p&gt;The good news for those of you on OS X is that you can.&lt;/p&gt;
                    
                    &lt;p&gt;Just install my cucumber-screenshot gem.&lt;/p&gt;
                    
                    &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;gem install cucumber-screenshot&lt;/code&gt;&lt;/pre&gt;
                    
                    
                    &lt;p&gt;And follow the &lt;a href=&quot;http://github.com/mocoso/cucumber-screenshot&quot;&gt;set up instructions&lt;/a&gt; to start snapping.&lt;/p&gt;
                    
                    &lt;p&gt;Enjoy.&lt;/p&gt;
                    
                    &lt;p&gt;If you are on another platform and want this functionality then feel free to change &lt;a href=&quot;http://github.com/mocoso/cucumber-screenshot&quot;&gt;the code&lt;/a&gt;.&lt;/p&gt;
                    
                    &lt;p&gt;Thanks go to &lt;a href=&quot;http://jurisgalang.com/&quot;&gt;Juris Galang&lt;/a&gt; for writing the &lt;a href=&quot;http://github.com/jurisgalang/snapurl&quot;&gt;snapurl gem&lt;/a&gt; (which actually handles making the screenshots) and to &lt;a href=&quot;http://aslakhellesoy.com/&quot;&gt;Aslak Hellesoy&lt;/a&gt; and &lt;a href=&quot;http://blog.mattwynne.net/&quot;&gt;Matt Wynne&lt;/a&gt; for their help and advice integrating this with Cucumber.&lt;/p&gt;
                  </content>
    <published>2009-11-04T06:52:25+00:00</published>
    <updated>2009-11-04T06:52:25+00:00</updated>
  </entry>
  <entry>
    <title>Tuning Mail.app / Gmail IMAP integration</title>
    <link href='http://blog.mocoso.co.uk/tuning-mail-app-gmail-imap-integration' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2009-09-04:/tuning-mail-app-gmail-imap-integration</id>
    <content type='html'>
                      &lt;p&gt;When setting up Mail.app on OS X to access your mail in your Gmail (or Google Apps) account via IMAP it is worth tweaking your 'Mailbox behaviours' and mailbox mappings  to make them work together more smoothly.&lt;/p&gt;
                      
                      &lt;p&gt;However there is conflicting advice on this (from &lt;a href=&quot;http://mail.google.com/support/bin/answer.py?answer=78892&quot; title=&quot;Recommended IMAP client settings&quot;&gt;Gmail&lt;/a&gt; and &lt;a href=&quot;http://www.macosxhints.com/article.php?story=2008041016554622&quot; title=&quot;A better Gmail IMAP to Mail.app sync&quot;&gt;Mac OSX Hints&lt;/a&gt; for example), so here's my definitive guide.&lt;/p&gt;
                      
                      &lt;!--more--&gt;
                      
                      
                      &lt;p&gt;In this guide I assume you have already set up your Gmail account access via IMAP in Apple Mail following these clear instructions for &lt;a href=&quot;http://mail.google.com/support/bin/answer.py?hl=en&amp;amp;answer=77663&quot; title=&quot;Set up Gmail IMAP access on Mail 2.0&quot;&gt;Mail 2.0&lt;/a&gt; or &lt;a href=&quot;http://mail.google.com/support/bin/answer.py?hl=en&amp;amp;answer=81379&quot; title=&quot;Set up Gmail IMAP access on Mail 3.0&quot;&gt;Mail 3.0&lt;/a&gt;.&lt;/p&gt;
                      
                      &lt;p&gt;In the guide below I will refer to changing your 'Mailbox behaviours' settings, you can find these by&lt;/p&gt;
                      
                      &lt;ol&gt;
                      &lt;li&gt;Open Preferences in Mail&lt;/li&gt;
                      &lt;li&gt;Select the 'Accounts' section&lt;/li&gt;
                      &lt;li&gt;Select your Gmail account&lt;/li&gt;
                      &lt;li&gt;Select 'Mailbox behaviours'&lt;/li&gt;
                      &lt;/ol&gt;
                      
                      
                      &lt;p&gt;I will also refer to configuring Mail to treat some of your IMAP mailboxes as 'special'. You can do this by&lt;/p&gt;
                      
                      &lt;ol&gt;
                      &lt;li&gt;Select the mailbox in your IMAP account you want to make 'special'.&lt;/li&gt;
                      &lt;li&gt;Select the 'Mailbox' menu&lt;/li&gt;
                      &lt;li&gt;Move the mouse over the 'Use This Mailbox For'&lt;/li&gt;
                      &lt;li&gt;Select what you want to use the mailbox for, i.e. 'Drafts', 'Sent', 'Trash', 'Junk'&lt;/li&gt;
                      &lt;/ol&gt;
                      
                      
                      &lt;h2&gt;Drafts&lt;/h2&gt;
                      
                      &lt;ul&gt;
                      &lt;li&gt;In 'Mailbox behaviours' tick 'Store draft messages on the server'&lt;/li&gt;
                      &lt;li&gt;Select the drafts mailbox in your IMAP account (probably [Googlemail]/Drafts) and set to be used as 'Drafts'.&lt;/li&gt;
                      &lt;/ul&gt;
                      
                      
                      &lt;p&gt;These settings ensure that drafts will be stored in your IMAP account and will appear in the standard 'Drafts' mailbox in Mail.&lt;/p&gt;
                      
                      &lt;h2&gt;Sent Mail&lt;/h2&gt;
                      
                      &lt;ul&gt;
                      &lt;li&gt;In 'Mailbox behaviours' tick 'Store sent message on the server'&lt;/li&gt;
                      &lt;li&gt;Select the sent mail mailbox in your IMAP account (probably [Googlemail]/Sent Mail) and set to be used as 'Sent'.&lt;/li&gt;
                      &lt;/ul&gt;
                      
                      
                      &lt;p&gt;These settings ensure that sent mail will be stored in your IMAP account and will appear in the standard 'Sent' mailbox in Mail.&lt;/p&gt;
                      
                      &lt;h2&gt;Junk&lt;/h2&gt;
                      
                      &lt;ul&gt;
                      &lt;li&gt;In 'Mailbox behaviours'
                      
                      &lt;ul&gt;
                      &lt;li&gt;Tick 'Store junk messages on the server'&lt;/li&gt;
                      &lt;li&gt;For 'Delete junk mail when' select 'Never'&lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;/li&gt;
                      &lt;li&gt;Select the junk mailbox in your IMAP account (probably [Googlemail]/Spam) and set to be used as 'Junk'.&lt;/li&gt;
                      &lt;li&gt;In Mail Preferences &gt; Junk Mail
                      
                      &lt;ul&gt;
                      &lt;li&gt;Tick 'Enable junk mail filtering'&lt;/li&gt;
                      &lt;li&gt;For 'When junk mail arrives', select move it to the Junk mailbox&lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;/li&gt;
                      &lt;/ul&gt;
                      
                      
                      &lt;p&gt;These settings mean that you are using both Mail and Gmail's spam filters and that you will train them in parallel, i.e. when you mark mail as Junk / Not Junk the information will be passed back to Gmail and will improve their spam filtering too.&lt;/p&gt;
                      
                      &lt;p&gt;I set the Junk mail to never be deleted because Gmail already does this after 30 days and set junk mail to be moved straight to the Junk mailbox so that it doesn't clutter my inbox (this matches the behaviour on Gmail too).&lt;/p&gt;
                      
                      &lt;p&gt;Note: if you 'Erase Junk Mail' in Mail.app it will remove the mails currently in your junk mailbox from Mail's view of your junk mail box but not actually delete them on the server.&lt;/p&gt;
                      
                      &lt;h2&gt;Trash&lt;/h2&gt;
                      
                      &lt;ul&gt;
                      &lt;li&gt;In 'Mailbox behaviours'
                      
                      &lt;ul&gt;
                      &lt;li&gt;Tick 'Move deleted messages to the Trash mailbox'&lt;/li&gt;
                      &lt;li&gt;Tick 'Store deleted messages on the server'&lt;/li&gt;
                      &lt;li&gt;For 'Delete trash when' select 'Never'&lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;/li&gt;
                      &lt;li&gt;Select the trash mailbox in your IMAP account (probably [Googlemail]/Bin) and set to be used as 'Trash'.&lt;/li&gt;
                      &lt;/ul&gt;
                      
                      
                      &lt;p&gt;These settings will ensure that mail you delete locally is marked as deleted in the IMAP server, and will leave the actual removal of deleted messages from your IMAP account up to GMail (30 days)&lt;/p&gt;
                      
                      &lt;h2&gt;Notes&lt;/h2&gt;
                      
                      &lt;p&gt;I don't use notes so I leave 'Store notes in Inbox' unticked in 'Mailbox behaviours'&lt;/p&gt;
                      
                      &lt;h2&gt;Updated - 28 Sep 2009&lt;/h2&gt;
                      
                      &lt;p&gt;I double checked storing sent mail on the server at Shad's suggestion (see comments below), and I have found that it no longer results in multiple copies of sent mail. I am not sure when this was fixed but I have updated the recommendations to suggest you store sent mail on the server as a result.&lt;/p&gt;
                      
                      &lt;p&gt;I've also corrected the label on the Notes checkbox to 'Store notes in Inbox'.&lt;/p&gt;
                    </content>
    <published>2009-09-04T05:12:29+00:00</published>
    <updated>2009-09-04T05:12:29+00:00</updated>
  </entry>
  <entry>
    <title>Ruby docs on OS X with Fluid</title>
    <link href='http://blog.mocoso.co.uk/ruby-docs-on-osx-with-fluid' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2009-06-22:/ruby-docs-on-osx-with-fluid</id>
    <content type='html'>
                        &lt;p&gt;Wouldn't it be nice to have a neat little an application on your desktop which allows you to search and view ruby docs.&lt;/p&gt;
                        
                        &lt;p&gt;Well it's just 4 easy steps away.&lt;/p&gt;
                        
                        &lt;h2&gt;Step 1: Install Fluid&lt;/h2&gt;
                        
                        &lt;p&gt;Download and install &lt;a href=&quot;http://fluidapp.com/&quot;&gt;Fluid&lt;/a&gt; a site specific browser for OS X, that enables you to turn a website into an application.&lt;/p&gt;
                        
                        &lt;h2&gt;Step 2: Download the Rails Searchable API Doc&lt;/h2&gt;
                        
                        &lt;ul&gt;
                        &lt;li&gt;Visit &lt;a href=&quot;http://railsapi.com/&quot;&gt;Rails Searchable API Doc&lt;/a&gt;&lt;/li&gt;
                        &lt;li&gt;Press 'select gems' and decide which versions of Ruby, Rails and other common gems you want to include in your ruby docs application&lt;/li&gt;
                        &lt;li&gt;Click download&lt;/li&gt;
                        &lt;li&gt;Unpack the zip file you download and save it to '/Users/you/Library/Application Support/RubyDocs' say.&lt;/li&gt;
                        &lt;/ul&gt;
                        
                        
                        &lt;p&gt;I chose the 'Rails Searchable API Doc' because it includes a number of other ruby gems, has a good search function and supports keyboard shortcuts.&lt;/p&gt;
                        
                        &lt;p&gt;Of course if you prefer a different rendering of the docs, e.g. &lt;a href=&quot;http://noobkit.com/&quot;&gt;Noobkit&lt;/a&gt; and &lt;a href=&quot;http://www.railsbrain.com/&quot;&gt;RailsBrain&lt;/a&gt; then you could download one of those instead.&lt;/p&gt;
                        
                        &lt;h2&gt;Step 3: Download a nice icon&lt;/h2&gt;
                        
                        &lt;p&gt;Download &lt;a href=&quot;http://www.flickr.com/photos/conekt/&quot;&gt;conekt's&lt;/a&gt; excellent &lt;a href=&quot;http://farm4.static.flickr.com/3392/3315357128_af7c165408_o_d.png&quot;&gt;RubyDoc icon&lt;/a&gt;.&lt;/p&gt;
                        
                        &lt;h2&gt;Step 4: Make your application&lt;/h2&gt;
                        
                        &lt;p&gt;Open Fluid&lt;/p&gt;
                        
                        &lt;ul&gt;
                        &lt;li&gt;Put the local URL of your docs, 'file:///Users/you/Library/Application%20Support/RubyDocs/index.html', say, in the URL field&lt;/li&gt;
                        &lt;li&gt;Put 'RubyDocs' in the name field&lt;/li&gt;
                        &lt;li&gt;Select 'Other' in the icon field and find your spiffy icon (downloaded in step 3)&lt;/li&gt;
                        &lt;li&gt;Press the create button.&lt;/li&gt;
                        &lt;/ul&gt;
                        
                        
                        &lt;p&gt;You're done. Enjoy.&lt;/p&gt;
                      </content>
    <published>2009-06-22T12:56:33+00:00</published>
    <updated>2009-06-22T12:56:33+00:00</updated>
  </entry>
  <entry>
    <title>Install old version of screen using Mac Ports</title>
    <link href='http://blog.mocoso.co.uk/install-old-version-of-screen-with-macports' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2009-06-11:/install-old-version-of-screen-with-macports</id>
    <content type='html'>
                          &lt;p&gt;The latest version of &lt;a href=&quot;http://en.wikipedia.org/wiki/GNU_Screen&quot;&gt;Screen&lt;/a&gt; (version 4.0.3 port revision 3) that comes with MacPorts has a &lt;a href=&quot;https://trac.macports.org/ticket/18235&quot;&gt;number of issues&lt;/a&gt;.&lt;/p&gt;
                          
                          &lt;p&gt;Most annoying for me were that 'mate' and 'gitx' stopped working from the command line (with the errors 'mate: failed to establish connection with TextMate' and 'gitx: failed to establish connection with GitX' respectively).&lt;/p&gt;
                          
                          &lt;p&gt;The screen port @4.0.3_1 (version 4.0.3 revision 1) is free of these problems and, with a little bit of work, you can install this version via MacPorts. The instructions below are based on Joe Horns' post, &lt;a href=&quot;http://journal.bitshaker.com/articles/2007/10/20/install-old-versions-of-ports-using-macports/&quot;&gt;install old versions of ports using MacPorts&lt;/a&gt;.&lt;/p&gt;
                          
                          &lt;!--more--&gt;
                          
                          
                          &lt;h2&gt;Instructions&lt;/h2&gt;
                          
                          &lt;ol&gt;
                          &lt;li&gt;&lt;p&gt;Set up a local port repository. In the file /opt/local/etc/macports/sources.conf, add this line before the rsync line:&lt;/p&gt;
                          
                          &lt;p&gt; &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;file:///Users/Shared/dports&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
                          
                          &lt;p&gt; and create that directory.&lt;/p&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;p&gt;Install the old revision of the port into your local repository, &lt;a href=&quot;http://trac.macports.org/browser/trunk/dports/sysutils/screen/Portfile?rev=45522&quot;&gt;revision 45522&lt;/a&gt; specifies screen port @4.0.3_1.&lt;/p&gt;
                          
                          &lt;p&gt;  &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;cd /Users/Shared/dports &amp;amp;&amp;amp; svn co --revision 45522 \&amp;#x000A;http://svn.macports.org/repository/macports/trunk/dports/sysutils/screen/ \ sysutils/screen/&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;p&gt;Run portindex so that ports now finds your new (old) version of Screen.&lt;/p&gt;
                          
                          &lt;p&gt; &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;portindex /Users/Shared/dports&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;p&gt;Now you should be able to see two versions of the screen port by running&lt;/p&gt;
                          
                          &lt;p&gt; &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;port list screen&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
                          
                          &lt;p&gt; However, rather unhelpfully, they will both be listed as version @4.0.3.&lt;/p&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;p&gt;Install Screen&lt;/p&gt;
                          
                          &lt;p&gt; &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;sudo port install screen @4.0.3_1&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
                          
                          &lt;p&gt; and you should be up and running.&lt;/p&gt;&lt;/li&gt;
                          &lt;/ol&gt;
                        </content>
    <published>2009-06-11T05:14:43+00:00</published>
    <updated>2009-06-11T05:14:43+00:00</updated>
  </entry>
  <entry>
    <title>Refresh data from production</title>
    <link href='http://blog.mocoso.co.uk/refresh-data-from-production' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2008-11-30:/refresh-data-from-production</id>
    <content type='html'>
                            &lt;p&gt;When working on web apps, it can really useful to be able to load production data into your development environment.&lt;/p&gt;
                            
                            &lt;p&gt;I am a sucker for anything that reduces typing so I put together a &lt;a href=&quot;http://github.com/mocoso/mysql_tasks/tree/master&quot;&gt;mysql_tasks&lt;/a&gt; rails plugin for my MySQL backed applications which makes it as easy as&lt;/p&gt;
                            
                            &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;rake mysql:refresh_from_production&lt;/code&gt;&lt;/pre&gt;
                            
                            
                            &lt;p&gt;Which makes a tar gzipped snapshot of the production database, downloads it into my development box and loads it into my development environment.&lt;/p&gt;
                            
                            &lt;p&gt;If you want to give it a go yourself then read these &lt;a href=&quot;http://github.com/mocoso/mysql_tasks/tree/master/README.markdown&quot;&gt;installation instructions for the mysql_tasks plugin&lt;/a&gt;.&lt;/p&gt;
                            
                            &lt;p&gt;This was inspired by &lt;a href=&quot;http://www.nateclark.com/articles/2007/02/23/rails-rake-tasks-to-sync-your-remote-database-to-your-local-development-environment&quot;&gt;the real Nate Clark&lt;/a&gt;.&lt;/p&gt;
                          </content>
    <published>2008-11-30T08:15:36+00:00</published>
    <updated>2008-11-30T08:15:36+00:00</updated>
  </entry>
  <entry>
    <title>Code Beautifier Textmate Bundle</title>
    <link href='http://blog.mocoso.co.uk/code-beautifier-textmate-bundle' rel='alternate' type='text/html' />
    <id>tag:blog.mocoso.co.uk,2008-09-25:/code-beautifier-textmate-bundle</id>
    <content type='html'>
                              &lt;p&gt;Textmate's indent functionality does a passable job of formatting your code BUT there is a great deal of room for improvement.&lt;/p&gt;
                              
                              &lt;p&gt;Inspired by the Paul Lutus's &lt;a href=&quot;http://www.arachnoid.com/ruby/rubyBeautifier.html&quot;&gt;ruby beautifier script&lt;/a&gt; and Tim Burks's &lt;a href=&quot;http://blog.neontology.com/posts/2006/05/10/beautiful-ruby-in-textmate&quot;&gt;post on making it into a Textmate bundle&lt;/a&gt; I've put together a &lt;a href=&quot;http://github.com/mocoso/code-beautifier.tmbundle/tree/master&quot;&gt;Code Beautifier Textmate bundle&lt;/a&gt;&lt;/p&gt;
                              
                              &lt;p&gt;It only supports Ruby at present but does improve upon Textmate's indent functionality, in particular it is better at indenting multiline statements and cleans up white space.&lt;/p&gt;
                              
                              &lt;p&gt;It's all hosted on &lt;a href=&quot;http://github.com/&quot;&gt;Github&lt;/a&gt; so if you want to make improvements then please fork away.&lt;/p&gt;
                              
                              &lt;!--more--&gt;
                              
                              
                              &lt;h2&gt;Installation&lt;/h2&gt;
                              
                              &lt;p&gt;Run this:&lt;/p&gt;
                              
                              &lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;cd ~/Library/Application\ Support/TextMate/Bundles&amp;#x000A;git clone git://github.com/mocoso/code-beautifier.tmbundle.git Code\ Beautifier.tmbundle&lt;/code&gt;&lt;/pre&gt;
                              
                              
                              &lt;p&gt;Then select 'Bundles &gt; Bundle Editor &gt; Reload Bundles' from Textmate's menus&lt;/p&gt;
                              
                              &lt;h2&gt;Updated on 21 May 2009&lt;/h2&gt;
                              
                              &lt;p&gt;Changed the URL of the repository on GitHub to http://github.com/mocoso/code-beautifier.tmbundle/tree/master to fix a typo in the name (oops).&lt;/p&gt;
                            </content>
    <published>2008-09-25T12:33:14+00:00</published>
    <updated>2008-09-25T12:33:14+00:00</updated>
  </entry>
</feed>

