Skip to content

Instantly share code, notes, and snippets.

View dsingley's full-sized avatar

David Singley dsingley

View GitHub Profile
@dsingley
dsingley / hadoop-streaming.rb
Created April 19, 2011 15:05
Hadoop Streaming API for Ruby
def emit(key, value, sep="\t")
STDOUT.puts('' << key << sep << value)
end
def map(*options)
options = [:split, "\t", 2] if options.empty?
STDIN.each_line do |line|
line.strip!
key, value = line.send(*options)
@dsingley
dsingley / setLCD.sh
Created February 19, 2013 22:51
set the text displayed on a Dell PowerEdge server's LCD
#!/bin/bash -e
set -u
MAX_LENGTH=14
text="$*"
length=$(echo -n "${text}" | wc -c)
if [ ${length} -gt ${MAX_LENGTH} ]; then
@dsingley
dsingley / damm_algorithm.rb
Last active December 14, 2015 11:09
Ruby class implementing H. Michael Damm's check digit algorithm
class DammAlgorithm
# http://en.wikipedia.org/wiki/Damm_algorithm
TABLE = [ [0, 7, 4, 1, 6, 3, 5, 8, 9, 2],
[3, 0, 2, 7, 1, 6, 8, 9, 4, 5],
[1, 9, 0, 5, 2, 7, 6, 4, 3, 8],
[7, 2, 6, 0, 3, 4, 9, 5, 8, 1],
[5, 1, 8, 9, 0, 2, 7, 3, 6, 4],
[9, 5, 7, 8, 4, 0, 2, 6, 1, 3],
[8, 4, 1, 3, 5, 9, 0, 2, 7, 6],
@dsingley
dsingley / ifup-local
Last active December 16, 2015 08:28
display the current IP address on the console of a RHEL (or derivative) server
#!/bin/bash
ip_address="$(ip addr show $1 2>/dev/null | awk '/inet / {print $2}' | sed -e 's/\/.*//')"
if [ "${ip_address}" ]; then
formatted_address="$(printf "%-10s%s\n" "$1:" ${ip_address})"
sed -e "s/IP_ADDRESS/${formatted_address}/" /etc/issue.TEMPLATE > /etc/issue
else
cp /etc/issue.DIST /etc/issue
fi
#!/bin/bash
LOGGLY_TOKEN=''
TAG='ifup'
URL="https://logs-01.loggly.com/inputs/${LOGGLY_TOKEN}/tag/${TAG}"
interfaces='{'
for interface in $(ip addr | awk '/state UP/ {print $2}' | sed -e 's/://'); do
ip_address=$(ip addr show ${interface} 2>/dev/null | awk '/inet / {print $2}' | sed -e 's/\/.*//')
mac_address=$(ip addr show ${interface} 2>/dev/null | awk '/link\/ether/ {print $2}')
@dsingley
dsingley / Dockerfile
Created July 24, 2016 13:06
awscli Dockerfile
FROM alpine:latest
ENV AWS_DEFAULT_REGION us-east-1
RUN apk add --update groff less python py-pip && pip install awscli