Week 4, day 4

Work continued on our bookmark manager website projects today. I had hoped to make a really slick front-end for it but that plan met with a lot of obstacles, first and foremost my lack of experience in html and CSS. But that's not a problem, it's good I now know that's something I want and need to work on.
We're made aware of the skills that employers look for and one thing that has come up a lot recently is our attitude toward work, and more importantly problems. Keeping a cool head and remaining effective when the shit is hitting the fan and everything is going wrong is essential, I think I tick those boxes but again, that's something I can improve.

The key to improving your design skills is to accept your errors cheerfully, remain detached from past design decisions, and refactor mercilessly.

  • Sandi Metz - Practical Object Oriented Design in Ruby (POODR).
Read More

Week 4, day 3

Had my code review today and I'm super happy about it. My coach this week is a coder with 30 years experience, a seriously knowledgable and very friendly guy. I think his niceness might temper his feedback slightly, I don't think he was harsh enough on me, but I'll take it!
The Makers Academy course is seriously hardcore and the first three weeks are hellish, for the first time I'm actually feeling like I can stop stressing and have fun.

Hi Sanj,
This is great work. Don't take my comments as indication of anything else. You've done really really well here and mastered a number of very sophisticated aspects of programming such as stubbing random behaviour.
It's partly because you've done so well that I'm focusing in on the areas where there is still room for improvement.
I'm going to give you a sticker and mark you completed because you've got a great product here - and the interface looks great, but I do hope you'll review my comments and think about making some of the changes I suggest, or at least bear them in mind going forward. :checkered_flag:

Detailed feedback and a bit more about last week's challenge after the break.

Read More

Week 4, day 2

After the long weekend we were back at the Makers Academy today. It's amazing how tightly bonded I feel to many of my co-coders, I was really glad to see them again. And to get on with the serious business of designing a database in PostgreSQL.

The interface leaves a lot to be desired but it's effective, that's for sure. The practical project we're building to hone our skills on is a bookmark manager, allowing us to Create, Retrieve, Update and Delete entries (CRUD). We're also building a web interface for it so that should give us some more CSS experience.

Lunchtime talk from Alex Tercete

Lunchtime talk by Alex Tercete from Energy Helpline on Commandless Git

Read More

Week 4, day 1

It's Easter Monday and it's a holiday! Yay! Not really, there's work to be done...
Finished up my 'final' version of RPS this morning, incorporating the option to play RPS-Lizard-Spock (RPSLS) and all the logic required for it.
Looking back at it now I feel like I got very lucky with things just working with as little headache as possible, and most of my errors came from typos and syntax.
My RPS challenge Github repo
I'm pretty happy with my Ruby code, less confident about my HTML and CSS but I'm just glad I've caught up with the course so far and look forward to some valuable feedback from my code review tomorrow.

1 class CPU
2   def choice
3     %w(Rock Paper Scissors).sample
4   end
5 
6   def choice_rpsls
7     %w(Rock Paper Scissors Lizard Spock).sample
8   end
9 end

That's all I used to generate a random selection from the computer player, 'choice' for regular RPS and 'choice_rpsls' for the Lizard-Spock variant of the game.

Read More

Week 3, day 7

Today I've been playing around with CSS, I had a hard time getting my stylesheet to load but then discovered it was because the public folder had to be in the same folder as the server.rb . I'm sure I could've configured it differently but my attempts proved unfruitful.
Once that was sorted, I was in business.

Play my amazing Rock-Paper-Scissors game here

RPS-v0.1-screenshot

Read More

Week 3, day 6

Woke up a new man today! Totally rested and regenerated, and I think it shows. Have managed to finish the barebones of the weekend Rock-Paper-Scissors challenge today and intend to spend tomorrow styling it nicely with CSS.
Looking at it now it's hard for me to believe that I was staring at a blank page this morning and I'm pretty proud of what I've achieved. It still needs lots of extra features but the foundations are there and I'm confident they're strong.

 1 require 'sinatra/base'
 2 require_relative 'lib/cpu'
 3 require_relative 'lib/decide'
 4 
 5 class RPS < Sinatra::Base
 6   enable :sessions
 7   cpu = CPU.new
 8   decide = Decide.new
 9   set :views, Proc.new { File.join(root, "views") }
10 
11   get '/' do
12     erb :index
13   end
14 
15   get '/game' do
16     redirect '/'
17   end
18 
19   post '/game' do
20     if params[:Choice]
21       @p1_choice = params[:Choice]
22       @p2_choice = cpu.choice
23       @decision = decide.make @p1_choice, @p2_choice
24       erb :result
25     else
26       session[:Name] = params[:Name] if params[:Name]
27       erb :game
28     end
29   end
30 
31   run! if app_file == $0
32 end

Above is my server file, really simple but does the job. Join me after the break for some more snippets.

Read More

Week 3, day 5

Today I rolled out of bed at 9am, such a sweet, sweet treat. I usually get up at 5.30am to catch the early train and beat the crowds, so a late start to the day is pure bliss.
I had a quick look at the weekend challenge but don't intend to do much work today, I really want to unwind.
I did play around in IRB and am happy to announce I've found many options that do not solve my problems. I'll start the challenge tomorrow and update then, for now, excuse me while I go back to re-watching Interstellar.
Happy Easter!

Read More

Week 3, day 4

Today we were issued our weekend challenge, to create a web version of a working rock-paper-scissors game. This will reinforce all our practice with Sinatra this week, and undoubtedly show the chinks in our armor.
Thankfully it's a long weekend due to Easter, so we have 4 days before we have to hand it in, and I'm not feeling particularly cofident about it at the moment.
The good news, however is that I've caught up on passing last weekend's challenge. My coach this week is a thorough coder and an excellent person to learn from, he showed me exactly how poor my design was before and how to use Single Responsibility Principles, Dependency Injection and Inversion to create a masterpiece in Ruby.
Follow me after the break to see my passing tests in all their glory.
Github link to the current repo for Makers Academy - Week 2 Weekend Challenge

Read More

Week 3, day 3

By the end of today we had made serious headway into the Battleships web game, I think the foundations for building the backend are engrained on our minds now. Most of the day was really painful and grueling, but once it clicked everything just flowed.

The 3rd floor workhouse

This is the 'workhouse' upstairs on the 3rd floor. It's filled with energy from 7am to 9pm.

Read More

Week 3, day 2

Work's going slow on re-doing the weekend takeaway challenge, there just aren't enough hours in the day. Besides that we also have new stuff to learn this week. But I do definitely like Cucumber and Sinatra.
In Cucumber you write your actual tests in plain English and then you define the code translation for that sentence structure. That means that you can re-use many instances of a single sentence structure without the need to re-code it.

Feature: Starting the game
  In order to play battleships
  As a nostalgic player
  I want to start a new game

Scenario: Homepage
  Given I am on the homepage
  When I follow "New Game"
  Then I expect to see "What's your name?"

Scenario: New Game
  Given I am on New Game page
  When I fill in "Name" with "Tupac"
  And click on "Submit"
  Then I expect to see "Sup Tupac!"

Scenario: Does not input name
  Given I am on New Game page
  When I fill in "Name" with ""
  And click on "Submit"
  Then I expect to see "Please enter name"
Read More

Week 3, day 1

Our coach for this week did a quick break-out session for us, explaining best practice for Object-Oriented design when tackling our takeaway-restaurant weekend challenge. Very few people in our cohort had actually done it right and I'm sorry to say I definitely didn't. So that'll be some out-of-hours work I'll have to re-do this week.
Which is actually fine, we want to do it right and now we know how to do that.
We were also assigned our weekly challenge, to create a web version of our battleships game.
The application code was made in Ruby, of course, and originally tested with Rspec/Capybara. But the web front end will be made in Sinatra and tested with Cucumber. It's all very exciting, we're learning new languages!

<div>
  <% if @visitor %>  
    Hello, <%= @visitor %>!
  <% else %>
    <form action="/hello">
      My name is <%= @name %>.
      What's your name?
      <input type="text" name="name">
      <input type="submit">
    </form>
  <% end %>
  <img src='http://bit.ly/1eze8aE'>
</div>
Read More

Week 2, day 7

Goodness me, I am knackered! After sleeping off the excesses of Saturday night I got to work on the takeaway-challenge and boy, was it hard work.
We were tasked with designing, testing and coding a takeaway system for a restaurant that could also send a delivery confirmation text, I didn't get nearly enough done on it so I'm not looking forward to my code review.
One thing I can report, however, is that I found a far more elegant solution to printing out my menu:

1 def show_menu
2   @menu.inject("") { |out, (dish, price)| out << "#{dish}: £#{price}\n" }
3 end
Read More

Week 2, day 6

All I want is to print out my menu. To be precise, my hash keys and values. Surely it can't be that hard, right? Wrong!
Here is where I start to hate myself for forgetting things I've already learnt the hard way. Luckily though, in my past life I was a bit of a pro at trouble-shooting the technical side of creative projects, so this feeling is very familiar to me.
I find I have to make the same mistake 2 or 3 times before the lesson really sinks in, and I can say for sure I won't be repeating this mistake.
Here's my menu and how I want it to appear:

1 menu  = { meal_small: 5, meal_medium: 10, meal_large: 15 }

meal_small: £5

meal_medium: £10

meal_large: £15

Read More

Week 2, day 5

Our cohort was issued a double-barreled weekend challenge today.

Write your own method to replicate the inject method in Ruby.

Write a take-away restaurant program that presents menus, takes orders and sends an SMS to customers to confirm delivery using Twilio

I had a pretty relaxed day at Makers Academy, touching base with a lot of people I haven't had enough time to interact with, then in the afternoon I set to work rewriting inject... and quickly stalled!
This was going to be tough. I continued in the evening and by about 11pm I had something that passed the tests and that I was somewhat ok with. I'm not sure how long the take-away challenge is going to take me, but if I can squeeze in more time around my social plans then I'll have another go at it, but for now here's what I came up with:

 1 class Array
 2   def my_inject(arg = nil, arg_sym = nil)
 3     arg.nil? || arg.is_a?(Symbol) ? result = self[0] : result = arg
 4     if arg.nil?
 5       self[1..-1].each { |value| result = yield(result, value) }
 6       result
 7     else
 8       if arg.is_a?(Symbol)
 9         self[1..-1].each { |value| result = result.send(arg, value) }
10         result
11       else
12         if arg && arg_sym
13           each { |value| result = result.send(arg_sym, value) }
14           result
15         else
16           each { |value| result = yield(result, value) }
17           result
18         end
19       end
20     end
21   end
22 end

Join me after the break for a look at how my code evolved from terrible to satisfactory.

Read More

Week 2, day 4

Today my pair-programming partner and I finished off the bare bones for our Battleship game and could hypothetically modify it to meet the requirements of most board games. It's been a really challenging couple of days of following our excellent coach's tutorials when we couldn't recreate the tests and code ourselves. This was all done in Ruby using Rspec for testing, this time around we didn't have any feature tests at all but a lot of unit tests. It's interesting to see how different people like to work, ultimately any style can be used to create a polished and lean end product. The greatest challenge was definitely coming to terms with doubles for purposes of unit testing. Below is a taster of just some of the doubles we had to employ in our most demanding spec file, the one used to test for board creation.

1 let(:cell) { double :first_cell, content: '' }
2 let(:second_cell) { double :second_cell }
3 let(:cell_class) { double :cell_class, new: cell }
4 let(:board) { Board.new({ size: 100, cell: cell_class, number_of_pieces: 5 }) }
5 let(:ship) { double :ship, size: 2, sunk?: false }
6 let(:small_ship) { double :ship, size: 1, sunk?: true }

Next week I think we will be using Sinatra to create a web-version of Battleships, but a weekend is a long time in coding and tomorrow we get our weekend challenge, so everyone is somewhat nervous once again.

Read More