Archive for the ‘General’ Category

A Few Rails Nuggets

Monday, September 7th, 2009

So with my book, Distributed Programming with Ruby, finally finished, and a nice long weekend I was able to sit down and work on a little pet project of mine. I decided to work on a little site that I could use to track my rather large Pez collection. (Yes, I know, I collect Pez – so what!)

While working on it I got to use some new technologies that I really haven’t had a chance to play, so I thought I would talk a bit about some of the ones I liked the most.

Authlogic

Love it! Finally a decent authentication system! The thing I love most about it? It doesn’t generate a lot of crap in your project. If I were to say one bad thing about it, it would be that it doesn’t generate enough in your project. :) I know that sounds silly, but it’s the truth. It gives you so much power, without having to generate a ton of lib code and crazy controller code, which is awesome. However, it would be nice if it had a generator that generated a ‘basic’ application for you. Just a little thing, apart from that, love it!

http://github.com/binarylogic/authlogic/tree/master

Cucumber/Webrat

I’m sure by now everyone has heard of Cucumber. I’m not going to pretend that I’m the first to that party! Over the last month or so I’ve really started to use it and it has completely changed my life. That’s not an overstatement.

Cucumber lets you write features and scenario in human readable format. Combine that with Webrat, which lets you do things like click buttons and follow links, you can write some amazing tests that look like something a project manager would write! Brilliant!

These tests beat the hell out of Rails integration tests. Trust me! I love watching Cucumber and Webrat click around my site while I just watch.

http://cukes.info/
http://github.com/brynary/webrat/tree/master

Web App Theme Generator

This cool little plugin helps you to quickly generate a very useful, and laid out, theme for your application. The themes would be familiar to anyone who has used sites like Lighthouse. They’re basic, but they are very well coded and get you on your quickly so you can have something that looks fairly decent.

My only gripe with this plugin is that it is a bit clumsy to use, but thankfully you don’t have to run it very often, only when you create a new controller/resource.

http://gravityblast.com/2009/07/30/2-minutes-admin-layout-with-rails-and-the-web-app-theme-generator/

Delayed Job

The last piece of tech is Delayed Job. I first discovered Delayed Job when I wrote about it in my book. It is a great way to handle and process background tasks. It’s easy, reliable, and scales really well. I’ve been using the Collective Idea fork of the project. It has a generator to create the migration you need. It also has a nice binary to run in the background on your server.

I’ve also been using a little gem I wrote that gives me hooks into Hoptoad, the is_paranoid gem, and a nice subclass for writing workers.

I have been completely enamored with Delayed Job from the first moment I used it, and I’m sure if you haven’t checked it out yet, and you do, you’ll feel the same!

http://github.com/collectiveidea/delayed_job/tree/master
http://github.com/markbates/delayed_job_extras/tree/master

There you go, that’s just a few things I’ve been playing with lately, that I think are going to become mainstays in any Rails project I work on. Hopefully this has given you a little for for thought on things you can use in your next project.

APN on Rails 0.3.0 Released

Friday, July 31st, 2009

The latest version of Apple Push Notifications on Rails (APN on Rails) has been released. This release brings a few bug fixes, a new migration, and Feedback processing.

Installing/upgrading is easy:

$ sudo gem install apn_on_rails
$ ruby script/generate apn_migrations
$ rake db:migrate

It’s important to always run the migrations generator after each update to get the latest database schema needed for the the gem.

To use the new Feedback integration you have to first make sure that you update the new last_registered_at column when your iPhone application calls home. This column is checked against the timestamp Apple returns with the device token. If the last_registered_at is older than Apple’s date then the device is deleted, otherwise the Feedback is ignored.

To get and process the list of devices from Apple’s Feedback service just run the following Rake task:

$ rake apn:feedback:process

Enjoy!

Almost There… Book Wise.

Monday, July 27th, 2009

I’m now entering the home stretch of writing the Distributed Programming with Ruby book. I’m just a few weeks away, well, technically I’m hours away from finishing the last chapter (Delayed Job) in the official table of contents, however, I’m going to add another chapter and a half. Why? Mostly because I’m a glutton for punishment. That and I want to deliver the best book possible. The extra chapter and a half, not featured in the table of contents below, will be on MapReduce technologies. It’s a really hot topic, and I think it will fit well in the book. What do you think?

Unfortunately, the “Rough Cuts” book on O’Reilly’s Safari site hasn’t been updated in nearly 3 months! I’m not sure why. I keep asking my editor to update it, but it hasn’t happened yet. I’m sure it will soon, especially since the first draft of the entire manuscript will be done in just a few weeks!

UPDATE: Today they updated the “Rough Cuts” with nearly the latest revisions. It’s still missing the chapters on Delayed Job and BackgrounDRb, but it’s closer than it was yesterday.

Anyway, as a public service announcement to you, the readers, I thought I would the table of contents as it stands right now, so you have a better idea of what the book is going to be about. So here it goes:

What do you think? Does it look good? Is this something you’d buy? Let me know. This is your chance to have an influence on a book. If you think something is missing or should be laid out differently, please let me know, it might just make it into the final product.

Ok, enough delaying here, let me get back to writing so I can finish up the Delayed Job chapter.

Apple Push Notifications on Rails

Friday, July 24th, 2009

The other night I submitted a new iPhone application to the Apple Store. The app, which I’ll speak about when, and if it gets approved, uses the new Apple Push Notification service available in iPhone OS 3.0. On the server side I have a Rails application that I am using to send the notifications to Apple. The problem I ran into was how.

Enter the APN on Rails gem. While searching I found one plugin for Rails that mostly worked for me, Sam Soffes’ apple_push_notification plugin. It was a great place to start, but I found that there were things that didn’t suite me. For starters, not having any tests is always a big turn off for me when it comes to any code. I also didn’t like that you didn’t need to save a notification in order to send it. That means you don’t have a record of what was sent and when. I also wanted to have devices stored separately from the notification. Finally, I wanted to be able to easily configure the plugin. Sam’s was using constants that would need to be changed when it hit production.

So, with all that said and done I took Sam’s great work, ripped it apart, and put it back together again, this time in gem form instead of a plugin, and here it is.

There are a few migrations, a few models, and a few Rake tasks, but here is the basic idea of how it works:

To get a better understanding of exactly how it works, and what it does, I highly recommend reading the RDOC.

There are a few things I still would like to add, for example, a controller to do CRUD for devices so iPhones can register with the Rails app. I’d also like to add a task that talks to Apple and finds out which devices are no longer accepting messages so they can be removed.

If you’d like to contribute, please feel free and for the project on GitHub:
http://github.com/markbates/apn_on_rails/tree

Again, a special thanks to Fabien Penso and Sam Soffes for their initial work on this project.

Becoming a Recording, sorry I meant Software, Engineer

Sunday, July 12th, 2009

Recently I was sent a survey from the college I attended, the Liverpool Institute for the Performing Arts. In the survey I was asked a question about what I’ve done in the field of music, that’s what my degree is in, since I’ve graduated. I typed up a rather long winded answer to the question and afterwards I thought it was actually thought it was an interesting commentary on the recording industry. It also shows the path a guy like me takes from being a musician to being a software engineer.

Anyway, I thought I would share this little story with you all. I hope you enjoy it.

About 3 – 4 after graduating I found myself unemployed and decided that I would take that opportunity and try to pursue a career as a recording engineer. I spent two years struggling and working very hard at one of the best studios around and I found that things were just not working out.

I don’t necessarily think it was a problem of my not having the skills needed for the job, but rather it had to do with several other factors. One, because of the state of the recording industry ‘proper’ studios are/were struggling to find work because more and more musicians are doing recording at home on their computers. While their results might not be as ‘high quality’ as those of the studios, the musicians are/were finding that it was good enough to help land them gigs in town.

Because the studio was struggling, and I was the lowest guy on the totem pole, because I was the ‘newest’, I found that I was only getting a few sessions each month, that compared with the ‘top’ engineers who were only getting a week or two worth of work each month.

It was at this point that I sat down and re-evaluated what I wanted most in life. I decided that was really important to me was to have a family and be happy with what I was doing, and to just generally enjoy my life. Realizing that, I had to decide if my current situation was really going to work for me. While I thoroughly enjoyed being a recording engineer, when I got to do it that is, I found the pay ($90 a day – awful!), the hours (usually 12-14 hours), and the lack of sessions to not be a viable way to raise a family.

Once I decided that being a recording engineer wasn’t going to work for me, I needed to find something that would. I thought long and hard about this, as well, and realized that I really enjoyed being a software engineer. It is strangely creative, the pay is very good, and I was damn good at it.