Monthly Archives: October 2013

Habits of Highly Successful Coders

Habits of Highly Successful Coders

Last night I went to another Ruby on Rails Development Hub, where I got some excellent help on an app that I am currently building for my work.

While there I also learnt (or was reminded about) the good habits I should be getting into as a coder. Good habits are, by nature, harder to get into than bad habits, so I feel I need to make a list to remember them. Let’s start with just four of the big ones;

  1. Make branches in Git – I usually only remember to do this when it’s already too late, and I have a semi-disaster going on.
  2. Get into Test Driven Development – Everyone is recommending RSpec. I really need to get into this. I have learnt how to do it through the Michael Hartl Rails tutorial, but I really need to make it a habit.
  3. Do smaller commits – rather than a general commit at the end of a few hours saying -m “Fixed some things, and it works ok right at this second”, I really need to break my commits into smaller, more easily understandable chunks.
  4. Use a Debugger – Rather than wailing in despair over not knowing what is wrong with something, I should use a debugger, like lovely coder Rob showed me last night (We used ByeBug).

Let’s revisit this list in a month or two and see if I am doing any of these things…

Leave a reply

Rails Project Seed Files

As I mentioned in my last post I have been working on our High Tea ratings app – and one of the last things I needed to do (other than try and make it ‘pretty’, which I am ‘pretty’ much giving up on) is to pre-populate it with the data we already have. I didn’t want to have to go through and enter each of them through my form.

So, to do this, you use the Seeds file db/seeds.rb. I had the information originally in a spreadsheet, so I needed to get that in a Ruby format.

First, I tried to complete as much of the information as possible.

Then, I used the concatenation formula in Excel to make each line into the appropriate format.

Excel ConcatenationExcel Concatenate for Seed File

Resulting Ruby Seed File Entry

Visit.create(:venue => 'QVB Tea Rooms', :city => 'Australia', :date => DateTime.strptime('09/14/2009', '%m/%d/%Y'), :ambience => 4, :tea => 4, :scones => 3.75, :savoury => 4, :sweets => 2, :service => 5, :bonus => 2, :comments => 'Make a comment', :price_cents => 1, :price_currency =>'AUD')

I quickly discovered that cut and pasting from Excel resulted in annoying things with regards to apostrophes (‘) and some other problems:

  • To make sure apostrophes within my formulae came through, I replaced them with the pipe symbol in my Excel spreadsheet (|) and then Find/Replaced them in sublime text.
  • I also discovered a problem with apostrophes within my text field (comments) and I had to fix those by putting a backslash in front of them. ( I just did a find/replace for my comments column in Excel)
  • The final problem I had was trying to prepopulate my Date field. It just wouldn’t accept the dates I was putting in, so I had to use this formatĀ Date => DateTime.strptime ('09/14/2009', '%m/%d/%Y')

Delete Old Data

At the beginning of your seed file, you probably want to include Visit.delete_all if you want to start your database fresh with your seed data.

Seeding in Development

After ironing out all the quirks, I went to terminal, stopped my server and ran $ rake db:seed

Seeding on Heroku

After I had checked that there were no problems in my development environment, I pushed all my changes to git. I then wanted to apply the seed file to Heroku as well, so I pushed all my changes to Heroku

git push heroku master

and then I ran the seed file on Heroku

heroku run rake db:seed

And that worked for me!



Leave a reply

Another Project – My High Tea App

I’m nearly finished (in a very simple way), another app – High Teas Around The World. (Note that if you click on this link it will take forever to load the first time, as I am still hosting on Heroku. I hope to move my apps at some point…).

Rating High Teas

(I know, for such a fancy name, it is a very boring-looking app).

After my General Assembly course I decided to straight away start another app from scratch so that I wouldn’t forget what I had learnt. I also took the opportunity to try a few different things on this one, for example, I tried using scaffolding – which was a time saver, but had added a lot of junk to my code. I also tried using Zurb foundation instead of bootstrap – I’m still not sure which one I prefer.

This app is part of the evolution of a little hobby my friend and I have – we love travel and cake, so we like to go to High Teas wherever we travel in the world. We came up with an elaborate rating system, and recorded all our visits. Originally it was in a notebook, which evolved to a spreadsheet, which was then a Google spreadsheet we could share, and now I am making an app version!

I’ve made it so that the only people that can contribute to the content are myself and people I choose, although any one can read our reviews. I am hopefully going to be populating it this week – I am trying to create a seed file from my existing spreadsheet data.

Similar to my restaurant app – the interface/look is woeful. I need some severe help in aesthetics. I know that no one is going to use my things if they look crap, but I also don’t know if developing my ‘design’ skills is something I can or should do. Shouldn’t I concentrate on learning to code, and learning how to create the functionality? Maybe what you need to do is partner up with a designer…?

Leave a reply