Skip to content

Instantly share code, notes, and snippets.

View AMMullan's full-sized avatar

Allan Mullan AMMullan

View GitHub Profile
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 July 18, 2024 09:27
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 August 22, 2023 16:43
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
@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
@AMMullan
AMMullan / snippets.py
Last active August 3, 2022 16:00
Useful Python Snippets
import re
def equal_dicts(d1, d2, ignore_keys=None):
''' Dictionary Comparison
Takes 2 lists and does a comparison, excluding the keys from ignore_keys
Arguments:
d1 {dict} -- First Dict