Monday, 3 October 2011

Bridgeway Security Solutions launched!

A new information security reseller, Bridgeway Security Solutions, has been launched in the Cambridge area.

Bridgeway has an exciting range of new information security products and services, and appears to be a thought-leader in this field.

Their IT security vendor partners include Splunk, MobileIron, MXI/Ironkey, Wave Systems and a host of other interesting security vendors.

We wish them well in their new venture.

Wednesday, 1 December 2010

Rails Nokogiri 'document already has a root node'

I'm attempting to master Ruby on Rails for a personal project and I'm not ashamed to say that I'm finding the learning curve rather steep in places.

One such place is in the generation of XML code using a builder. The advice on the web seems to strongly recommend Nokogiri, so this is what I tried to use. I ensured my Gemfile was correctly updated and ran bundle install

However, two main stumbling blocks exposed my Rails ignorance: how to properly call the XML builder from within the Rails controller, and how to cope with the dreaded cryptic 'document already has a root node' error.

The first one must be a common rookie mistake. The scaffold-generated controller had this default respond_to snippet:

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @thing }
end

It appears what this does is to ask Rails to convert @thing into an XML representation of @thing. This is not what I wanted and it took a while to realise why my XML building code in both thing.xml.erb and thing.xml.builder were being completely ignored.

Fixing it was simple enough, remove the render block so that it reads as:

respond_to do |format|
format.html # new.html.erb
format.xml
end

This will now search for the .erb and .builder files. Time now for my next ignorant mistake.

If you call Nokogiri::XML::Builder from within a .builder file, it will fail with a 'Document already has a root node' error message.

It took me a long time to work out why. I checked my code, I copied the examples on the Nokogiri tutorials, tried various configurations and just could not find the solution. Google searches on "rails3 'document already has a root node'" did not clarify the situation either, with the few hits that showed up remaining unanswered.

Well, the solution is very straightforward: it appears Nokogiri barfs in this manner when you try running in from a .builder file. Move the code to a .erb file, and it should work fine (though you'll need to wrap it all in a %lt;%= %%gt; construct).

Simple when you know how, frustrating and tiring when you don't.

Nokogiri's slogan is: XML is like violence - if it doesn’t solve your problems, you are not using enough of it.

I clearly hadn't been using enough then...

Wednesday, 10 November 2010

Christmas gift ideas for 2010

Christmas is fast approaching and as usual, we're now starting to think (panic?) about which Xmas presents to buy for our family and friends.

As usual at this time of year, my gliding club has announced a set of trial flight vouchers for consideration as unique Christmas gifts and presents. Whether looking for a special Christmas gift for your girlfriend or boyfriend, or a Xmas present for your husband or wife, please do spend a moment looking at their range.

Merry Xmas everybody!

Thursday, 2 September 2010

Creating a Word label in Applescript

In my line of work, I regularly have to send evaluation units out to prospective customers. They email me their address and I then generate a label in Microsoft Word to print off and attach to the envelope/box I'm sending.

As I do this reasonably often, and as I use an Apple Mac, I thought this would be a great excuse for creating an AppleScript program to automate the process for me.

I couldn't find examples of this in the wild, so I include the code as a starting point for anyone attempting something similar.

I've added it as an Entourage script (see image above), but it should also work in other applications just as well.

(*
Create Word label from selection v1.0

Created: 2010.09.02
Modified: 2010.09.02
*)

on run

(* Grab the selected text *)

set theText to ""
tell current application
try
set theText to the selection
if theText is "" then
error
end if
on error
display dialog ¬
"This script works on text selected in a message." buttons {"OK"}
set theText to ""
end try
end tell

(* Launch Word, confirm label positioning and generate label *)

try
if theText is not "" then
tell application "Microsoft Word"
activate

(* Collect label Row & Column data from user and ignore non-numerical entries *)

display dialog "Enter label row:" with title "Label Row" default answer "1" buttons {"Set..."} default button 1 giving up after 5
try
set labelRow to (text returned of result) as number
on error
set labelRow to 1
end try

display dialog "Enter label column:" with title "Label Column" default answer "1" buttons {"Set..."} default button 1 giving up after 5
try
set labelColumn to (text returned of result) as number
on error
set labelColumn to 1
end try

(* The magic command and pixie dust... *)

create new mailing label document mailing label object address theText single label yes row labelRow column labelColumn

end tell
end if
on error
display dialog "There was an error creating the label." buttons {"OK"}
end try

end run

Wednesday, 5 May 2010

Fellow pilot?

I noticed a curious blog entry recently - I guess another glider pilot?

I will keep an eye on them and see if I can work out who they are - it is likely to be another member of the same gliding club I go to. Curious.

Tuesday, 20 April 2010

Birthday gift ideas

Struggling for a Birthday gift idea or present? Well, if you live near to Cambridge, Bedford, St. Neots, Biggleswade, Huntingdon, Royston or Peterborough - or for that matter, anywhere within Cambridgeshire, Bedfordshire, Huntingdonshire or even Essex, why not try a unique birthday gift idea?

A glider trial flight voucher is being offered at Cambridge Gliding Centre suitable for those who have everything and/or are tricky to buy birthday gifts for.

Monday, 19 April 2010

Cambridge Gliding Centre Open Day

It's that time of year again - Cambridge Gliding Centre is holding an Open Day! This year's open day will be held on the 9th May, 2010.

I didn't make it last year, but this 2010 Open Day looks to be well attended. I'm looking forward it very much and hoping the weather holds out for it.

Certainly not expecting the volcanic ash to disrupt the open day - it's too high to affect us and we certainly don't have the jet engines the commercial airlines have.

Still, it should prove to be a fun event - see you there, perhaps?