Friday, January 11, 2019

Encoding binary data into python source code

source

Effectively

python import base64
image = open('deer.gif', 'rb')
image_read = image.read()
image_64_encode = base64.encodestring(image_read)
image_64_decode = base64.decodestring(image_64_encode)
image_result = open('deer_decode.gif', 'wb') # create a writable image and write the decoding result image_result.write(image_64_decode)

Thursday, January 10, 2019

Post commit hook for terraform


source

A commit hook to check that terraform files are created properly:


#!/usr/bin/env bash
set -e

# Formats any *.tf files according to the hashicorp convention
files=$(git diff --cached --name-only --diff-filter=d)
for f in $files
do
  if [ -e "$f" ] && [[ $f == *.tf ]]; then
    /usr/local/bin/terraform fmt -check=true $f
  fi
done


Place into:

/usr/share/git-core/templates/hooks/