Saturday, November 7, 2009

Blogging software for Mac

I used to use Windows Live Writer in the old days but now I'm a trendy Mac user I need something suitable.  Seems like there are a number of paid options that people rate quite highly but I'm too cheap to pay for software.

I just tried Quamana and it looked promising.  Unfortunately it kept throwing errors, didn't download tags from Blogger and then failed to actually publish the post!

I'm now trying Flock which is a full featured browser built on the same stuff as Firefox, that happens to have a blog editor built in.  I don't think it's as clean as Live Writer, but appears to have enough functionality for my basic use.

MacBook Pro AirPort autoconnect

We just installed a new wireless router with WPA security (with the last one we were using WEP).  My MacBook Pro connected just fine first time.  The problem was that whenever I close the lib and reopen the Airport would not automatically connect, it would ask me which network to connect to.

The surprising solution was to move /Applications/Utilities/System Preferences.app into /Applications/System Preferences.app

Now AirPort reconnects all by itself every time.

Saturday, June 27, 2009

Using simple_auto_complete

I'm working on my first public Rails application for managing small skydiving businesses.  The primary feature is to track when a person gets in an aircraft to make a skydive.  In skydiver speak, that's: "Jumpers are manifested in a Slot on a Load". I'm using a model named Account to hold Jumpers, Pilots and in fact anyone who does business with the dropzone.

So, My models look like:
class Load < ActiveRecord::Base
  has_many :slots, :dependent => :destroy
end
and:
class Slot < ActiveRecord::Base
  belongs_to :account
end
The form for editing a load contains:
<%= render :partial => 'slot', :collection => @load.slots %>
and the _slots.html.erb partial contains something like:
<% fields_for "load[slot_attributes][]", slot do |slot_form| -%>
  <%= slot_form.label :account_name, 'Jumper:' %>
  <%= slot_form.text_field :account_name %>
<% end -%>

This all works great, so it's time for a little flair ... what I'd like is for the Account.name field to present a list of accounts that match the text that I've typed so far and allow me to pick one (like the Google search field does these days).

Enter simple_auto_complete.

The instructions in the README describe the steps to get the simplest example working but left me scratching my head.  What I needed was the following...

In SlotsController (something I didn't even need before):

class SlotsController < ApplicationController
  autocomplete_for :account, :name, :order => 'name ASC'
end

in _slot.html.erb, I changed to:

<% fields_for "load[slot_attributes][]", slot do |slot_form| -%>
  <%= slot_form.label :account_name, 'Jumper:' %>
  <%= slot_form.text_field :account_name, :class => 'autocomplete', 
      :autocomplete_url => autocomplete_for_account_name_slots_path %>
<% end -%>
I updated my routes.rb to include:
map.resources :slots, :collection => { :autocomplete_for_account_name => :get}
Finally, I added to my application.html.erb layout:
<%= stylesheet_link_tag 'site', 'jquery.autocomplete' %>
<%= javascript_include_tag 'jquery', 'jquery.autocomplete', 'application', 'prototype' %>
And it works like a champ!

Saturday, February 28, 2009

Permission denied - db/test.sqlite3

I'm investigating creating a plugin for Redmine and having a good old time when I decide to clear out the test database:

C:\dev\redmine>rake db:test:purge
(in C:/dev/redmine)
rake aborted!
Permission denied - db/test.sqlite3

Boo! 

I don't know what made me think of it but I tried unsetting my RAILS_ENV environment variable (I had it set to "test"):

C:\dev\redmine>set rails_env=

C:\dev\redmine>rake db:test:purge
(in C:/dev/redmine)

C:\dev\redmine>

Hurrah!

Sunday, February 22, 2009

Formatting README.rdoc on github

Github has a neat feature that displays a README file, that it finds in the root directory of a project, on the project page. The README formatting page describes a number of different formats that it will render based on the file extension. I tried renaming to README.rdoc but it still rendered as plain text. The trouble was that the file was intended to be used with a full RDOC site for the source. When I removed the "link" tags from the file and pushed ... Github renders it correctly ... Hurrah!

Saturday, February 14, 2009

BDD WxRuby applications with Cucumber and Nobbie

For a long time now, I've been wanting to write some Cucumber features to describe a WxRuby application I have. A couple of weeks ago, I found a library called wx-nobbie on Rubyforge that seems to be almost exactly what I was looking for.  It provides a simple, high level interface for driving WxRuby applications through commands like "click", "choose" and "type".  I had a little trouble getting the tests to pass to start with, but with a few minor tweaks I got there.  I contacted the original author and got his permission to take it forward.

I created a GitHub repository for Wx-Nobbie and have made a few updates over the last week.  Currently, I've got 4 feature scenarios with 10 steps:

C:\dev\wx-nobbie>rake features
(in C:/dev/wx-nobbie)
In order to test drive a WxRuby application  # features/acceptance_test.feature
As a developer
I want Nobbie to provide acceptance test access to the application
  Scenario: Choosing a radio button  # features/acceptance_test.feature:5
    Then "radio_button" is not chosen# features/step_definitions/acceptance_test_steps.rb:21
    When I choose "radio_button"     # features/step_definitions/acceptance_test_steps.rb:1
    Then "radio_button" is chosen    # features/step_definitions/acceptance_test_steps.rb:17

  Scenario: Choosing a check box  # features/acceptance_test.feature:10
    Then "check_box" is not chosen# features/step_definitions/acceptance_test_steps.rb:21
    When I choose "check_box"     # features/step_definitions/acceptance_test_steps.rb:1
    Then "check_box" is chosen    # features/step_definitions/acceptance_test_steps.rb:17

  Scenario: Type into a text control        # features/acceptance_test.feature:15
    When I type "123" into "text_ctrl"      # features/step_definitions/acceptance_test_steps.rb:5
    Then I should see "123" in "text_ctrl"  # features/step_definitions/acceptance_test_steps.rb:9

  Scenario: Type into a combo box           # features/acceptance_test.feature:19
    When I type "456" into "combo_box"      # features/step_definitions/acceptance_test_steps.rb:5
    Then I should see "456" in "combo_box"  # features/step_definitions/acceptance_test_steps.rb:9


4 scenarios
10 steps passed

With just these 4 scenarios, RCov tells me I have 62.9% coverage.

Hurrah!

Sunday, January 25, 2009

Building a Ruby Extension With Visual C++ Express 2008

Edit March 29, 2009: While the instructions below describe how to build the Win32::GuiTest extension, I didn't get very far with using it before I found Wx::Nobbie which I much prefer and have taken up the maintenance of at Github.

I'd like to be able to use Cucumber to drive the development of Windows applications so I went looking for something like Webrat for desktop GUI's. I found Win32::GuiTest.  There is a project of the same name on RubyForge that contains the same source but that's as far as that went. 

Win32::GuiTest is a C extension that was compiled with Cygwin, so I wanted to rebuild a native version.  I found some instructions on Kevin Kleinfelter's blog that look much like below, but using VC++ 2008 I got to skip a couple of steps:

  1. Download and install Visual C++ Express Edition (this is free, I got the 2008 version)
  2. Edit $RUBY_HOME/lib/ruby/1.8/i386-mswin32/config.h and delete the “#error MSC version unmatch” line
  3. Open a Visual Studio 2008 Command Prompt
    • Start
    • All Programs
    • Microsoft Visual C++ 2008 Express Edition
    • Visual Studio Tools
  4. cd C:\temp\guitest020218\ext\cguitest
    • I'm building the guitest extension
  5. ruby extconf.rb
  6. nmake
  7. mt.exe -manifest cguitest.so.manifest -outputresource:cguitest.so;2
    • Copy and paste the command above. You need it all from the 'mt' to the ';2'
  8. nmake install
  9. cd \temp\guitest020218
  10. ruby install.rb config
  11. ruby install.rb install
  12. To test:
    • irb
    • require 'win32/guitest'
    • check response is '=> true'