Skip to content

Instantly share code, notes, and snippets.

@seansummers
seansummers / walk.py
Last active August 17, 2021 01:23
Walk a Visitor to Leaves on a Graph in Python
from collections.abc import MutableMapping, MutableSequence
from typing import Callable, Iterable, Union
MutableCollection = Union[MutableMapping, MutableSequence]
Visitor = Callable[[str], str] # we only support string scalars for now
def visit(value: str) -> str:
"""Visit a string scalar, and mutate it if needed before returning it."""
if len(value) > 4: # example criteria
@seansummers
seansummers / jwks2asn1.py
Last active October 26, 2021 12:32 — forked from jonlundy/conv.py
JWKS parsing
#!/usr/bin/env python3
#
# openssl asn1parse -noout -out private_key.der -genconf <(python jwks2asn1.py private_key.json)
# openssl rsa -in private_key.der -inform der > private_key.pem
#
# rfc7517.3 : urlsafe_b64decode
# rfc7517.A.1 : ints are big-indian
#
import base64
@seansummers
seansummers / s3_buffered_writer.py
Last active September 24, 2023 23:31
S3 Utilities
import contextlib
import os
import tempfile
half_lambda_memory = 10**6 * (
int(os.getenv('AWS_LAMBDA_FUNCITON_MEMORY_SIZE', '0')) / 2)
@contextlib.contextmanager
@seansummers
seansummers / create_ami.py
Last active February 19, 2021 22:39
Lambda Gists
import secrets
import boto3
import cfnresponse
ec2 = boto3.resource('ec2')
def create_ami(instance_id, ami_name, description):
instance = ec2.Instance(instance_id)
@seansummers
seansummers / update-api-keys.sh
Created December 3, 2018 15:36
AWS cli tools
#! /bin/bash -xe
# This script requires `jq` and optionally `awsume`
awsume --session-name ssummers-update-api-keys # or whatever method to assume an mfa session
AWS_EXPIRING_ACCESS_KEY=$(aws configure get aws_access_key_id)
AWS_USER=$(aws sts get-caller-identity --query Arn --output text | awk -F/ '/:user/ {print $2}')
if [[ $(aws iam list-access-keys --user-name ${AWS_USER} --query '*[]|length(@)') -ne 1 ]]
then
# ----------------------
# Git Aliases, mostly from https://jonsuh.com/blog/git-command-line-shortcuts/
# ----------------------
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add --all'
alias gau='git add --update'
alias gb='git branch'
alias gbd='git branch --delete '
alias gc='git commit'
@seansummers
seansummers / inventory-global.template.yml
Last active September 15, 2023 11:21
AWS Configuration Tracking
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Global assets needed for Inventory Discovery
Metadata:
AWS::CloudFormation::Interface:
@seansummers
seansummers / ec2.yml
Created March 29, 2018 17:40 — forked from ssummer3/ec2.yml
AWS LIBND
AWSTemplateFormatVersion: '2010-09-09'
Description: Template to create libnd EC2
Conditions:
HasNetworkInterfaceId: !Not [!Equals [!Ref NetworkInterfaceId, '']]
HasPrivateIpAddress: !Not [!Equals [!Ref PrivateIpAddress, '']]
Parameters:
AMI:
ConstraintDescription: must be an AMI available in the EC2 instance's region
Default: ami-6869aa05
Description: Base AMI
@seansummers
seansummers / create_and_attach_volume.yaml
Created March 29, 2018 17:40 — forked from ssummer3/create_and_attach_volume.yaml
AWS: Create and Attach a Volume to an EC2 Instance
AWSTemplateFormatVersion: '2010-09-09'
Description: Create a Volume from scratch and attach it to an instance.
Metadata:
AWS::CloudFormation::Interface:
@seansummers
seansummers / convert.json
Created March 29, 2018 17:39 — forked from ssummer3/convert.json
Contentful Stuffs
{
"universityarchives": "5561",
"reservesmicrotextandmediadesk": "5557",
"medievalinstitutelibrary": "5558",
"circulationservicedesk": "1483",
"engineeringlibrary": "5566",
"architecturelibrary": "5563",
"kelloggkroclibrary": "5567",
"mahaffeybusinesslibrary": "5564",
"chemistryphysicslibrary": "5565",