Skip to content

Instantly share code, notes, and snippets.

View garrensmith's full-sized avatar

Garren garrensmith

View GitHub Profile
@garrensmith
garrensmith / server.go
Created February 11, 2013 07:23
Sql invalid memory address or nil pointer deference error
ab -c 35 -n 1000 http://127.0.0.1:8000/
%Replace from line 251 in couch_httpd_misc_handlers.erl
% httpd log handlers
handle_log_req(#httpd{method='GET'}=Req) ->
ok = couch_httpd:verify_is_server_admin(Req),
Bytes = list_to_integer(couch_httpd:qs_value(Req, "bytes", "1000")),
Offset = list_to_integer(couch_httpd:qs_value(Req, "offset", "0")),
Chunk = couch_log:read(Bytes, Offset),
case couch_httpd:qs_value(Req, "format", "text") of
"json" ->
@garrensmith
garrensmith / gist:3780648
Created September 25, 2012 08:32
Bluepill setup for Rails and Resque
ENV["RAILS_ENV"] = "staging"
Bluepill.application("my_app-staging", :log_file => '/var/my_app/shared/log/bluepill.log') do |app|
app.process("unicorn") do |process|
process.pid_file = '/var/my_app/shared/pids/unicorn.pid'
process.working_dir = '/var/my_app/current'
process.start_command = "/usr/local/bin/bundle exec unicorn -c /var/my_app/current/config/unicorn.rb -E staging -D"
process.stop_command = "kill -QUIT {{PID}}"
@garrensmith
garrensmith / deploy_conf
Created September 25, 2012 08:29
Sudoers file to run applications via sudo without requiring a password
%deploy ALL=(ALL) NOPASSWD: /usr/local/bin/bluepill, /sbin/start my_app_bluepill , /sbin/stop my_app_bluepill
@garrensmith
garrensmith / deploy.rb
Created September 25, 2012 08:12
Capistrano, Unicorn, Upstart and Bluepill
after "deploy:restart", "deploy:restart_workers"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
sudo 'start bluepill_conf'
end
task :stop, :roles => :app, :except => { :no_release => true } do
sudo "bluepill stop"
@garrensmith
garrensmith / bluepill_config.conf
Created September 25, 2012 07:57
Bluepill Upstart
description "Demo app Bluepill"
start on runlevel [2]
stop on runlevel [016]
expect daemon
exec bluepill load /var/my_app/current/config/staging.pill
respawn
@garrensmith
garrensmith / instrumentation.rb
Created June 26, 2012 16:41
CouchRest Instrumentation for Rails 3
# add to config/initializers/instrumentation.rb
module CouchRest
class Database
alias_method :old_get, :get
alias_method :old_view, :view
alias_method :old_update_doc, :update_doc
alias_method :old_delete_doc, :delete_doc
@garrensmith
garrensmith / train.erl
Created February 19, 2012 15:05
Train Server
-module(train).
-behaviour(gen_fsm).
%public api
-export([start_link/0, start_engine/0, move/0, stop/0, stop_server/0, slow/0, hit_the_break/0, open_doors/0, close_doors/0]).
% gsm api
-export([init/1, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3, code_change/4]).
% state api
@garrensmith
garrensmith / kitchen2.erl
Created January 29, 2012 07:43
Fridge Process implementation
-module(kitchen2).
-compile(export_all).
start(Items) ->
spawn_link(?MODULE, restarter, [Items]),
timer:sleep(100). %delay for processes to startup befor can issue commands
% register(fridge, Pid).
restarter(Items) ->
@garrensmith
garrensmith / mathStuff.erl
Created January 11, 2012 15:49
Couchdb and erlang course
-module(mathStuff).
-export([perimeter/1]).
perimeter({square,Side}) ->
Side * 4;
perimeter({rectangle,A,B}) ->
(A * 2) + (B * 2);
perimeter({circle,Radius}) ->
Radius * 2 * 3.1415;