Skip to content

Instantly share code, notes, and snippets.

View AMMullan's full-sized avatar

Allan Mullan AMMullan

View GitHub Profile
@AMMullan
AMMullan / upgrade_awscli.sh
Last active January 16, 2025 11:58
Script to install/upgrade AWS CLI in $HOME
#!/bin/bash
#
# This script can be used to install the AWS CLI in $HOME/.local/ rather than global
# Why? Because then we don't have to keep using sudo needlessly.
#
# It creates a choices.xml which the pkg installer uses to select the correct path.
# The binaries are then linked to the $HOME/.local/bin folder - make sure this is in your $PATH
#
def percent_of(x: float, y: float) -> float:
return (x / 100) * y
def what_percent_of(x: float, y: float) -> float:
return (x / y) * 100
def percent_change(x: float, y: float) -> float:
return ((y - x) / x) * 100
@AMMullan
AMMullan / excel-formulas.txt
Last active November 26, 2024 12:32
Excel Formulas
# Far better alternative to VLOOKUP
# Works in both Excel and Google Sheets
# VLOOKUP is _NOT_ case-sensitive and doesn't handle situations where the return value is in a column BEFORE the lookup.
# This uses a table called Table1 with Name and Age Columns, with the lookup being in cell A1
=INDEX(Table1[Name], MATCH(TRUE, EXACT(A1, Table1[Age]), 0))
# The following does the same but it finds text ANYWHERE inside the cell, rather than an exact value.
=INDEX(Table1[Name], MATCH(TRUE, ISNUMBER(SEARCH(A1, Table1[Age])), 0))
@AMMullan
AMMullan / logs_insights.sql
Last active November 18, 2024 15:09
CloudWatch Logs Insights Queries
-- Get number of emails sent by each IAM User broken down in hourly segments
stats count(*) by IAMUser, bin(1h) as period
| filter EventType in ["Delivery"]
| sort IAMUser desc, period desc
-- Get statistics for each event type (i.e. Delivery, Bounce and Complaint) for each user
fields @timestamp, EventType, IAMUser
| filter EventType in ["Delivery", "Complaint", "Bounce"]
| stats count() as email_count by IAMUser, EventType
| sort IAMUser asc, EventType asc
@AMMullan
AMMullan / README.md
Last active November 8, 2022 17:03
ECS Notes

ECS Notes

A Task Definition is a collection of 1 or more container configurations. Some Tasks may need only one container, while other Tasks may need 2 or more potentially linked containers running concurrently.

The Task Definition allows you to specify things like:

  • Which Docker image to use
  • Which ports to expose
@AMMullan
AMMullan / find_duplicate_files.ps1
Created August 16, 2022 08:47
Finding Duplicate Files Fast
# https://powershell.one/tricks/filesystem/finding-duplicate-files
function Find-PSOneDuplicateFile
{
<#
.SYNOPSIS
Identifies files with duplicate content
.DESCRIPTION
Returns a hashtable with the hashes that have at least two files (duplicates)
@AMMullan
AMMullan / snippets.sh
Last active September 22, 2022 15:00
# Remove all folders called .terraform in this dir
find . -type d -name .terraform -exec rm -rf {} +
# Create zip package from git
git archive --format zip --output [zip_file] --remote [repo_ssh_url] [branch_name]
# List packages and sort by size
rpm -qa --queryformat '%10{size} - %-25{name} \t %{version}\n' | sort -n
# Test VirtualHost
@AMMullan
AMMullan / ipcalc
Last active November 11, 2020 16:45
#!/usr/bin/env python3
import sys
import socket
import struct
import platform
try:
import ipaddress
except:
@AMMullan
AMMullan / create_lambda_layer.sh
Last active July 22, 2022 13:07
Create Lambda Layer for Python (Multiple Runtimes)
#!/bin/bash
# Expects a requirements.txt in the same folder
# Note: if the package includes NumPy and SciPy, consider defining the package
# and the dependencies that aren't these as they're natively available in Layers
# Supported Docker Images are available here:
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-image-repositories.html
layer_versions="python3.8 python3.9"
@AMMullan
AMMullan / aws_lambda_self_destruct.py
Created September 15, 2020 15:26
Self-Destructing Lambda
import os
import boto3
lmbda = boto3.client ('lambda')
def lambda_handler(event, context):
lmbda.delete_function(FunctionName=context.function_name)
return True