Skip to content

Instantly share code, notes, and snippets.

Aaron Bull Schaefer elasticdog

Block or report user

Report or block elasticdog

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@elasticdog
elasticdog / ephemeral-port
Created Apr 4, 2019
A pure Bash script to return a random *unused* ephemeral TCP port
View ephemeral-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 / pre-commit
Created Sep 20, 2018
Git pre-commit hook for linting YAML files
View pre-commit
#!/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 / vault-cp
Created Jul 27, 2018
A script to copy Vault secrets from one path to another
View vault-cp
#!/usr/bin/env bash
# ensure we were given two command line arguments
if [[ $# -ne 2 ]]; then
echo 'usage: vault-cp SOURCE DEST' >&2
exit 1
fi
source=$1
dest=$2
@elasticdog
elasticdog / setup.md
Created Jul 3, 2018
Git Triangular Workflow
View setup.md
  1. Fork an upstream repo -- I'll use terraform-provider-vault as an example.

  2. Clone your forked copy of the repo:

    git clone git@github.com:elasticdog/terraform-provider-vault.git
    cd terraform-provider-vault/
    
  3. Add the upstream repo as a remote:

@elasticdog
elasticdog / config.nix
Last active May 3, 2017
~/.nixpkgs/config.nix package override for Ansible v2.1.4.0
View config.nix
{
packageOverrides = pkgs: rec {
ansible2 = pkgs.stdenv.lib.overrideDerivation pkgs.ansible2 (oldAttrs: rec {
variable = "2.1.4.0";
name = "ansible-${variable}";
src = pkgs.fetchurl {
url = "http://releases.ansible.com/ansible/${name}.tar.gz";
sha256 = "05nc68900qrzqp88970j2lmyvclgrjki66xavcpzyzamaqrh7wg9";
};
View git-dmz-flow.md

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
clean up old versions of vagrant boxes
View vagrant-box-clean
#!/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 / poolboy_demo.ex
Created Oct 23, 2015 — forked from henrik/poolboy_demo.ex
Example of using Poolboy in Elixir to limit concurrency (e.g. of HTTP requests).
View poolboy_demo.ex
defmodule HttpRequester do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, nil, [])
end
def fetch(server, url) do
# Don't use cast: http://blog.elixirsips.com/2014/07/16/errata-dont-use-cast-in-a-poolboy-transaction/
timeout_ms = 10_000
View gist:de721744a9718cc85745
javascript:(function(){var%20ps=document.getElementsByTagName("pre");for(var%20i=0;i<ps.length;i++){ps[i].style.whiteSpace="pre-wrap";ps[i].style.width="600px";}})();
@elasticdog
elasticdog / english.rs
Created Nov 11, 2014
Determine likelyhood of text being in English using Rust
View english.rs
/// Uses the Bhattacharyya coefficient to determine if text is likely to be English.
///
/// Higher is better.
pub fn probability_english(text: &str) -> f64 {
// count of the number of times a character occurs in the given text
let mut count: BTreeMap<char, f64> = BTreeMap::new();
for letter in text.chars() {
match count.entry(char::to_uppercase(letter)) {
Vacant(entry) => { entry.set(1f64); },
Occupied(mut entry) => *entry.get_mut() += 1f64,
You can’t perform that action at this time.