It’s good to have pet projects and hobbies. Music has unfortunately been in a lull as far as collaboration is concerned, and will probably stay that way until I have a good way to cart my crazy large keyboard around.
In the meantime, I’ve been getting a bit more serious about my bike. The trek really got me thinking about biking as a means of transportation, as a workout, as an activity, and as something just plain fun. The problem with bikes is that they’re a money sink. I thought I was saving money when I got a pair of bike shoes for 65% off, and a bike jersey for around 50% off. And then I buy the pedals/cleats, and the multi-tool, and the odometer, and all of the sudden… Bikes might be the most efficient means of transportation, but recently, it’s been the most efficient way of thinning out my wallet.
I had my first ride in my new cleats today. Cleats really help with efficiency, but the flip side is that it can be kind of hard to get your shoe out of the pedal when you need to. For beginners (which is me), you’re supposed to practice releasing your foot from the pedals at a fair distance away from where you actually want to stop. This was working fine today, until 5 miles into my 10 mile 8 mile ride, my chain decided to derail at the bottom of a hill. No time to prepare to release, I was kind of stuck, and really lucky that I was able to get my feet out and avoided falling into the road (which almost happened). I’ll have to take a look at the chain/gears… I’m not at the point where I can actually service my bike (though I did manage to put the new pedals on), but I want to learn. At some point, not this season but within the next 2 or 3 years, I want to do a century (100 miles). At that point, the Trek Across Maine might be nothing. (Here’s hoping.)
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.
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.
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.
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?