Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working on AWS' cloud

John Preston JohnPreston

🏠
Working on AWS' cloud
View GitHub Profile
@JohnPreston
JohnPreston / CIDR_regexps.py
Created Feb 27, 2020
Regexps for CIDR/IP validation (checks it is within 0-255 range)
View CIDR_regexps.py
ipv4_ip = r'((((((([0-9]{1}\.))|([0-9]{2}\.)|(1[0-9]{2}\.)|(2[0-5]{2}\.)))){3})(((((([0-9]{1}))|([0-9]{2})|(1[0-9]{2})|(2[0-5]{2}))))){1,3})'
ipv4_ip_link = 'https://regex101.com/r/vIL3oX/3'
ipv4_cidr = r'((((((([0-9]{1}\.))|([0-9]{2}\.)|(1[0-9]{2}\.)|(2[0-5]{2}\.)))){3})(((((([0-9]{1}))|([0-9]{2})|(1[0-9]{2})|(2[0-5]{2}))))){1,3})\/(([0-9])|([1-2][0-9])|((3[0-2])))$'
ipv4_cidr_link = 'https://regex101.com/r/vIL3oX/4'
View gist:ebbf8e7499aee697eda207f3f1eee135
#For specific file extension
(^(s3:\/\/)([a-z0-9.-]+)(\/+)?(\/[a-zA-Z0-9.-_\/]+(\/)?)?(\/)([\w-_.]+.sql))
#For specific file extension or no extension at all
(^(s3:\/\/)([a-z0-9.-]+)(\/+)?(\/[a-zA-Z0-9.-_\/]+(\/)?)?(\/)([\w-_.]+)(.zip)?)
View tmux_multi_windows_start.sh
#!/usr/bin/env bash
# creates a new TMUX session and opens windows in predefined folders, and for python, activates virtual environment
session=v2
tmux new-session -s $session\; \
send-keys 'cd /home/john/work/pe_v2_common' C-m \; \
send-keys 'source .venv/bin/activate' C-m \; \
new-window -t $session:1 \; \
send-keys 'cd /home/john/work/pe_v2_core' C-m\; \
send-keys 'source .venv/bin/activate' C-m \; \
@JohnPreston
JohnPreston / aws_delete_default_vpc.sh
Created May 23, 2019
Delete default VPC in all regions
View aws_delete_default_vpc.sh
#!/usr/bin/env bash
for region in $(aws ec2 describe-regions --region eu-west-1 | jq -r .Regions[].RegionName); do
echo "* Region ${region}"
# get default vpc
vpc=$(aws ec2 --region ${region} describe-vpcs --filter Name=isDefault,Values=true | jq -r .Vpcs[0].VpcId)
if [ "${vpc}" = "null" ]; then
echo "No default vpc found"
@JohnPreston
JohnPreston / AWS_regexps.py
Last active Mar 23, 2019
Useful python re regexp for AWS
View AWS_regexps.py
lambda_layer_pattern = r'(^arn:aws:lambda:[a-z]{2}-[a-z]{1,12}-[0-9]{1}:[0-9]{12}:layer/[a-z]+:[0-9]+$) or (^[a-z]+:[0-9]+$)'
View cleanup_ecr_images.sh
for images in `docker images |grep ecr | awk '{print $3}'`; do docker ps -a |grep $images | awk '{print $1}' | xargs -i -P10 docker rm {} ; docker rmi $images ; done
View extract_top_map_names.sh
for map in `sed 's/^ .*//1' $file | sed '/^\s*$/d' | sed 's/\://g'`; do touch "$file"_"$map.yml"; done
View regexes_cheatsheet.txt
AWS ARN TOPIC (py 3.6, re)
'(arn:aws:sns:([a-z]{2})-(east|west|central)-([0-9]{1}):([0-9]{12}):([a-z0-9]{1,256}))?'
View keybase.md

Keybase proof

I hereby claim:

  • I am johnpreston on github.
  • I am johnpreston78 (https://keybase.io/johnpreston78) on keybase.
  • I have a public key whose fingerprint is 5C93 2084 E03F 7DD1 3ED8 16A4 9145 77AC 111D 1F0A

To claim this, I am signing this object:

@JohnPreston
JohnPreston / addip.service
Created Mar 8, 2017
Systemd call to script to add an IP
View addip.service
[Unit]
Description=Add Secondary IP
After=network-service.target network.target
Wants=network.target
[Service]
Type=forking
ExecStart=/etc/addip.sh 10.163.59.174/21
You can’t perform that action at this time.