Skip to content

Instantly share code, notes, and snippets.

@vvalgis
vvalgis / Capistrano tasks for starting unicorn.rb
Created May 7, 2010 08:13
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
# http://unicorn.bogomips.org/SIGNALS.html
rails_env = ENV['RAILS_ENV'] || 'production'
rails_root = ENV['RAILS_ROOT'] || "/data/github/current"
God.watch do |w|
w.name = "unicorn"
w.interval = 30.seconds # default
# unicorn needs to be run from the rails root
@bopm
bopm / book.rb
Created April 29, 2011 21:08
Batch processing in rails
class Book < ActiveRecord::Base
has_many :pages
belongs_to :p2fline
belongs_to :print_profile
belongs_to :publish_profile
acts_as_audited :except => [:name, :file_name]
include AASM
aasm_column :state
@Bregor
Bregor / spec__requests__history_items_spec.rb
Created June 29, 2011 09:09
Capybara request helpers for devise
require 'spec_helper'
describe "HistoryItems" do
before(:each) {login_as :user}
describe "GET /history_items" do
it "works!" do
visit history_items_path
response.should be_success
end
end
@qichunren
qichunren / client.rb
Created November 18, 2011 02:29
ruby udp
require 'socket'
socket = UDPSocket.new
socket.send("I am ok.", 0, 'localhost', 1234)
text, sender = socket.recvfrom(16)
socket.close
@tonyc
tonyc / gist:1384523
Last active June 3, 2024 15:34
Using strace and lsof

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)

- unless Rails.env.development?
/ Require jQuery
= javascript_include_tag 'http://yandex.st/jquery/1.7.1/jquery.min.js'
/ Require Google's jQuery if Yandex is down
:javascript
window.jQuery || document.write('<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">\x3C/script>')
/ Require local jQuery if Google is down / is development env
:javascript
window.jQuery || document.write('<script src="#{asset_path('jquery.js')}">\x3C/script>')
@asmuth
asmuth / gist:1557137
Created January 3, 2012 21:54
FnordMetric: setting user picture/name and unique gauges
# i hope this helps...
# to set the username and picture send these events to fm
# -> you don't need to define any event handlers
# -> the session token (_session) could be your unique session id
# or the unique user id (it's hashed)
# set the user name
{ "_type": "_set_name", "name": "Tingle Tangle Bob", "_session": "mysessiontoken" }
@route
route / gist:2601441
Created May 5, 2012 10:45
Static page generator
namespace :app do
namespace :error_pages do
desc "Generates static pages 500, 403, 404, 422"
task :generate => :environment do
av = ActionView::Base.new
av.class_eval do
include ApplicationHelper
include Rails.application.routes.url_helpers
end
@mikhailov
mikhailov / 0. nginx_setup.sh
Last active June 29, 2024 23:43
NGINX+SPDY with Unicorn. True Zero-Downtime unless migrations. Best practices.
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#