Skip to content

Instantly share code, notes, and snippets.

@afa
afa / deploy.rb
Created July 28, 2011 11:34 — forked from bradly/deploy.rake
Simple Rails Deployments with Net/SSH
require 'net/ssh'
desc "Deploy site to production"
task :deploy => :environment do
host = 'yourhost.com'
user = 'username'
options = {:keys => '~/.ssh/keys/yourserver.pem'}
remote_path = '/path/to/rails_app'
commands = [
@afa
afa / resque_web.rb
Created September 14, 2011 08:22 — forked from grosser/resque_web.rb
Mountable resque-web for rails 3+ apps
# https://gist.github.com/1214052
require 'sinatra/base'
class ResqueWeb < Sinatra::Base
require 'resque/server'
use Rack::ShowExceptions
if CFG[:user].present? and CFG[:password].present?
Resque::Server.use Rack::Auth::Basic do |user, password|
user == CFG[:user] && password == CFG[:password]
@afa
afa / gist:2497280
Created April 26, 2012 07:44 — forked from dhh/gist:2492118
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@afa
afa / bluepill.rb
Created July 5, 2012 10:35 — forked from bopm/bluepill.rb
bluepill unicorn pill
# http://devmull.net/articles/unicorn-resque-bluepill
# http://www.jamievandyke.com/want-some-campfire-with-that-bluepill
app_name = 'rails'
app_env = 'production'
Bluepill.application(app_name) do |app|
RAILS_ROOT = "/var/www/#{app_name}/"
app.uid = app.gid = "www-rails"
app.working_dir = RAILS_ROOT
worker_queues = %w[queue]
@afa
afa / deploy.rb
Created July 5, 2012 11:01 — forked from mikhailov/0. nginx_setup.sh
Nginx+Unicorn (production-ready setup)
# Capistrano configuration
#
# require 'new_relic/recipes' - Newrelic notification about deployment
# require 'capistrano/ext/multistage' - We use 2 deployment environment: staging and production.
# set :deploy_via, :remote_cache - fetch only latest changes during deployment
# set :normalize_asset_timestamps - no need to touch (date modification) every assets
# "deploy:web:disable" - traditional maintenance page (during DB migrations deployment)
# task :restart - Unicorn with preload_app should be reloaded by USR2+QUIT signals, not HUP
@afa
afa / 0. nginx_setup.sh
Created July 30, 2012 13:07 — forked from mikhailov/0. nginx_setup.sh
Nginx + secure pseudo-streaming
# Nginx can serve FLV/MP4 files by pseudo-streaming way without any specific media-server software.
# To do the custom build we use 2 modules: --with-http_secure_link_module --with-http_flv_module
# This module "secure-link" helps you to protect links from stealing away.
#
# NOTE: see more details at coderwall: http://coderwall.com/p/3hksyg
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.2.tar.gz
$ tar xzvf ./nginx-1.2.2.tar.gz && rm -f ./nginx-1.2.2.tar.gz
class Symbol
def | other
if other.is_a? Proc
-> arg { other.call(arg.send(self)) }
else
-> arg { arg.send(self).send(other) }
end
end
def call *args
@afa
afa / README
Created May 31, 2013 09:22 — forked from andoriyu/README
unicorn_profiles="dev prod"
unicorn_dev_enable="yes"
unicorn_dev_user="devuser"
unicorn_dev_listen="/tmp/unicorn.dev.socket"
unicorn_dev_dir="/usr/local/www/dev"
unicorn_dev_config="/usr/local/www/dev/config.ru"
unicorn_dev_env="development"
unicorn_dev_flags="" # any additional flags
unicorn_dev_rails="YES" # For rails

Когда мы хотим скопировать данные из production окружения Ruby on Rails приложения в development или staging, обычно, нам нужно скопировать дамп базы данных и статические файлы (например, изображения загруженные пользователями). Копирование базы может не представляет проблем (например, ее можно копировать из бэкапов или резервных серверов БД). А вот копирование статических файлов занимает много времени и ресурсов сервера с которого копируют (и на который копируются) файлы.

В рассылке ror2ru Макс Лапшин предложил

@afa
afa / gist:8434886
Created January 15, 2014 11:51 — forked from anaumov/gist:8432161
class CarConfig
include ActiveSupport::Configurable
config_accessor :brand
end
class Car
attr_accessor :brand
def initialize
self.brand = self.class.config.brand