Skip to content

Instantly share code, notes, and snippets.

@mijdavis2
mijdavis2 / hop-with-ssh-keys.sh
Created November 7, 2019 17:24
Bring ssh keys along through jump boxes without copying private keys onto nodes.
eval $( ssh-agent )
# Can add as many keys as you want
ssh-add /path/to/key
ssh -A user@host
@mijdavis2
mijdavis2 / aws_security_group_rule-missing_sg_id-output.txt
Last active February 5, 2020 03:24
Result of malformed aws_security_group_rule resource; TF v0.12.6; provider.aws v2.47.0
#
# For security purposes, the output has been obfuscated with '***' in a few places.
#
Error: Expected to find one security group with ID "", got: []*ec2.SecurityGroup{{
Description: "SG for access to *** layer",
GroupId: "sg-*****",
GroupName: "*****",
IpPermissions: [
{
@mijdavis2
mijdavis2 / .gitconfig
Last active May 22, 2021 14:15
Git config - helpful aliases
[core]
editor = vim
[alias]
reup = !git stash && git fetch && git rebase origin/master && git stash pop
au = !git add -u && git fetch >/dev/null && git diff --cached --no-ext-diff origin/master | grep --color=always 'pdb.set_trace()' -B 6
re = reset
dc = diff --cached
st = status
co = checkout
@mijdavis2
mijdavis2 / fish_prompt.fish
Created March 17, 2021 21:28
My fish prompt (.config/fish/functions/fish_prompt.fish)
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
if not set -q __fish_git_prompt_show_informative_status
set -g __fish_git_prompt_show_informative_status 1
end
if not set -q __fish_git_prompt_hide_untrackedfiles
set -g __fish_git_prompt_hide_untrackedfiles 1
end
if not set -q __fish_git_prompt_color_branch
set -g __fish_git_prompt_color_branch magenta --bold
@mijdavis2
mijdavis2 / get-aws-windows-password.sh
Created May 4, 2021 20:59
Get an AWS Windows EC2 password from a private IP
#!/bin/bash
# inputs: AWS_PROFILE, IP, PATH_TO_PRIV_KEY
instance_id="$(aws --profile $1 ec2 describe-instances --filter Name=private-ip-address,Values=$2 --query 'Reservations[].Instances[].InstanceId' --output text)"
echo "Instance ID: $instance_id"
passwd="$(aws --profile $1 ec2 get-password-data --instance-id ${instance_id} --priv-launch-key $3 --query 'PasswordData' --output text)"
@mijdavis2
mijdavis2 / clone-repos.sh
Last active May 22, 2021 14:14
Clone all repos from org or user via gh cli (GitHub cli)
#!/bin/bash
#
# Requires `gh` --> https://cli.github.com/
#
# Ensure you setup gh cli via `gh auth login`
# and select the `ssh` option if you are cloning private repos - much easier.
#
# Usage:
# $ ./clone-repos.sh some_org target_dir
@mijdavis2
mijdavis2 / get-aws-windows-password.fish
Created May 22, 2021 14:35
Get an AWS Windows EC2 password from a private IP
#!/usr/bin/env fish
# inputs: AWS_PROFILE, IP, PATH_TO_PRIV_KEY
function get-aws-windows-password
set instance_id (aws --profile $argv[1] ec2 describe-instances --filter Name=private-ip-address,Values=$argv[2] --query 'Reservations[].Instances[].InstanceId' --output text)
echo "Instance ID: $instance_id"
set passwd (aws --profile $argv[1] ec2 get-password-data --instance-id $instance_id --priv-launch-key $argv[3] --query 'PasswordData' --output text)
echo "Password: $passwd"
end
@mijdavis2
mijdavis2 / pre-commit
Last active June 2, 2021 21:18 — forked from jcromartie/pre-commit
Git pre-commit hook to help stay up-to-date with master
#!/usr/bin/env bash
# hook to enforce that current branch is up-to-date with latest
# changes from master before committing
# put me in .git/hooks and make me executable
# the output of rev-list in the following test will be empty if there
# are no commits in master that aren't in the current branch
@mijdavis2
mijdavis2 / dict_to_obj.py
Created August 19, 2021 12:06
Convert dict to js style object in Python 3
"""
Not actually sure when this would be a good idea,
but had the idea when porting some js/node to python.
Inspired by https://stackoverflow.com/questions/6578986/how-to-convert-json-data-into-a-python-object
"""
import json
from types import SimpleNamespace
@mijdavis2
mijdavis2 / browse_runtime_lambdas.sh
Created December 3, 2021 18:45
AWS lambda runtime discovery command
#!/bin/bash
# Helpful for finding lambdas that are using an old runtime, etc.
RUNTIME=node
ARN_SUFFIX=etl
aws lambda list-functions --region us-west-2 | \
jq '.Functions[] | select(.Runtime | startswith("${RUNTIME}")) | select (.FunctionArn | endswith("${ARN_SUFFIX}")) | .FunctionName'