Skip to content

Instantly share code, notes, and snippets.

@elasticdog
elasticdog / english.rs
Created November 11, 2014 18:05
Determine likelyhood of text being in English using Rust
/// 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,
@elasticdog
elasticdog / keybase.md
Created May 6, 2014 22:20
Keybase.io GitHub Verification

Keybase proof

I hereby claim:

  • I am elasticdog on github.
  • I am elasticdog (https://keybase.io/elasticdog) on keybase.
  • I have a public key whose fingerprint is 5FC9 160D A643 E0E9 B83A F4BB 5E34 0427 C31E 7946

To claim this, I am signing this object:

@elasticdog
elasticdog / delete-ami
Last active March 7, 2023 12:19
Deregister an Amazon Machine Image (AMI) and delete its corresponding root device snapshot
#!/usr/bin/env bash
#
# delete-ami
#
# A script to deregister an Amazon Machine Image (AMI) and
# delete its corresponding root device snapshot.
#
##### Functions
@elasticdog
elasticdog / gist:9276527
Created February 28, 2014 18:13
Broken AWS Repository
stderr: E: Failed to fetch http://us-east-1.ec2.archive.ubuntu.com/ubuntu/pool/universe/a/arpack/libarpack2_3.1.5-2_amd64.deb 403 Forbidden
@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

@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 / 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 / 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
}
package main
import (
"encoding/hex"
"flag"
"io"
"io/ioutil"
"log"
"net"
"os"
@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