Skip to content

Instantly share code, notes, and snippets.

@sgmac
sgmac / 0_reuse_code.js
Created June 3, 2014 21:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sgmac
sgmac / gist:4235197
Created December 7, 2012 18:13
Show break attempts
#!/bin/bash
# Shows number of break attempts per user.
# threshold($1): Min number of break attempts.
sba() {
local threshold=${1:-10}
grep -Ei "(invalid|failed)" /var/log/auth.log | \
sed -ne 's/.*sshd\[\([0-9]\+\)\].*for \(invalid user\)\? \(.*\) from \([0-9]\+\.[0-9]\+.[0-9]\+\.[0-9]\+\).*/sshd \1 \3 \4/p' | \
awk -v limit=$threshold 'BEGIN {printf "USER\t ATTEMPTS\n"} {attempts[$3]++}END{ for (key in attempts)if (attempts[key] >= limit) printf "%-12s%d\n",key,attempts[key] }' | sort -n -k2
}
@sgmac
sgmac / puppet_bootstrap.sh
Created November 11, 2012 21:15
Installing puppet from repositories
#!/bin/bash
LSB="/etc/lsb-release"
RELEASE=$(test -e $LSB && sed -ne 's/DISTRIB_CODENAME=\(.*\)/\1/gp' $LSB)
TMP='/tmp/puppet'
[[ -n "$RELEASE" ]] && (test -d $TMP-$RELEASE || mkdir -p $TMP-$RELEASE) || (echo "This is not an Ubuntu system based" && exit 1 )
download() {
@sgmac
sgmac / rbenv_boot.sh
Created June 14, 2012 21:15
autoinstall rbenv
#!/bin/bash
# Installing
printf "Installing rbenv....\n"
PLUGINS="${HOME}/.rbenv/plugins"
cd $HOME && [[ ! -d .rbenv ]] && git clone git://github.com/sstephenson/rbenv.git .rbenv
[[ ! -d $PLUGINS ]] && mkdir ${PLUGINS} && cd $PLUGINS && git clone git://github.com/sstephenson/ruby-build.git
# Configuring
printf "Updating %s\n" $HOME/.bashrc