brad garland

web * mobile * IoT

Latest Posts

On Writing

Every now and then I get a strong urge to start writing again. Each time, I’ve probably written something here but either didn’t finish it or decided it was too much of a rant – I had a lot of unpublished posts which I’ve now trashed.

So again, I’ve decided to start writing but with so many ideas and topics I immediately feel a little overwhelmed.  In order to reduce the scope and thus make writing a little more manageable I’m going to add some constraints – keep the topic light for now and a limit of 300 words.

A light topic will help to ensure that I’m comfortable posting the article.  A limit of 300 words will help to ensure that I don’t get carried away in an attempt to write a large piece, get distracted and never finish it.

I’m also going to look out for other ideas on how to get started with writing – surely there are some simple writing assignments/exercises on the internet.

XSDs are inflexible and redundant

I recently had to do some work supplying an XML feed for a client. I used Ruby’s built-in .to_xml on the array of ActiveRecord objects and it generated this XML which I was happy with:

      <date type="date">2012-04-17</date>
      <certificate-number nil="true"></certificate-number>
      <certified-at type="datetime">2012-04-18T07:23:00Z</certified-at>

Nice and simple.

Unfortunately, the organisation that was consuming this XML wanted an XSD. And provided one. But it required the namespace xsi for nil values (replacing the nil="true" above with xsi:nil="true". I thought this would be an easy change…

It is not possible to provide settings to Rails’ to_xml to include the namespace attribute xmlns:xsi="http://..." into the <vehicles> tag so that it could be used wherever there were nil values.

It seem it is impossible to get an XSD to support the XML as supplied.

As a result I had to manually build the xml using builder. Now sure, there’s nothing particularly complex about this XML, but now I needed to write xml.builder views and write my own xml tag helper to identify nil/blank values and put in the appropriate attribute:

  def nil_tag(tag, value)
    if value.nil? || value.blank?
      @xml.tag!(tag, value, 'xsi:nil' => true)
      @xml.tag!(tag, value)

I also then had to format my DateTime output as .xmlschema as the default to_s is not valid in XML. Added an extra day of work all because the XSD couldn’t describe the XML I had.

I should have insisted on JSON.

Code smells: a = a

In a project I’m working on at the moment, I saw some rather unusual code at the top of a number of views – it looked like it was trying to set a default value in the event the variable wasn’t defined, for example:

name = undefined_to_false(name)

and the definition of undefined_to_false:

def undefined_to_false(variable)
  if !defined?(variable)
    return false
    return variable

My first reaction to that method was that it couldn’t work – if I have an undefined variable and attempt to pass it into the undefined_to_false method, I will get a “NameError: undefined local variable or method” before ruby attempts to pass it into that method. The only was around this was to pass in a Proc.

I pulled up irb and confirmed that this method would not work, yet it was being used in a production system. Rcov confirmed that the return false never got called in any tests. Given this information I removed the method and every reference to it – if any of the callers of this method actually needed this method, I figured we would have already had NameErrors.

Then someone complained that their view wasn’t working anymore, and I started to wonder if there was some other magic that made this work. I had confirmed that passing an undefined variable into a method cannot work which meant that the variable must have been defined before it called that method.

A colleague confirmed that

name = undefined_to_false(name)

did in fact work when name was previously undefined (and it was undefined in a number of views). Then it occurred to me:

a = a

In an assignment, the variable on the left hand side will become defined prior to evaluation of the right hand side. Thus, even if a was not defined prior to that line, it will be by the time of evaluation and therefore will not generate a NameError.

So I replaced all the old occurrences of a = undefined_to_false(a) with just a ||= false, although to be more correct I could have replaced them all with a = a but that just looks silly – and smells bad.

Cucumber tests failing – looked like it was using a different database

Just spent the morning tracking down an issue where a number of our cucumber tests were failing to find the database in the state that I had just set up with my step definitions.

For example, I had a step definition:

Given /I have (\d+) servers$/ do |num_servers|
  num_servers.to_i.times {Factory.create(:server)}

When the browser visited the page after this code had run, it still saw the “server” records from the fixtures instead of the factory generated record.  I checked the database connections, and even put debugging code into the step above to confirm the records that were in the database.  The debugging output matched the step definition, but the browser didn’t.  I confirmed visually by using the Selenium WebDriver that it was still seeing fixture records.

I bit of googling and I found a page discussing Browsers and Transactions – I remember reading and fixing this once before, but a quick check of the features/support/env.rb file showed that my “fix” had been changed.

The line:

DatabaseCleaner.strategy = :transaction

won’t work as any change to the database done inside a step will not be seen by the web browser.  A quick change, resetting this back to:

DatabaseCleaner.strategy = nil

and all tests working again.

Of course, this all would have much easier to track if this company had automated testing and a decent version control system, but that’s a topic for another post.

Godaddy deleted my emails

Seems Godaddy implemented a new feature on their email hosting: “Auto-purge”.  As the name suggests it will automatically delete emails.  Now that’s fine for folder like Spam and Deleted Items but they put it on my Sent Items!  Goodbye 7 years of email history…

As a loyal *paying* customer for 7 years, who has recommended them many times, I’m pissed off.  After a few emails, they restored 30 days worth of stuff that I had already deleted (so I just had to delete them again) but not my Sent Items.  Still waiting to hear if they’re going to do anything…

Looked at migrating to Google Apps.  According to Godaddy though, I have to pay them MORE money to upgrade to an IMAP plan so that I can get my emails off them…

Facebook and Rails

Ok, so I thought of developing a Facebook application using Rails and kind of assumed that there’d be some fantastic library that just did all the hard work leaving me to write the app.

It seems there are a number of attempts to develop a ruby library for Facebook but finding one that is still active and useful wasn’t easy.

A quick roundup of what I found (mostly via google).

Facebooker – This seems to be the one that is recommended and there’s a book on Peepcode although it’s been said that it expects your entire app to be a facebook app.

RFacebook – The author says “I may cease development on RFacebook in favor of Facebooker”

Giant Robots useful article (one of the most recent I found!)

Facebook on Rails – The author (Hoan) has discontinued support for this plugin.

Facetime – for adding to an existing system with a User model

SocialonRails – Nothing at all at their repository:

After some attempts at using these, I’m going to proceed down the path of using Facebooker.  The docs indicate that there is an “excellent” tutorial at but it is out of date to say the least.  So perhaps I’ll write one while I’m developing an app.

Huwai e169 GSM modem using Virgin on Ubuntu 8.1

Took a few days but I finally got the Huwai e169 to work on Ubuntu 8.1.  Seems there’s a bug with the Network Manager that means you can’t save the settings which meant you couldn’t log in.  But there is a way!

From information you’ll find elsewhere, you should already have these settings:

APN: VirginBroadband   <–  Ensure this is not VirginInternet
Number: *99#
Username: blank
Password: blank

Then in the Point-to-Point Protocol (PPP) tab, under Use Authentication, you need to unselect everything except PPP.  The problem is if you only change these settings it won’t save the changes!  So, also tick Connect Automatically.  Then hit ok and it should go and save those settings and connect.

Tick Connect Automatically to ensure the PAP setting saved

Tick Connect Automatically to ensure the PAP setting saved

You may also want to go back in to untick Connect Automatically which will save – and you’ll also see that the other Authentication options are still unticked and have saved.

Running a business is a full time job

I gave up my full-time job to run a company and I guess I had pretty high expectations of what we’d achieve – even though we actually created optimistic, realistic and pessimistic plans.  We’re currently behind on even the pessimistic plan.  That is not to say that our product is not great value to those who use it, but running a company is more than just having a great product.

Robert Kiyosaki, in his book Before You Quit Your Job talks about five basic jobs of a business and labels them as Product, Legal, Systems, Communications and Cash Flow.  Now my skills are in developing products and systems and I think we’ve done pretty well on those, but our marketing (communication) and cash flow are poor.  While it is easy for me to focus on products and systems, it takes a lot more effort to just get the basics in each of the other areas and then, when you’re trying to do it yourself, that creates a lot of work.

Kiyosaki goes on to say that if you don’t have the skills yourself, to make an offer to someone who does have those skills – so that you build a complete team covering each of those jobs.  The members of the team can be employees, external consultants or be offered a slice of the business if there’s no other way to pay them.

Our strategy so far has been to keep ownership of the company and either pay consultants (such as lawyers) or offer them revenue shares, but not shares in the company.  After speaking with David Bolliger, founder and CEO of Storyz, I’m starting to think that perhaps owning the company isn’t so critical – we can offer shares in the company and still ensure that we own a controlling share.

I’m interested in how other technical start-ups have found good marketing, legal and capital-raising people and how you’ve convinced them to join you.