Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
mrrooijen / api_base_controller.rb
Last active Aug 29, 2015
Ember.js + Rails API setup with header-based API key and API version configuration.
View api_base_controller.rb
class Api::BaseController < ActionController::Base
protect_from_forgery with: :null_session
before_action :unauthorized_if_signed_out
layout false
def current_user
@current_user ||= (
authenticate_or_request_with_http_token do |token, options|
User.find_by(api_key: token)
end
@mrrooijen
mrrooijen / resque_stale_worker_cleaner.rb
Last active Aug 29, 2015
Prune stale Resque workers.
View resque_stale_worker_cleaner.rb
class ResqueStaleWorkerCleaner
SLOWEST_JOB = (ENV["SLOWEST_JOB"] || 30).to_i # minutes
def call
Resque.workers.each do |worker|
worker.unregister_worker if old_worker?(worker)
end
end
private
@mrrooijen
mrrooijen / out-of-memory.sh
Last active Aug 29, 2015
Dokku Information
View out-of-memory.sh
echo 1 > /proc/sys/vm/overcommit_memory
@mrrooijen
mrrooijen / gist:913056
Created Apr 11, 2011
My Heroku Asset Packager setup
View gist:913056
# Gemfile
gem 'jammit-s3', :git => 'git://github.com/meskyanichi/jammit-s3.git'
# config/assets.yml
s3_bucket: mybucket
s3_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
s3_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
s3_permission: public_read
embed_assets: on
@mrrooijen
mrrooijen / sendgrid-smtp.rb
Created May 12, 2011
SMTP Settings for SendGrid
View sendgrid-smtp.rb
# This is what people apparently use:
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => 25,
:domain => 'mysite.com',
:authentication => :plain,
:user_name => 'sendgrd_username@mysite.com',
:password => 'sendgrid_password'
}
@mrrooijen
mrrooijen / unicorn.pill
Created May 16, 2011
Bluepill Process Monitoring configuration for Unicorn Ruby App Server.
View unicorn.pill
#! /usr/bin/env ruby
Bluepill.application("app_name-production") do |app|
app.process("unicorn") do |process|
process.pid_file = File.join(RAILS_ROOT, 'tmp', 'pids', 'unicorn.pid')
process.working_dir = RAILS_ROOT
process.start_command = "/usr/bin/env UNICORN_SERVERS=#{ENV['UNICORN_SERVERS']} #{UNICORN_PATH} -D -c config/unicorn.rb -E production"
process.stop_command = "kill -QUIT {{PID}}"
process.restart_command = "kill -USR2 {{PID}}"
@mrrooijen
mrrooijen / unicorn.rb
Created May 16, 2011
Unicorn sample configuration file
View unicorn.rb
# encoding: utf-8
# Spawn 3 workers
worker_processes ENV['UNICORN_SERVERS'].nil? ? 3 : ENV['UNICORN_SERVERS'].to_i
# Restart any workers that haven't responded in 30 seconds
timeout 30
# Listen on a Unix data socket
listen File.join(ENV['HOME'], 'tmp', 'sockets', 'rails', 'unicorn.sock'), :backlog => 2048
@mrrooijen
mrrooijen / deploy.rb
Created May 16, 2011
Unicorn + Bluepill + Capistrano with RVM
View deploy.rb
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :application, "my_app"
set :repository, "git@trunksapp.com:myuser/myapp.git"
set :branch, "production"
set :rvm_ruby_string, "1.9.2"
set :deploy_to, "/var/applications/"
set :user, "username"
@mrrooijen
mrrooijen / nginx.conf
Created May 23, 2011
Faye + PrivatePub + HTTPS (SSL) Protocol
View nginx.conf
location /faye {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
root /var/applications/current/faye;
proxy_pass http://127.0.0.1:4001; # im running faye on port 4001
break;
}
@mrrooijen
mrrooijen / Gemfile
Created Jun 9, 2011
Compass with Rails 3.1
View Gemfile
gem 'compass', :git => 'https://github.com/chriseppstein/compass.git', :branch => 'rails31'