Learn Time released

An iPhone/iPod Touch program to learn to read the time has been approved by the app store. It shows a fun and colourful clock with multiple levels of difficulty that is fine for beginners and more advanced learners. The child must move the hands of the clock to the correct time. More details can be found here and it is available on the app store.

iPhone apps

I have released a couple of iPhone/iPod Touch apps recently but have yet to create a space for them on this website. It has been an interesting experience developing for the platform even if I haven’t quite go my head around Objective-C. It certainly isn’t the same as programming for BeOS or Ruby on Rails (or C# & .net) but it is a decent language.

If anyone has any suggestions then please feel free to contact me at kumo@kumo.it with any ideas. Also I am looking for translations for my Roman Numerals application (external link to itunes) so if anyone would like to help out I would be most grateful. I have Italian, Korean, and Chinese (Traditional and Simplified) so far.

acts_as_confirmable rails plugin

acts_as_confirmable is a Ruby on Rails plugin that is useful when you want to know who ticked a check box and when they did so. It can be found on GitHub.

This plugin treats a datetime attribute and an integer attribute as a boolean. This boolean can then be used as normal attribute in a check box (or in any part of the program) and when it is checked, the datetime records the moment and the integer records the id of the current user.

It is assumed that there is a Users table and that the current user can be found at User.current_user. If the current user cannot be accessed then 1 is used as the id.

Installation

$ cd vendor/plugins
$ git checkout git://github.com/kumo/acts_as_confirmable/tree

Usage

  • On models where you want to be able to confirm X add a X_confirmed_at datetime and X_confirmed_by integer.
  • In the model put acts_as_confirmed :X
  • In the views add check boxes (check_box :X)

Example

create a new rails app

$ rails confirm
$ cd confirm

create users table and items table with 3 confirmable fields

$ script/generate scaffold user name:string
$ script/generate scaffold item name:string \
      started_confirmed_by:integer started_confirmed_at:datetime \
      finished_confirmed_by:integer finished_confirmed_at:datetime \
      ready_confirmed_by:integer ready_confirmed_at:datetime

add the plugin to the model

class Item < ActiveRecord::Base
  acts_as_confirmable :started, :finished, :ready
end

add 3 check boxes in items/new.html.erb and items/edit.html.erb

<p>
  <%= f.label :started %><br />
  <%= f.check_box :started %>
</p>
<p>
  <%= f.label :finished %><br />
  <%= f.check_box :finished %>
</p>
<p>
  <%= f.label :ready %><br />
  <%= f.check_box :ready %>
</p>

show the confirmation info in items/list.html.erb

<td>
  <%=h item.started? %>
  <%=h item.finished_confirmer.name if @item.finished? -%>
</td>

example of assigning a user to current_user

class User < ActiveRecord::Base
  cattr_accessor :current_user
end

class ItemsController < ApplicationController
  before_filter :load_user

  def load_user
    User.current_user = User.find(:first)
  end
end

Available fields

If a model has the attributes fields started_confirmed_at and started_confirmed_by, then the plugin provides:

  • started? true if it has been confirmed by someone on a specific date
  • started same as above but is normally used by a check box tag
  • started= the assignment method that is used by the check box when posting
  • started_confirmer the user that confirmed it
  • started_at when it was confirmed

Designing a quiz with plain text user stories

Over the next couple of posts I thought that I would like to discuss the redevelopment of my hiragana and katakana quiz software. This software originally started out as a command-line Perl script, became a PHP web script, before turning into a Ruby on Rails web application. Unfortunately, although the development language changed and possibilities increased, the overall functionality remained very much trapped in the original design. As I have started in other posts, I have plans for my quiz software, but it remains rather static, so perhaps it would be a good idea to talk about user stories as a way of providing clarity and focus.

I tend to prefer to use development tools that simplify the tasks that I have come to find routine, but perhaps more importantly provide me with a fresh and powerful way of looking at new problems that I need to solve. The latest tool to find me is user stories with RSpec. Now, I must say that I was already using RSpec to ‘test’ other Ruby on Rails applications and I think that everyone should try and play around with it for a bit, but user stories—in particular the plain-text flavour of them—are what currently occupy my notebook scribbles.

Let me show a somewhat simplistic and incomplete example of a user story:

Story: starting a quiz
  As a visitor
  I want to start a quiz
  So that I can hopefully learn something

  Scenario: quiz doesn't exist
    Given a quiz named hiragana
    When I start another quiz
    Then I should see the 404 error page
    And I should see a link to the list of quizes

  Scenario: quiz does exist
    Given a quiz named hiragana
    When I start the quiz
    Then I should see the quiz
    And I should see a question

We have a story with two scenarios: when the quiz exists and when the quiz doesn’t exist. It is not very interesting, but at least we know that the user should see an error page if they try and start a quiz that doesn’t exist, and that they should also see a list of quizes that are available instead. If the quiz does exist then they should see a question.

This might be useful if we want to ensure that the 404 page is shown when the requested quiz doesn’t exist, but it is not very satisfactory to write down and seems a bit pointless. It also doesn’t help us understand what happens when a user starts a quiz.

One of the main thing that I like about plain text user stories is that I can easily scribble them down on a piece of paper. I can focus on describing my goals without worrying about the implementation details and afterwards even use this “pseudotestcode” directly. The plain text user story also is nicely separated from the implementation code that is needed to make it work and because of this, it is easy to fit an understandable and detailed story in a manageable page or two.

I think I will use the following story in my quiz redevelopment and next time I will discuss other stories, and also how to test these stories.

Story: starting a quiz
  As a visitor
  I want to start a quiz
  So that I can hopefully learn something

  Scenario: quiz doesn't exist
    Given a quiz named hiragana
    And a quiz named katakana
    When I start another quiz
    Then I should see the 404 error page
    And I should see a list of quizes
    And the list of quizes should have 2 items

  Scenario: default configuration
    Given a quiz named hiragana
    When I start the quiz
    Then I should see the quiz
    And I should see a question
    And I should see the text "Question 1 of 5"
    And there should be 3 textboxes

  Scenario: 10 questions
    Given a quiz named hiragana
    And the quiz has been configured for 10 questions
    When I start the quiz
    Then I should see the quiz
    And I should see "Question 1 of 10"

  Scenario: 5 hiragana per question
    Given a quiz named hiragana
    And the quiz has been configured for 5 hiragana
    When I start the quiz
    Then I should see the quiz
    And there should be 5 textboxes

Quizes back online

UPDATE: well the old quiz should be back online so if there are any problems please let me know! I am going to start documenting my work on the new version of the quizes so let’s see how it goes.

Hello, I am sorry to say that I am putting the quizes temporarily offline. The reason being that they are in definite need of changes and I haven’t updated the code for a long time; mainly because it was too awkward deploying new versions. I am starting to take the steps to simplify the whole process, but it may take a couple of days to return.

As I want to go to Japan this summer I think this will be a good opportunity for me to sort out the quizes and make them more useful for me which in turn should be more useful for you!