Skip to content

Instantly share code, notes, and snippets.

View ericjsilva's full-sized avatar
🦉
silently correcting your grammar.

Eric Silva ericjsilva

🦉
silently correcting your grammar.
View GitHub Profile
@ericjsilva
ericjsilva / count_terraform_resources.py
Created June 22, 2023 21:54
Iterates over all S3 buckets in an AWS account, locates the Terraform state files and gets a count of all resources in the state files.
import boto3
import json
import pyjq
boto3.setup_default_session(profile_name="aws")
s3 = boto3.resource("s3")
s3_client = boto3.client("s3")
BUCKET_NAME_FILTER_PREFIX = "mybucket-prefix"
@ericjsilva
ericjsilva / uninstall_mcafee.sh
Last active June 18, 2020 12:33
Script to fully remove McAfee Endpoint Security from macOS
#!/bin/bash
echo "Uninstalling McAfee Endpoint Security..."
echo "Stopping all services..."
sudo ps auxww | grep -i 'VShieldScanner\|VShieldScanManager\|masvc\|McAfee' | grep -v grep | awk ‘{ print $2 }’ | sudo xargs kill -9; kextstat | grep -i mcafee | awk ‘{ print $6 }’ | sudo xargs -n1 -I{} kextunload -verbose 2 -bundle-id ‘{}’
echo "Uninstalling ATP..."
sudo /usr/local/McAfee/uninstall ATP
echo "Uninstalling ThreatPrevention and Firewall..."
sudo /usr/local/McAfee/uninstall ThreatPrevention Firewall module
echo "Uninstalling Endpoint Security..."
sudo /usr/local/McAfee/uninstall EPM
@ericjsilva
ericjsilva / package.py
Created April 3, 2020 16:37
Sample files for packaging and optionally deploying a Python project to AWS Lambda
#!/usr/bin/env python
import os
import shutil
import datetime
import tempfile
PKG_FILENAME = 'my_lambda_function-{}.zip'
def zipdir(path, ziph):
# ziph is zipfile handle
@ericjsilva
ericjsilva / table_size.sql
Created July 3, 2018 18:33
List the size of tables in MySQL database
SELECT
table_schema as `Database`,
table_name AS `Table`,
round((data_length / 1024 / 1024), 2) `Data Size in MB`,
round((index_length / 1024 / 1024), 2) `Index Size in MB`,
round(((data_length + index_length) / 1024 / 1024), 2) `Total Size in MB`,
round(((data_length + index_length) / 1024 / 1024 / 1024), 2) `Total Size in GB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
@ericjsilva
ericjsilva / query_free_space.sql
Created May 18, 2018 19:16
Query Free Space in Redshift
SELECT
SUM(capacity) / 1024 as capacity_gbytes,
SUM(used) / 1024 as used_gbytes,
(SUM(capacity) - SUM(used)) / 1024 as free_gbytes
FROM
stv_partitions WHERE part_begin = 0;
@ericjsilva
ericjsilva / optimize_tables.sql
Created May 4, 2018 01:06
Create MySQL Optimize statements
SELECT CONCAT('OPTIMIZE TABLE ',TABLE_NAME, ';') FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='my_schema';
@ericjsilva
ericjsilva / aws_vpc_check.md
Created April 26, 2018 11:39
Determine if AWS VPC is in use

The following AWS CLI command will determine if there are any network interfaces attached to a given VPC ID.

aws ec2 describe-network-interfaces --region eu-west-1 --filters 'Name=vpc-id,Values=vpc-12345678' --query 'NetworkInterfaces[*].NetworkInterfaceId'

If the array returns empty (e.g. []), there are no active network interfaces attached. Otherwise, a list of interface IDs will be returned.

@ericjsilva
ericjsilva / s3_bucket_size.md
Created April 26, 2018 11:36
Determine size of AWS S3 Bucket

Determine size of S3 bucket

Below are AWS CLI commands that can be used for quickly determining the current size of an S3 bucket.

in MB

aws s3 ls s3://[bucket_name] --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'

in GB

@ericjsilva
ericjsilva / update-gems.md
Last active September 10, 2017 18:33
Update All Ruby Gems at once

How to Update All Your Ruby Gems At Once

If you want to update every gem on your system, and don’t want to sit and do it one-by-one (and why would you want to do it one-by-one!?), here’s one way to do it. (I’m sure there are better ways, and I’d love to hear about them in the comments.)

sudo gem update `gem list | cut -d ' ' -f 1
@ericjsilva
ericjsilva / encrypt_keys.sh
Created May 5, 2017 16:33
Encrypt AWS keys and secrets in Travis-CI
$ travis encrypt AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
$ travis encrypt AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY