Nottingham to John O’Groats by bike

This is about how I cycled from Nottingham to John O’Groats in May 2009 to buy a mug. Fifteen Years ago I did the complete Lands End to John O’Groats trip and bought a souvenir mug at each end. I dropped the one from Scottland and have often thought about getting another one.

The ride was such a physical experience that its hard to write about, but these grainy clips convey something of the roadkill, wind, sheep and potholes that preoccupied me for the week.

Continue Reading »

Version conundrum with Rails, Passenger and Active Scaffold

Late last night I found that Passenger 2.1.3 and Rails 2.3.2 don’t work if I try to use a sub URI, like www.guyroberts.co.uk/community_accounting_map where community_accounting_map is the Rails application.

Great. (The reason I am changing to Passenger in the first place is that Mongrel does not seem to be supported any more - I came across a problem caused because a method that Mongrel needs is no longer part of Rails, really frustrating).

The first thing this morning I changed environment.rb to use Rails 2.2.1 and got this error,

“This version of ActiveScaffold requires Rails 2.3 or higher. Please use an earlier version”

I remember last week finding that people were struggling to get a working version of ActiveScaffold from either svn or git.

Think I’ll remove ActiveScaffold from the project for now.

Update: I now use Google My Maps and this Rails app is redundant.

Aliens ate my server

The disc on the server that hosts this web site went wrong last weekend. Happily I had backups of everything, but unhappily I’ve had to put it all back together by hand on top of a new OS image. These are the things I had to get working;

  • The iptables firewall
  • Apache
  • Php with bonus modules
  • Mysql
  • Java and Tomcat
  • Ruby and Rails
  • Subversion
  • Capistrano
  • Drupal
  • Wordpress
  • Postfix, Dovecot and mutt
  • Backup scripts

The worst aspect of installing all of this is having to read eighty nine million pages of instructions, especially for the iptables and mail server set up.

The second most important thing I learned is that people use something called yum to manage things on Centos and that its daft to build things from the source code because you can’t keep track of updates and dependencies.

But the really really main lesson was not to accidentally configure Apache as an open web host when you really just meant to run a local proxy. Otherwise thousands of requests will be proxied through the server by people looking at stuff anonymously. As happened today.

Bird song quiz

treecreeperx350

I’ve made a bird song quiz for the Friends of Sharphill Wood. Its funny how I know most of these songs but have no idea which birds make them. And its been relaxing to listen to the twitterings as I’ve worked.

What are they singing about ? My brother says its all either “I saw a big worm today” or “Want to come back to my nest ?”.

I used PhotoShop Elements to reduce the photos in a big batch, that saved a lot of time. The Drupal Quiz module did most of what I needed, although I had to change the html it produces to put a div around each question so that I could float it. Lightbox worked quite well with these beautiful photos.

We hope that local primary schools might set the quiz as extra homework, and the winners will get to assemble one of our home made bird box kits and have it installed in the wood. Everyone is a winner !

The photographs were taken by John and Eileen Smith and the sound recordings were originally made by David Tombs and WildSounds.

 

Save Sharphill Again

holding_hands350

There is a hill near here that I love to run up. Its in the Greenbelt and offers a way out of the suburbs and into the countryside. Over the last three weeks a Public Inquiry has been hearing evidence from builders who want to ‘develop’ these fields.

I spent a day building Save Sharphill Again, a Drupal web site to encourage people to go the the Inquiry and speak out.

The Inquiry is over now and we wait, rather pessimistically for the Inspectors report.

 

Cheating at Rock Paper Scissors

Rock Paper game

To learn a bit more about the Ruby language I’ve been doing the Ruby Quiz. Each week a bigger anorak than me sets a puzzle to be solved using Ruby. So I worked through the one about Rock Paper Scissors.

The aim is to write some Ruby that will play the game against somebody else’s version. The normal rules of the game applied and in the end the author of the highest scoring Ruby script won.

The best bit is that the winner, Bill Atkins cheated by getting his program to change the opponents code to always choose scissors and then his own player just needed to choose paper each time.

class BACheater < Player
def initialize opponent
   Object.const_get(opponent).send :define_method, :choose do
      :paper
    end
  end
 
  def choose
   :scissors
  end
end

The cheat just finds the opponents class using the argument passed to it. Then it rewrites the other sides :choose method so that it always chooses paper.

And from what I know about Ruby meta programming so far, this flexibility is a blessing and a curse, depending on who is writing the code and how much sympathy they have for the eventual maintainer.

Ruby on Rails validation for two connected fields

On a recent Ruby on Rails project I needed to validate an address form so that when submitted, either the house number or the house name or both were present.

Although this post nearly did it, I had to modify Eric’s code slightly and this is the result (taken from the address.rb model file)

This also shows how I validate UK postcodes. Can’t remember where I found that regular expression but
I am pretty sure I did not make it up myself !

class Address < ActiveRecord::Base
  belongs_to :user, :validate => true
  belongs_to :property  
  belongs_to :guest 
  validates_presence_of  :town, :message => 'Town is missing'
  validates_presence_of  :street1, :message => 'Street1 is missing'
  validates_presence_of  :postcode, :message => 'Postcode is missing '	
  validates_format_of :postcode,
   :with => /^([A-PR-UWYZ][A-HK-Y0-9][A-HJKS-UW0-9]?[ABEHMNPRVWXY0-9]? 
         {1,2}[0-9][ABD-HJLNP-UW-Z]{2})$/,  :message => "Invalid postcode " 
 
  def self.validate_at_least_one_of(*attrs)
     configuration = { :message => "One of #{attrs.to_sentence} must be set", 
                                    :on => :save }
 
     configuration.update(attrs.pop) if attrs.last.is_a?(Hash)
     error_key = ""
 
     # The key to put in your view should be xxx_yyy_ where xxx and 
     # yyy are attrs[0], attrs[1] etc.
     attrs.each do |attrib|
       error_key = error_key + attrib.to_s + "_"
     end        
 
     options = configuration
     send(validation_method(options[:on] || :save)) do |record|
       found_non_blank = false 
       attrs.each do |attr|  
         value = record.send(attr)          
         if !value.blank?
            found_non_blank = true
         end  
       end # attrs.each
 
       if ! found_non_blank   
         record.errors.add(error_key, configuration[:message])
       end
     end  # send
   end
 
   validate_at_least_one_of :house_number, :house_name, :on => :save	
end

Then in the form itself, I used the following code to display any error message. (The address model belongs to the user model)

<div class="error_field">
<%= if @user.address != nil then @user.address.errors.on :house_number_house_name_ end %>
</div>

Thematic Google Maps

A thematic map is one where regions are coloured according to some statistic, for instance unemployment rate or the population density.

Here is a way to generate your own google maps with thematic overlays, log in with demo/demo.

The data is currently random, I will make it possible to upload your own datasets. I described the origins of this web application last year, its based on Richard Milton’s Google Map Creator, but my version lets you do it with a web browser.

The finished map tiles could be made available as a zip file, but at present they are just left on my server.

The application is a mixture of Ruby on Rails (which processes the ESRI shape files) and a Struts java application that calls Richard’s clever code.

A new Drupal web site for CA Plus

I am pleased with the new Drupal web site that I have built and hosted for CA Plus. CA Plus provide management and accountancy advice to voluntary groups around Nottinghamshire.

CA Plus

The project started with a disembodied conversation over the garden wall when my neighbour, John O’Brien, Chief Executive at CA Plus struck up a conversation about renewing his static web site. Many ‘meetings’ were held over the garden wall while John feed his chickens (Doris, Matilda and Barbara) and I made compost.

John O’Brien and Andrew Monroe at CA Plus were very quick to learn how to write content and they have produced dozens of articles about employment, book keeping and financial management. Clients can subscribe to notification emails to keep them up to date with new material.

For the staff staff photo page we created a new content type together with a view to layout the new content. Staff members edited their own biographies and photos to keep the content up to date.

Bumble bees in my compost

As I dug over my compost heap a flurry of bees flew up from inside. I felt guilty about disturbing them and gingerly put what was left of the nest into a big plant pot. Over the next few weeks my little insect friends went peacefully about their business and built a much bigger nest. I covered the entrance with soil and noticed that junior bees were sent out to rearrange the dirt. Here is a little time lapse film of their methodical efforts.

Sadly after about two months the nest died and became home to an elderly slug, a big spider, seventeen caterpillars and a newt. Not before the bees had excavated an eight inch tunnel into the surrounding soil though.