Archive for the 'programming' Category



chris blogs: Ruby Symbols are not Lisp symbols

I’ve started learning Lisp. I already know Ruby quite well, having used it for years now. Lisp symbols as are different than Ruby symbols: chris blogs: Ruby Symbols are not Lisp symbols.

Advertisements

Unobtrusive Zebra Striping

Today I needed yet another zebra-striped table on a page. Having just converted this app to use jQuery, I thought, “there must be a simple way to decorate a table unobtrusively.” It was absolutley simple.

$(document).ready(function() {
  // adds classes for zebra striping table rows
  $('table.zebra tr:even').addClass('zebra_stripe');
}

Now, any table with the zebra class has its even rows decorated with the zebra_stripe class and those rows are styled like so:

tr.zebra_stripe {
  background-color: #F1F5FA;
}

How to Change the Case of Finder Labels in Leopard

A quick search of the term “uppercase” at Macosxhints.com got me this. Took me about 2 minutes and now I have capitalized rather than uppercased labels. Now to find out how to change Mail and iCal and I will be a happy Leopard user…

Before:

finder-sidebar.png

After:

finder-labels-altered.png

Capistrano and Solaris

Recently I’ve been using Capistrano to deploy projects to Solaris. One client uses a Joyent Accelerator (OpenSolaris) and another (University of Virginia) uses Solaris 5.8. The Accelerator is great as it has ZFS, the new Solaris Services, speed, etc. But Solaris is not the same as Linux or FreeBSD when it comes to certain common utilities and this has caused me problems on both servers.

ln

The main culprit is ln. Capistrano use ln -nfs all over the place to make soft links. Unfortunately, the version in Solaris’s /usr/bin does not remove existing soft links with this command. Oy. My first response was to rewrite the tasks like :symlink and :on_rollback to add rm -rf in front of the link command. After forgetting to do this once or twice in new deploy scripts, I posted to the TextDrive forums. Someone mentioned that the Blastwave version of ln (gnu’s version) worked. Well I’m using Blastwave (and you should too), but I don’t remember seeing that. It turns out that gnu’s ln is in /opt/csw/gnu/, not /opt/csw/bin/.

So I just needed that in front of my path, but when Capistrano logs in through ssh, it doesn’t pick up either /etc/profile or ~/.profile. (I don’t have links handy, but apparently this depends on how bash was compiled.) There are two ways of dealing with this. You can add a path to your ssh config (here’s some info), but I prefer making the change in /etc/default/login. I want the Blastwave stuff to take precedence all the time.

More on Should

I was reading a post to Rails Studio mailing list today when I came across this:

If you’re using mocha/stubba, you can say:
@user_notifier.expects(:deliver_activation).never

If you’re using flexmock, you can say:
flexmock(@user_observer).should_receive(:deliver_activation).never

Which would I rather use? Disregarding the frameworks, if you read my previous post, you know the answer: use the active verb! expects is far preferable to should_receive.

Hackety Hack: the Manifesto

_why has started a new and interesting project: Hackety Hack: the Manifesto. The accompanying blog is http://hackety.org/.

Form Test Helper Plugin

This week I found the FormTestHelper plugin by Jason Garber. It both enhances and simplifies form testing in Rails functional and integration tests. The great thing is the FormTestHelper tests the form, not just the submission of the form data. For example, if you try to set a form element that doesn’t exist, an error is thrown.

Here’s my first pass at using FormTestHelper:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
assertions = proc do |response|
  assert_response(response)
  assert(exhibit = assigns(:exhibit), 
   "Should have assigned :exhibit")
  assert(exhibit.errors.empty?, 
   "@exhibit should not have errors: #{exhibit.errors.inspect}")
end

exhibit_count = Exhibit.count
get(:new)
assertions.call(:success)

submit_form('new_exhibit') do |f|
  f.exhibit.title = "New Exhibit"
  f.exhibit.exhibit_type_id = 1
  f.exhibit.license_id = 1
  f.exhibit.annotation = "Exhibit notes."
end

assert_equal(exhibit_count += 1, Exhibit.count )
assertions.call(:redirect)
assert_redirected_to(edit_exhibit_path(assigns(:exhibit)))
assert(flash[:notice])

Pages

Categories

Copyright ©2008-2013 James E Orchard-Hays, All Rights Reserved
Advertisements