A Hapi Ninja for Node.js #

Earlier this year we had Eran Hammer on the podcast to talk about the success of Node.js at Walmart for the infamous influx of traffic that Black Friday brings them. At the core of their success lies Hapi, the rich framework for building web applications and services with Node from Walmart Labs.

Hapi is a lot like Sinatra for Ruby in the fact that you start with a single server file and expand as needed from there to create a file and directory structure to organize and support your application code.

While hacking on Hapi recently, I found Hapi Ninja. If you’re just getting started like me, Hapi Ninja can serve as a boilerplate to learn from with Hapi, or even as the starting point for your Node web service.

It was also a pleasant surprise to see Saul Maddox was a native Houston Texan like myself. Sadly we’ve never met.

minicron: a system to manage and monitor cron jobs #

minicron is a web interface to manage and monitor scheduled tasks across a series of servers. It’s still in early development, but the tool sets out to solve a pain that anybody with more than a few servers has probably felt. I know I have.

minicron is pre-semantic-1.0 and has a roadmap in the readme. Looks like a great time to get involved.

Dashing creates gorgeous dashboards #

Dashing is a framework from Shopify for building gorgeous dashboards that can be displayed on large TVs throughout your office.

It ships with pre-made widgets, is completely customizable, and can be deployed to Heroku in a breeze. See Dashing in action here and here.

Stringer: a self-hosted, anti-social RSS reader #

With July 1st’s closing of Google Reader looming ever closer, the open source community has risen to the challenge of providing viable alternatives to the popular feed reading service.

Stringer is Matt Swanson’s entry into the RSS ecosystem. Matt describes Stringer like so:

Stringer has no external dependencies, no social recommendations/sharing, and no fancy machine learning algorithms. But it does have keyboard shortcuts and was made with love! When BIG_FREE_READER shuts down, your instance of Stringer will still be kicking.

Here’s a screenshot of it in action. (Bonus points for featuring a Changelog post!)

Stringer is written in Ruby and built on Sinatra with a PostgreSQL datastore. It deploys easily to Heroku and is a self-professed work-in-progress. One thing the web app currently lacks is a solid mobile offering, so please get involved if you have mobile ideas and/or chops!

The project is MIT licensed and hosted on GitHub.

Stripe Push is money in the bank — the Sinatra and Mac app behind it open sourced #

Let’s start this post the right way. WE LOVE STRIPE!

Stripe powers the payments for our memberships, job link board and donations. I’m likely preaching to the choir here, but Stripe is by far the easiest payment platform to work with — at the UX level as well as the developer level. The entire experience of Stripe is simply awesome.

Naturally, when Alex MacCaw, Engineer at Stripe, announced his side-project Stripe Push back in February I immediately installed it. Now every time we get a new member, a new charge goes through, or a transfer kicks off I get to do a happy dance. But somehow in the midst of all my excitement of installing it, I gapped the fact that Alex open sourced the Sinatra and Mac app behind it. Whoops.

Stripe Push

From the announcement post:

Stripe Push is a little side-project that sends you Apple Push Notifications whenever you get a new charge or transfer via Stripe. You can configure what type of notifications you want to receive and their frequency. I’ve open sourced the Sinatra and Mac app behind it on GitHub.

Check out the Sinatra and Mac app behind Stripe Push on GitHub, and install it on the Mac App Store.

sinatra-asset-pipeline: Sprockets for Sinatra #

I remember being really excited for Rails 3.1, and that’s because it was going to have ‘the asset pipeline,’ helping us manage the assets our application needed. I also remember being so excited by it, I fooled around with sprockets 2.0.0.beta6 to get it running on my Sinatra apps, as well. It took me a while, and when beta7 came out, it didn’t work any more…

But this isn’t a story about me. It’s a story about Joakim Ekberg. He did better than I ever did: when he put Sprockets on Sinatra, he made a gem out of it. He calls it sinatra-asset-pipeline.

It’s pretty easy to use: just

gem 'sinatra-asset-pipeline'

in your Gemfile. After bundling, add this to your Rakefile:

require 'sinatra/asset_pipeline/task.rb'
Sinatra::AssetPipeline::Task.define! MyApp

and add it to your application, too:

require 'sinatra/asset_pipeline'

class MyApp < Sinatra::Base
  register Sinatra::AssetPipeline
end

Then, sinatra-asset-pipeline gives you the rake tasks you’d expect:

$ rake assets:precompile
$ rake assets:clean

Sinatra-asset-pipeline is still pretty young, and currently only supports the stock Haml, Sass, and CoffeeScript options that the Rails asset pipeline uses. Hopefully, future releases will integrate Tilt so that you can use arbitrary endings, but there’s a reason why these are default in Rails: they’re the most popular alternate options from the defaults.

Vote this up on Hacker News.

Showbot – An IRC Bot for 5by5.tv built w/ Cinch and Sinatra #

Showbot is a sweet IRC bot with a web interface for 5by5.
Built on cinch and sinatra.

Showbot

If you’re a fan of Build and Analyze hosted by my good friend Dan Benjamin and Marco Arment or any other live show and you hang out in the 5by5 chat room, you’ve probably shared what you “think” the show should be titled with Showbot.

The jackals in the 5by5 Chat think they know what the title of the show should be. Showbot passes no judgements. Showbot collects the title suggestions from IRC and shows them here. Showbot is here to help.

Checkout the readme for more details.

A few tools to craft JSON output in a Ruby web app API #

It seems a solid API that returns JSON is almost a prerequisite for any new web app these days. Often these JSON data structures return nested associated data, composed from several models in the system. There has been some discussion this week around tools and approaches to building JSON data structures in a Ruby web app API.

Perhaps the biggest buzz this week has been around Jbuilder which DHH announced on Twitter. While the world doesn’t need another J_Anything_, it does provide a nice API that can be used stand alone from controllers or as a view template:

Jbuilder.encode do |json|
  json.content format_content(@message.content)
  json.(@message, :created_at, :updated_at)

  json.author do |json|
    json.name @message.creator.name.familiar
    json.email_address @message.creator.email_address_with_name
    json.url url_for(@message.creator, format: :json)
  end

  if current_user.admin?
    json.visitors calculate_visitors(@message)
  end

  ...
end

… which produces:

{ 
  "content": "<p>This is <i>serious</i> monkey business",
  "created_at": "2011-10-29T20:45:28-05:00",
  "updated_at": "2011-10-29T20:45:28-05:00",

  "author": {
    "name": "David H.",
    "email_address": "'David Heinemeier Hansson' <david@heinemeierhansson.com>",
    "url": "http://example.com/users/1-david.json"
  },

  "visitors": 15

  ...
}

Another promising gem is Boxer from the team at Gowalla. While tied more closely to ActiveRecord and Rails, Boxer lets you define multiple views for an object, allowing you to expose extended attributes, usually based on permissions:

Boxer.box(:user) do |box, user|
  box.view(:base) do
    {
      :name => user.name,
      :age  => user.age,
    }
  end

  box.view(:full, :extends => :base) do
    {
      :email      => user.email,
      :is_private => user.private?,
    }
  end
end

Finally John Nunemaker shared his thoughts learned building the Gaug.es API on his popular Rails Tips blog. John uses the Presenter pattern to craft the JSON output.

For even more projects in this space, check out the JBuilder README which provides a list of resources at the bottom. The most mature of these looks to be RABL from Nathan Esquenazi.

SMTPRoutes – Python-powered SMTP server with Sinatra-style routes #

A cool project from Benjamin E. Coe for SMTP using an elegant DSL in Python:

class ExampleRoute(Route):

    @route(r'(?P<prefix>open)@(?P<suffix>.*)')
    def open_route(self):
        print "%s at %s sent the message: nn %s" % (
            self.prefix,
            self.suffix,
            self.message
        )

Messages are routed to methods in your class based upon rules in the @route decorator. Routes can even specify sender authentication:

@route(r'(?P<prefix>spf)@(?P<suffix>.*)', sender_auth=SPFAuth)

Check the README for complete feature list and usage information.

Renee – Sinatra-inspired Rack framework for über DRY routing #

Josh Hull knows Sinatra. As part of the Padrino, he also knows about creating new alternatives to popular frameworks. His latest effort is Renee, a web framework for Rack that aims to DRY up your routes.

We wondered though, as Sinatra fans, if we were to come up with a cleaner and more powerful DSL, what might that look like? Let’s consider an example from Sinatra to see where we can do better.

The result is a pivoted syntax that turns the routing DSL on its side:

path 'blog' do
  var do |id|
    @blog = Blog.get(id)
    get { halt @blog }
    put { @blog.update(request.params); halt :ok}
  end
end

I can see how powerful this could be for creating complex REST APIs. Check out the nicely designed web site for more.

Padrino 0.10.3 features Sinatra 1.3 support, improved docs, and switch to Minitest #

It’s nice to see the Padrino framework offering support for Sinatra 1.3 so soon after its release. The new streaming API in Sinatra as well as projects like sinatra-synchrony should pay big dividends for Padrino. Nathan Esquenazi and the rest of the team believe the combination of simplicity and power makes Padrino the ideal Ruby web framework for newcomers.

It’s also interesting to see the team move from Shoulda to Minitest:

We have been using test-unit and shoulda in Padrino as long as the framework has been around. I am a personal fan of test-unit + shoulda and have been using the combination successfully in many projects. However, times change and the fact that Ruby 1.9 seems to recommend minitest over test-unit encouraged us to take a look at the pain of upgrading.

We wanted a faster test suite and less external dependencies. So we decided to bite the bullet and convert our entire test suite over to the minitest test library. Built into 1.9 but available as a gem for 1.8.X, this library is quite stable and fast. The best part is that it has a lot of the great parts of shoulda built in.

Check out the newly improved, YARD-powerd API docs or Episode 0.2.7 for more on Padrino.

Sinatra 1.3 is out! #

Sinatra 1.3.0 is out with two big news items. The Chairman is now traveling with his own band. Sinatra Contrib, the community-sourced collection of extensions, is now versioned with Sinatra itself, ensuring compatibility. Sinatra Contrib provides some niceties on top of Sinatra for common tasks like config files, content_for, respond_with and other things you might miss from Rails.

Perhaps the bigger news is that Sinatra gigs can be streamed. No matter if you run evented servers like Thin, Rainbows! or Ebb or sequential servers like Unicorn, Passenger, or Mongrel, you have a single API:

get '/' do
 stream do |out|
   out << "It's gonna be legen -n"
   sleep 0.5
   out << " (wait for it) n"
   sleep 1
   out << "- dary!n"
 end
end

Of course, you’ll need an evented server to keep connections open to things like:

set :server, :thin
connections = []

get '/' do
 # keep stream open
 stream(:keep_open) { |out| connections << out }
end

post '/' do
 # write to all open streams
 connections.each { |out| out << params[:message] << "n" }
 "message sent"
end

Smaller but just as cool changes include:

  • request.accept? for Accept headers
  • informal?, success?, redirect? and client_error? based on HTTP status code.
  • Support for If-Unmodified-Since header

Check out the official announcement or the changelog for a complete list of updates. Congrats to Konstantin Haase and the other contributors who made this happen.

Deployinator – Deploy with Style, by Etsy #

I am super excited to make this post.

One of my favorite engineering blogs is Code as Craft. Etsy is one of my favorite startups, they’ve got cool people working there, they help people make and sell neat things, and contribute a lot back to the community.

A while ago, they mentioned that they had an in-house, custom deployment tool. And they were thinking about open sourcing it. I’m really fascinated by what (by now) is being hailed as “DevOps,” and so I was really interested to see what they were building.

And then I waited.

And now, they’ve released it. From their GitHub, it’s just a little Sinatra app that you can run. It has the concept of ‘stacks,’ so you can roll things out in waves if you’d like. They give an example of having a ‘search’ stack and a ‘web’ stack. Each stack can have environments, so you have ‘search staging’ and ‘search production,’ for example.

It’s a bit light on documentation at the moment, and since it came out under an hour ago, I have yet to try it out for myself. But I’m super excited to, and wanted to share. Bust out those fork buttons!

Check out the source on GitHub.

rstat.us – Distributed Twitter with Ruby and ostatus #

So, I’m sure you’ve all been waiting with baited breath for me to begin my licensing series. I got lots of great feedback, but something’s made me put it off for a moment: coding. I plan on starting the series in earnest next week, but in its stead, I offer you this: rstat.us.

If you didn’t hear, a week ago Friday Twitter changed their terms of service. This got a lot of people upset, including me. My friends and I started thinking about it, and the real problem is this: any software that’s owned by one entity, corporate or not, is open to the possibility of being abused.

So we decided to fix it. Ten days later, here we are: http://rstat.us/ is born.

rstat.us

To boil it down, rstat.us is a Sinatra application that clones the basic functionality of Twitter. Fine. But here’s the interesting part: if you want to follow someone that’s not on the main rstat.us site, you can copy/paste a URL into a form, and from then on out, it just transparently works. We’re building on the ostatus protocol that other sites like Identi.ca uses, so you can actually follow Identica users on rstat.us right now, and after we work out a kink or two, they can follow you, too.

Oh, and I should mention that: this is very much an alpha release. rstat.us was put together by 6 or 8 of my closest friends in a marathon coding session, so there’s some refactoring work to be done. The documentation is also a bit obtuse, partially to slightly discourage people from running their own nodes just yet. Eventually, this should be a two or three line process, and you can be running your own node up on Heroku. We also want to significantly improve our test coverage.

There’s some pretty big plans for the future: we want to extract a Sinatra extension that will enable anyone to easily build their own distributed network. We’re also releasing three Ruby gems that will let anyone work with the few standards that we build upon, so that other people can make their own tools that work with us, or build their own implementations and copy of the site. Check it out on GitHub, or drop by #rstatus on Freenode if you’d like to say hello.

It’s a distributed world that we live in. Own your own data. Build decentralized networks. Take control of your own social networking. And help us do it. :)

[GitHub] [README] [Discuss on HN]

Sinatra 1.2 is out #

Sinatra 1.2 is out and thanks to R. Konstantin Haase and others, The Chairman has added a number of ditties to his set list. Highlights of the release include:

  • Slim support
  • Inline Markaby
  • Layout engines, so you can have a layout in Haml and templates in ERb for instance
  • Conditional before, after filters
  • URL helper
  • Templates with different scopes
  • Configurable template lookup

For Ruby 1.9 users, you can now use named captures in your routes:

get %r{/(?<year>d{4})/(?<month>d{2})/(?<day>d{2})/?} do
  date = Date.new params[:year].to_i, params[:month].to_i, params[:day].to_i
  @posts = Post.pubished_on date
  erb :posts
end

As Sinatra fans, we’re excited about this release anxious to see what projects like Padrino and NestaCMS can do with it.

[Source on GitHub] [Announcement] [Web site]

BBC Zeitgeist: All the news fit to tweet, powered by Ruby, Sinatra, RabbitMQ #

BBC Research & Development has released Zeitgeist, a directory of the most shared BBC links on Twitter.
Screenshot

Tweets and stories are indexed by topic and location and can be filtered by time period to include only the last 24 hours or 7 days.

Perhaps even more valuable than the news to the web development geek, is the well documented source:

Install instructions

Zeitgeist is a Sinatra app that consumes the Twitter Gardenhose and Track APIs using workers in a RabbitMQ queue.

[Source on GitHub] [Demo]

Slim: A PHP5 Sinatra Clone #

Screen shot

Frank Sinatra was the Chairman of cool. Some fourteen years after his death, the crooner is still imitated.

Just like its namesake, Sinatra, the class Ruby web application DSL still inspires all sorts of projects from Sammy.js to Padrino to Denied.

Slim, a PHP5 project from Josh Lockhart is the latest project to cover the classics.

Setup

To get started, just require the script and call init

<?php
require('slim/Slim.php');
Slim::init();
?>

Routing

Slim supports the familiar Sinatra-style routes for all four HTTP verbs:

Slim::get('/books/:id', function ($id) {
    //Do something
});

Slim::post('/books', function () {
    //Do something
});

Slim::put('/books/:id', function ($id) {
    //Do something
});

Slim::delete('/books/:id', function ($id) {
    //Do something
});

Middleware and callbacks

Slim also allows you to run code before and after your actions:

Slim::before(function () {
    //Do something
});


Slim::after(function () {
    //Do something
});

Templating

Slim supports a variety of templates including Smarty and Twig.

[Source on GitHub] [Hompage]

Mailman: If Sinatra worked at the post office #

As part of the Ruby Summer of Code, Jonathan Rudenberg has released Mailman. Mailman aims to provide the classy Sinatra declarative style for handling incoming mail:

Mailman is a Ruby gem so it’s easy to install:

sudo gem install mailman

Then you’re ready to start handling some mail:

require 'mailman'

Mailman.config.maildir = '~/Maildir'

Mailman::Application.run do
  to 'ticket-%id%@vipsupport.com' do

    Ticket.find(params[:id]).add_reply(message)
  end

  from('%user%@example.org').subject(/RE: (.*)/) do
    params[:user] #=> 'chunkybacon'
    # it is an indifferent hash, so you can use strings and symbols
    # interchangeably as keys
    params['captures'][0] #=> 'A very important message about pigs'
  end
end

Simple and classy.

The comments on Jonathan’s original blog post suggested he change the name to something more Googleable. Jonathan, if you’re open to suggestions, might we suggest KarlMalone?

[Source on GitHub]

#27: Padrino Ruby web framework

Adam and Wynn caught up with Arthur Chiu and Nathan Esquenazi from Padrino, the Ruby web framework built on top of Sinatra. Items mentioned in the show: Padrino – über modular web framework built on top Sinatra #padrino – Padrino’s IRC channel @ irc.freenode.net Ramaze – “Web framework for Rubyists” Mountable apps in Padrino Rack […]

Express – Sinatra cover band for Node.js #

We’ve covered cool things from TJ Holowaychuk before, but Express, a new Sinatra-ispired DSL-based web framework for Node.js brings us to our feet.

To install, simply clone the project from The Hub:

$ git clone git://github.com/visionmedia/express.git
$ cd express && git submodule update --init

or install via Kiwi

$ kiwi -v install express

From there, the syntax should look very familiar for the Sinatra fan:

require.paths.unshift('path/to/express/lib')
require('express')

get('/', function(){
  this.redirect('/hello/world')
})

get('/hello/world', function(){
  return 'Hello World'
})

run()

Features in this version include:

  • RESTful DSL
  • Focus on high performance
  • Multi-part file upload support
  • Cookie support
  • Session support
  • Redirection helpers
  • Environment based configuration
  • Light-weight class implementation
  • Persistent flash messages
  • Route passing
  • MIME helpers
  • Logger plugin with many formats
  • View support (haml, sass, etc)
  • Cache API
  • RESTful HTTP client

[Source on GitHub] [Homepage]

Showoff – the best darn presentation software a developer could ever love #

From GitHub’s own @schacon, Showoff aims to do presentations developer style.

ShowOff is a Sinatra web app that reads simple configuration files for a presentation. It is sort of like a Keynote web app engine.

Scott’s goals are:

  • show simple text
  • show images
  • show syntax highlighted code
  • re-enact command line interactions
  • do simple transitions (instant, fade, slide in)
  • show a timer – elapsed / remaining
  • perform simple animations of images moving between keyframes
  • show syncronized, hidden notes on another browser (like an iphone)
  • show audience questions / comments (twitter or direct)
  • let audience members go back / catch up as you talk
  • let audience members vote on sections (?)
  • call up a menu of sections/slides at any time to jump around.

[Source on GitHub]

Middleman: A static site generator with Haml, Sass, Compass + YUI compression and cache busting #

Written in Ruby – Middleman is built upon Sinatra. In fact, the Middleman init.rb is evaluated within a Sinatra context so anything you could do in Sinatra can be done in Middleman. Very nice!!

Middleman watches your template files (Haml, Sass, Erb, Builder, Maruku & Markaby) for changes and provides a development environment for rapid site creation and prototyping. Some important features are layouts, ruby helpers and the integration of the Compass CSS library. Hawt!!

Hat tip: http://bit.ly/8bWzxO

[code on GitHub] [homepage]