Skip to content

Instantly share code, notes, and snippets.

View dsoprea's full-sized avatar
💭
Head in yesterday. Hands in today. Heart in tomorrow.

Dustin Oprea dsoprea

💭
Head in yesterday. Hands in today. Heart in tomorrow.
View GitHub Profile
@dsoprea
dsoprea / yaml_apply_context.py
Created April 1, 2022 06:51
Replace tokens into YAML during load
import string
import yaml
def load_yaml(f, context=None):
if context is None:
context = {}
def string_constructor(loader, node):
import os
import json
import requests
_PUBLIC_SECRET = os.environ['KLAVIYO_PUBLIC_SECRET']
_API_ROOT = 'https://a.klaviyo.com/api'
_VALID_EXTRA_ATTRIBUTES = [
@dsoprea
dsoprea / sentry_generate_release_commit_arguments.py
Last active September 13, 2024 17:41
Generate a list of commit arguments from a submodules superproject for a Sentry release
#!/usr/bin/env python3
# MIT LICENSE
#
# Copyright 2023 Dustin Oprea
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@dsoprea
dsoprea / assert_yaml_uniqueness.py
Last active January 13, 2024 09:32
Assert Uniqueness In YAML dictionaries using PyYAML
import yaml
def load_and_assert_uniqueness(x):
# We'd like to detect duplicates. Since PyYAML both loads things depth-first
# *and* doesn't give us the parent when processing a child node, we'll index
# of all of the object IDs as we're constructing them, and then see which
# are disappeared from the final hierarchy. Since all we can do is pass a
# class, we need to inline the class in order to load into an index within
# our scope.
@dsoprea
dsoprea / redis_transaction.py
Last active June 28, 2024 05:28
Redis: Transaction Queued Operations
import logging
import collections
_LOGGER = logging.getLogger(__name__)
_OPERATION_METADATA_COLLECTION = \
collections.namedtuple(
'_OPERATION_METADATA_COLLECTION', [
'reader_input_metadata',
'reader_output_metadata',
@dsoprea
dsoprea / dictionary_to_string.py
Created July 20, 2024 09:24
Tools to convert between dictionaries and strings with proper escaping
_ENCODED_ESCAPE_TRANSLATION = str.maketrans({
'\\': r'\\',
',': r'\,',
'=': r'\=',
})
def dictionary_to_string(d):
components = [
@dsoprea
dsoprea / aws_ecs_list_tasks
Last active September 13, 2024 18:13
aws: Poll the tasks running for a certain cluster and task-definition
#!/usr/bin/env python3
"""
Copyright 2024 Dustin Oprea
MIT LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@dsoprea
dsoprea / aws_cloudwatch_make_log_urls.py
Last active September 13, 2024 18:13
aws: Generate URLs for Cloudwatch logs
"""
Copyright 2024 Dustin Oprea
MIT LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@dsoprea
dsoprea / redis_cut_by_prefix
Last active September 13, 2024 18:13
Browse and cleanup a Redis DB. Group and browse like-prefixed keys, and optionally remove.
#!/usr/bin/env python3
"""
Copyright 2024 Dustin Oprea
MIT LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@dsoprea
dsoprea / csv_translate_values
Last active August 29, 2024 22:31
Translate CSV values based on the columns in other CSVs
#!/usr/bin/env python3
"""
Apply data from one or more CSVs to translate values in the CSV on STDIN.
This will only read a certain source CSV once even if provided multiple times to
translate multiple columns in the principal data.
"""
"""
Copyright 2024 Dustin Oprea