Upgrading to Rails 2.3
I spent most of today working on upgrading chi.mp to Rails 2.3. Upgrading required more than just simply freezing the new gems. Here are my notes so far:
application.rb becomes application_controller.rb
The source file application.rb becomes application_controller.rb.
uninitialized constant Rails::Plugin::OpenIdAuthentication
The OpenIdAuthentication plugin needed to be upgraded to the latest from github:
script/plugin install git://github.com/rails/open_id_authentication.git --force
undefined method `use_transactional_fixtures=’ for Test::Unit::TestCase:Class
Two problems occurred that caused this. First, the test/unit/test_helper.rb was opening up Test::Unit::TestCase to add additional items when it should be opening up ActiveSupport::TestCase. Additionally some of our tests were old and still extended from Test::Unit::TestCase instead of ActiveSupport::TestCase.
formatted_xxx_url
Formatted URLs should now use the normal xxx_url methods and just include :format => format in the options Hash.
has_many collections do not support .destroy(id)
They did, I’m certain (and I have code from 2.2.2 that works to prove it), but it no longer works. The easiest way to fix this is to replace collection.destroy(id) with collection.find(id).destroy. There is a lighthouse ticket for this as well if you’re interested in following along at home: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2306-associationcollections-destroy-method-is-not-compatible-with-old-version.
Enumerable.group_by now returns an OrderedHash
This one was maddening. First of all, as mentioned, Enumerable.group_by now returns an OrderedHash instead of an array of arrays. This taken by itself would have been ok, but our test expectation for this was showing the result as being a Hash where the keys were the arrays and the values were nil.
Local cache strategy freezes memcached objects
The local cache strategy now uses MemoryCache as a local storage mechanism in front of remote caches like memcached. Unfortunately the MemoryCache#write method freezes the objects and therefore if you try to modify them afterward an error is raised. The only way I’ve found to stop this for the moment is to change value.freeze to value in the MemoryStore.write method. This probably isn’t the best solution but it does the job.
That’s it so far, running locally. Next step is to test in an integrated environment.
Displaying A Default Image
Posted by Anthony in JavaScript, Technology on March 13, 2009
Have you ever wanted to display a default image if the img tag source references a file that cannot be found? You might think that you could use the onerror event on the img tag, but don’t be fooled into thinking it’s that easy! No, it isn’t, because most browsers don’t support that event in the way you expect.
Here’s a little bit of JavaScript that I have used to successfully replace a broken image with a default (assumes prototype is used). Also note that this has been extracted somewhat from my implementation and thus may have gathered bugs during the extraction, but the concept should still be clear.
$$('img.my_class_name').each(function(e) {
var i = new Image();
i.onerror = function() {
e.src = "error.png";
e.onerror = "";
return true;
};
i.src = e.src;
});
RDDB on Github
Posted by Anthony in Uncategorized on March 6, 2009
I just imported the source code for RDDB from RubyForge into Github. First let me say that the SVN import from Github is hot – they’ve done a really good job. Second, please do not interpret this as an indication that I am going to resume work on RDDB – I’m not (I don’t think). At this point I’m just trying to get all of my projects on Github because it rocks and if I do want to work on any of these projects I can easily and others can fork them, which is really the big win.
Anyhow, if you want RDDB go to github: http://github.com/aeden/rddb/tree/master
Unrelated to RDDB, I also put support into the Moneta S3 implementation for passing :multi_thread as an option to the Moneta::S3.new method.
Have fun!
S3 in Moneta
Posted by Anthony in Uncategorized on March 2, 2009
Sometimes you just have to shave a yak, mostly because it’s fun.
I am working on a project where I need access to a distributed key/value store, in my case S3. I could have just gone to S3 directly but since Yehuda Katz recently announced Moneta, which is a generic key/value store interface I figured I’d give a shot at building an S3 implementation. The result is in my fork on github.
Some points of interest. I refactored the specs so that specs which had dependencies (such as the memcache implementation) are in their own spec files. This makes it much easier to run only a single spec for one implementation at a time, highly useful since some of the dependencies are not things I really want or need on my dev machine, nor do I really want to run all of the specs every time.
The Moneta interface includes the ability to specify :expires_in with a number of seconds as a common means for setting expiration of the key in the store. This is not something S3 supports out of the box. Initially I tried to make it work with HTTP Expires header to no avail. I settled on using a meta header (non-standard HTTP headers used by S3 for client info) to store the expiration date and then I check for the expiration when retrieving the S3 key object. This actually worked quite well even though it did require jumping through some implementation hoops and resulted in more code than I was originally hoping for.
I also had to raise the expiration times just a smidge in the specs since it was quite possible that the test operation would not complete before 1 second would pass and it was causing random behavior. Once I got the expiration working it was golden and all of the specs were passing.
Side note: I don’t usually use RSpec, but the ability to useĀ it_should_behave_like “some spec” is quite elegant.
That’s all for now. Enjoy!
ActiveWarehouse-ETL and Adapter Extensions Released
I’ve finally got around to publishing a new release of ActiveWarehouse-ETL and the AdapterExtensions library. This release brings these two libraries up to date with how RubyGems works and cleans up a bunch of details. It also should make them both work with Rails 2.2 (although I haven’t tested it recently to be 100% confident).
I also updated the activewarehouse RubyForge site at the same time.
Now that those are out it’s time to get a new tutorial written. Hopefully I’ll be able to do that in the next couple of weeks. Additionally I’m going to try to spend a little bit of time moving the documentation over to the github wiki. Good times.
Autotest Growl Notifications with Growl-Glue
While trying to set up Growl notification from autotest today I came across a nifty little gem called growl-glue. Growl-glue makes autotest play nicely with Growl without having to jump through hoops in your .autotest configuration.
Installation is a snap, just sudo gem install growl-glue and then add this snippet to your .autotest config:
require 'growl_glue'
GrowlGlue::Autotest.initialize
You can configure the images that are displayed, enable sound playback depending on what the autotest result is, and so on. I really love little gems like this that do one task well and make my life a little bit easier.
Sneaky Code (Or When Branches Get Tainted)
We use git at work. Today it turned out that some code that was not meant for the current release sneaked into the branch that got published. This code though was then followed by code that was meant for the current branch. Confusion ensued and I was tasked to fix it. Here’s my solution:
First I took the branch in question and executed a git log. This provided me with a list of commits and their messages. I then branched to a new branch. As part of the branch command I also included the commit I wanted the branch HEAD to be at. This commit was before the shenanigans began. At this point I then began cherry-picking the commits that were supposed to be in the release. It would have been nice to just provide lists of commits, but I couldn’t figure out a way to get this to work with cherry-pick. Once I had all of the commits cherry picked, I pushed this branch to the remote git repo and executed my deploy.
This is the first time I’ve had to do this, and there may be a better way, but all in all I was happy that git provided a means for me to do this at all.
Bailout Proposal
Posted by Anthony in Uncategorized on November 17, 2008
If the people of the United States of America are expected to bail out any companies, then I believe we should be allowed to specify some provisions that must be adheared to. My suggestions are as follows:
- To receive bailout money your CEO must get on national television and explain how they and the other executives have failed to create a profitible company.
- That same CEO must also provide a business plan that shows to the American people how they intend on bringing their company back to being a profitable business. That plan must be made available online.
- Anyone in the company making more than $200,000 a year must take an immediate pay cut of 50% or more.
- Anyone in the company making more than $1 million a year must agree to not be paid until the company becomes profitable.
It’s time to put up or shut up. If I and every other taxpayer is going to invest in your business you better prove to all of us that you have what it takes, that you believe in the company and are willing to stake your career on it. Small businesses do this all the time – it’s time for big businesses to do the same.
The iTunes Genius I Want
Posted by Anthony in Flotsam, Technology on September 19, 2008
I listen to quite a bit of net radio. In fact I would go so far as to say that when I’m listening to music on my laptop I almost always listen to net radio. When I’m on the road and using my iPhone it’s a different story – there I listen to stored tunes. So what does this have to do with the Genius feature added to iTunes? I really, really want Genius to be able to analyze what is being played on my net radio stations and use that to recommend new music to me. If Apple could bring this to me I would probably spend significantly more than I do now, if for no better reason than to have music on the go that matches my tastes when I’m tethered to the laptop.
chi.mp 1.5 Released
We’ve released version 1.5 of the chi.mp service, with a list of the major changes published on the chi.mp blog.
This was a tough but important release. We’ve implemented some significant architectural changes to improve the performance of the system and to make it easier for us to support a growing community of owners over the next few months. The actual release process was relatively smooth, but any time you make a major changes to your operational architecture (like moving certain processes from a single machine to multiple machines) you face new integration challenges. Ultimately I am pleased with the results and feeling very good about our ability to grow going forward.



