Skip to content

Instantly share code, notes, and snippets.

@keithrozario
keithrozario / solution_matrix.py
Created February 21, 2025 01:36
Solve Question 13 with matrices
def calculate_pushes(a_x, b_x, a_y, b_y, prize_x, prize_y) -> tuple[int, int]:
"""
Using matrix multiplication
if A . [x,y] = [prize_x, prize_y]
then [x,y] = A^-1 . [prize_x, prize_y[]
"""
A = np.array([[a_x, b_x], [a_y, b_y]])
P = np.array([prize_x, prize_y])
a_pushes, b_pushes = np.linalg.solve(A, P).round().astype(int)
@keithrozario
keithrozario / solution.py
Last active February 21, 2025 00:26
Question 13: Advent of Code
prize_x, prize_y = 8400, 5400
a_x, a_y = 94, 34
b_x, b_y = 22, 67
token_counts = []
for a_pushes in 100:
for b_pushes in 100:
if a_pushes * a_x + b_pushes * b_x == prize_x:
if a_pushes * a_y + b_pushes * b_y == prize_y:
@keithrozario
keithrozario / privacy.md
Created July 18, 2024 01:24
Privacy Policy

I treat your data very seriously.

We do not store any data.

We will delete it even before you ask -- but if you ask, we'll delete it again.

@keithrozario
keithrozario / iam.py
Created September 22, 2021 07:06
Check which users are not in groups
import boto3
iam = boto3.resource('iam')
def list_users() -> list:
"""
List all users in an account
:return: list of usernames
"""
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
au! BufNewFile,BufReadPost *.{yaml,yml} set filetype=yaml foldmethod=indent
let g:indentLine_color_term = 100
@keithrozario
keithrozario / paginator.py
Created December 5, 2020 11:14
Paginators for DynamoDB
import boto3
# Create your own session
my_session = boto3.session.Session(region_name="regionA", profile_name="profileA")
client = my_session.client('dynamodb')
paginator = client.get_paginator('scan')
# Option 1, paginate through paginator, a bit clunky, but possibly better performance
response_iterator = paginator.paginate(
TableName="kl.Klayers-prodp38.db"
@keithrozario
keithrozario / remove.md
Created June 22, 2020 14:49
removing old commits

git checkout -b <branch_name> git --set-upstream origin <branch_name> git rebase -i

Squash all commits where necessary

:qw

Change commit message where necessary

git push +

@keithrozario
keithrozario / scrapper.py
Created May 9, 2020 04:39
AWS This is my Architecture Scrapper
import requests
import json
import csv
base_url = "https://aws.amazon.com/api/dirs/items/search"
params = {
"item.directoryId": "this-is-my-architecture",
"sort_by": "item.additionalFields.airDate",
"sort_order": "desc",
@keithrozario
keithrozario / powertools.py
Last active May 30, 2020 01:41
Logging with Powertools
from aws_lambda_powertools.logging import Logger
logger = Logger()
@logger.inject_lambda_context
def handler(event, context):
important_list = [1,2,3]