Skip to content

Instantly share code, notes, and snippets.

@bradland
bradland / tping
Created May 4, 2012 14:16
tping is ping with a timestamp
#!/usr/bin/env bash
# Drop this file somewhere in your path and give execute perms. Usage:
#
# $ tping <hostname>
ping $1 | while read pong; do echo "$(date): $pong"; done
@bradland
bradland / backup_appname.sh
Created March 30, 2012 01:39
Simple backup script
#!/bin/bash
RHOST='user@hostname'
LPATH='/var/www/app-directory/'
DBPATH='/home/user/appbackup/app-name/db/'
SHAREPATH='/home/user/appbackup/app-name/shared/'
DBNAME='database_name'
DBUSER='database_user'
DBPASS='database_password'
@bradland
bradland / Rakefile
Created March 1, 2012 21:21
Rake default lists tasks
desc "The default task; lists tasks"
task :default do
puts `rake --tasks`
end
desc "Go ahead, you deserve it"
task :endulge do
puts "You're great. You really are."
end
@bradland
bradland / custom.cnf
Created February 22, 2012 21:19
Custom MySQL settings
[mysqld]
# Slow query logging
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
# Binary logging/replication; requires CUSTOMIZATION after auto-build!
#server-id = 1 # required for master/slave replication
log_bin = /var/log/mysql/mysql-bin.log
@bradland
bradland / rla_day_report.rb
Created February 17, 2012 19:47
RLA wrapper
#!/usr/bin/env ruby -wKU
rvm_result = `source "$HOME/.rvm/scripts/rvm" && rvm use ruby-1.9.3-p0@log-examiner`
puts rvm_result
require 'date'
# Example: ./report_day.rb production.log 2012-02-18
class App
@bradland
bradland / analyze_concurrency.rb
Created January 30, 2012 21:43
Concurrency analyzer
#!/usr/bin/env ruby -wKU
require 'csv'
# Usage: This script accepts filenames as arguments. The script expects the files
# passed to be the output of the CDRTool CSV export feature. The script is written
# to be as "unixy" as possible. Output is written to the stdout (and can be
# redirected). Status and errors are written to stderr. Output contains four
# columns in tab-separated value format:
#
@bradland
bradland / gencert.sh
Created January 27, 2012 20:39
Generate a self-signed SSL cert
#!/bin/bash
# Bash shell script for generating self-signed certs. Run this in a folder, as it
# generates a few files. Large portions of this script were taken from the
# following artcile:
#
# http://usrportage.de/archives/919-Batch-generating-SSL-certificates.html
#
# Additional alterations by: Brad Landers
# Date: 2012-01-27
@bradland
bradland / analyze.rb
Created January 27, 2012 15:37
Analyze TSV log
#!/usr/bin/env ruby -wKU
class DataAnalyzer
def initialize
# Check for Ruby 1.9
unless RUBY_VERSION.scan('1.9').length > 0
puts "This script reqires Ruby 1.9 (specifically, ordered hashes). Sorry! Check out RVM or rbenv for easy management of Ruby versions."
exit 1
end
# We must have at least one file to process
@bradland
bradland / compare_mysql_vars.rb
Created January 26, 2012 17:43
Compare MySQL variables between servers
#!/usr/bin/env ruby -wKU
require 'csv'
$: << File.expand_path(__FILE__)
# Compares the output of `show variables;` run in the CLI mysql client. The
# script expects the output of this query executed with the `--tables` flag.
# Output is written to the STDOUT, so you'll need to use standard shell
# redirection. Output format is CSV. Example usage:
@bradland
bradland / collect_keys.rb
Created January 26, 2012 16:51
Collect keys in nested hash
def collect_mysql_variables
@data.values.collect { |value| value.key }.uniq!
end