zerosum dirt(nap)

evolution through a series of accidents

zerosum dirt(nap)

Resque Mailer

January 09, 2010

We've been making heavy use of Chris Wanstrath's Resque library in my latest project. Resque is a Redis-based background job system that Chris built for GitHub. It's easy to use, especially if you're already leveraging Redis in other parts of your infrastructure, and also has a nice Sinatra front-end for monitoring job status.

Anyway, Resque jobs are just Ruby classes that respond to the special perform method. They're placed on a queue — you can place different jobs on different queues — and later, a worker polls the queue, pops the jobs off and performs the task.

We have a number of different asynchronous jobs happening in Mogo, many of which are domain-specific. But one thing we're doing that's very common is using the background system to process mail delivery asynchronously. Because synchronous mail delivery is for jerks.

Outgoing mail in a Rails app is generally handled by ActionMailer, which expects you to implement message delivery types as class methods on an ActionMailer "model" (a butchering of the term). So a typical mailer might look like this:

class Notifications < ActionMailer::Base

  def signup(user_id, sent_at = Time.now)
    @user = User.find(user_id)

    subject    'Welcome to Mogo'
    recipients @user.email
    from       'Mogoterra <noreply@mogoterra.com>'
    sent_on    sent_at
  end

end

Then, to send a signup message, you use the following method call from somewhere else in your codebase:

Notifications.deliver_signup(@user.id)

So this all works good but it's synchronous. You'd like to be able to background these tasks and use Resque. But you don't really want to mess around with the mailer implementation. Right? Me too.

So ResqueMailer does just that.

Following in the footsteps of DelayedJobMailer, ResqueMailer allows you to shift processing of your existing mailers to an async Resque worker without doing pretty much anything. Just install the gem in your Rails project (via Gemcutter) and then mix the Resque::Mailer module into your mailer.

class Notifications < ActionMailer::Base
  include Resque::Mailer

  # ...
end

You'll need to restart your Resque workers and make sure at least one of them is working on the special mailer queue (or * for all queues). Now when you call MyMailer.deliver_signup, the task will be placed on the mailer queue and processed by the first qualifying worker.

It's always nice when a tiny amount of code makes a task transparent. Check out the project page on GitHub for more information.

comments »


 

Rdoc.info Updated

November 22, 2009

Rdoc.info is now serving up fresh docs using YARD 0.4.0. Doesn’t that new template look nice?

If you’re a Ruby OSS developer and haven’t checked out YARD yet, you really should. It’s easily the best way to generate sexy documentation for your projects and Loren has done a really awesome job with the latest release. The experimental new live docs service (with php.net-style user comments) that he’s testing out is swanky too, and we hope to roll this stuff into Rdoc.info shortly.

In the meantime, you can enjoy the latest YARD features and an updated look and feel. Make sure to add a post-commit hook to your GitHub-hosted project and we’ll automatically rebuild docs whenever you push a new release to your remote. Docs for older versions are maintained as well, and accessible via the usual commit hash url [example].

comments »


 

EC2 Deployment with Rubber

November 17, 2009

At NH.rb last night I gave a talk about deploying web applications to the EC2 cloud with Rubber. Rubber is an extension to Capistrano written by Matt Conway that makes provisioning and managing multi-instance EC2 deployments magically delicious [GitHub].

Want to bring up an instant multi-role staging server fully loaded with Apache, Passenger, MySQL, and your Rails app? All gem’d up, migrated, and ready to use? Sure you do. First, sign up for an EC2 account, generate your keypair, and then…

gem install rubber

cd my-rails-project
script/generate vulcanize complete_passenger_mysql
edit config/rubber/rubber.yml

cap rubber:create_staging

It uses a Ubuntu AMI and provisions an EC2 small instance by default. If you added your account credentials and the apt packages and gems you needed to rubber.yml (and provided that there weren’t any unexpected problems), you should now have a fully functional staging server for your web app that you can visit at http://appname.your-domain.com.

Since it’s EC2 you only pay for what you use. What’s more is you can horizontally scale this out with relative ease — breaking out the individual roles to separate instances as needed — and/or add your own custom roles as needed (see the other templates available for examples).

Want to learn more? Peep my slide deck and then check out the Rubber Wiki.

comments »


 

Reflections on *Camp

November 15, 2009

Last weekend I attended the first-ever New Hampshire PodCamp, organized chiefly by my friend Leslie Poston along with a crew of enthusiastic volunteer co-organizers (myself included). I only made it to the second of the two days due to prior obligations but had a good time and enjoyed meeting everyone.

If you’ve never been to a PodCamp (I hadn’t) it’s sort of like a branded BarCamp event that focuses more on how people are using technology — such as podcasting, blogging, social networks, video and music on the web — than on straight-up technical topics. I gave a presentation on Developing Twitter Micro-Apps, which I think was pretty well received.

We talked about why building apps that leverage existing social networks can be advantageous, how you can have fun with it, and how to get going really really quick with easy-to-use Ruby tools like Grackle, Rails templates, TwitterAuth (a Rails engine), Darcy’s BirdGrinder toolkit, and my own simple Retweet / Sinatra recipes. You can check out the slides if you want to learn more.

[ Note: The slides were made with slidedown. Although it’s still a little rough in places, it’s quickly becoming my favorite tool for creating slideshows in plain text. ]

That’s me looking pretty intense, live-coding some Twittery shit during the talk. Because, I’m hardcore like that. Unfortunately I didn’t have anyone record the live-coding portions of the presentation, in which we built a conversation aggregator as well as a simple faux-popularity reporting service. Ah well. Other attendees gave talks on topics as various as building interactive and community television outlets on the web, Facebook app development, film promotion, digital photography, and creating Firefox add-ons.

The event itself was held at the New Hampton school in the middle of nowhere New Hampton, NH, which is about an hour north of Manchester. It was quite isolated but the campus was beautiful and the solitude gave people a chance to get away from everything and kept everyone in one spot, resulting in less distractions and more focus on community. Although I really enjoy urban city-center events a lot — especially when they intelligently integrate other elements of the host city into after-hours events — there’s something really nice about isolated rural events (the first New England Railscamp was another example of this)

As someone who has never been very involved in organizing non-virtual conferences / events before, it was also interesting to observe and assist with the process of venue selection, sponsor lineup, and so on. In short: it’s a lot of work, but the payoff is great if it’s done well. Congrats and a big thank-you to Leslie (and all the other co-organizers) for putting this all together. There’s already talk of scheduling the next one for June 2010.

comments »


 

Notes from MIT Startup Bootcamp

October 14, 2009

Yesterday (October 12th) I attended MIT’s Startup Bootcamp. As someone who is seriously thinking about taking some time off from his consulting lifestyle to work on bootstrapping a product, it was definitely a worthwhile event for me, and I’m glad I took good notes. I thought I’d share some of them in case you’re interested and couldn’t attend.

(If you were there, and I got something wrong or you have something else to add, please leave a comment…)

1. Adam Smith of Xobni (a Y-Combinator company). Adam was the first speaker of the day and did a nice job relating Xobni’s story. He talked at length about finding cofounders (“shake the friends tree”), their early days, angel funding, and achieving product-market fit. He stressed that being nimble is the key difference between successful and unsuccessful as a startup founder and mentioned how difficult — but necessary — it was for them to scrap an early product and change direction. “Don’t give up [on your idea],” Adam says, “90% of execution is keep going when everyone else gives up.”

2. Alexis Ohanian of Reddit (a Y-Combinator company). An energetic speaker, Alexis talked about embracing your users, and the need for evangelists to spread your message through organic traffic (“web 2.0 aka labor 2.0”). He encouraged audience members to go above and beyond when interacting with their users. Make their experience memorable, weird, fascinating, amazing, much like Zappos overdelivering (literally) on their shipping. Alexis also stressed that you need to be down-to-earth — “you don’t need to be naturally charismatic, just don’t be a dick. Be root-for-able” — both in your dealing with your users as well as with your cofounders. Most of all, do something you love.

3. Ken Zolot of MIT. Ken is the founder of MIT’s Innovations Teams program. He talked briefly about what makes interesting technology the basis of a viable company or business, and how to make that transition. Ken also stressed the importance of good communication and having tangible results to show early on.

4. Dan Theobald, Vecna. As founder of a robots company, Dan’s background was an interesting contrast to his largely web 2.0-centric peers at this event. He talked extensively about the social responsibility of a good company and incentivizing your employees. Dan is also strongly opposed to over-use of venture capital, and advised the audience to only deal with it if absolutely necessary. “Other peoples money makes you stupid,” he quipped, “avoid it at all possible”. One of the most interesting passages from Dan’s talk was about how Vecna profit shares with their employees and uses a “peer to peer” points system (employees give “cookies” to one another to reward those who are providing value) to determine distributions.

5. Kyle Vogt, Justin.tv (a Y-Combinator company). Kyle’s talk was centered around a list of “productivity hacks” but the most interesting portion of his talk was about how Justin.tv dealt with the failure of their original idea and, instead of giving up, used it as an opportunity to change direction and embrace a more mainstream approach to get to where they are today. Also, perhaps his most important advice: “stick to dot-com [domain names]”.

6. Angus Davis of Tellme. Angus, another enthusiastic speaker, related stories about Tellme’s rise and eventual acquisition by Microsoft. He also talked about his experience as an angel investor. His talk gets points for best use of technology as he employed a text messaging feedback system so audience members could tell him which vignettes they wanted to hear more about.

7. Hemant Teneja of General Catalyst Partners. Hemant, a venture capitalist with GC, talked not only about what GC looks for in prospective portfolio companies but also about what founders should look for in a VC, term sheets, and so on. An advocate of bootstrapping (is this rare for a VC?), he agreed with previous speakers that you should delay looking for VC unless you really need it, and make sure you’ve created something demonstrable and have a viable business strategy before you make that decision. What gets GC excited? Brilliant founders, solving “very hard” problems, addressing large markets, and being ahead of the curve.

8. Dharmesh Shah, Hubspot (and author of the popular On Startups blog). Dharmesh apologized to the crowd at least once for not being a professional speaker, but this seemed largely unnecessary as he had one of the more polished presentations of the day (although he did run through it a bit fast!) His talk was basically a “marketing 101” for early stage founders. “How do you get customers with $0 budget?” he asked. The answer is through inbound, not outbound, marketing; building the best experience for those who are already looking for you or the products you offer through mechanisms like search engine optimization. “Make marketing about creativity, not cash” he counseled.

9. Robin Chase of Zipcar / GoLoco. Robin talked candidly about the origin and growth of Zipcar, sustainability, and the challenges that are facing the world and environment, and how “doing good” can be a foundation for business opportunities, too. On the topic of inspiration vs execution she says that “execution is everything” and advised audience members to get started today, by building the absolute smallest thing that they can to start with. Luck is important, too, she admitted, and noted that luck happens when “preparation meets opportunity”. Be prepared!

10. Dan Bricklin, VisiCalc. Dan is an entrepreneur, programmer, and author. He created the first electronic spreadsheet application in 1979 and has been innovating ever since. Dan’s talk was a fast moving flurry of images from the early days, growth, and acquisition of VisiCalc and his company, Software Arts, and his experiences — both good and bad — as “an entrepreneur 30 years later”. His talk was refreshing and filled with humor. “You will live through things you do not expect”, Dan said as he was wrapping up.

11. Aaron Schwartz of Infogami / Reddit (a Y-Combinator company). At 14, Aaron co-authored the original RSS 1.0 specification, and has been active in the technology, entrepreneurial, and political action communities ever since. As part of the first Y-Combinator program, his company was eventually merged with Ohanian’s Redit. He talked about launching a startup and joked about what to not do (“the hollywood launch”) and what might be a better strategy (“the gmail launch”, incremental features and invitations).

12. Drew Houston, Dropbox (a Y-Combinator company). Drew’s startup, Dropbox, is now serving over 2.5 million users. Drew talked about his personal experiences from the creation of Dropbox to growing it to this point, and the challenges he faced along the way. He championed engineering-centric organizations and noted that “it’s much easier for engineers to pick up the business side than for business people to pick up the engineering side”. He also counseled the audience to “get in over their heads” and out of their comfort zones to learn things. Having friends in startups is tremendously helpful too; surround yourself with kindred spirits (which is why programs like Y-Combinator work so well).

comments »


 

Remote Pair Programming Resources

September 15, 2009

I usually don’t double-post or call out the articles I write for DDJ Code Talk too much here (links are in the sidebar), but I wanted to make sure that this one got noticed.

I’ve had the good fortune lately to be working with a client who really appreciates the power of pair programming (something I’ve been admittedly a bit slow to embrace in my role as a freelancer). Since I’m only on-site with their team 2 days a week, I’ve been forced to learn a fair bit about what’s available for remote pairing tools.

Here’s the short summary: Screen + Vim + Skype is a recipe for awesome. Read the full article if you want to find out about other options.

comments »


 

Rumble Results

September 03, 2009

The results are in for the 2009 Rails Rumble. Check em out and peep the winners. Some pretty impressive stuff for a single 48-hour sprint, right? Right!

I’d like to personally thank all the sponsors, expert panelists, and especially the contestants that made this years contest the best one yet. We’re looking forward to using the feedback we’ve received this year to make the next one even better, and starting to seriously discuss doing some more language/framework-agnostic events too.

But first, we need a little bit of a break :). Some downtime next weekend sure will be nice!

comments »


 

Rumble Build Weekend

August 22, 2009

This weekend is Rails Rumble Build Weekend, which means that over 200 teams of 1-4 people are, at this very moment, working diligently (tirelessly!) to build the next awesome 48-hour micro-app.

This is the third year in a row we’ve run the contest and things seem to be going smoother than ever. Well, so far. Big thanks to Darcy Laycock, Erin Shine, and Jeff Rafter for being incredible co-conspirators, to all our competition sponsors, and especially to the participants who are really pouring their everything into this. I can’t wait to see how some of these ideas turn out.

Rails Rumble

In case you’re curious, we’re running the voting process a little bit differently this year, and have assembled a fine panel of expert judges to help qualify the best of the best before they go on to public voting. These people come from all corners of the web startup ecosystem and I’m really amazed that most of them were able to find the time in their busy schedules to help us out — we’re honored! So a big thanks to them, too.

The competition wraps tomorrow (Sunday) night at midnight UTC, and then the expert panelists have a couple days to work their magic. Public voting should probably open on Thursday if all goes to schedule. If you’re not competing you can still register for an account and help us judge! For more information, head on over to the competition site or check out the blog. Make sure to subscribe for updates. Thanks!

comments »


 

Testing ActiveRecord Observers

July 25, 2009

Need to unit test those pesky ActiveRecord observers you’re using? I don’t use em often, but there are times when they’re definitely useful. Fortunately, since AR::Observer leverages Ruby’s Observable module all you have to do is call MyModel.delete_observers in your test setup or before block.

ZombieSighting.delete_observers

Better yet, add the exclusions to your test or spec helper file. Then you can unit test your models comfortably in isolation, and write tests for your observers that look like this:

describe Observer
  before(:each) do
    @obs = ZombieSightingObserver.instance
    @thing = Factory.build(:zombie_sighting)
  end

  it 'should generate a new notification' do
    lambda { 
      @obs.after_create(@thing)
    }.should change(Notification, :count)
  end
end

We wouldn’t want to couple zombie sightings too tightly with notifications, after all, as that might anger them even further (zombies are known to be crazy about SRP).

comments »


 

Rails Camp New England

July 22, 2009

Last Friday, about 30 people descended on a large house in Bryant Pond, Maine for Rails Camp New England. Organizer Pat Allan has been running Rails Camp events in the UK and his home nation of Australia for quite some time, but this was the very first North American event (co-organized by Boston.rb’s own Brian Cardarella). Personally, I think it was a smashing success and I’m really glad I had the chance to be a part of it.

Our weekend retreat basically consisted of group hacking and pair programming, lots of lively discussions, gaming, and plenty of R&R. Frisbee was played. Food was eaten. Canoes were canoed. Urban Terror was instigated. Werewolves were slain by lakeside campfire light. Alcohol was consumed. In no particular order, of course.

Rails Camp

In addition to the ever-important extra-curriculars, we had time to work on personal projects and share with others through a series of BarCamp-style sessions. These sessions included topics as diverse as Ruby Gems, GemCutter, Internationalization, CouchDB, and RadiantCMS. There were also a number of app demos and lots of peer consulting and mentoring going on. Experience levels ranged from complete beginners to seasoned professionals, but all egos were checked at the door and everyone seemed to get along like old friends. Social games and sessions really helped people get to know one another, and keeping the event small meant that by the time you left, everyone was on a first-name basis.

I’m not sure how (cough) productive I was over the course of the weekend, but I sure had a great time, met a lot of interesting people, and learned a lot from them. If you’ve never attended anything like this I strongly encourage you to. It’s a great mix of learning and fun, and the freestyle format allows you to make of it what you want. A far better experience than any conference I’ve attended in the past year, imo, and far less costly at a mere $120 for the entire weekend, including all lodging and food.

A big thanks to Pat and Brian for all their hard work, to Thoughtbot and ZenDesk for sponsoring, and to everyone else that showed up for being full of awesome. Hopefully we’ll do another RC New England event soon. I’m thinking that a mid-winter ski lodge excursion sounds like a damn good idea… Yeh?

comments »


 
← Older Newer →