Skip to content

Instantly share code, notes, and snippets.

View blasterpal's full-sized avatar

Hank Beaver blasterpal

View GitHub Profile
@blasterpal
blasterpal / gist:7250398
Created October 31, 2013 14:06
Backup DB to S3, backup model example.
# encoding: utf-8
##
# Backup Generated: nightly_s3_db
# Once configured, you can run the backup with the following command:
#
# $ backup perform -t nightly_s3_db [-c <path_to_configuration_file>]
# $ backup perform -t nightly_s3_db -c ./config.rb --root_path '/db/backups'
#
@blasterpal
blasterpal / watcher.rb
Created September 4, 2013 17:40
pid watcher and then do something
#!/usr/bin/ruby
pid = ARGV[0]
puts "watching and waiting for pid #{pid} to complete"
while `ps --no-headers #{pid}`.size > 0
puts "pid lives, waiting"
sleep 10
# try again
end
# do something now, notify,etc
@blasterpal
blasterpal / sidekiq_cli_info
Created September 3, 2013 13:02
Basic Sidekiq queue info mixin.
module Sidekiq
class Info
class << self
def queue_names
Sidekiq.redis {|conn|
conn.smembers('queues').sort
}
end
def queue_counts
queue_status = {}
@blasterpal
blasterpal / add_read_only_pg_user.rb
Created August 28, 2013 12:57
Add read only user to PG 9 on DB, cookbook snippet.
# Create a user with Login
sql = [%(CREATE ROLE jsmith WITH PASSWORD 'foobar' LOGIN)]
# # Allow to connect
sql << %(GRANT CONNECT ON DATABASE reports TO jsmith)
# # Allow to use schema
sql << %(GRANT USAGE ON SCHEMA public TO jsmith)
# # grant on current objects
sql << %(GRANT SELECT ON ALL TABLES IN SCHEMA public TO jsmith)
# # grant on future objects
sql << %(ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO jsmith)
@blasterpal
blasterpal / sidekiq_stats_reset.rb
Created August 23, 2013 13:23
Reset Sidekiq Stats for Dashboard
conn = Sidekiq.redis {|conn| c = conn}
conn.get 'stat:processed'
conn.set 'stat:failed', 0
@blasterpal
blasterpal / tmux.conf.local
Created July 19, 2013 15:27
My tmux.conf.local to add/override defaults.
# This needs to be in tmux.conf
# Should always be last to allow for overrides
# source-file ~/.tmux.conf.local
# Start numbering at 1
set -g pane-base-index 1
set -g base-index 1
## C-b is not acceptable -- Vim uses it
set-option -g prefix C-a
@blasterpal
blasterpal / tmux.conf
Created July 19, 2013 15:25
Baseline tmux.conf - derived from work's latest.
set -g default-terminal "screen-256color"
setw -g xterm-keys on
set -g status-bg white
set -g status-fg black
set -g history-limit 999999999
bind C-d detach
bind r source-file ~/.tmux.conf
set -g prefix C-z
@blasterpal
blasterpal / vimrc.local
Created July 19, 2013 15:24
My custom vimrc.local to add to Janus
" Add this to ~/.vimrc.after
" should always be last here
"if filereadable(expand('~/.vimrc.local'))
"source ~/.vimrc.local
"endif
let g:NERDTreeMapOpenSplit = 'i'
set nu
set et
set ts=2
@blasterpal
blasterpal / dynamic_config_class.rb
Created June 14, 2013 16:46
Simple Config object for Rails or Ruby
require 'yaml'
class SSOConfig
class << self
attr_accessor :config
def method_missing(method_name)
config[method_name.to_s]
end
end
end
SSOConfig.config = YAML.load(File.open(File.join(Rails.root,'config/signon.yml')).read)[Rails.env]
@blasterpal
blasterpal / pause_sidekiq_queues.sh
Created May 14, 2013 20:15
Pause all Sidekiq queues
ps -ef | grep sidek | grep -v grep | cut -c10-14 | grep -v tail| xargs kill -USR1
# after this you'll need to restart Sidekiq via sidekiqctl or monit,etc