September 2008

'dreaming lately' posted

new song posted to 'snippets' - posted 2 months ago with 0 comments - tagged as [ music ]

I just posted the song dreaming lately in the snippets category. Let me know what you think.

on the road again

at least, technically speaking - posted 2 months ago with 0 comments - tagged as [ biking ]

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'm thinking like a rubyist

and you can be too. - posted 2 months ago with 0 comments - tagged as [ code ruby ]

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.

1 def set_mobile 2 @request.env['HTTP_USER_AGENT'] = 'nokia' # or any other random phone 3 end
Calling this method at the beginning of my test will run the rest of the test within a mobile context, like this:
1 def test_mobile_should_allow_signup 2 set_mobile 3 test_should_allow_signup 4 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:

1 def self.add_methods_to_mobile_tests args 2 args.each do | method_name | 3 define_method "test_mobile_#{method_name}" do 4 set_mobile 5 eval("test_#{method_name}") 6 end 7 end 8 end
I just add that method to my test_helper, and then call it like this from my test:
1 require File.dirname(__FILE__) + '/../test_helper' 2 class UsersControllerTest < ActionController::TestCase 3 add_methods_to_mobile_tests %w( should_allow_signup should_require_login_on_signup ) 4 #... a bunch of tests 5 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!

but somehow, faster. crrazy. - posted 3 months ago with 0 comments - tagged as [ merb rails ]

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.

login »
click to login