Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<!--[if lte IE 6]><html class="preIE7 preIE8 preIE9"><![endif]-->
<!--[if IE 7]><html class="preIE8 preIE9"><![endif]-->
<!--[if IE 8]><html class="preIE9"><![endif]-->
<!--[if gte IE 9]><!--><html><!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>title</title>
@mijdavis2
mijdavis2 / remove-v-from-git-tags.sh
Last active May 15, 2018 16:11 — forked from ahmednuaman/remove-v-from-git-tags.sh
Remove the v from git tags
# Fetch
git fetch
# Create tags without v from tags that start with v
for tag in $(git tag)
do
if [[ $tag =~ ^v.*$ ]]
then
git tag "${tag/v/}" $tag
fi
# Gets latest aws linux ami published by amazon
# Example use with an optional var:
# ${upper(var.ami) == "NONE" ? data.aws_ami.default.id : var.ami}
data "aws_ami" "default" {
most_recent = true
filter {
name = "name"
values = ["amzn-ami-*-x86_64-gp2"]
}
filter {
@mijdavis2
mijdavis2 / timeit.py
Last active July 12, 2019 00:12
Decorator for timing functions in python
import time
def timeit(method):
"""
Decorator useful for timing functions.
Source: https://medium.com/pythonhive/python-decorator-to-measure-the-execution-time-of-methods-fa04cb6bb36d
Usage:
@timeit
def my_function():
@mijdavis2
mijdavis2 / print_table.py
Last active February 17, 2019 14:57
Print a table from a list of dictionaries
def print_table(data, column_order=None):
""" Pretty print a list of dictionaries (data) as a dynamically sized table.
If column names (column_order) aren't specified, they will show in random order.
Author: Thierry Husson - Use it as you want but don't blame me.
Source: https://stackoverflow.com/questions/17330139/python-printing-a-dictionary-as-a-horizontal-table-with-headers
PEP8ed by: mijdavis2
"""
if not column_order:
column_order = list(data[0].keys() if data else [])
l = [column_order] # 1st row = header
@mijdavis2
mijdavis2 / threadwrap.py
Created February 25, 2019 14:10
Python multithreading made easy
"""
Note: Found somewhere on Stack Overflow but was unable to find again.
If found, please comment and I will update this gist with the source.
"""
def threadwrap(func, args, kwargs):
class res(object):
result = None
def inner(*args, **kwargs):
res.result = func(*args, **kwargs)
@mijdavis2
mijdavis2 / available_azs.tf
Created March 12, 2019 15:06
How to get available AZs in terraform from data and subnet list.
data "aws_availability_zones" "available" {}
# Assuming we vars for list of private_subnet_ids and or public_subnet_ids
# we take a slice of available AZs.
#
# Add or remove private/public vars when necessary.
locals {
available_azs = "${
slice(
data.aws_availability_zones.available.names,
@mijdavis2
mijdavis2 / get-instance-names.sh
Last active October 29, 2020 21:10
Get "Name" tag for all AWS EC2 instances in a region
#!/bin/bash
PROFILE=${AWS_PROFILE:-default}
TAG=${TAG:-Name}
STATE=${STATE:-running}
aws ec2 --profile ${PROFILE} describe-instances \
--filters Name=instance-state-name,Values=${STATE} | \
jq .Reservations[].Instances[].Tags | \
jq -c ".[] | select(.Key | contains(\"${TAG}\"))" | \
@mijdavis2
mijdavis2 / upload-cert-to-aws-iam.fish
Created July 19, 2019 05:09
Upload SSL cert to AWS IAM (useful for LB incompatible certs like 4096)
#!/usr/bin/fish
# Name allows for "."
# so might as well use full domain minus the "*"
# if you are using a wildcard cert...
#
# But you should at least use one subdomain if you wildcard
# ...for security... just sayin.
# Using absolute path is more reliable.
@mijdavis2
mijdavis2 / dockercleanup.sh
Created September 11, 2019 15:58
Docker cleanup
#!/bin/bash
#
# To add this as a fish function:
# function dockercleanup
# docker volume rm (docker volume ls -f dangling=true -q); docker system prune -a
# end
# funcsave dockercleanup
#