Monday, December 14, 2009

Install Memcached from source on Debian Lenny

Debian is quite simply excellent, and I wouldn't even consider running any other distro in production anymore.

Occasionally though, there are packages that become a bit outdated, and a source install is needed.

For me, Memcached is one of those packages. The latest in the Debian Lenny Apt repositories is 1.2.2, but the latest stable build is actually 1.4.4. Good luck seeing that in the stable apt repositories anytime soon :)

So, to make life easy, I've put together a fairly simple bash script that downloads and installs Memcached, and libevent, for you.

The script is a blunt instrument, and assumes...

  1. You haven't installed memcached from apt repositories on this machine
  2. You won't be sad when it puts config and startup files at
    • /etc/memcached.conf
    • /etc/init.d/memcached
    • /usr/share/memcached/scripts/start-memcached

Thursday, December 10, 2009

Fix POST for Ruby 1.9.1 and Passenger

How exciting! A new Ruby release to play with.

I figured it was time to migrate this particular app to 1.9.1 on the integration server. We've been developing this app with 1.9 and all looks good.

So I...

  • Upgraded Nginx to version 0.7.64
  • Installed Ruby 1.9.1-p376
  • Installed Passenger 2.2.7
  • Configured Nginx to use the new versions of Ruby and Passenger
  • ... and restarted Nginx

I hit the home page of the app.... Sweet, it works! Yay!

At this point I did a minor happy dance. Nothing over the top, you know... just a little wiggle :)

Then I tried to login to the app... "500 Internal Server Error"

Oh. :(

I stopped dancing right there.

It turns out that POST requests fail for Ruby 1.9.1 and Passenger.

Fortunately, there is a patch.

Patching tempfile.rb did the trick. On that particular machine, tempfile.rb was located at /usr/local/lib/ruby19/1.9.1/tempfile.rb

Thanks to Ryan Bigg for confirming the fix is good.

Tuesday, November 24, 2009

Remember Which Goals are Important

John Nunemaker made an excellent comment which reminds us of the value of setting goals.
In the "crazy" world of software development, we are often pushed to make software the best, the biggest, or the option with the most features.
But...
When Boeing prepared to launch the design of the 727 passenger plain in the 1960s, its managers set a goal that was deliberately concrete: The 727 must seat 181 passengers, fly nonstop from Miami to New York City, and land on Runway 4-22 at La Guardia. (The 4-22 runway was chosen for its length--less than a mile, which was much to short for any of the existing passenger jets.) With a goal this concrete, Boeing effectively coordinated the actions of thousands of experts in various aspects of engineering or manufacturing. Imagine how much harder it would have been to build a 727 whose goal was to be "the best passenger plane in the world."
Setting those few important goals helped make the 727 a successful and versatile aircraft. This same concept can be applied to anything we do, even on a much less grand scale.
This is a great reminder to not lose focus on what is important to your project.
Now, back to creating the best software I can :)

Tuesday, November 10, 2009

Factory.create(:factory_girl, :fixtures => false)

Rails fixtures are a great starting point, but you can't live with them on a large project.
While working on a feature recently I kept breaking other unit tests while working with working in the associated fixtures. The relationship graph between all these objects is quite large, and I quickly decided this wasn't a game I wanted to play anymore.
FactoryGirl isn't new, and I've actually played around with FactoryGirl in the past. It didn't take much effort to add a test/factories.rb, specify a few Factory objects and then bask in the win.
Tests written. New feature added. Existing tests continue to work. Everybody is happy.
Over the last few weeks we have almost entirely replaced fixtures as we've encountered them. At this point in time it is quicker to replace the fixtures than it is to continue repairing fixtures.
Yay, our tests aren't as brittle anymore :)
For everything but the most trivial project, I'll be dropping fixtures at the start of the project.

Friday, March 20, 2009

Australian Website Blacklist. Would you like lies with that?

So it seems the Australian government lied about how many URL's are on their blacklist.

Fair enough I suppose, we weren't meant to ever know what was on the list anyway.

Of course they lied. Whenever power is wielded in the absence of transparency do we ever hear about how it was secretly used for out benefit? No, we don't.

Senator Conroy says that this isn't the list. Now, because the list is supposed to be a secret there is nothing to weigh this statement against, so it must be taken on faith alone.

Ah, faith...

This is where we get to the other part of the problem. Senator Conroy represents a group of Australians that think it is OK to push their religious views onto others. We all know how great religious zealots are at being open and honest. They've scored a 0 out of 10 for that. These guys are as "open and honest" as they need to be to push their agenda, or to escape prosecution. Don't tell me you need examples.

What about my agenda? I don't have one. I'm also a nobody with no power. I just want information to be out on the open where it wants to be. If you or I want information, we should be able to find it. I do not want my Government telling me what information I should or should not see, as it has proven so often in the past to be way too tempting to Governments to use censorship to help keep themselves in power. Again, you don't need examples, I'm sure you can think of many instances of this being reported... eventually.

"But won't someone think of the children?!", some of you cry. Will someone think of the children years from now when they are denied access to information about about other political parties in Australia, or news about the latest bad things the Government has been doing to Australians.? OK, that may not happen, but once a blacklist exists it can happen. You don't need examples provided for this either.

I'm quite sure if the Labour Party had made it known they were planning on introducing web censorship the balance would not have tipped in their favor at the last election. I suppose thats why they want to get the blacklist implemented in the early part of their term. Voters have short memories generally.

Once we've all been conditioned to accept with censorship of the information we can see, your opinion as an individual is worthless. You lost the power to make your vote mean what you intended it to mean, because without all the information available to you, how can you make an informed decision?

As an Australian I'm incredibly disappointed about this whole mess, although the cynic inside me is not at all surprised.

Sunday, March 8, 2009

scottbarr-number_to_text RubyGem

I was playing around with a bit of Ruby to convert numbers to text a few weeks ago but never finished it and forgot all about it. Today Guest11057 (thats an extremely boring nick!) on the #rubyonrails IRC channel asked if something like this existed, and apparently it doesn't. That reminded me about the mothballed code, and motivated me to finish it off and package it up as a RubyGem. To convert a number to text:
n = Number.new(119)
puts n.to_text # => "one-hundred-and-nineteen"
I'm not happy with how the implementation came, but it does the job. I'll clean it up to work a bit nicer sometime :) If you need to convert numbers to text in Ruby, take a look at http://github.com/scottbarr/number_to_text/tree/master

Sunday, February 15, 2009

YahooCurrency Gem

I recently created the YahooCurrency Ruby gem that gets currency exchange rates from Yahoo! Finance. Originally the code was part of a working Ruby on Rails demo I created about 12 months ago. A project we are currently working on needed exchange rates, so i created a Gem from the original code so we could easily reuse it across any of our future Ruby projects. We discussed making the project open source, and agreed that it would probably be useful for others, and also great for Global IT Creations to contribute something back to the open source. It is only a small contribution, but you have to start somewhere. Here is some example code...
exchange_rate = YahooCurrency.get_rate!("JPY", "USD")
exchange_rate.from #=> "JPY"
exchange_rate.to #=> "USD"
exchange_rate.rate #=> 0.0111
exchange_rate.timestamp #=> Wed Feb 11 22:20:00 +0800 2009
Get the source or the gem from http://github.com/scottbarr/yahoo_currency/tree/master Hopefully this will be the first of many projects that GITC releases as Open Source.

Thursday, February 12, 2009

Horror Movie Code

For the last few days I've had the displeasure of working through some code that we have inherited from another company, which I will not name. One section of code I'm looking at has a 300+ line if/elseif block, up to 9 levels deep! And if you want to see some real crap, you can look anywhere else in the remaining 700+ lines of code. As for the project in general there are no meaningful unit tests, all the code is crammed into the Controllers, and it is so un-DRY you need a raincoat to get through it. Code like this makes me want to cry. This code is concrete evidence that if your parents are blood relatives you should not write software. (No offence intended to non-code writing inbreeds.)