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.
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.
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].
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).
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.
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).
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.
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!
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.
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!
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).
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.
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?
Michael Bleigh’s TwitterAuth gem is truly full of awesome. It’s a complete OAuth authentication and API access solution for building Twitter apps with Rails. It uses familiar conventions borrowed from the Restful Authentication plugin, too. If you’re building a Rails-based app and you want to allow your users to Sign in with Twitter there’s just no better way to go.
For this particular app, I’m using the dynamic duo of Cucumber and Webrat to whip up integration tests. Since I initially stumbled a little bit when thinking about how to test integrated authentication against an external source like Twitter, I thought I’d doc the solution here in case other people were having the same issue.
Ready? Let’s do it.
Setup
First, install the TwitterAuth gem and use the provided generator to whip up the appropriate facilities. You’ll need to register your Twitter application accounts too. Or you know what? Screw it. If you want to make this super easy on yourself, Mike wrote a really great Twitter app Rails template that does all the setup for you, including walking you through getting the dev accounts. It’s nice, try it out. You’ll be up and writing Twitter apps in no time.
For the rest of this I’m going to assume that you have all of that working, and have installed Cucumber too. Don’t have Cucumber? Install it using RubyGems and then just run script/generate cucumber inside your Rails app.
Authentication Feature
So let’s write a Cucumber feature to test authentication in our boilerplate Twitter template application. Put the following in features/authentication.feature:
Feature: Authentication
In order to create and edit games
As a user
I want to sign in with Twitter
Scenario: Login via Twitter
When I go to "the homepage"
And I follow "Login via Twitter"
And Twitter authorizes me
Then I should see "Logged in as"
Scenario: Checking login status
Given I am signed in
When I go to "the homepage"
Then I should see "Logged in as"
Scenario: Log out
Given I am signed in
When I go to "the homepage"
And I follow "Log out"
Then I should see "Login via Twitter"
Step Definitions
Next, you’ll need to write step definitions to satisfy the missing steps. Do that by creating a file called features/step_definitions/auth_steps.rb. The content of the file should define the following two steps:
Given /^I am signed in$/ do
visit login_path
visit oauth_callback_path
end
When /^Twitter authorizes me$/ do
visit oauth_callback_path
end
Fake Style
The secret sauce here is FakeWeb. We’ll use it to fake out responses from the Twitter auth service so that your integration tests stay local (and reliable). Make sure to gem install fakeweb, and add the following to tests/environments/cucumber.rb:
Here we’re stubbing out the interaction with Twitter auth, and responding to all outbound authorization attempts with canned data. Note that this references a fixture file, containing a sample verify_credentialsAPI response from Twitter. You can obtain a copy using curl from the comfort of your terminal prompt (substitute your own username and password):
Alright that should do it. Go ahead and run rake features. Everything should be green. And green is good. If you need to write other features that are dependent on a login requirement, you can reuse the same “Given I am signed in” step that we created earlier.
Thanks to b.kocik, whose original post on using FakeWeb to stub Twitter auth was 80% of the solution I needed here.
We opened registration for the 2009 Rails Rumble yesterday. This is the third year in a row that we’re running the contest and it’s sure to be the best one yet. The build weekend is August 22nd-23rd but you need to register this week if you want a seat. If I were you, I’d go register now before it fills up ;-).
In other news, I’ll be presenting at the second Portsmouth Pecha-Kucha Night tomorrow, July 8th. I’ll actually be talking about the creative power of constraints, and describing our experiences organizing the Rumble will be a big part of that. If you’re in town, make sure to check it out. I’ve never done a p-k talk before but it sounds like it’s going to be a lot of fun.
Last night we headed to Londonderry NH to view our submission to the 2009 48 Hour Film Project on the big screen alongside all the other New Hampshire submissions. In case you haven’t been following my tumblr (where I tend to post less techie things), I thought I’d double-post it here for your viewing pleasure:
For those of you that don’t know, the 48HFP is a filmmaking challenge to write, shoot, and edit a short 5-7 minute film in a weekend. It was also probably the biggest single influence in our putting together the Rails Rumble, which follows a similar model but is geared towards web development and tech startup bootstrapping.
It’d been a couple of years since I last participated in the project (when I was living in Boston, attempting to make bad sci-fi movies). This time around John Herman, our director, ran the project like a sea captain leading a battleship to war. It really demonstrated, to me, the power of having a consistent vision and the right people lined up to do the right jobs ahead of time. Although I’m a little bummed that I missed out on being part of the crew due to prior obligations this year, being on the brainstorming / writing team was a great experience, and I probably would have just gotten in the way during production anyway ;-).
In filmmaking as with development, constraints are a powerful thing, and the 48HFP is a real showcase of this. It also demonstrates that many of the fundamentals of the "Getting Real" philosophy can be applied equally well to all sorts of art forms and mediums. IE, don’t let time limitations or overcommitted schedules stop you from showing off your bountiful awesome.
If you’ve got a few minutes, check out www.48.tv, where you can watch a bunch of other 48HFP films — I think you’ll be impressed by the creativity in a lot of them, not to mention the production values they achieved under duress. Props to John, Dan Freund, Ryan Plaisted, Bodhipaksa, and everyone else who was involved. And thanks for letting me tag along.
Winners of the NH competition will be announced at the upcoming “Best of NH” screening, and the winner of that will move on to compete in Filmapalooza at NAB Las Vegas 2010. Many of the other films we saw last night were pretty incredible, including entries from local filmmakers like Marc Dole and Bill Rogers, so I’m not holding my breath just yet, but it certainly would be cool. Either way, the best part of these things isn’t winning, but rather seeing what you can do, and watching other people bring their A-game too. It’s inspiring.
I’m currently available for consulting work. I took a bit of time off for some personal projects and a much-needed spring vacation and now I’m once again ready to dive into an interesting client / startup project. Are you looking for a motivated, opinionated, yet thoughtful Ruby developer who enjoys mountain biking, foreign cinema, and long walks on the beach?
Web Development: My core expertise is end-to-end web application development for Ruby, Rails, or Sinatra projects – If you’re looking for a project lead or a team to build your next big web application, I can help. Or if you need an additional hand to augment the development speed or best practices of your existing team, I’m happy to do that too.
Code Reviews: Concerned about the quality of your codebase or maybe just looking to get an outside perspective? Reviews include analysis of your code organization and structure, test coverage and effectiveness, and overall complexity / runtime efficiency.
In addition to the Ruby skill set, I’m also well-versed in JavaScript, Flash/ActionScript, social media tools, and the other standard systems and services that the web is built on. If you’ve read this blog and browsed my OSS project contributions, you already know that I’m passionate about technology, embrace web standards, and thoroughly enjoy working on innovative new ideas. I’ve also read a lot of comic books, and listen to all sorts of weird music, in case that helps.
I can provide references and an expanded portfolio by request; a rather smallish selection of work samples is currently visible on my freelance business micro-site. If you’re interested, you can get in touch via email (nap at zerosum dot org) or contact me on Twitter.
After I pooped out the initial version of rdoc.info a week or two ago, Jeff and I were bullshitting about the kind of stuff we could add to it when he had a bit of an epiphany: “the place for documentation about GitHub projects is on GitHub”. Yes! Of course! Why didn’t we think of that before?
So we registered the “docs” user on GitHub and went about building an extension to rdoc.info based on the GitHub pages platform. As of now, when you enter a project on rdoc.info, it’ll build docs for them locally and also generate a GitHub-themed set and push them to the docs user account pages on GitHub. In fact, you never even have to visit rdoc.info if you don’t want to (although project documentation will continue to be available there). For an example, see Nunemaker’s HTTParty API Docs. Make sure to play with the methods and namespaces buttons in the header.
As far as I know, we’re the first ones to use GitHub pages as an actual “app platform”, which makes me kind of giddy. You can read more about what we did and how we did it over on Jeff’s blog. He deserves most of the credit for this one, including that awesome GitHub YARD theme and more than a fair bit of tricksy JavaScript goodness. Of course, GitHub deserves a lot of credit too, for building an awesome and extensible service. If you run into any issues with the docs stuff (which is still kinda experimental), please report them via the GitHub project. Thanks!
You're reading the web journal of Nick Plante. Nick is a freelance web app / software mercenary and startup enthusiast. He writes about Ruby, emerging technologies for the web, weird art, and other stuff that doesn't suck.