Skip to content

Instantly share code, notes, and snippets.

View glebm's full-sized avatar

Gleb Mazovetskiy glebm

View GitHub Profile
@glebm
glebm / bluepill
Created August 3, 2012 23:43 — forked from migrs/bluepill
bluepill init script
#!/bin/sh
### BEGIN INIT INFO
# Provides: bluepill
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: bluepill daemon, providing process monitoring
# Description: bluepill is a monitoring tool. More info at http://github.com/arya/bluepill.
@glebm
glebm / gitlab.pill
Created August 4, 2012 00:10
Gitlab Bluepill: Unicorn + Resque
#!/bin/sh
### BEGIN INIT INFO
# Provides: bluepill
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: bluepill daemon, providing process monitoring
# Description: bluepill is a monitoring tool. More info at http://github.com/arya/bluepill.
@glebm
glebm / ruby.yml
Created October 24, 2012 15:55
RVM setup
# script/setup/rvm.rb to install
default: &default
name: 1.9.3-perf
patch: falcon # about this patch: https://gist.github.com/1688857
gemset: my_app_gemset
env:
RUBY_HEAP_MIN_SLOTS: 1600000
RUBY_GC_MALLOC_LIMIT: 100000000
RUBY_HEAP_FREE_MIN: 500000
@glebm
glebm / rainbows.production.conf
Created October 24, 2012 15:57
Example Rainbows Config
# -*- encoding : utf-8 -*-
#= Rainbows HTTP server (on unix socket!)
#== Rainbows can be used to manage multiple forked workers in a specified concurrency-IO model
# Set working directory for Capistrano
# pwd -L keeps symlinks
working_directory `pwd -L`.chomp
# Listen through a unix socket
@glebm
glebm / Procfile.production
Created October 24, 2012 15:59
Example Procfile.production
# = Here is how to export to upstart:
# sudo foreman export upstart /etc/init -f Procfile.production -u my_app_user -a my_app
# sudo find /etc/init/ -name "my_app*.conf" -exec sed -i 's/releases\/[0-9]*/current/g' {} \;
web: subcontract --rvm --with-rubies . do -- env RAILS_ENV=production bundle exec rainbows -c config/rainbows.production.rb
worker: subcontract --rvm --with-rubies . RAILS_ENV=production bundle exec rake resque:work QUEUE=*
scheduler: subcontract --rvm --with-rubies . RAILS_ENV=production bundle exec rake resque:scheduler
@glebm
glebm / deploy.rb
Created October 24, 2012 16:08
Capistrano commands (rainbows + rvm)
namespace :deploy do
task :restart_web, role: :web do
pid_path = "#{current_path}/tmp/pids/server.pid"
run "[[ -s #{pid_path} ]] && (cat #{pid_path} | xargs kill -USR2) || sudo service jl-web start", shell: 'bash'
end
end
@glebm
glebm / url_subdomain.rb
Created November 6, 2012 13:58
Get subdomains working in tests (scary)
# -*- encoding : utf-8 -*-
module UrlSubdomain
def subdomain!(sub = 'account')
# Some day this hack won't be necessary
# (when Capybara, Rspec, and Rails learn to work together)
# For now it only works if we run it twice
# I do not know why, and it would be a waste of time to find out
2.times do
sub = 'account' if sub.blank?
host = "#{sub}.#{DOMAIN}"
@glebm
glebm / gist:4102735
Created November 18, 2012 01:51
top redis
17917 redis 20 0 2310m 1.6g 424 D 5 41.3 0:00.61 /usr/bin/redis-server /etc/redis/redis.conf
11790 redis 20 0 2310m 1.5g 928 S 0 39.7 0:10.39 /usr/bin/redis-server /etc/redis/redis.conf
@glebm
glebm / cache_if.rb
Created November 20, 2012 01:24
Conditional fragment caching
require 'haml/helpers/action_view_mods' # if you use haml, you have to require its mods first
require 'action_view/helpers/cache_helper'
module ActionView
module Helpers
module CacheHelper
def cache_if(condition, *args, &block)
if @dont_cache || !condition
# Disable cache usage for all `cache` calls within a false condition cache_if block
disable_caching { yield }
else
@glebm
glebm / gist:4215614
Created December 5, 2012 13:45
puma error backtrace
ActionView::Template::Error (closed stream):
5: else
6: url = create_item_path
7: text = I18n.t("common.post_free_ad")
8: end
9: %a.post-free-ad{href: url}
10: %span.icons.icon-myposts
11: %span.icon-text= text
java/lang/Thread.java:1567:in `getStackTrace'
org/jruby/runtime/backtrace/TraceType.java:171:in `getBacktraceData'