This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| namespace :monit do | |
| desc "Monit unicorn configuration" | |
| task :unicorn_service_tests, roles: :web do | |
| run "mkdir -p #{shared_path}/config" | |
| template "monit_unicorn.rb.erb", "/tmp/monit_unicorn" | |
| run "#{sudo} mv /tmp/monit_unicorn /etc/monit/conf.d/unicorn_#{application}_#{rails_env}.conf" | |
| unicorn_worker_pids.each do |val| | |
| worker_template "monit_unicorn_worker.rb.erb", "/tmp/monit_unicorn_#{application}_#{rails_env}_#{val}_worker", val | 
| Rails.configuration.middleware.use Rack::OpenID | |
| Rails.configuration.middleware.use RailsWarden::Manager do |manager| | |
| manager.default_strategies :remember_me_token, :password_form, :api_token, :openid | |
| manager.failure_app = ExceptionsController | |
| end | |
| # Setup Session Serialization | |
| class Warden::SessionSerializer | |
| def serialize(record) | 
| # == Paperclip without ActiveRecord | |
| # | |
| # Simple and lightweight object that can use Paperclip | |
| # | |
| # | |
| # Customized part can be extracted in another class which | |
| # would inherit from SimplePaperclip. | |
| # | |
| # class MyClass < SimplePaperclip | |
| # attr_accessor :image_file_name # :<atached_file_name>_file_name | 
| // derived from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm | |
| function map() { | |
| emit(1, // Or put a GROUP BY key here | |
| {sum: this.value, // the field you want stats for | |
| min: this.value, | |
| max: this.value, | |
| count:1, | |
| diff: 0, // M2,n: sum((val-mean)^2) | |
| }); | 
| # Add these methods to your ApplicationController. Then, any controller | |
| # that inherits from it will have these methods and can programmatically | |
| # determine what filters it has set. | |
| class ApplicationController < ActionController::Base | |
| def self.filters(kind = nil) | |
| all_filters = _process_action_callbacks | |
| all_filters = all_filters.select{|f| f.kind == kind} if kind | |
| all_filters.map(&:filter) | |
| end | 
| # as we’re going to use Unicorn as the application server | |
| # we’re not going to use common sockets | |
| # but Unix sockets for faster communication | |
| upstream shop { | |
| # fail_timeout=0 means we always retry an upstream even if it failed | |
| # to return a good HTTP response (in case the Unicorn master nukes a | |
| # single worker for timing out). | |
| # for UNIX domain socket setups: | |
| server unix:/tmp/shop.socket fail_timeout=0; |