I'm thinking like a rubyist

posted | comments

I’ve been feeling the urge to blog about some of the code stuff I’ve been working on. So, after taking a little while to install a code highlighter on my carpeliam.com blog, I’m ready to get started.

On HungryWorcester.com, we’re trying hard to integrate mobile capabilities into the website. This starts with serving a version of the site to phones that doesn’t include a ton of graphics, css, or javascript. Thanks to the popular mobile_fu plug-in, this is possible. But inevitably, because I’m doing most of my development on a desktop machine and not a mobile phone, I forget to make equivalent views for the mobile site. Because I’m viewing the site through firefox, I rarely ever detect a problem, until somebody else says “Hey, is page x supposed to work on the mobile site?”

Of course, like every other coder out there, I’m diligently using TDD. (You are using TDD, aren’t you?) But writing tests for the mobile site is a pain, and I haven’t been doing it.

I figured it was time to find a way, and so I set out to do some mobile testing.

Unit testing in Ruby is pretty similar to most other languages: you’ve got your setup, your test method that starts with the word “test”, and your teardown. I wanted to take certain tests that were already running and run them again in the context of a mobile session. First, I had to figure out a way to emulate a mobile session. That’s easy.

def set_mobile
  @request.env['HTTP_USER_AGENT'] = 'nokia' # or any other random phone
end

Calling this method at the beginning of my test will run the rest of the test within a mobile context, like this:

def test_mobile_should_allow_signup
  set_mobile
  test_should_allow_signup
end

But I don’t want to write this block for every single mobile test, that would take forever. And then I wouldn’t have time to blog about it afterwards. I knew that in Java/JUnit, you can wrap your tests in a test suite, and use annotations to describe which tests should be run under which contexts. But Ruby doesn’t have annotations, as far as I know.

I guess that’s because it’s not the Ruby Way. So I thought about it: what is the Ruby way? doesn’t Ruby have some really great metaprogramming options? Turns out, it does. In Ruby, it’s easy to add methods at runtime. How easy? This easy:

def self.add_methods_to_mobile_tests args
  args.each do | method_name |
    define_method "test_mobile_#{method_name}" do
      set_mobile
      eval("test_#{method_name}")
    end
  end
end

require File.dirname(__FILE__) + '/../test_helper'
class UsersControllerTest < ActionController::TestCase
  add_methods_to_mobile_tests %w( should_allow_signup should_require_login_on_signup )
  #... a bunch of tests
end

This way, it’s as easy to test functionality in a mobile browser as adding the test name to an array. I probably could find a way to refer to these methods as actual methods instead of strings, which would make it a little bit less error-prone, but this is good enough for me. All in all, it makes the tests more robust, it cuts down on the amount of coding I have to do, and makes us all happier people.

...aaaannnnnnd we're back!

posted | comments

carpeliam.com has finished moving across the internet to a new host, and the result is a better, faster, stronger website. It looks like it finally finished propagating itself across the internet (I think I was the only one who couldn’t see it for a while), so I guess it’s safe to announce its return.

carpeliam.com is currently built on top of the ever so lovely and talented Ruby on Rails platform. It’s fantastic. But there’s another, leaner, faster fish in the sea of Ruby web frameworks called Merb, and I’ll be redesigning the website to use this framework in the near future. Don’t expect anything too soon, as it’s going to be redesigned both front and back, inside and out - a brand new face to go with its brand new shiny interior. But when it’s live, oh baby. Well, hopefully it doesn’t suck.

I'm playing a solo show for 3 hours this Saturday.

posted | comments

Copper Tree had a 3 hour show scheduled for this Saturday at Sangria’s Bar and Grill in Lowell. Unfortunately, Ravi and Damien won’t be able to be there :( so I’m kind of in this awkward position of playing a solo show. Right now, I’m scrambling to figure out how this is all going to work. Knowing 3 hours of material is surprisingly the part I’m least concerned with. I’m more concerned about finding people who can come. Sangria’s is a nice-looking bar and grill located in scenic Lowell, Massachusetts. They serve dinner until 10pm, so if you want to get some food, you should probably get there in the first hour. Because they serve alcohol too, it’s 21+. If you could come, I would be ecstatic.

So, details:

  • solo show
  • Sangria’s Pub [on the web] [directions]
  • 21+
  • a whole bunch of Copper Tree songs
  • a whole bunch of other good original songs that never got rolled into Copper Tree
  • a whole bunch of covers, because, hey, I don’t have 3 hours of original material (probably most of these will be in the first hour)
  • you, coming because you want to hear good music and you want to save my ass from being all by itself all night.

Let me know if you might be able to make it, again I’d be seriously ecstatic if you can.

liam can cook

posted | comments

Want to cook together? Let’s do that.

I hate eating by myself. Eating to me is such a social thing, I love to eat with other people. A while back, I tried to start a “Feed a Liam” campaign, but it never really got off the ground, maybe because it involved eating out, which doesn’t work into a lot of peoples’ budgets/diets. I’m also not a very experienced cook, either. Most of my home cooking involves some kind of prepared meal-in-a-bag deal, which isn’t really particularly healthy or cost-effective. I hate cooking by myself too, because it’s a lot of effort for little return.

I was thinking- I’ve got a lot of time on my hands (and not much money), I really should learn how to cook. I’d also like to resurrect the Feed a Liam campaign, though eating out isn’t such a good idea. So here’s what I think would be great.

Let’s cook together. You pick the day, you pick the time, breakfast, lunch or dinner. We agree on the food, and I’ll pay for at least 50% of it. I’m aiming for making meals that I can learn and remember and potentially cook by myself if necessary. My car situation at the moment is a little sketchy, so cooking/eating at my place is preferred, unless your place is within walking distance or you want to pick me up. Doesn’t this sound like just the best thing ever?

the sound of music

posted | comments

If for every door that closes, another one opens, I’m currently standing out in the hallway in front of the Copper Tree door, still somewhat ajar, but slowly and silently closing. Yeah, in other words, Copper Tree is quietly ceasing to be. And I get the sense that all three remaining band members are implicitly ok with that. Any one of us could be propping the door open, but it seems that none of us want it badly enough, including me. And that shouldn’t be taken for anything more than it is- the band ran its course, it was enjoyable, it’s just not going to last. It may have been better if we had figured this out before we decided to pay for studio time, but at least now I have some recordings for songs like Silhouette and All These Lazy Angels that I know some friends have wanted. And we do have a few more shows in the works before we all go in our separate directions, so I’ll keep you all updated with that.

In the meantime, I’ve been writing more material. Now that I’m not writing with Copper Tree in mind, I’m able to be more personal and more honest, less concerned with “can this work in a 3-piece piano rock band”. I even posted a song the sound of music on youtube:

</embed>

The next step is to find musicians that’ll stretch me in a different direction. I met a girl at Castellana’s who’s kind of a jazz singer, but she’s starting this Mars Volta-esque group, could be interesting. I’m curious what it’d be like in a band where other people are writing a lot. We’ll see where things go.