The Shell Meme

2008-12-30 18:29:35

I ran across The Shell Meme on Lincoln Stoll's blog, and figured I'd, uh, borrow it.

Run this command in a new shell:

history|awk '{a[$2]++} END{for(i in a){printf "%5d\t%s\n ",a[i],i}}'|sort -rn|head

I get this as the output

379 git
221 cd
181 ssh
77  sudo
69  ruby
66  ls
34  rake
33  m
32  bb
31  m.

bb changes directory straight into my BrightBox source directory. m and m. are TextMate alias's to open files or directories in TextMate for editing.

Sending Array elements as individual arguments in Ruby

2008-12-26 07:25:15

Lets imagine we've got an array of strings, and we want to print it out as a list of strings using printf. (If you're complaining about my logic here, hold fire for just a second good sir/madam.)

So we start off with the array of strings, and then pass it to printf with the right amount of %s's in the format string:

arr = ["one", "two", "three"]

printf "%s, %s, %s", arr
# ~> -:3:in `printf': too few arguments (ArgumentError)
# ~>    from -:3

Oh whoops, we've actually only passed "%s, %s, %s", ["one", "two", "three"] to printf. So of course it whinges about not getting enough arguments. Now how do we fix this, how do we pass an array with each element a seperate argument to a method?

We use the * of course! Just prefix the variable name with * and the method is passed each element as separate arguments, rather than the whole array as one arguement.

Going back to our printf example above, we simply insert one character (the lowly *) and end up with a string being outputted.

printf "%s, %s, %s", *arr
# >> one, two, three

Now I realise this is a partially stupid example, but it serves to explain the point I wanted to make. If you were complaining about my choice of printf earlier, here is the way I think most rubyists would solve this problem instead.

arr = ["one", "two", "three"]

print arr.join(" ")
# >> one two three

And if I wanted to be slightly cleverer with the printf version, and print out an array containing an unknown number of strings, but of a set width, then I could do the following. (NB: This is actually how I ran into this problem.)

arr = ["one", "two", "three"]

printf arr.map { "%6s" }.join, *arr
# >>    one   two three

And that is where the lowly * comes in.

Merry Testing

2008-12-25 15:01:54

Just a few examples of the same test written in a few languages. Its testing setting the date on an object that is created in the tests' setup method already. These fall under the unit testing, rather than full-stack testing.

Testing in ObjC with OCUnit

// Add a date and time
- (void)testSettingDate
{   
    NSDate *theDate = [NSDate date];        

    STAssertNoThrow([calc setDate:theDate], @"Shouldn't raise an exception");
    // And it should match when pulled out as well
    STAssertEqualObjects([calc date], theDate,
                         @"%@ should match %@",
                         [calc date], theDate);

}

Testing in Ruby using RSpec

it "should set the date successfully" do
  the_date = Date.today

  @calc.date = the_date
  # And it should match when pulled out as well
  @calc.date.should == the_date
end

Testing in Ruby using Test::Unit

def test_setting_date
  the_date = Date.today
  @calc.date = the_date
  # And it should match when pulled out as well
  assert_equal(@calc.date, the_date)
end

Testing in PHP using PHPUnit

function testSettingDate()
{
    $date = date();
    $calc->date = $date;
    # And it should match when pulled out as well
    $this->assertEquals($calc->date, $date);
}

Think Visibility: An Online Marketing Conference

2008-12-20 13:48:05

Now I'm not one for blogging about events usually—if I'm attending one then I'll just talk about it on twitter quite a bit beforehand. However, seeing as this one is being organised by my housemate and I like to keep him in a good mood so he doesn't do something daft like change the locks, I figured I'd blog about this one. (Also its really rather a good idea, I'll be paying to attend and think he's bloody mad to organise a conference!)

The conference is Think Visibility, which is a

one-day mini conference with a focus on the areas of web development and marketing which are usually left behind in the creation process: SEO, PPC, Monetisation, Blogging, Accessibility and Usability.

The speaker line-up has rather a lot of big names in it if you follow the SEO/Online marketing world, and its only £30 to turn up for the day and listen to them speak. Oh, and theres an afterparty with free drinks (Sponsor permitting) where you can get drunk with your hero's. (Or something.)

Me, I'm attending simply because up until a year or so ago I thought SEO was a complete heap of crap, but having known Dom for a while, and worked for an SEO agency, I'm starting to appreciate that there is an art to it, and it is a much needed skill to run a successful website.

Fix Mail.app crashing after 10.5.6 upgrade

2008-12-17 13:58:04

When you upgrade to Mac OS 10.5.6, Mail.app might start crashing a few seconds after starting due to the GPG Bundle.

The solution is to grab the updated version of the GPG bundleGPGMail_d55_Leopard.dmg

--More--