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_load_and_assert_uniqueness.py
Last active October 11, 2024 03:02
Prevent dupicate keys in dictionaries
"""
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
copies of the Software, and to permit persons to whom the Software is
@dsoprea
dsoprea / hierarchy.py
Last active September 13, 2024 18:12
Tools to work with hierarchical data
"""
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
copies of the Software, and to permit persons to whom the Software is
@dsoprea
dsoprea / diff.py
Last active September 13, 2024 18:12
Tools to diff data
"""
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
copies of the Software, and to permit persons to whom the Software is
@dsoprea
dsoprea / photoframe_zip_expander_and_uniquifier
Last active September 7, 2024 08:28
Find all ZIPs in the source path, extract all files, and rename base portion of the output name to be the SHA1 digest of the data of that file.
#!/usr/bin/env python3
# Requirements: tqdm
import sys
import os
import argparse
import logging
import zipfile
import tempfile
@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
@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 / 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 / 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 / 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 / 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',