Skip to content

Instantly share code, notes, and snippets.

View medwig's full-sized avatar

Jonathan Medwig medwig

  • Faire
  • Kitchener, Canada
View GitHub Profile
@welbornprod
welbornprod / Embedded Python in BASH
Created August 14, 2014 23:22
A little trick to embed python code in a BASH script.
#!/bin/bash
# Here are some embedded Python examples using Python3.
# They are put into functions for separation and clarity.
# Simple usage, only using python to print the date.
# This is not really a good example, because the `date`
# command works just as well.
function date_time {
@gene1wood
gene1wood / role_arn_to_session.py
Created December 29, 2016 17:38
Simple python function to assume an AWS IAM Role from a role ARN and return a boto3 session object
import boto3
def role_arn_to_session(**args):
"""
Usage :
session = role_arn_to_session(
RoleArn='arn:aws:iam::012345678901:role/example-role',
RoleSessionName='ExampleSessionName')
client = session.client('sqs')
"""
@bradmontgomery
bradmontgomery / LICENSE.txt
Last active December 1, 2023 21:01
A python decorator that logs execution time.
Copyright 2020 Brad Montgomery
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
@BGBRWR
BGBRWR / workit.bash
Last active February 10, 2019 06:58 — forked from gibatronic/workit.bash
Automatically run workon when entering a directory
function check_for_virtual_env {
[ -d .git ] || git rev-parse --git-dir &> /dev/null
if [ $? -eq 0 ]; then
local ENV_NAME=`basename \`pwd\``
if [ "${VIRTUAL_ENV##*/}" != $ENV_NAME ] && [ -e $WORKON_HOME/$ENV_NAME/bin/activate ]; then
workon $ENV_NAME && export CD_VIRTUAL_ENV=$ENV_NAME
fi
elif [ $CD_VIRTUAL_ENV ]; then
@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;