Archive for the ‘geek’ Category

Feisty to Gutsy Upgrade - Duo CPU Detection for D620

Tuesday, October 30th, 2007

I completed the upgrade from feisty fawn (4.10) to gutsy gibbon (7.10) over the weekend. There were a few issues - the upgrade hung during the installation of a package and I had to resume it manually using dpkg. This was not really much of a big deal - the same thing happened when I upgraded from edgy.

However today I was sliding my mouse over the KDE Power Manager and I noticed that the CPU Frequency only displayed one processor. Given my Dell D620 came equipped with a duo core processor I took immediate notice. Inspecting /proc/cpuinfo revealed the issue wasn’t with the PowerManager but rather in the CPU detection being performed by the kernel.

It turned out that during the upgrade a 386 kernel was installed and made the default. The 386 kernel lacks duo support (I believe) based on a few things I read on the topic. I rebooted into the generic kernel and the Power Manager displayed the two processors.

After determining that was the problem I removed the 386 kernel from my system which fixed my system to use the correct generic kernel as that was the next one on the list.

I am not sure why the upgrade process nixed the cpu detection but given the ease of the fix not something I will dwell on much. It could have been caused by my interrupted upgrade, the fact my kernel had been patched for vmware, or something wrong with the upgrade process itself.

excel charting - ignoring values with na()

Wednesday, September 5th, 2007

On my current project I am playing an iteration manager role. Coming from the development kingdom I have avoided excel like the plague it rightfully is. However I am unable to avoid it any longer and I’ve been playing around with charting. I was creating a simple iteration burn up chart from a series of values. The table itself was simple:

Date Scope Complete Total Complete
Sep 1 10 2 5
Sep 2 12 3 5
Sep 3 12

My challenge was the red highlighted values. I wanted to make my table smart so it summed the total complete based on the days progress. That was simple (by summing that days plus the previous day’s total complete value). I used the if(condition, value if true, value if false) function to set the value to blank (”") when there was no value present:

=IF(ISBLANK(C4),"",C4+D3)

This worked visually but then when I charted the values the blanks were displayed as zeros which considering the values were at the tail end of the iteration looked rather silly on top of being inaccurate. It’s not often when a team undoes all the work it has done the last 2 days of a 5 day iteration!

A bit of searching yielded the charting solution. I found this excel newsletter which described the na() function. All na() does is set the value of the cell to “no value available” which the excel charting is clever enough to ignore. My table now looks like this:

Date Scope Complete Total Complete
Sep 1 10 2 5
Sep 2 12 3 5
Sep 3 12 #N/A

And the Total Complete function now looks like this:

=IF(ISBLANK(C4),NA(),C4+D3)

This is not as preferable as a null which could display as a blank but for the sake of the burn up chart it will have to do. I have no doubt this is hardly worthy of the designation “excel tip” and is something any seasoned excel veteran is familiar with but I found difficult and also found the solution (buried away on the Windmill Software Newsletter #62 from October 2003) difficult to find as well.

As an aside I was reading some excel forum and some guy signed his posts with the phrase “Keep Excelling”. After you get over your involuntary shudder I suggest you all take a look at OpenOffice calc which I have had great success with.

RoundCube Webmail - thoughts a few weeks in

Thursday, August 30th, 2007

Three weeks ago I migrated my webmail from trusty old Squirrel to RoundCube. I did this for a few reasons

  • I was tired of squirrel mail not being more reactive.
  • I was tired of errors reading HTML mail. The process to view in HTML mode would break a lot and when viewing the HTML portion of the email the “reply” button was lost. Generally I have no interest in reading the HTML version of an email but occasionally I do want to see the pretty pictures.
  • I wanted an ajax preview pane so I would be able to more easily navigate from message to message without a lot of full page refreshes
  • I was really tired of not having address book integration. I was constantly going through old email’s looking for addresses. Squirrel mail had some LDAP options but nothing that was accessible from the composition page. I use plaxo and would have loved integration with that but I didn’t need it. Roundcube promised an ajax address book lookup which sounded golden.

I installed roundcube easily enough. LAMP application and the configuration was fairly obvious. The look and feel was immediately snazzy. Aside from my browser shell roundcube gives the impression of a modern web 2.0 application.

I opened an email and was immediately bothered by the full page view. I was expecting the index page to split and see a message preview (I had looked at roundcube in the past and specifically recalled a screenshot showing this). I figured it was in the preferences somewhere but didn’t see anything. After digging through the roundcube roadmap and issue tracker I discovered the preview pane had been pulled out (due to it being buggy) and it was slated for a later release. This was a real bummer.

I said to myself “Well someone must have added a plugin for this” and set about looking for the roundcube plugin repository. To my shock there wasn’t one. On the trac ticket for the preview view I found a patch I could apply to my install and a few roadmap milestones away was the feature “Implement the plugin API with documentation.” under Milestone 3 Beta. Considering the application is in .1 RC1 and there are no timetables I was completely surprised. After the excellent design of roundcube and the ambitious ajax / drag drop feature set (which appears to be custom developed..no scriptaculous/prototype js files) the lack of a plugin architecture up front shocked me. Particularly after using wordpress with it’s outstanding plugin support I really was left speechless. I had no desire to apply a patch to my roundcube install (and the subsequent upgrade hell that follows).

The composition address completion worked great. Even adding addresses to the built in address is a breeze although checking to see if I already have the address and not presenting the “+” button next to the name would be nice.

I noticed a few inconsistent bugs when moving messages using drag and drop. The first few times I tried it the messages did not move. Later the problem went away and I had no issues moving messages among folders.

There is no empty trash button which was strange for an IMAP client.

HTML rendering of email is fantastic. Remote images are blocked by default like I would expect.

So overall I guess I am satisfied. The ajax features are excellent, the IMAP performance is improved, and I can’t say squirrel mail is any better at a preview pane. Roundcube still feels much like a beta application (which is what it is). It shows a lot of promise but I would be greatly concerned about its absolute lack of extensibility. I’d love to contribute (or use) a plaxo address book extension / plugin but there is no easy way to do so. An application like roundcube should be designued up front for drop in extensions and plugins - not a clunky diff / patch system.

Howto Rails Generators with SeaCucumber

Monday, August 20th, 2007

Over the weekend I spent some time working on some generators for SeaCucumber the javascript testing framework I am working on with Mike Ward. There is quite a bit of redundant HTML code that serves as plumbing to the framework and a generator would simplify that.

I found the most useful generator documentation is on the RoR wiki: Understanding Generators.

The generator code itself was very simple although it will be interesting to try for a more complex generator.

class SeacucumberGenerator < Rails::Generator::NamedBase
  def manifest
    record do |m|
      m.directory File.join('test/javascripts')
      m.directory File.join('public/javascripts')      

      m.file 'unittest.js', File.join("public", "javascripts", "unittest.js")
      m.file 'test.css', File.join("test", "javascripts", "test.css")

      m.template('javascript_template.js',
          File.join("public", "javascripts", "#{file_name}.js"))
      m.template('seacucumber_template.html',
          File.join("test", "javascripts", "#{file_name}_test.html"))
    end
  end
end

This generator does three basic things.

  • m.directory - Creates directories if necessary.
  • m.file - Copies static files without modification to the target directory.
  • m.template - Executes the two templates using ERB and writes them to the target location.

I used a NamedBase which take an argument. For example I might run this:

script/generate seacucumber MyFunction

Rails::Generator::NamedBase exposes a number of accessible attributes which are created from the argument. The most useful thing this class does is provide a bunch of attributes you can use from the manifest or template. It takes a trip to the source code to find out what they all are. To save time I thought I’d list them along with their values which follow standard rails inflection rules:

  • name MyFunction
  • class_name MyFunction
  • singular_name my_function
  • plural_name my_functions
  • table_name my_functions
  • class_path (blank)
  • file_path my_function
  • class_nesting (blank)
  • class_nesting_depth 0

Next I need to add a bit more sophistication to the templates I am generating to make them sensible for when someone is starting to develop a JavaScript function and needs to generate the Sea Cucumber plumbing.

WordPress Plugin for Google Syntax Highlighter

Wednesday, August 15th, 2007

I am a big fan of the source code highlighter used by the Waffle project. Michael Ward recommended it for me to use when I set my blog up a few weeks ago.

Screenshot

The highlighter itself is simple to use on its own - it’s just a javascript include but I had been using another code highlighter which had a WordPress plugin that made it’s use a snap.

I figured it wouldn’t be too hard to create a plugin for the syntax highlighter (which had larger language support including ruby which I needed) and so I did. The plugin is being hosted by WordPress and I encourage you all to take a look and use in your own blogs.

Google Syntax Highlighter for WordPress

Debian etch webdav issues

Friday, August 10th, 2007

I was setting up my webdav (which I had not used since I upgraded my debian installation to etch from sarge) to talk to Windows XP and ran into a couple of unexpected issues.

AuthDigestFile becomes AuthUserFile
Somewhere in the upgrade to etch the AuthDigestFile directive went invalid (I recall I just disabled my webdav site when i upgraded). and is now AuthUserFile. Otherwise everything else stays the same.

XP forces NTLM Authentication
When I tried adding my web dav as a network place using my username / password the authentication failed and in the windows authentication box I saw servername/username instead of just my username. I did a bit of digging around various webpages and found a few client and a few server fixes. The easiest one for me was to create a new user in the form of user@server that bypassed the windows forcing NTLM authentication bug.

Etch denies DavLockDB
Finally I was able to connect but then I noticed that both cadaver (which I was using as a sanity check) and windows could not write to the dav. Windows reported the error a device attached to the system is not functioning. In Cadaver I was receiving an I/O error. It turned out that the apache2 user (www-data) could not write to the DavLockDB which was at /var/lock/apache2/DAVLock. I changed the owner of that file to www-data and from that point on the WebDAV was functional from both cadaver and WindowsXP.

The Windows XP authentication error was something I would have encountered but the sarge => etch upgrade path did not make it easy for my WebDAV. I am not sure if there was a reason why the DavLOCK database was no longer accesible to www-data (perhaps the default location for this database was moved) or why the Apache directive for digest authentication changed.

BDD Model Validation using RSpec and extensions to Hash

Wednesday, August 8th, 2007

I avoid writing fixtures for testing. They are cumbersome to write and management (particularly after the fact) is a hassle. When testing a model’s validations I want to work with a generally static model that only changes one or two attributes which illustrate the test condition I am working on. To this end I followed Luke Redpath’s blog post on BDD and models in particular that uses a more behavior driven approach to testing a model and it’s attributes.

As such in my rails projects now I like to use this Hash extension when defining the validation rules for my model.

module HashExtension
  def except(*keys)
    self.reject { |k,v|
      keys.include? k.to_sym
    }
  end
end

And then I can define a model’s allowed behavior using RSpec. For example:

describe "a test model" do
  def valid_model_attr
     { :name => "name", :age => 21}.extend(HashExtension)
  end 

   it "should be valid" do
      Model.new(valid_model_attr).should be_valid
   end

   it "should be invalid without name" do
       model  = Model.new(valid_model_attr.except(:name))
       mode.should_not be_valid
       model.errors.on(:name).should_not be_nil
   end

  it "should be invalid if age is under 21" do
       model  = Model.new(valid_model_attr.except(:age))
       model.age = 20
       mode.should_not be_valid
       model.errors.on(:age).should_not be_nil
  end
end

I can add as many tests as I want without defining several test specific fixtures which need to be updated when the validation rules for a model change. Using an attribute hash and except I can update one hash.

This technique gets a little more complicated when testing a model with a has_many / belongs_to relationship but I recently had success with that on this site I developed (www.clowndown.net). In that case I defined a test hash a such:

  before(:each) do
    @team  = Team.new
  end

  def valid_team
    {
      :name => "team name",
      :contact_number => "call me here!",
      :people => [valid_person, valid_person],
      :knowledge_of_chicago => "pretty good",
      :why_will_win => "might get lucky",
      :relationship => "great"
    }.extend(HashExtension)
  end

  def valid_person
    person = Person.new
    person.attributes = {
      :email => "email@email.com",
      :name => "My Great Name",
      :shirt_size => "L",
      :hometown => "Chicago",
      :team => @team,
      :occupation => "occupation"
    }
    person
  end

And I was able to write specs like this that used an object relation that focused on testing of the behavior of the has_many / belongs_to relation.

  it "is invalid with 1 person" do
    @team.attributes = valid_team.except(:people)
    @team.people = [valid_person]
    @team.should_not be_valid
    @team.errors.on(:people).should_not be_nil
  end

Inconsistent/Broken WordPress Category Feeds

Wednesday, August 8th, 2007

I have been setting up WordPress on my Debian etch server and everything seemed fine. That is until I tried using category specific feed.

I am assigning all of my posts On my blog I have a couple categories that I would like to have feeds for. These are:

http://www.peterryan.net/category/geek/feed/
http://www.peterryan.net/category/cooking/feed/

They both correspond to the following category archives:

http://www.peterryan.net/category/geek/
http://www.peterryan.net/category/cooking/

However as far as I can observe the readers I am testing with (Firefox Live Bookmarks, Thunderbird RSS Reader, Google Reader, and ThoughtWorks blogs which should be subscribing to the geek category) are not processing the results correctly. Sometimes the wrong category is returned (such as the cooking category is returned when I access the geek feed) and sometimes in Firefox an HTML instead of an XML page is rendered (and sometimes the wrong version of that).

This problem goes away if I do not use pretty permalinks (as described in the WordPress Codex and use the default. I would like to avoid using ugly links but I feel like I am running out of options.

I have looked at the following word press support threads plus I am sure more:

http://wordpress.org/support/topic/111113
http://wordpress.org/support/topic/112673
http://wordpress.org/support/topic/111356
http://wordpress.org/support/topic/124459?

And I have opened my own support forum with no help received so far:

http://wordpress.org/support/topic/129238

I am currently attempting to find help on the wordpress irc channel but have not had much success. Since this problem could be related to either my debian apache2 server, my php5 configuration, mod_rewrite, or wordpress I am a bit at a loss as to how to proceed. I would greatly appreciate any help related to this problem.

My HTACCESS file (generated by wordpress) is:



RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I would greatly appreciate any help.

Enumerable::group_by extension

Friday, August 3rd, 2007

I was working recently on a simple RoR website and needed an easy way to display columns of data on the front page. The easiest possible query was a simple find(:all) but after that I wanted to divide the items returned into groups that would be rendered separately. I wasn’t aware of any grouping available in enumerable so I did a bit of a search and ran across this discussion thread. I didn’t read the entire thread (and it’s mention of Set::classify which I was not aware of) but liked the group_by extension it proposed.

module EnumerableExtension
   def group_by(store=Hash.new)
     self.each do |elem|
       group = yield elem
       (store[group] ||= []) << elem
     end
     store
   end
end
Enumerable.send(:include, EnumerableExtension)

controller

@collections = Collection.find(:all).group_by do |collection|
        collection.name.to_sym
end
@left = collections[:left]
@right = collection[:right]

view

<%= render :partial => “left_well”, :locals => {:items => @left} %>
<%= render :partial => “right_well”, :locals => {:items => @right} %>

If I had to do this again I probably would have used Set::classify but I still like the group_by available in Enumerable and I like not being forced to create a set simply to group objects.

SeaCucumber - JavaScript Testing Tool based on Script.aculo.us

Monday, July 30th, 2007

Michael Ward and I are working on extracting the Script.aculo.us Test.Unit.Runner into a rails gem / plugin. We used this testing framework at our last client and we found it very useful. We would like an easier way to use the testing framework (in and our of Rails). We have called the project Sea Cucumber and are hosting it on RubyForge.