This script enables you to launch your Rails application in production environment (port:80) with Nginx and Unicorn.
Please make sure that your Gemfile in your rails application includes unicorn.
| # config/initializers/active_admin.rb | |
| ActiveAdmin.setup do |config| | |
| config.current_user_method = :current_user | |
| config.authentication_method = :authenticate_user! | |
| config.before_filter :admin_role_filter | |
| end | |
| # Adding all recource names to Permissions table after ActiveAdmin is loaded |
| namespace :db do | |
| require "sequel" | |
| Sequel.extension :migration | |
| DB = Sequel.connect(ENV['DATABASE_URL']) | |
| desc "Prints current schema version" | |
| task :version do | |
| version = if DB.tables.include?(:schema_info) | |
| DB[:schema_info].first[:version] | |
| end || 0 |
| module ActiveAdmin | |
| module Inputs | |
| class FilterCountryInput < FilterSelectInput | |
| include FilterBase | |
| def collection | |
| ::ActionView::Helpers::FormOptionsHelper::COUNTRIES | |
| end | |
| end |
| # Credit http://stackoverflow.com/a/2514279 | |
| for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r |
| -- show running queries (pre 9.2) | |
| SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
| FROM pg_stat_activity | |
| WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
| ORDER BY query_start desc; | |
| -- show running queries (9.2) | |
| SELECT pid, age(clock_timestamp(), query_start), usename, query | |
| FROM pg_stat_activity | |
| WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
| require 'strong_parameters' | |
| class ActiveRecord::Base | |
| include ActiveModel::ForbiddenAttributesProtection | |
| end | |
| class ActionController::Base | |
| # Use this with CanCan's load_resource to permit a set of params before | |
| # it tries to build or update a resource with them. |
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| #!/usr/bin/ruby | |
| require 'rss' | |
| # Usage | |
| # $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/ | |
| # episodes.rss | |
| # OR | |
| # $ ./railscasts.rb | |
| p 'Downloading rss index' |
| more: https://github.com/justinfrench/formtastic | |
| -> make form for all db columns | |
| <%= semantic_form_for @user do |f| %> | |
| <%= f.inputs %> | |
| <%= f.buttons %> | |
| <% end %> | |
| -> select cols | |
| <%= semantic_form_for @user do |f| %> |