Capistrano 2 rolling task

This took a long time to track down, but this will allow rolling deploys or tasks with Capistrano 2.x.

task :rolling, roles: :web do 
    find_servers_for_task(current_task).each do |s|
        puts roles[:web].clear()
        server s.host, :web
        puts "Deploying to #{s.host}..."
        find_and_execute_task('deploy')
    end
end

Ref: https://groups.google.com/forum/#!topic/capistrano/H-tizsMN2Tk

AngularJS dynamic filter

/*
 * Use this to dynamically pass a filter from a controller or somewhere else 
 * as a string. It will use DI to lookup the filter and apply it.
 *
 * In the template:
 *
 *     {{row.label | date | dynamic:nameFilter }}
 *
 * In the controller:
 *
 *     $scope.nameFilter = 'mycustomerfilter'; 
 */
app.filter('dynamic', ['$injector', function($injector) {
  return function(text, filter) {
    var result = text;
    if (filter) {
      var f = $injector.get(filter + "Filter");
      if (f) { result = f(text); }
    }
    return result;
  }
}]);

Short MongoDB Fields with Mongoid

Need to have shorter field name in MongoDB, but still use readable names in code?

# Mongoid Timestamps
include Mongoid::Timestamps::Short

# fields
field :aid, as: :application_id, type:String

# one to one
embeds_one :address, :store_as => :ad

# collections
field :aid, as: :application_id
belongs_to :application, foreign_key: :aid