Category Archives: Uncategorized

Backing up your database from Heroku

I’m writing a quick post on this, because every time I do it I fck around for a while and eventually get it – so this time I am writing my steps!

And yes, I know there is documentation on Heroku, but it never quite works for me. So!

  1. Make sure you have a database created and migrated into which you are going to put your backup
  2. Capture a backup with $heroku pg:backups capture --app rails-girls-events
  3. It will give you a backup id, which you can use in the next command to get the public url of that backup $heroku pg:backups public-url b006 --app rails-girls-events
  4. When you visit that url, it will download to your machine
  5. Use the path to that download to upload it $pg_restore --verbose --clean --no-acl --no-owner -h localhost -U tracymusung -d your-data-base-name path-to-your-download


Leave a reply

Handling Ruby Exceptions and Errors

How to handle exceptions in Ruby? What do `raise` and `rescue` do?

def walk_the_dog(dog)
if dog == nil or dog.size == 0
raise"Can't walk nothing")
puts "Walking #{dog}"

You can use a raise here, to make sure that there is always a dog when you puts "Walking #{dog}". Note that fail is the same raise.

If this raise gets called, nothing after that line will be run.

Exception Handling

If you don’t want your code to just stop when it hits a particular error, you can use rescue, to stop the programme from ending.

Use a begin and end block to handle exceptions and use one or more rescue clauses to tell Ruby what kind of exceptions you want to handle

def raise_an_error
raise 'An error occured.'
puts 'Programme rescued.'

Anything after the raise and before the rescue won’t be run, but anything after the rescue WILL be run.

You can also put a parameter on rescue so you can tell your programme to ONLY rescue certain kinds of errors (that is, the ones you think are acceptable for the circumstances).


rescue StandardError => e

if you don’t say what kind of error, the code will assume StandardError.

rescue StandardError => e
you can shortcut it by
rescue => e
and it will assume you mean Standard Error

It’s important to note that the exception names you use are class names, so if you rescue, for example, StandardError, you will rescue any errors that inherit from that.

You can also create your own exception classes, and you probably want them to inherit from StandardError.

So for example, you probably never want to go
rescue Exception
because this will rescue every exception, because all exceptions inherit from the Exception class.

Errors that inherit from StandardError are NoMethodError, TypeError, RuntimeError, but you can see the whole Exception hierarchy like here

Testing Exceptions

assert_raise(TriangleError) do triangle(0, 0, 0) end

Tests if the given block raises an exception. Acceptable exception types maye be given as optional arguments. If the last argument is a String, it will be used as the error message.



Leave a reply

Gem Dependency Nightmares

As part of the Spree open source project I have been working on, I have encountered a more than usual number of Gem dependency issues. I put this down to the fact that Spree is a big huge project, with multiple engines, each with their own gemfile.

However, today I discovered it could also be because I have not been managing my gems effectively! I wrote a blog post on our Spree project blog, about how I should be managing my gems in the future.

Far out this is a short blog post.

Leave a reply

Ruby Conf Sydney 2014

Only 2 days ago I was feeling a bit apprehensive about attending Ruby Conf in Sydney. I wasn’t sure what I would get out of it, I thought I wouldn’t understand any of the lectures and that because I wasn’t a real programmer,  I wouldn’t fit in.

However, after the very first keynote, I was inspired, reinvigorated and so glad I came. The take home for me from that first keynote was that – yes, programming and developing apps is an exciting and totally possible way for me to influence the world around me – and I want to keep going ahead and trying to do that.

The Highs of Ruby Conf

  • The talk about alternative pathways to becoming a programmer
  • The venue – Luna Park-  with beautiful views of Sydney Harbour, the Harbour Bridge and the Opera House.
  • Getting to go on the rides!
  • Seeing the people I had met at Rails Camp, Roro and other events.
  • The second keynote, which was on diversity, humility and civility by Pat Allan. You hear some horrible things online about the brogrammer culture. These words, coming out of the mouth of a popular Australian programmer, made me feel really hopeful.
  • Missing out on a few of the talks, which meant that I got to have longer, more interesting conversations with people outside the frantic/loud group time in between talks.
  • Being reminded AGAIN about how lovely, welcoming, helpful and interesting the members of Ruby Australia are. One of the mentors from Rails Girls Brisbane, which I attended last June, remembered me and came over to ask me how my coding was going. Just so lovely.
  • Getting some thoughts, from a range of programmers, about the apps I am currently building.

The Lows of Ruby Conf

  • I didn’t go to the Yum Cha, which meant I also missed out on surprise Karaoke!!!

What I Learnt at Ruby Conf

  • We need to keep innovating, and learning how to do new things, because there is skill erosion when things are too easy
  • That with the rise of the international community, and the ability for remote working or outsourcing, you can either be a commodity or part of the creative class – i.e. what value will you add above being able to code?
  • That maybe I should start using MiniTest instead of Rspec, because MiniTest is lightweight and ships with Ruby.
  • That I should do a Computer Science course online (or at least the first few subjects) – Stanford was recommended to me.

Things I need to look up now

  • Learn how to use MiniTest
  • What is mocking/stubbing?
  • What is a struct?
  • Database theories – ACID vs CAP
  • What is a distributed system (databases)
  • Wtf is a node? (Database)
  • MongoDB (everyone making fun of this)
  • Clustered Databases
  • Node.js
  • Middleman?
  • Blocks vs Procs vs Lambdas

Diversity in the Speakers at Ruby Conf

The idea of female speakers is something that has been discussed in programming circles online a lot recently. The final keynote speaker at Ruby Conf, Eleanor Saitta, finished her speech with a slide of names, (all women I assume) saying something along the lines of “These are just 34 names of female speakers I found within 5 minutes of searching on Google, and who would have been great speaking at this event.”

Unfortunately she was the last speaker, and just after she finished they got all the speakers on the stage – which demonstrated quite clearly, how white and male the lineup was.

Of course the Ruby Conference had tried to get female speakers, and it featured a male speaker who spoke of the importance of diversity in his keynote. But as Eleanor pointed out on Twitter, all she can judge it is by the results – not by the trying.

That old favourite “but we just want the best speakers” was also trotted out. Conference organisers don’t want to choose female speakers, just for being female. They think their attendees deserve the best speakers no matter what their sex. But, with the massive gender imbalance in coding, the odds of getting the best speakers is always going to be in the males favour.

Saying you want female speakers, but only if they are the best speakers, doesn’t immediately result in diversity. Because in an 80% male industry, the best speaker is more likely to be male.

To make it more even you would have to either

a) increase the number of women to be 50% – and there is a lot of work being done to encourage this, but of course it is a longer term goal; or

b) provide more opportunities for women to get experience in speaking (so that they can be better speakers) or other kinds of training to improve their speaking. Maybe more assistance to help them put together great topics by the conference organisers?

I’m not 100% sure what the answer is, but I know that just saying “We tried, and there just aren’t enough great women speakers” probably isn’t enough to increase diversity. It’s just leaving it to chance.

Leave a reply