ninja-decorators

A couple of us at SnapMyLife were a bit surprised you couldn’t easily use around_filters outside of rails for general ruby programs, so we implemented them and put it up on github. We called the gem ninja-decorators, mostly in a mocking sense that everything seems to be rockstars and cool_fu these days. To install the gem:

gem sources -a http://gems.github.com 
sudo gem install haruska-ninja-decorators 

Here is a simple example:

require 'rubygems'
require 'ninja_decorators'

class NinjaClass
  include NinjaDecorators

  attr_accessor :ret

  around_filter :common_around, [:foo, :bar]

  def foo
    @ret += "foo"
  end

  def bar
    @ret += "bar"
  end

  private

  def common_around
    @ret = "common "
    yield
    @ret += " around"
  end
end

produces

irb(main):076:0> n = NinjaClass.new
=> #<NinjaClass:0x220decc>
irb(main):077:0> n.bar
=> "common bar around"
irb(main):078:0> n.foo
=> "common foo around"

We’ll add before_filter and after_filter soon.

fb2twit taken down

This little experiment started with me having a software problem, as most good projects do. There isn’t a good way to have Facebook status updates get copied to twitter but not the other way around.

I’ve found out that open source software works, however open source services do not. I cannot believe the number of people demanding I fix or improve things on the project.

Also, it was costing me real money. I had to host a server to ping Facebook for status updates of the 500+ users and update twitter every 5 minutes. It’s only $120 / year but I couldn’t get anyone to step up and sponsor it (Twitter, hello?)

But I think the biggest factor is I don’t really update my status on Facebook anymore. I use twitter daily, but that’s because I have a core group of people there that expect me to “bother” them with the little ideas that pop into my head 120 characters at a time.

So, in the end I was maintaining a code base and a web service that I wasn’t even a customer for anymore. Time to shut it down.

Of course, the code to fb2twit is up on github (it always has been.) All any of the lechers have to do is pay to host it and put it up there.

git makes open source webapps easy

I actively try and open source as much of my code as possible. I’ve recently found I’m writing more and more mini-webapps in rails. With subversion these were very hard to share with the public.

It mostly comes down to secrets. You don’t want to share your database.yml file, etc. But how do you share the project, without screwing up deployments and without giving up secrets? How many hoops do you really want to jump through to give away your code?

Well, git removes all of those hoops. With multiple remote repositories, it’s trivial to have a remote repo that is open source and another that is private. Just point your production server to the private git repo for its code and you’re good to go.

fb2twit, a small facebook app that posts status updates to twitter when entered in facebook, is open sourced on github.

Reflections on RailsConf 2008

Portland has been overrun with ruby and rails geeks this week. This was my first RailsConf (out of the three) and I’m really glad I took the six hour flight from Boston. Most of the attendees are still truly interested in perfecting their craft and finding cool code to make their projects easier. I’m glad there were pure ruby talks, including a very good talk on meta-programming. Sure, you could take the time to catch up on RSS feeds and new projects around the rails community from your basement but it isn’t the same as being able to sit face-to-face with fellow developers. Lots of us work in small startups where you may have one or two developers to bounce ideas off of. At RailsConf, just watching people live code is insightful on areas you can improve. I’ve been inspired (or compelled) to revive some small plugins and clean them up on github. If you were at RailsConf but not following the twitter feed on summize, you were missing out. Instantaneous feedback was provided on all the talks (the good, bad, and ugly) along with where people were meeting up etc. Also, interesting to note everyone uses Macs and iPhones (myself included). This is an interesting observation on a bunch of geek early adopters. Hmmm, what personal platform should you be considering? I love conferences where it doesn’t matter what you’re wearing, how you present, etc. If you can code, you’re accepted, if not hang out and learn… put up or shut up. Some of the best presentations were actually the unorganized lightning talks. This is where you give people a chance to signup and present for 5 minutes the latest thing their working on. Matt gave one on rubber, along with some pretty interesting ideas on everything from testing, deploying, to hooking into SMS / Jabber, etc. I’ve actually met a lot of Boston rubists out here as well… I guess it sometimes takes a plane ride to the west coast to talk to your local geeks. So, overall a smashing success. The keynotes were hit-and-miss and some of the rooms were over crowded; but, the essence of geeks hanging out and talking passionately about code was preserved. Excellent work to everyone who made the gathering possible.

polymorphic_include and multi_smtp on GitHub

I finally took the time to wrap up two useful pieces of code into Rails plugins.

The first - polymorphic_include - I’ve mentioned before. It allows you to eager load polymorphic associations. I’ve cleaned up the code, including fixes for some nasty eval memory leaks.

The second plugin - multi_smtp - came about out of using gMail as our SMTP server for sending notifications on SnapMyLife. Google limits the number of messages per account and recommends you set up multiple accounts if you have to send more. This plugin allows you to define multiple accounts that Rails will spread the email load around.

Hope others find the plugins useful. These are my first experiments with git and GitHub, so I’m also seeing how easy it is for others to submit their ideas. I by no means want to be “keeper of the code” and like git’s SCM style.

To start using git on OS X, download the dmg package from the git google code page.

Desktop version of SML launched

Following yesterday’s post about the iPhone version of the site, we also launched a desktop browser version of SnapMyLife.

This was accomplished much the same way as the iPhone site. Rails 2 makes it a snap for additional formats to be added.

We attempt to redirect you to the most optimal version of the site based on your user agent string, but you are free to choose which site you want. All three sites have a “change format” link.

iPhone version of SML on rails

This week we officially released the iPhone version of SnapMyLife. This was fairly straightforward with rails 2.0 and the iui javascript framework.

Rails now uses custom formats as part of the incoming request. So I just added an “iphone” format and created views like “index.iphone.erb” where needed. This is really excellent MVC separation while allowing various versions of the site.

It took a while to get used to the everything-is-an-ajax-request style of iui. Basically, there is a single DOM that you add nodes to as navigation is followed. The javascript then adjusts the DOM as you navigate through the site.

Development wasn’t without snags. The most interesting problems had to do with Rails flash display and advertising on the device. I adjusted how iui handles the server respone. Now flash messages and a new html advert are passed along with the html data snippet. Javascript then breaks up the server response into its components and displays them properly using the iui DOM and CSS. I’ll clean it up and post it if other Rails / iui projects are interested.

SnapMyLife at MoMo Boston last night

from xconomy:

And several intriguing Web-based iPhone apps from local developers were on display last night. One of the coolest that I saw was Snapmylife, an online photo sharing community for camera-phone users built by Needham, MA-based Mobicious. It’s basically Flickr for phones, and it’s drop-dead simple

MoMo Boston was interesting. I’m glad Apple let hackers get up and talk about “open” development for the iPhone. I wonder if these guys will release sanctioned apps when they’re being sold on iTunes.

testing helpers in rails 2.0

I’ve been testing helper classes in rails using the method from the Rails Recipes book. That seems to be broken in rails 2.0 since @params and @request are no longer accessible in controllers. Luckily I also use mocha for mocks and stubs, so this was a quick fix.

So, the new code for testing rails helpers is (for me anyway):

require File.dirname(__FILE__) + '/../test_helper'

class ApplicationHelperTest < Test::Unit::TestCase
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::TextHelper
  include ActionView::Helpers::TagHelper
  include ApplicationHelper

  def setup
    @controller = HomeController.new
    request = ActionController::TestRequest.new
    @controller.expects(:params).returns(Hash.new)
    @controller.expects(:request).returns(request)
    @controller.send(:initialize_current_url)
  end

  ...tests...
end