Skip to content

Instantly share code, notes, and snippets.

View kepstein's full-sized avatar

Kevin Epstein kepstein

View GitHub Profile
@kepstein
kepstein / secrets.py
Created March 15, 2022 02:41
Generating secure random strings
#!/usr/bin/env
# Python Docs https://docs.python.org/3/library/secrets.html
import secrets
secrets.token_hex(5).upper() # The number of actual character returned will be double the number in token_hex(n)
@kepstein
kepstein / 3xplus1.py
Created February 20, 2022 03:12
3x + 1 Math problem
num = 27
steps = 0
# while steps < 30: # use this while logic to show that it continuously loops 4,2,1. The number 30 can be changed to any arbitrary number
while num != 1:
if num % 2 != 0:
num = num * 3 + 1
else:
num = num / 2
print(num)
steps += 1
@kepstein
kepstein / jq-cheetsheet.md
Created January 21, 2022 18:15 — forked from olih/jq-cheetsheet.md
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@kepstein
kepstein / gp2gp3.sh
Created August 27, 2021 23:17
Script to automatically change all gp2 volumes to gp3 with aws-cli
#! /bin/bash
region='us-east-1'
# Find all gp2 volumes within the given region
volume_ids=$(/usr/bin/aws ec2 describe-volumes --region "${region}" --filters Name=volume-type,Values=gp2 | jq -r '.Volumes[].VolumeId')
# Iterate all gp2 volumes and change its type to gp3
for volume_id in ${volume_ids};do
result=$(/usr/bin/aws ec2 modify-volume --region "${region}" --volume-type=gp3 --volume-id "${volume_id}" | jq '.VolumeModification.ModificationState' | sed 's/"//g')
@kepstein
kepstein / Create-RandomFiles.ps1
Created June 15, 2021 02:03
PowerShell utility to create random files
#Function Create-RandomFiles{
<#
.SYNOPSIS
Generates a number of dumb files for a specific size.
.DESCRIPTION
Generates a defined number of files until reaching a maximum size.
.PARAMETER TotalSize
Specify the total size you would all the files combined should use on the harddrive.
@kepstein
kepstein / prowler.yaml
Last active April 25, 2021 21:14
CloudFormation to deploy Prowler as a CodeBuild project
---
AWSTemplateFormatVersion: 2010-09-09
Description: Creates a CodeBuild project to audit an AWS account with Prowler and stores the html report in a S3 bucket. This will run onece at the beginning and on a schedule afterwards. Partial contribution from https://github.com/stevecjones
Parameters:
ServiceName:
Description: 'Specifies the service name used within component naming'
Type: String
Default: 'prowler'
LogsRetentionInDays:
@kepstein
kepstein / lambda_account_id.py
Created April 13, 2021 17:29
Get AWS Account ID with Lambda
# https://www.radishlogic.com/aws/lambda/how-to-get-the-aws-account-id-in-lambda-python/
def lambda_handler(event, context):
aws_account_id = context.invoked_function_arn.split(":")[4]
print(aws_account_id)
@kepstein
kepstein / us-phone-regex.sh
Created October 12, 2019 03:40
regex for US phone number
\+?1?\s?\-?\(?\d{3}\)?\s?\-?\d{3}\s?\-?\d{4}
@kepstein
kepstein / BBEdit-TextWrangler_RegEx_Cheat_Sheet.txt
Created June 10, 2018 05:34 — forked from ccstone/BBEdit-TextWrangler_RegEx_Cheat_Sheet.txt
BBEdit-TextWrangler Regular Expression Cheat-Sheet
————————————————————————————————————————————————————————————————————————————————————————————————————
BBEDIT/TEXTWRANGLER REGULAR EXPRESSION GUIDE MODIFIED 2016/02/29 17:26
————————————————————————————————————————————————————————————————————————————————————————————————————
NOTES:
The PCRE engine (Perl Compatible Regular Expressions) is what BBEdit and TextWrangler use.
Items I'm unsure of are marked '# PCRE?'. The list while fairly comprehensive is not complete.