Skip to content

Instantly share code, notes, and snippets.

require 'capistrano/recipes/deploy/strategy/copy'
set :application, "YOUR APPLICATION NAME"
set :location, "YOUR DOMAIN (e.g. myapp.com)"
set :repository, "YOUR SOURCE CONTROL REPOSITORY"
set :user, "THE USER ON YOUR SERVER THAT WILL BE DEPLOYING"
set :local_user, "LOCAL USER"
set :database_name, "YOUR DATABASE NAME"
set :scm, SET WHAT SOURCE CONTROL METHOD YOU USE
require 'new_relic/recipes'
set :rails_env, RUBBER_ENV
on :load do
set :application, rubber_env.app_name
set :runner, rubber_env.app_user
set :deploy_to, "/mnt/#{application}-#{RUBBER_ENV}"
end
$ cap deploy:cold
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote git@mydomain.com:/home/git/myapp.git HEAD"
* executing "git clone -q git@mydomain.com:/home/git/myapp.git /var/www/myapp/releases/20100204223421 && cd /var/www/myapp/releases/20100204223421 && git checkout -q -b deploy 14dd2843341cd0984afb147050a02228ee7eae02 && (echo 14dd2843341cd0984afb147050a02228ee7eae02 > /var/www/myapp/releases/20100204223421/REVISION)"
servers: ["mydomain.com"]
[mydomain.com] executing command
command finished
namespace :delayed_job do
desc "Start delayed_job process"
task :start, :roles => :app do
run "cd #{current_path}; RAILS_ENV=production script/delayed_job start"
end
desc "Stop delayed_job process"
task :stop, :roles => :app do
run "cd #{current_path}; RAILS_ENV=production script/delayed_job stop"
end
#acts-as-taggable-on-2.0.0.rc1/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb [RO] 64,3
def related_tags_for(context, klass, options = {})
tags_to_find = tags_on(context).collect { |t| t.name }
exclude_self = "#{klass.table_name}.id != #{id} AND" if self.class == klass
klass.scoped({ :select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count",
:from => "#{klass.table_name}, #{Tag.table_name}, #{Tagging.table_name}",
:conditions => ["#{exclude_self} #{klass.table_name}.id = #{Tagging.table_name}.taggable_id AND #{Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND #{Tag.table_name}.name IN (?)", tags_to_find],
:group => grouped_column_names_for(klass),
@floehopper
floehopper / README.markdown
Created December 3, 2010 18:12
Generate, send, receive, and parse a multipart/related HTTP POST request in Ruby

Setup Apache to listen on a port and log incoming HTTP requests including body

terminal 1

$ cat /etc/apache2/sites-enabled/mms-test 
Listen 50690
LogLevel debug
DumpIOInput On
# DumpIOOutput On

$ sudo tail -f /var/log/apache2/error.log | grep "mod_dumpio.c(74)" | sed "s/.*HEAP.: //"

@fguillen
fguillen / git_tips.md
Created December 19, 2010 20:53
Git Tips

(Several of these git examples have been extracted from the book 'Pragmatic guide to GIT' of Travis Swicegood )

Git tips

Global git user

git config --global user.name "Fernando Guillen"
git config --global user.email "fguillen.mail+spam@gmail.com"

Repository git user

cd /develop/myrepo

@xdite
xdite / gist:758319
Created December 29, 2010 07:56
Ruby / Rails Convention of Techbang

Rails 開發注意要點

About Ruby Syntax

  • 編輯器設定 soft tab (space=2),以 2 格空白符號做為程式內縮距離(不分語言)。
  • 函式如果只有一個參數,就不強制打()
  • 函式如果有二個以上的參數,通通都要有 ()
    • (避免發生奇怪的paser bug跟保持專案一致性)
  • 字串限定用雙引號包覆
  • 善用 "#{str1} #{str3} " 等字串改寫技巧取代不需要的字串加法。
New Developer Setup
READING
You can find the old wiki dump, of which some of these pages are based off of, attached as a pdf at the bottom of this page.
[new dev pages start around pg 170, additional tips at the end of the pdf... some info is outdated, so look here first]
The Pragmatic Programmers have a few solid books that are considered essential reading within the ruby community:
Programming Ruby 1.9 "The Pickaxe Book" (we aren't using 1.9 yet but moving our code from 1.8 to 1.9 is a priority) [ http://pragprog.com/titles/ruby3/programming-ruby-1-9 ]
Agile Web Dev w/ Rails 4.0 (in beta right now & covers Rails 3.0 exclusively, which we aren't on. The 3rd ed. is recommended for now.)
@dzinevich
dzinevich / gist:864219
Created March 10, 2011 15:06
rubber.yml
# REQUIRED: The name of your application
app_name: streaming
# REQUIRED: The system user to run your app servers as
app_user: app
# REQUIRED: Notification emails (e.g. monit) get sent to this address
#
admin_email: mail@gmail.com