Gavin Morrice

Half entrepreneur, half software nerd, half writer, half weightlifter

This is what I've been doing lately...


On I wrote

How to protect your website from Mobilegeddon!

A few days ago Google rolled out their latest update which brought the start of Mobilegeddon. This post will explain how you can avoid being hurt by the changes

On I interviewed the CEO of DateME Kenya

Interview with Ian Isherwood, CEO of DateME Kenya

I interviewed Ian Isherwood, CEO of DateME Kenya to find out what makes him tick,the unique problems he faces, and what advice he can share.

On I wrote

How meditation can physically change your brain

Despite misconceptions though, meditation is not just a spiritual or religious practice. It's not about about good-feelings, wearing tunics, selling your earthly possessions or reaching Englightenment. Mindfulness Meditation is a powerful tool for continuous brain development and there are real, measurable, physical changes that take place in the brain of those who meditate regularly.

On I wrote

Ruby 2.0.0: An error occurred while installing binding_of_caller

I recently updated two of the Rails apps I'm working with to use Ruby 2.0 and came across an error - here's the solution.

On I wrote

How to Install Ruby 2.0 With RVM

So I've finally set aside some time to play with Ruby 2.0 and it's great fun!

Here's what I had to do to install Ruby 2 on my iMac (iOS 10.8.2) using RVM and Homebrew

First off, there were a few of the library dependencies I didn't have on my machine (It's a pretty new setup) so I had to install them:

$ brew install autoconf
$ brew install pkg-config
$ brew install libyaml
$ brew install readline
$ brew install libxml2
$ brew install libxslt

You may already have some of these installed, or there may be dependencies that you still require - don't worry, RVM will let you know when you run the next step:

$ rvm install ruby-2.0.0-p0

To use this version, simple type

$ rvm use ruby-2.0.0

... or include this in your .rvmrc file

$ rvm use ruby-2.0.0

You can now start to make use of Ruby 2's cool new features, including named parameters:

def foo(bar, name: "Foo bar")
  puts "#{bar} with #{name}"
end

foo("sing", name: "Cher") # => "sing with Cher"

Using Ruby 2.0 With Rails

Ruby 2.0 seems to be fully backwards compatible so it should be safe to use with Rails 3 apps. We're already running it on two apps we're developing at the moment and haven't come across any problems at all!.

Here are some more of the new features in Ruby 2

On I wrote

Reading and writing to plist files in Rubymotion

In two of the projects I'm working on just now I'm using plist files to store data. To save me from having to duplicate work in both apps, I created a module to make light work of reading and writing to plist files.

http://github.com/KatanaCode/PListReadWrite/

Installation

When I'm creating Ruby modules to share across more than one app I prefer to install the modules as git submodules. That way if I need to update/patch I only need to update once, not in every app!

# From your project root dir
git submodule add git@github.com:KatanaCode/PListReadWrite.git lib/plist_rw

Alternatively you can just copy/paste the file directly to your app.

Example Usage

Lets assume we have this plist file in our resources directory...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>jim</key>
    <dict>
      <key>name</key>
      <string>Jim</string>
      <key>email</key>
      <string>jim@jimsemail.com</string>
    </dict>
    <key>jane</key>
    <dict>
      <key>name</key>
      <string>Jane</string>
      <key>email</key>
      <string>jane@janesemail.com</string>
    </dict>
  </dict>
</plist>

... and we want to copy it over to our app's documents directory so we can update/edit the plist.

# Check if the plist exists in our documents dir
PListRW.exist?(:users, directory = :documentsDir) # => false

# Check if the plist exists in our main bundle
PListRW.exist?(:users, directory = :mainBundle) # => true

# Copy the plist file from the main bundle to the documents dir
PListRW.copyPlistFileFromBundle(:users)

# Fetch the object from the plist file
@users_hash = PListRW.plistObject(:users, Hash) # => A hash containing the User data

# Update the data
@users_hash[:jim] # => { name: "Jim", email: "jim@jimsemail.com" }
@users_hash[:jim][:name] = 'James'

# Store the data back in the plist
PListRW.updatePlistFileWithObject(:users, @users_hash)

# Check this worked OK
PListRW.plistObject(:users, Hash)[:jim][:name] # => "James"
On I wrote

A Poem For Movember

"Give me yo' money!"

- by Gavin Morrice

Yo yo yo,
lovely ladies and bros...

So, as most of you know,
I've been growing this mo',
and raising some dough,
'Cause cancer blows!

So please kindly show,
some support and go,
to mobro.co,
and up my cash flow!

http://mobro.co/gavinmorrice

On I wrote

The Movember Guys Missed a Trick With Their URL design...

I've seen a few guys on Facebook and Twitter advertise their "Mo Space" pages (Movember profile page where people can give donations) this month. Kudos boys!

The problem is, the link they've shared is the generic "mospace" URL which shows your own profile when you've logged in (http://uk.movember.com/mospace/) and not the unique URL for their profile (e.g. http://mobro.co/gavinmorrice). They've clearly just copy/pasted the URL from the address bar - a pretty understandable mistake.

To put this into perspective, imagine seeing something on your Facebook news feed you thought was funny so you send your friend a link to http://facebook.com expecting them to see the same thing (they don't, they see their own news feed). What ends up happening is, when people click the URL to go and donate they're either redirected (because they don't have a Movember account) or they're shown their own Movember profile page.

Given that the whole point of a Mo Space page is to share the URL with others and get some donations - I really think this UX faux pas should be addressed in the next release and unique user URLs used instead.

#JustSayin

On I wrote

How to load one Gemfile from another Gemfile in Ruby

I'm working on a Rubymotion project just now in which most of the application code is held within a submodule (so it can be shared across multiple apps).

The submodule has it's own gem dependencies and it's own Gemfile.

I was looking for a way to load the submodule's Gemfile from within the main application's Gemfile and I discovered I can do this:

# in my main app's Gemfile
source 'http://rubygems.org/'

eval_gemfile File.join(File.dirname(__FILE__), "vendor/MyPlugin/Gemfile")

gem "some_other_gem"

It's that easy

On I wrote

I'm growing a handlebar moustache for Movember...

I'd just like to inform you all that I'm growing a stache for Movember

If I'm prepared to do this to my beautiful face, the least ya'll can do is have one beer or gingerbread latte less this week and donate £2 (or more) here =>http://mobro.co/gavinmorrice