Skip to content

Instantly share code, notes, and snippets.

View phil-monroe's full-sized avatar

Phil Monroe phil-monroe

View GitHub Profile
@phil-monroe
phil-monroe / gen_signed_ssl_cert.sh
Created July 1, 2011 01:31
This shell script facilitates the creation of a signed SSL certificate. The SSL certificate is signed using a Certificate Authority(CA) that is generated.
#!/bin/bash
# Basic Config
certs_dir='certs'
num_bits=2048
serial_num=01
ca_name='ca'
server_name='server'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%% Creating Directory to hold Certs %%'
@phil-monroe
phil-monroe / routes.rb
Created September 23, 2011 23:31
Routes file for App-Runway
AppRunway::Application.routes.draw do
constraints(:subdomain => "") do
devise_for :users do
get "/login" => "devise/sessions#new"
delete "/logout" => "devise/sessions#destroy"
end
resources :users do
resources :apps do
resources :emails, only: [:index]
@phil-monroe
phil-monroe / cap_tail_logs.rb
Created June 8, 2012 16:42
Capistrano task to tail log files
# Based off of this stack overflow answer, but has a nicer output
# http://stackoverflow.com/questions/5218902/tail-production-log-with-capistrano-how-to-stop-it
#
# Set max_hostname_length and tag to whatever you wish. I currently have it for pretty EC2 output
desc "tail log files"
task :logs, :roles => ENV['ROLE'] || :web do
last_host = ""
max_hostname_length=19
run "tail -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
@phil-monroe
phil-monroe / tag_deploy.rb
Created June 12, 2012 19:44
Capistrano tasks to deploy from commit references and separate repos
# Have `cap deploy` ask for tag to deploy from. Can be automated like this `cap deploy TAG=some-tag-name`
set :branch do
if ENV['REF'] # Tag passed in via arg
ref = ENV['REF']
else # Prompt for reference to use
default_ref = `git tag`.split("\n").last
ref = Capistrano::CLI.ui.ask "Tag to deploy (make sure repo is up to date): [#{default_ref}] "
ref = default_ref if ref.empty?
@phil-monroe
phil-monroe / rails_c_cap.rb
Created June 16, 2012 00:49
Capistrano task to remotely connect to rails console
# Based off of https://gist.github.com/1115513
desc "Remote console on the production appserver"
task :console, :roles => ENV['ROLE'] || :web do
hostname = find_servers_for_task(current_task).first
puts "Connecting to #{hostname}"
exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && cd #{current_path} && bundle exec rails c #{rails_env}'"
end
@phil-monroe
phil-monroe / web_prof.sh
Created July 17, 2012 03:21
Repeatedly hits a website
URL="https://prosearch-alpha.identified.com/api/prospects/search?page=1&experience=0&first_degree=true&second_degree=true&sort_filter=score&third_degree=true&within=25"
while true; do
curl -b cookies.txt $URL -o out
done
@phil-monroe
phil-monroe / Rails Models.rb
Created August 14, 2012 23:45
Collect all Model Classes
def models
Module.constants.inject([]) do |models, k|
klass = Kernel.const_get k
models << klass if klass.respond_to? :ancestors and klass.ancestors.include? ActiveRecord::Base
models
end
end
@phil-monroe
phil-monroe / db_lag.rb
Created September 29, 2012 00:21
Calculate the lag in WAL transmission for postgres databases
# math based on http://eulerto.blogspot.com/2011/11/understanding-wal-nomenclature.html
dbname = ""
dbuser = ""
host_master = ""
host_slave = ""
previous_recieved_lags = []
previous_replated_lags = []
@phil-monroe
phil-monroe / clone_vm.rb
Created November 14, 2012 19:51
Clone vm with IP
identity = RbVmomi::VIM.CustomizationLinuxPrep({
hostName: RbVmomi::VIM.CustomizationFixedName(name: "test"),
domain: "test.com"
})
global_ip_settings = RbVmomi::VIM.CustomizationGlobalIPSettings({
dnsServerList: ["172.31.10.37"],
dnsSuffixList: ["identified.com"]
})
@phil-monroe
phil-monroe / rails_2_papertrail.rb
Created December 19, 2012 00:30
Things needed to log rails to papertrail.
class MultiIO
def initialize(*targets)
@targets = targets
end
def write(*args)
puts "writing"
@targets.each { |t| t.write(*args) }
end