Skip to content

Instantly share code, notes, and snippets.

View mikegrima's full-sized avatar

Mike Grima mikegrima

View GitHub Profile
@mikegrima
mikegrima / event.json
Created August 20, 2019 18:55
SNS Lambda Sample Invocation Event
{
"Records": [
{
"EventSource": "aws:sns",
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:REGION:ACCOUNT:TOPICNAME:SOME-ID",
"Sns": {
"Type": "Notification",
"MessageId": "SOME-ID",
"TopicArn": "arn:aws:sns:REGION:ACCOUNT:TOPICNAME",
@mikegrima
mikegrima / pytest_fixture_mock_moto_lambda.py
Last active March 25, 2024 15:41
pytest fixture to mock out the moto AWS Lambda capability such that it DOES NOT try to execute the code in a Docker container
import pytest
import moto
from mock import mock, patch
from moto import mock_lambda
@pytest.fixture(scope='function')
def aws_credentials():
"""Mocked AWS Credentials for moto."""
@mikegrima
mikegrima / strip_unicode_from_dict.py
Created December 12, 2019 20:21
Strip unicode from Python 2 Dictionary
# Strip out the unicode keys from a Python 2 dictionary (also includes nested Lists, Dicts, and Sets):
def py2_strip_unicode_keys(blob):
"""For Python 2 Only -- this will convert unicode keys in nested dictionaries to standard strings."""
if type(blob) == unicode:
return str(blob)
elif type(blob) == dict:
for key in list(blob.keys()):
value = blob.pop(key)
blob[str(key)] = py2_strip_unicode_keys(value)
@mikegrima
mikegrima / edit_brave_dictionary.md
Last active December 12, 2024 19:40
Edit Brave Browser Dictionary

Fix Brave Browser Dictionary

If you have ever mistakenly added a word to the Brave browser dictionary, you need to manually edit the Custom Dictionary.txt file.

As of March 2020, the Brave UI lacks a feature to do this.

Where is the file?

This will depend on your OS. Google for where this is on your OS.

The file on macOS is at: ~/Library/Application\ Support/BraveSoftware/Brave-Browser/Default/Custom\ Dictionary.txt.

@mikegrima
mikegrima / proper_speed.md
Last active April 11, 2025 05:30
Make Ur-Quan Masters Playable

The Ur-Quan Masters Gameplay Speed Reduction

I loved playing Star Control on the Sega Genesis and was really happy that The Ur-Quan Masters came out. However, I find that the ship combat speed is way too fast. If you've played the Sega Genesis version of Star Control, you'd be used to a much slower gameplay speed.

It turns out that you can make Ur-Quan Masters run at a similar (or whatever) speed you want: you just need to edit the source code to do this. However, the good news is, it's pretty straightforward.

TL;DR: What do I fix?

@mikegrima
mikegrima / unjson.py
Last active May 9, 2023 21:14
Un-json nested JSON strings from AWS Config
import datetime
import json
from typing import Any
from urllib.parse import unquote_plus
def un_wrap_json(json_obj: Any) -> Any:
"""Helper function to unwrap nested JSON in the AWS Config resource configuration."""
# pylint: disable=C0103,W0703,R0911
# Is this a field that we can safely return?
@mikegrima
mikegrima / get_regions.py
Created June 27, 2022 16:41
Get the available regions for a given AWS service
# Get the available regions for a given AWS serivce:
# As seen on: https://github.com/boto/boto3/issues/188
import boto3
print(boto3.session.Session().get_available_regions('sns'))
# ['af-south-1', 'ap-east-1', 'ap-northeast-1', 'ap-northeast-2', 'ap-northeast-3', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ap-southeast-3', 'ca-central-1', 'eu-central-1', 'eu-north-1', 'eu-south-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'me-south-1', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2']
@mikegrima
mikegrima / boto_sts_bullshit.py
Created August 26, 2022 17:07
Boto3 STS endpoint "fun"
# If doing STS things, you will need to make sure that you use the proper STS endpoint now.
# You need to remember that you need to pass in the endpoint URL. Use this for CloudAux:
from typing import Any, Dict, List
from botocore.client import BaseClient
from cloudaux import sts_conn
from cloudaux.aws.decorators import paginated
ROLE_TO_ASSUME = "AssumeThisRole"
ACCOUNT_NUMBER = "012345678910"
@mikegrima
mikegrima / README.md
Last active November 23, 2022 23:38
GitHub GraphQL Queries

GitHub GraphQL is annoying AF.

These are some sample queries that I have needed to do and am logging it here so I don't forget them.

API endpoint: https://api.github.com/graphql, Method: POST. Authorization requires a Bearer token, and apparently: Personal access tokens with fine grained access do not support the GraphQL API... So that's lame! (as of November 2022)

@mikegrima
mikegrima / conftest.py
Last active December 22, 2022 01:51
Mock Python retry decorator
"""Pytest fixutre for mocking out the retry decorator as found here: https://pypi.org/project/retry/."""
import mock
from typing import Callable, Generator
import pytest
@pytest.fixture
def mock_retry() -> Generator[None, None, None]:
"""This mocks out the retry decorator so things don't retry or block."""
def mock_retry_decorator(*args, **kwargs) -> Callable: