• My Portfolio

    If you're looking for a Web Developer, I may be able to help you. Take a look at my portfolio.

My First iOS app is now available from iTunes

My first iOS app has been released! It’s a loan calculator for Pepper Home Loans as part of my work at Hothouse Interactive.

It was built using Rhodes which promises a lot but has a number of quirks that meant the job took longer than expected. It’s those little things that can often take up so much time.

Anyway, happy with it and another should be coming out soon…

Share

Filed under: Rhodes, mobile | No Comments

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:

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

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)
    else
      @xml.tag!(tag, value)
    end
  end

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.

Share

Filed under: Uncategorized | No Comments

How to reindex a Radiant CMS site running solr

For a rails app, you just need to run:

rails sunspot:reindex

But this finds models in the app/models folder and a Radiant CMS site does not have this folder. To tell sunspot which models to reindex you can do this:

rake sunspot:reindex[100,ArticlePage]

This will reindex ArticlePage objects, 100 at a time. You may also want to reindex other objects.

Share

Filed under: radiant+cms, rails | No Comments

Repeat Yourself Frequently (RYF)

Where does the database schema live?

Hi XXXXX,

Yes, the GUI reads the csv and populates the performance tables.

The tables and views were not documented in Internal_table.xlsx spreadsheet or in the create_db.sql script, as in a Rails project the correct place for database schema information is in the db folder within the project – adding it elsewhere is duplication which leads to errors, missing information and unnecessary overhead.

There really needs to be a single place for database information and in Rails, that place is migrations. A sql script could be generated from the database after migrations have run, and the schema could be exported to Excel if necessary for reporting purposes. It makes no sense to have 3 original sources of the same information.

Regards,
Brad.

Share

Filed under: Uncategorized | No Comments

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
  else
    return variable
  end
end

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.

Share

Filed under: Uncategorized | No Comments

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|
  UI::Server.delete_all;
  num_servers.to_i.times {Factory.create(:server)}
end

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.

Share

Filed under: rails | No Comments

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…

Share

Filed under: Uncategorized | 1 Comment

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: http://code.google.com/p/socialonrails/

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 http://apps.facebook.com/facebooker_tutorial but it is out of date to say the least.  So perhaps I’ll write one while I’m developing an app.

Share

Filed under: Uncategorized, rails | 1 Comment

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.

Share

Filed under: technology | No Comments

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.

Share

Filed under: business | No Comments