Skip to content

Instantly share code, notes, and snippets.

View cowboy-cod3r's full-sized avatar

Sean Humbarger cowboy-cod3r

  • The Walt Disney Company
View GitHub Profile
@cowboy-cod3r
cowboy-cod3r / bash_conditional_checks.txt
Last active January 1, 2016 22:19
Some handy bash conditional checks
Integer comparison
-eq
-ne
-gt
-ge
-lt
-le
@cowboy-cod3r
cowboy-cod3r / open_classes.rb
Created December 27, 2013 06:15
Ruby: Open Classes The concpet of extending existing classes in ruby (including those in the standard library) is called Open Classes. Here is an example.
# Extend the String class with a new method called my_new_method
class String
def my_new_method()
end
end
@cowboy-cod3r
cowboy-cod3r / ext_disk_space
Last active January 1, 2016 05:39
Disk: Extend Disk Space on a Linux VM
1. Add disk space to the vm by adding another virtual disk.
2. In the linux VM, issue the following commands:
# List existing disks
fdisk -l
# Scan for the new disk created in step 1.
echo "- - -" >/sys/class/scsi_host/host0/scan
# List existing disks (should see the new disk)
@cowboy-cod3r
cowboy-cod3r / exit.rb
Created December 21, 2013 04:29
Ruby: Exit Hook
# This will get executed upon exit of a ruby process
at_exit { puts "Hello Sean" }
@cowboy-cod3r
cowboy-cod3r / spaceship-ruby.rb
Created December 14, 2013 15:27
Ruby: Spaceship
# == Description
# the <=> operator returns 1, 0, or -1, depending on the value of the left arugment relative to the right
# This operator is good to use when you want to define how to compare two like object
# The operator must return -1 for less than, 1 for greater than, and 0 for equal to
class Expense
# Modules
include Comparable
# Accessors
@cowboy-cod3r
cowboy-cod3r / ruby-datetime-format.rb
Created December 14, 2013 15:10
Ruby: Convert the Format of a Date
#!/opt/apps/ruby/ruby/bin/ruby
require 'date'
# The initial date format as a String
my_date = "2013-10-03 21:03:46Z"
# Convert the Date to a DateTime Object
date_obj = DateTime.strptime(my_date,'%Y-%m-%d %H:%M:%S%Z')
# Re-Format the date - returns a String
@cowboy-cod3r
cowboy-cod3r / ruby-time-diffs.rb
Created December 14, 2013 14:53
Ruby: Determine Time Differences
#!/opt/apps/ruby/ruby/bin/ruby
require 'date'
# Hold the time differences to calculate averages
time_diffs = []
# Get three time differences
1..3.times do
initial_time = DateTime.now()
sleep 1
@cowboy-cod3r
cowboy-cod3r / bash_ask_input.sh
Created December 7, 2013 18:41
Bash: Prompt for Input
# Ask use for input
# -e - if standard input is coming from a terminal, readline is used to obtain the line
# -p - display prompt on stderr without a trailing new line
default="/usr/locol/etc/"
read -e -p "Enter the path to the file [${default}]: " FILEPATH
FILEPATH=${FILEPATH:-${default}}
echo $FILEPATH
@cowboy-cod3r
cowboy-cod3r / bash_root.sh
Created December 7, 2013 18:08
Bash: Root User?
if [[ $EUID -ne 0 ]]; then
echo "ERROR: The user must be root in order to execute this script."
exit 1
fi
@cowboy-cod3r
cowboy-cod3r / bash_files_folders.sh
Created December 7, 2013 18:05
Bash: File/Folder Functions
# Get the current file
current_file = $0
# Get the full path to the current file
full_file_path="$(readlink -f $(dirname $0))/$(basename $0)"
# Get the full directory path to the current file
full_dir_path="$(readlink -f $(dirname $0))"