Wednesday, 22 February 2012

Gov.uk portal - the poster child for Agile Railers and Responsive Designers



The new Gov.uk portal is still in Beta, but already we can see that the Government Digital Service really are doing things differently to what we might have come to expect of government IT projects. An in-house team with good leadership have been given the freedom to use a leading-edge approach to design and build. They are Agile, they use Ruby on Rails, they are on GitHub, and their interface uses responsive design.

Rapidly disappearing are the days when big organisations demand MicroSoft. That Marketing Director with the six-figure budget no longer needs to fear open source technology - if the Government uses it, it must be ok!

Digital agencies that use open source technologies will start to get pitches for the bigger projects they may have been previously excluded from, and Gov.uk will no doubt become the poster-child of open-sourcers, agilers, railers and responsive designers in the UK and possibly worldwide. Rightfully so. Big-up the GDS!

Thursday, 16 February 2012

Flurry analytics gathering UDID - as seen in mitmproxy

I had a play with mitmproxy today and opened a few apps on my phone to see what kind of traffic was going on. An interesting point of note was the use of Flurry in the Met Office app, and the fact that it sends my UDID over the network to a mahoosive database. Flurry and other mobile analytics tools are quite commonplace so there's nothing sinister about the Met Office app in particular (Rightmove and Pinterest are two others on my phone that I could have picked on), but the UDID can reveal a lot about a user and ultimately identify them. For identical privacy concerns Google Analytics stopped revealing visitors' IP addresses several years ago, if my memory serves me correctly. Anyhow, here's a snapshot from mitmproxy:








It's worth noting that Apple have deprecated the use of UDID in iOS5 and it'll presumably die sometime in the not too distant future. Just like losing IP addresses was no biggy for Google, losing UDID will surely be no biggy for the likes of Flurry.

Bigger losers might be some app developers that have used UDID in some fundamental manner to identify users - not for any creepy tracking or marketing way but as a convenient (lazy?) means of identification or authentication.

I'm pretty sure I wasn't asked about sharing data with Flurry when I installed any of my apps, but I did find this link where you can tell Flurry you don't want your activity monitored.

Switching Rails app from SQLite to Postgres

I decided that my new Rails app was to be hosted with Heroku, but I decided it a little too late, having already built most of it using, by default, SQLite. I tried to wing it and hope that there would be no compatibility problems, but I was getting errors in some db queries on Heroku that I wasn't seeing locally on SQLite.

So, time to switch my app to Postgres. This Youtube video gave me most of what I needed about installing Postgres on my Mac, but because I'm running Lion I then needed to consider this stackoverflow thread too, as only at this point did I learn that postgres is bundled into Lion already.

Once postgres was installed and running I created a database named myRailsApp_development and gave it a user (all shown in the youtube video linked above), and modified the database.yml file in my Rails app thus:

development:
  adapter: postgresql
  encoding: utf8
  database: myRailsApp_development
  pool: 5
  username: myUser
  host: localhost

Then I ran rake db:migrate, and it all worked!

Tuesday, 14 February 2012

NSDate from Rails datetime via JSON

I'm building an iPhone app that uses a Ruby Rails JSON api and frequently I need to convert the Rails datetime string into an NSDate object. Here's how its done:

NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];

NSDate *myDate = [formatter dateFromString:@"2012-02-14T12:01:41Z"]; 

and then if you need to display this later, you can convert it back to a string like this, where I display it in a British dd/mm/yyyy format:

[formatter setDateFormat:@"dd-MM-yyyy HH:mm"];
myLabel.text = [formatter stringFromDate:myDate];

Wednesday, 8 February 2012

Environment-specific configuration in iOS / Xcode

Specifying different config values for your different environments in Xcode (Debug, Release etc) can be achieved in different ways, but this great blog post explains one method in detail.

In summary this approach adds a new Configuration/${CONFIGURATION} Key/Value to the main plist file, a new plist file specifying values, and a singleton to load up and share the values throughout your code.

I won't repeat it in detail. Take a look yourself.

Tuesday, 7 February 2012

Emails from Devise on localhost

Need to get your Devise email notifications working in your development environment on localhost? Just drop this into your development.rb config file:

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

  config.action_mailer.delivery_method = :smtp

  config.action_mailer.smtp_settings = {
    :enable_starttls_auto => true,
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "gmail.com",
    :authentication => :login,
    :user_name => "test@example.com",
    :password => "Test123",
  }

Adding 'confirmable' to Devise

I found myself needing to add 'confirmable' to Devise today, and I wish I'd installed it in the first place. For this you need the following migration:

class AddConfirmableToUsers < ActiveRecord::Migration
  def change
    add_column :users, :confirmation_token, :string
    add_column :users, :confirmed_at, :datetime
    add_column :users, :confirmation_sent_at, :datetime
    add_column :users, :unconfirmed_email, :string
  end
end
Initially I missed out the 'unconfirmed_email' column, but it transpired I needed it - I'm not entirely sure why because I've yet to see any emails go into there, even unconfirmed ones. Not including it produced errors. And of course you need to add ':confirmable' to the list of modules specified in your user.rb model. Mine looks like this:
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable,
         :registerable,
         :recoverable,
         :rememberable,
         :trackable,
         :validatable,
         :token_authenticatable,
         :confirmable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

Wednesday, 1 February 2012

TestFlight for distributing and testing beta iOS apps

Just had my first play with TestFlight. It's an online service that takes the pain out of distributing for testing iOS apps. I'm mighty impressed, even though all I've done so far is recruit a single tester and upload and distribute a simple test iPhone app (.ipa file) to him and myself. The process went like a dream and the information and control you get is amazing.



There's loads more to it - for example download the TestFlight SDK and it'll give you full diagnostic info about crashes as well as details about your testers' usage sessions. And all for free (for how long I wonder?). Amazing!