This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Borrowed from https://www.ruby-forum.com/topic/136579 | |
require 'json' | |
def json_valid?(str) | |
JSON.parse(str) | |
return true | |
rescue JSON::ParserError | |
return false | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install tmux on Centos release 6.5 | |
# install deps | |
sudo yum install -y gcc kernel-devel make ncurses-devel | |
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL | |
curl -OL https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz | |
tar -xvzf libevent-2.0.21-stable.tar.gz | |
cd libevent-2.0.21-stable | |
./configure --prefix=/usr/local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def return_min(array) | |
min = array[0] | |
for i in array | |
if i < min | |
min = i | |
end | |
end | |
return min | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
def flatize(array) | |
error_msg = 'Method only accepts nested arrays of integers' | |
raise ArgumentError, error_msg unless array.is_a? Array | |
flattened_array = [] | |
array.each do |element| | |
if element.is_a? Array | |
flattened_array += flatize(element) | |
else | |
raise ArgumentError, error_msg unless element.is_a? Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
check_md5sum(){ | |
sums=$(md5sum $1 $2) | |
file_1=$(echo $sums | awk '{print $2}') | |
file_2=$(echo $sums | awk '{print $4}') | |
checksum_1=$(echo $sums | awk '{print $1}') | |
checksum_2=$(echo $sums | awk '{print $3}') | |
if [[ "$checksum_1" == "$checksum_2" ]]; then | |
echo "OK: $file_1 and $file_2 md5 Checksums Match" | |
echo $checksum_1 $file_1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def make_change(change_amount) | |
#denominations to use. Could easily be made a parm. | |
#Note that these are integers, not floats | |
denominations = { | |
Penny: 1, | |
Nickel: 5, | |
Dime: 10, | |
Quarter: 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
#at its most basic, it looks like this: | |
Benchmark.bm do |bm| | |
bm.report {some code} | |
bm.report {some other code} | |
end | |
#A more robust example | |
iterations = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ex: 2016-12-28_230652 | |
var now = new Date(); | |
var dd = now.getDate(); | |
var mm = now.getMonth()+1; | |
var yyyy = now.getFullYear(); | |
var min = now.getMinutes(); | |
var sec = now.getSeconds(); | |
var hh = now.getHours(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log(){ | |
datestamp=$(date +%Y-%m-%d_%H:%M:%S) | |
msg="$@" | |
echo "[$datestamp]- $msg" | |
} | |
#call with: log <whatever msg you want> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#return the containing directory of file | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
OlderNewer