Skip to content

Instantly share code, notes, and snippets.

@elasticdog
elasticdog / javaversion.rb
Created April 24, 2013 15:00
Custom Facter facts for the installed version of Java
# Fact: javaversion & javamajversion
#
# Purpose:
# Return the version of the installed Java package in both its full form and
# just the major release version.
#
# Resolution:
# Uses the output from the `java -version` command to establish the full
# version, and then parses that value to return just the major version
# number. It will return the full javaversion if the major version could not
package main
import (
"encoding/hex"
"flag"
"io"
"io/ioutil"
"log"
"net"
"os"
@elasticdog
elasticdog / gist:6367040
Last active December 21, 2015 21:18
shell function to generate user-specific passwords for cjdns
hypepass () {
if [[ -z $1 ]]; then
echo 'Usage: hypepass <USERNAME>'
echo 'Generate a user-specific password for allowing someone to peer with your cjdns host'
else
desired=64
random=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w $(( ${desired} - ${#1} - 1 )) | head -n 1)
echo "{ \"user\": \"${1}\", \"password\": \"${1}:${random}\" }"
fi
}
@elasticdog
elasticdog / rpm2cpio.sh
Created October 23, 2013 04:35
rpm2cpio written in shell (i.e., tiny with no dependencies) https://trac.macports.org/attachment/ticket/33444/rpm2cpio
#!/bin/sh
pkg=$1
if [ "$pkg" = "" -o ! -e "$pkg" ]; then
echo "no package supplied" 1>&2
exit 1
fi
leadsize=96
o=`expr $leadsize + 8`
@elasticdog
elasticdog / verify-chain
Last active December 28, 2015 05:59
verify the ssl certificate chain for multiple domains using openssl
#!/bin/bash
readonly FILE='domains.list'
readonly MAX_CHAIN_LENGTH=5
readonly PORT=443
while IFS= read -r domain; do
echo -ne "${domain} $(/usr/bin/dig ${domain} +short | tail -n 1)\n"
echo QUIT | /usr/bin/openssl s_client -verify ${MAX_CHAIN_LENGTH} -connect ${domain}:${PORT} 2>1 | grep 'Verify return code'
done < "$FILE"
@elasticdog
elasticdog / git-dmz-flow.md
Created October 4, 2016 18:29 — forked from djspiewak/git-dmz-flow.md
Git DMZ Flow

Git DMZ Flow

I've been asked a few times over the last few months to put together a full write-up of the Git workflow we use at RichRelevance (and at Precog before), since I have referenced it in passing quite a few times in tweets and in person. The workflow is appreciably different from GitFlow and its derivatives, and thus it brings with it a different set of tradeoffs and optimizations. To that end, it would probably be helpful to go over exactly what workflow benefits I find to be beneficial or even necessary.

  • Two developers working on independent features must never be blocked by each other
    • No code freeze! Ever! For any reason!
  • A developer must be able to base derivative work on another developer's work, without waiting for any third party
  • Two developers working on inter-dependent features (or even the same feature) must be able to do so without interference from (or interfering with) any other parties
  • Developers must be able to work on multiple features simultaneously, or at lea
@elasticdog
elasticdog / vagrant-box-clean
Last active May 25, 2018 13:44
clean up old versions of vagrant boxes
#!/usr/bin/env bash
##### Functions
# print this script's usage message to stderr
usage() {
cat <<-EOF >&2
usage: vagrant-box-clean [-p PREFIX] [-d] [-h]
EOF
}
@elasticdog
elasticdog / pre-commit
Created September 20, 2018 20:35
Git pre-commit hook for linting YAML files
#!/usr/bin/env bash
current_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
if [[ $current_branch = 'master' ]]; then
printf 'Direct commits to the master branch are not allowed.\n'
exit 1
fi
if command -v yamllint > /dev/null; then
@elasticdog
elasticdog / ephemeral-port
Created April 4, 2019 15:11
A pure Bash script to return a random *unused* ephemeral TCP port
#!/usr/bin/env bash
#
# ephemeral-port
#
# A script that returns a random *unused* TCP port within the IANA-suggested
# ephemeral port range of 49152 to 65535. Defaults to checking the localhost,
# but takes an optional hostname as an argument.
#
# See:
@elasticdog
elasticdog / gist:8806073
Last active May 9, 2019 18:19
Working with Git Submodules

Add New Submodule

$ cd ~/.dotfiles/
$ git submodule add http://github.com/scrooloose/nerdtree.git vim/bundle/nerdtree
$ git submodule init
$ git commit -m 'Add nerd tree plugin as submodule'

Updating