Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / cap.rb
Created June 20, 2012 05:55 — forked from jeanmartin/cap.rb
Kill resque workers using rake task, let god handle the restart
after "deploy:restart", "resque:stop_workers"
namespace :resque do
task :stop_workers, :except => { :no_release => true } do
run "cd #{current_path} && rake RAILS_ENV=#{rails_env} resque:stop_workers"
end
end
@jhjguxin
jhjguxin / gist:3144247
Created July 19, 2012 14:17 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@jhjguxin
jhjguxin / AddFieldToUser.rb
Created July 30, 2012 09:14 — forked from wesgarrison/AddFieldToUser.rb
Using Rails Migration on different database than standard “production” or “development”
class AddFieldToUser < ActiveRecord::Migration
ActiveRecord::Base.establish_connection "user_#{Rails.env}"
def self.up
add_column :users, :field, :type
end
...
end
@jhjguxin
jhjguxin / notifier.coffee
Created August 3, 2012 15:16 — forked from sishen/notifier.coffee
Web Notifications integration in Pragmatic.ly
class Notifier
constructor: ->
@enableNotification = false
@checkOrRequirePermission()
hasSupport: ->
window.webkitNotifications?
requestPermission: (cb) ->
window.webkitNotifications.requestPermission (cb)
@jhjguxin
jhjguxin / smser.rb
Created August 27, 2012 00:40 — forked from mimosz/smser.rb
短信宝
# -*- encoding: utf-8 -*-
require 'digest/md5'
require 'nestful'
class Smsbao
attr_accessor :login, :passwd
def initialize(login, passwd)
@login = login
@passwd = Digest::MD5.hexdigest(passwd)
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
@jhjguxin
jhjguxin / Capistrano-Deployment-Recipe.rb
Created September 3, 2012 06:39 — forked from mrrooijen/Capistrano-Deployment-Recipe.rb
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
@jhjguxin
jhjguxin / deploy.rb
Created September 28, 2012 06:19 — forked from agaidot/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:create_symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@jhjguxin
jhjguxin / active_record_associations.rb
Created November 9, 2012 05:38 — forked from karmi/active_record_associations.rb
An example of elasticsearch & Tire setup for ActiveRecord associations
# An example of elasticsearch & Tire setup for ActiveRecord associations.
#
# A `Book has_many :chapters` scenario, with mapping and JSON serialization
# for indexing associated models.
#
# Demonstrates three important caveats as of now:
#
# 1. You you have to use `touch: true` in the `belongs_to` declaration,
# to automatically notify the parent model about the update.
#
@jhjguxin
jhjguxin / deploy.rb
Created December 19, 2012 06:40 — forked from andruby/deploy.rb
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"