Skip to content

Instantly share code, notes, and snippets.

View medwig's full-sized avatar

Jonathan Medwig medwig

  • Faire
  • Kitchener, Canada
View GitHub Profile
@medwig
medwig / enum_attribute_pynamodb.py
Last active May 14, 2024 15:55
An enumerated type (enum) attribute for pynamodb
from pynamodb.models import Model
from pynamodb.constants import STRING
from pynamodb.attributes import UnicodeAttribute
ENUM = ('FOO', 'BAR', 'BAZ')
class EnumUnicodeAttribute(UnicodeAttribute):
"""
An enumerated unicode attribute
@medwig
medwig / .zshrc
Created November 24, 2018 15:02
Powerlevel9k custom python version in prompt
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(virtualenv custom_pyenv)
POWERLEVEL9K_CUSTOM_PYENV="echo \$(python -c 'import sys; print(\".\".join(map(str, sys.version_info[:2])))')"
@medwig
medwig / .zshrc
Last active November 27, 2018 21:13
List cloudformation outputs of Serverless Framework deployment
sls_stack () {
if [ -z "$1" ];
then
output=$(sls info | grep -oP 'stack: \K.*$')
else
output=$(sls info -s $1 | grep -oP 'stack: \K.*$')
fi
if [ ! -z "$output" ];
then
echo $output
@medwig
medwig / serverless.yml
Created March 13, 2019 22:56
Split SSM variable in Serverless Framework
service: splitssm
provider:
name: aws
ssm_var: ${ssm:x}
ssm_var_split: { 'Fn::Split': [ ",", "${ssm:x}" ] }
@medwig
medwig / snippet.tf
Created March 18, 2019 18:33
Merge Terraform Maps
tags = "${merge(
var.common_tags,
map(
"Environment", "${var.env}"
)
)}"
@medwig
medwig / pre-push
Last active March 29, 2019 22:33
Git pre-push hook protect branch
#!/usr/bin/python3
"""
Git pre-push hook:
Prevents pushing to protected branches
"""
import sys
PROTECTED_BRANCHES = ["develop", "master"]
@medwig
medwig / buildspec.yml
Created April 7, 2019 16:57
Install Terraform in AWS Codebuild
version: 0.2
phases:
install:
commands:
# install terraform binary
- curl -s -qL -o terraform_install.zip https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip
- unzip terraform_install.zip -d /usr/bin/
- chmod +x /usr/bin/terraform
finally:
@medwig
medwig / copy_files.py
Created April 13, 2019 17:21
Copy files from $HOME folder with python
import os
import shutil
HOME = os.path.expanduser('~')
FILES = [
".bashrc",
".vimrc",
]
@medwig
medwig / list_files_by_size_linux.bashrc
Last active April 15, 2019 14:47
List files sorted by size - Linux
alias ducks="du -cksh .[^.]* * 2> /dev/null | sort -h -r | head"
@medwig
medwig / sls aws set profile
Last active July 18, 2019 14:26
Bash alias run sls with --aws-profile
# Set default aws-profile
AWS_PROFILE=myprofile
# Run sls with an aws-profile
sls_with_aws_profile() {
if [ -z ${AWS_PROFILE+x} ];
then printf "\e[1;31mAWS_PROFILE is not set\e[0m\n$ export AWS_PROFILE=profile_name\n" \
&& return;
fi
export AWS_SDK_LOAD_CONFIG=true;