Today is November 5th! 

Filed under: Blogroll on Monday, November 5th, 2007 by jeremy | Comments Off

Remember to contribute as much as you can - especially today - to Ron Paul! Both Tasha and I just submitted our donations.

2nd Annual McWeiland Chili Cookoff Photo Montage 

Filed under: Blogroll on Monday, November 5th, 2007 by jeremy | Comments Off

And first YouTube upload ever. Tasha did the video on her new MacBook - like that “Ken Burns” effect? Enjoy!

RubyConf ‘07 

Filed under: Blogroll on Sunday, November 4th, 2007 by jeremy | Comments Off

I'm in the final hours of my first RubyConf, the annual international conference for rubyists being held in Charlotte, NC this weekend. There's been way too much information for me to possibly absorb completely, but the exposure to the community, the attitudes and thinking, and the possibilities people are exploring has certainly been a wonderful phenomenon to experience. 'm also seeing that I really haven't even scratched the surface of ruby - there's much more for me to learn than I suspected in my most pessimistic estimates.

Conference highlights (from memory) are as follows:

  • Jim Weirich's talk on Advanced Ruby Class Design. I was struck by his focus on the problem rubyist's essential dillemna / task of thinking outside the box when approaching a problem. Using rake and other examples, he showed how Ruby makes possible ways of coding that make the old, standard Java-esque OO approaches obsolete and unnecessarily one-dimensional. This is something I constantly struggle with, because I get used to solving a class of problems in one way instead of looking at each unique problem as an opportunity for a creative and expressive Ruby solution. I need more experience with a variety of Ruby projects: I learned more about Ruby by doing a scripting program over a week or two for a buddy than I have in 1.5 years of Rails coding.

  • Ben Bleything on Controlling Electronics Using Ruby was damn cool. This is an area I've been trying to get into for a while. I've wanted to do a custom security setup tied to my home computer ever since I did it professionally at NetTalon. I really feel like Ruby could make it fun, but I dunno - I'm easily frustrated and electronics seems frustrating. But it's awesome to see support out there for rubyist electronics hobbyists.

  • Evan Phoenix on Rubinius, a new virtual machine for Ruby, was cool. He seemed to focus on the challenge of implementing as much of the language source in Ruby, which strikes me as the perfect OO approach. It's very exciting.

  • Luke Kanies on Essential Incompleteness in Program Modeling was my favorite presentation. Where Weirich talked about the need to approach problems differently, Kanies introduced one way to find new approaches: look at solutions to similar problems in science and math. He invoked examples from biochemistry, physics, and fractal geometry to help demonstrate a way to constrain the scope of research into solutions, make good use of your effort and energy, and more - I need to watch the presentation again (or another two times) and read the books he suggested. It promises to be a key to real strides in my programming style.

  • Laurent Sansonetti is an Apple OS X engineer who gave a presentation entitled Mac OS X Loves Ruby. He demonstrated Leopard's unprecedented support for Ruby. Highlights were DTrace (you can read more about that elsewhere) and RubyCocoa, a bridge between Ruby and Cocoa that looks insanely powerful when combined with Interface Builder. I'm not an Apple fan boy in the least, but as a Mac user this stuff was definitely cool. It's nice, I guess, to see rubyists' loyalty to Apple reciprocated in some way.

  • Matz's keynote was awesome. I have a problem with accents, but what I could understand was really enjoyable. Matz is funny and demonstrates a humility and good-natured approach to coding from which I think every community could stand to learn. I love that somebody who isn't crazy about the enterprisey destination that Ruby is heading towards who doesn't have to get all dogmatic and "opinionated" about it. He stressed attitude as the advantage of Ruby - rubyists like the way Ruby allows them to code, even if it isn't always the ideal tool for the job. People matter.

  • Ben Scofield gave a talk called Cleanliness is Next to Domain Specificity that tied in concepts from linguistics to DSLs and domain modeling. He offers tips on finding good ways to represent your domain and build upon your domain knowledge through the language. Very cool and entertaining.

I had a great time hanging with all my new and old friends. Props to the #rubycodejam / CVREG peeps (Jamie, Mel, Jim, Anoop, Jon), my new co-workers at Intridea (Chris, Pradeep, Michael), my old friends (Ryan, Patrick, Ben, and others from Viget Labs) and new friends (Andrew, Jay, Brian, and sorry if I can't remember you - I'm on little sleep). I did a lot of drinking, not much sleeping, and a lot of participating in great conversations. And I'm excited about a CVREG collaboration with the DCRUG as well as getting cracking on Bookmarker with Mel.

Summary: CVREG.success? #=> true

Web Development - The Next Generation 

Filed under: Blogroll on Monday, October 22nd, 2007 by jeremy | Comments Off

Over at the Central Virginia Ruby Enthusiasts Group (cvreg.org) blog I recently contributed an article reflecting on my talk to a local high school web design class. Since the overwhelming topic was money and jobs, not the art of programming and design, I had a chance to impart some of my observations of the industry to them. Here’s an excerpt:

Get used to learning constantly. Things move way too fast in this industry for you to learn one language and have that make your career. It’s better to challenge yourself by engaging in a wide variety of technologies to hone your general programming, debugging, testing, and other skills. Try out new languages, read blogs, go to conferences, and do your own experimental projects to challenge yourself. Be the guy that can solve any problem with the right tool, rather than “the Java guy” or even “the Ruby guy”.

Selenium_on_rails Quick Start 

Filed under: Blogroll on Monday, October 8th, 2007 by jeremy | Comments Off

Over the past few days I’ve been diving into Selenium, a automated functional testing tool for web apps. It’s pretty slick - in fact, like most of the technologies I’ve been using over the past two years, it does so much for you that the obstacle always ends up being a matter of getting out of its way and letting it do its thing. So I’m gonna throw out some pointers on using Selenium within the Rails testing framework via selenium_on_rails plugin; the only caveat I’ll mention is that this post is especially geared towards the newbie wading into a project with pre-existing selenium tests. So I’m focusing on how you can get started with writing tests and integrating them into what’s already there.

Open up firefox and install the Selenium IDE extension. This allows you to record your test by simply using the browser. The IDE keeps track of where you click - just make sure the record button is on. Go ahead and click through your test application and watch as the IDE records your actions.

Now you need to go into your selenium_on_rails plugin area and edit config.yml. In the browser config area, make sure it’s pointing to your browser binary. For example, I kept most of the defaults, but made sure the following lines were there, uncommented:
environments:
  - test
browsers:
  firefox: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'

Next, especially if this is a project with existing tests, make sure you’ve installed the right user extensions. These are prefabbed actions for doing things like logging in via javascript. In my project I found this file in

vendor/plugins/selenium_on_rails/selenium_core/scripts/user_extensions.js

All you need to do is point the IDE at this file by opening the IDE window and navigating in the top menu to “Options > Options > General tab”. Put the path to user_extensions.js in the input box entitled “Selenium Core extensions (user-extensions.js)”.

OK, so let’s take a look at the existing selenium tests. They’re probably in test/selenium. If there’s subdirectories under that, these are probably test “suites”. For example, in the project I’m working on, they’re organized depending on which type of user the test is geared towards: user or admin. The actual test scripts can be recorded in a variety of formats; mine are all HTML tables, where each row is a step in the process.

So let’s get to recording tests. First, start your server in the test environment:

mongrel_rails start -e test

The key to testing is executing an action and verifying the response. In Selenium, this is accomplished via assertion statements. The IDE makes this elementary: when you’ve reached a page on which you need to verify the output, just highlight the text and right click. At the bottom of the popup menu, several approaches to verifying the text are mentioned. I don’t understand all the “selenese” yet but there’s simple commands like “assertText” that ensure a particular passage is included on the page - that should get you started.

So you’ve recorded the steps necessary - now click “File > Export Test As” and save it in the correct test directory. Now you should be able to run this test via rake test:all. That’s it! I’ll try to keep

Back to work! 

Filed under: Blogroll on Thursday, October 4th, 2007 by jeremy | Comments Off
Well, Ive put the update on my life off for far too long, time to come clean. As of Tuesday I am working for a D.C.-based web development firm that is focusing on Ruby and Rails. I get to work from home in Richmond and the work Im doing is some pretty cutting edge stuff - rspec, behavior driven development, acts_as_solr, mocha - hotness. Im very happy with the situation. I should also mention that Tasha doubled what was till then her all time sales record at the Crafty Bastard show in D.C. It worked out well for me to go up with her because (a) she needed the help - at one time she had a line going out her booth of young, hip people buying her stuff - and (b) I got to have coffee with my present boss. Plus I had ethiopian food for breakfast - and it was delicious! Not only that, I also found out that the guys who led the political action committee project I just came off of are interested in doing some for-profit things with the codebase. The cool thing is that Im already a partner without even having to work on the code ever again! Also, the 2nd Annual McWeiland Chili Cookoff will be held October 20th. Invites are going out soon, but if you didnt attend last year and want to, let me know. Finally, I have to say that I just stumbled on essembly.com today, and if youre interested in a decent politically-oriented online community, check it out. Im hooked - Ive had some of the best political conversations in years on there (not a high bar to clear, you understand).

text_field and currency values 

Filed under: Blogroll on Sunday, September 16th, 2007 by jeremy | Comments Off

I’ve asked around about this issue and nobody has been able to give me a straightforward solution. It is for that reason that I’m not afraid to share my hack. If there’s a better way to do this in Rails, let me know.

The problem: you’re using some sort Numeric field for storing monetary values. But you can’t guarantee how those values will be formatted in the view. It looks best when a field containing a dollar amount is formatted like “2.00″ instead of “2″ or “2.0″ or, god forbid, “2.000″. But you can’t do formatting of the Numeric type (you should be using BigDecimal, btw) and there’s no way to get between the view’s conversion of the number to a string. At least, not without a custom getter / setter in the model.

My solution keeps formatting code in the view, where it belongs. I essentially create a helper method for that view called “monetary_field” that does the string conversion when the text_field tag is rendered. In my template:

<%= monetary_field 'contribution', 'amount', @contribution.amount %>

And my helper method:

def monetary_field(objname, method, value)
text_field "#{objname}", "#{method}", :value => ("%0.2f" % value), :size => 6
end

It works very well for my purposes, though you could make it prettier and more universally applicable. Unfortunately, my deadline is tomorrow, so none of that. But hopefully if anybody else has this problem they’ll find this super simple way to get between the model and the view easily.

Quick Rails Logging Tip 

Filed under: Blogroll on Friday, September 14th, 2007 by jeremy | Comments Off

It’s not difficult to alter how Rails logs requests. Just look at ActionController::Base#log_processing (see code here), and you can see that’s it’s basically just printing request.inspect. So if you override that method in your ApplicationController, you can change how requests are logged. This was important for me, because I’m using gsub to wipe credit card numbers from the log. Works like a charm!

I can take your money 

Filed under: Blogroll on Thursday, September 13th, 2007 by jeremy | Comments Off

Or, rather, the Rails web app I’ve been working on for the past month can. After a very frustrating week of slack-ass-edness from Wachovia, we finally got stuff hooked up right for credit card donations to this new political action committee. So the big hurdle has officially been crossed - though at the cost of much wailing and gnashing of teeth.

And the application is really coming together. The app’s not very complex; it just accepts donations on behalf of others. What has truly impressed me this time around is the agility with which the framework handled the demands I put on it.

At some very inconvenient junctures, I’ve done one major domain model redesign on top of constant controller and view changes, I haven’t yet done something that I feel is technically dubious. Everything has been pretty straight forward and in line with MVC philosophy. I’ve engaged in some “science experiments”, trying to test out better ways of doing certain things I already knew how to do but suspected were accomplished better, but I was never stuck without a tool to get the job done if I needed it.

Rails has enabled me to create a very elegant app, due in no small part to my recent in-depth studies of Ruby. I’ve also been able to get the project done only slightly off schedule in a fraction of the normal development time. I don’t know of any other programming experience where I’ve ever felt I’ve done as clean and thorough a job. And I really think that has a lot more to do with Rails than with me.

Question on migrations 

Filed under: Blogroll on Sunday, September 9th, 2007 by jeremy | Comments Off

OK. So you have been using migrations to iteratively modify your database and populate it with information as you flesh out your application. Awesome. Now, what happens when you change the model definitions and try to rollback and then roll forward?

This is the problem I’m encountering. For example, I’ve made changes to my models through the lifecycle of the app, mostly in adding new fields and deleting others. The model code validates the presence of the most recent set of fields. But in those earlier migrations, I populated the database with model objects that don’t supply that field, or supply different fields, based on the model definition at that time. So if I ever roll back to those earlier migrations, they are apt to fail because model objects are being created based on an outdated model definition.

What is the proper Rails method of dealing with the mismatch between the current model code and legacy migrations that use out-of-date model definitions? I haven’t been able to find any guidance on this matter, which leads me to conclude that I’m asking the wrong question here.