Archive for the 'Rails' Category

Flushing memcached servers the easy way

Tuesday, June 10th, 2008

This is easy right?  Can’t you just restart the memcached server? Well yes, but you may cause errors in applications that are already connected to it. You can follow your memcached restart with an application restart, eg for a Ruby on Rails app:

# /etc/init.d/memcached restart && mongrel_rails cluster::restart

Of course if you have more than one application server you have to restart your app on every single one. This would work on an engineyard slice assuming you have the eycap gem installed:

$ cap production memcached:restart
$ cap production mongrel:restart

Restarting your application is not ideal however, you will lose anything cached in memory, cause delays to users trying to access your site, that sort of thing.

So what can be done? The answer is really simple. Assuming a memcached running on the local machine on the default port:

$ echo ”flush_all” | nc localhost 11211

Easy!

Announcing finder.overcycle.com

Wednesday, January 23rd, 2008

It is my pleasure to announce the Recycling group finder, Something I have been working on for the past couple of weeks with my wonderful employer 29degrees. For those of you who don’t know, Freecycle is a worldwide recycling network, in their own words:

The Freecycle Network™ is made up of 4,205 groups with 4,211,000 members across the globe. It’s a grassroots and entirely nonprofit movement of people who are giving (& getting) stuff for free in their own towns. It’s all about reuse and keeping good stuff out of landfills. Each local group is moderated by a local volunteer (them’s good people).

As the name suggests, Freecycle Group Finder is a new way to find Freecycle groups.

Finding a group - the old way

To find a group you enter a location to search for in the box on the Freecycle homepage. I live in Romiley, so I enter that and click search. But it can’t find any groups! Failed freecycle search

In order for it to find my local group I would have to guess it was called ‘Stockport‘ and search for that. I could have used the Freecycle group browser but who browses anymore? People demand search! I wanted to make this better so I wrote the Recycling Group Finder.

Finding a group - the finder.overcycle.com way

Just enter any location into the search box on the homepage and it will find all your local groups: Successful  freecyclegroupfinder.com search

The Freecycle search gets it right sometimes. Take a search for Alameda, CA. It lists all the groups nearby, but Freecycle Group Finder does better. Freecycle Group Finder shows you a map of where all the local groups are! It lets you scroll around and visually determine the closest group (Try it for yourself!). An improvement we feel, and one that will help more people join up and start recycling.

What keeps it rolling?

At 29degrees we’re big fans of Ruby on Rails. It helps us make web applications faster, and with more fun, and it was no exception for the Freecycle Group finder. We are using Postgres for the database and serving it all with mongrel and of course Apache. Of course if wouldn’t be anwhere near as good if it wasn’t for Tony, 29degrees co-founder and designer extroadinaire!

Don’t F**king Repeat Yourself

Wednesday, July 4th, 2007

Carl has suggested some interesting improvements to the standard Rails migrations:

So, you’re a Rails developer? CHECK! You have this great idea for a new application, the one which will surely get Yahoo and Google involved in a bidding war? CHECK! But you don’t actually start developing it because you are fed up having to run script/generate model model_name, editing the migration for the table, writing the tests for all the rules which are implied by the database (Such as maximum lengths for columns and column uniqueness), and then editing the model to pass those tests? CHECK!

(digg here if you’re that way inclined)

Rails sucks

Thursday, June 21st, 2007
Logger debug message consisted entirely of “cocksucker.” Took it out. Seemed minimally informative, and impolite.

Excellent.

Hi I’m Ruby on Rails

Wednesday, May 16th, 2007

Another funny Ruby on Rails/PHP video:

Hi I’m Ruby on Rails

Tuesday, May 15th, 2007

A couple of funny videos in the style of the new Apple adverts:

Rails and Java

Rails and PHP

freelymoving.com goes live

Thursday, December 15th, 2005

A while ago a friend of mine asked me to put together a site for his new band, Freely Moving, and this is the result.

To get it started he came over one evening and we hammered out a design. It was really great having him there to bounce design ideas off and to get an immediate response, it really sped up the design process. I then took the design and developed the backend using RubyonRails, which made the whole development relatively pain free!

The site seems quite popular with the fans but check it out for yourself. I recommend checking out the music downloads section where you can get their latest EP in mp3 format.

Quoting in ActiveRecord

Thursday, September 15th, 2005

Quite often I need to take a string from an HTML form, such as “one two three” and search a database field for each of the words contained in the string, eg:

SELECT * FROM table WHERE text ilike '%one%' AND text ilike '%two%' AND text ilike '%three%'

Obviously the strings need quoting, or I am going to be vulnerable to SQL injection attacks. In perl I used to do something like this:

join(" AND ", map {"field ilike " . $dbh->quote("%" . $_ . "%")} qw/one two three/)

I was hoping that ActiveRecord would have a nice way of doing this automatically when passed a string or array of strings, but there doesn’t seem to be one. Instead I came up with this:

@items = Item.find(:all, :conditions => @params["search"].split.map{|x| “item ilike ” + Item.quote(”%” + x + “%”)}.join(” AND “))

The interesting bit broken out looks like this:

"some string seperated by spaces".split.map{|x| "item ilike " + Item.quote("%" + x + "%")}.join(" AND ")

In particular the #quote method of the Item object: Item.quote("%" + x + "%")

The #quote method depends on a PostgreSQL database adaptor being used. The MySQL adapter has a #quote_string method that looks like it does the same thing, but I have not experimented with it.

It would be nice to know if there was a better way of doing this, particularly one that was independent of the database adaptor.

Thanks to leeo on IRC who pointed out that #quote is a method of AbstractConnector (from which both the PG and MySql addapers inherit)

Railsday over

Friday, June 10th, 2005

Railsday is officially over (5 days ago anyway). Carl wrote about it and our entry in more detail and you should head off there first to read a good summary of how it went. Judging has recently been extended by 8 days so we will find out how we did on the 18th June.

In general the competition was fairly well organised, especially since it was the first time it has been run, but there are improvements that could be made for next time.

  • Finalise the environment available to competitors well before the competition and stick to it.
  • Keep the start and end times of the competition as static as possible.
  • Expand on the judging criteria, there should be as little room for ‘interpretation’ as possible.

But apart from those, a big thank you to the organisers for making it happen. I will hold off thanking the judges until I know how we did!

Raising the bar

Monday, May 16th, 2005

I was talking about railsday a few days ago with Carl (we are thinking about entering if we come up with a good enough idea) but it occurred to me that it is getting increasingly difficult to create a truly groundbreaking app.

When Google launched gmail everyone was wowed by the new style of user interface they provided. A large part of this was due to their use of Ajax. It didn’t take long before the number of other sites started using Ajax, and Ruby on Rails now has excellent bundled support. This has led to some excellent uses of the Ajax that are really pushing a paradigm shift in web application user-interface design, with some of the most succesfull examples being written by the folks at 37signals.

However, as more sites are being released using these new interface technologies and ideas the bar is being raised. For example sticking with 37signals ouput, we first saw Basecamp and Tadalist, some simple ideas but brought together in a well thought out way. They created a lot of buzz and rightly so, but 37signals latest offering, backpack, has not created nearly the excitement that their previous sites did, despite being a more complex and at least as effective use of the technology.

Because of this railsday will probably produce some very good apps, but it would take something very very special to recreate the initial Ajax buzz. I am not expecting miracles, the competition only allows 24 hours of work per project after all, but the bar for ’special’ apps has been raised high.