Skip to content

Instantly share code, notes, and snippets.

View wyllie's full-sized avatar

Andrew Wyllie wyllie

View GitHub Profile
@wyllie
wyllie / gist:82f029acf308c3ec1dd1138ccb10716e
Created March 6, 2018 16:56
AWS KMS encrypt/decrypt from CLI
# Get the key-id from KMS
% aws kms list-keys
# To encrypt some text:
% aws kms encrypt --key-id <KeyId> --plaintext <text to encrypt>
# To decrypt it:
% aws kms decrypt --ciphertext-blob fileb://<(echo <blob from encrypt step> | base64 -D) --output text --query Plaintext | base64 -D
@wyllie
wyllie / gist:8f67b301a2325ea3d6b09affc1099b7b
Last active May 15, 2018 20:34
Copy MongoDB Atlas collection
# this will copy the collection 'my_original' to 'my_copy'
db.my_original.aggregate([{$match: {}}, {$out: "my_copy"}])
# to move the collection to another db within the same Atlas mongodb cluster
db.adminCommand({renameCollection: "my_db.my_copy", to: "other_db.other_name"})
@wyllie
wyllie / gist:f60e272f1ad871ad34c8d4feb75f1db8
Created June 1, 2018 12:06
Common Mongo cli commands
# these are some common mongodb cli commands
# Get help
MongoDB Enterprise > help
# get a list of databases
show dbs
# get list of collections
show collections
@wyllie
wyllie / python.sh
Created June 20, 2018 19:59
Python Virtual Environment Config
# Python environment
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Projects
# Set up virtual wrapper env
source /usr/local/bin/virtualenvwrapper.sh
# for testing, set pytest to verbose by default
alias pytest='pytest -v'
@wyllie
wyllie / check_eni.sh
Created July 22, 2018 13:55
Check status of lambda eni
#!/usr/bin/env sh
aws ec2 describe-network-interfaces --filters "Name=vpc-id,Values=vpc-53acd32a" \
| jq -r '.NetworkInterfaces[] | select(.Description | contains("Lambda")) | .RequesterId, .Attachment'
#.RequesterId, .Description, .Attachment.AttachTime'
@wyllie
wyllie / parse_ini.sh
Created July 22, 2018 17:04
Parse aws credentials file in bash
#!/usr/bin/env bash
INI_FILE=~/.aws/credentials
while IFS=' = ' read key value
do
if [[ $key == \[*] ]]; then
section=$key
elif [[ $value ]] && [[ $section == '[default]' ]]; then
if [[ $key == 'aws_access_key_id' ]]; then
@wyllie
wyllie / python_layout
Last active September 6, 2018 02:49
Python Package Layout
repo_name/
README.md - yeah, do us a favor and give us a quick overview of what this is and how to use it
PackageName/
ModuleName/
__init__.py
module_file_1.py
module_file_2.py
...
AnotherModule/
__init__.py
# This is an interesting way to profile code
# Probably would not be too hard to add some foo activate/deactivate it
# and then maybe use it in integration test code. The decorator will
# produce a file called <function_being_profiled>.profile which can
# be processed with 'snakeviz' (pip install snakeviz)
import cProfile
import functools
def profile_this(func):
#!/bin/bash
# remove containers that have exited
docker rm -v $(docker ps -a -q -f status=exited)
# remove images that are not being used
docker rmi -f $(docker images -a "dangling=true" -q)
# remove volumes that are not being used
docker volume rm $(docker volume ls -qf dangling=true)
#!/bin/sh
BUCKETNAME=$1
echo Checking: $BUCKETNAME
echo Size of objects, number of objects
set result=`aws s3api list-objects --bucket $BUCKETNAME --output json --query "[sum(Contents[].Size), length(Contents[])]"`
echo Number of Objects: $3
echo Size of Objects: $2