Skip to content

Instantly share code, notes, and snippets.

View danielloader's full-sized avatar

Daniel Loader danielloader

  • 03:40 (UTC +01:00)
View GitHub Profile
@DomWeldon
DomWeldon / README.md
Last active January 25, 2023 17:39
SSM + pydantic: ARNs in environment variables are queried at load time

SSM + Pydantic

Query values from SSM when deployed, by placing an SSM ARN as the environment variable

Background

I wanted to query secrets from SSM at runtime, to laod them into a pydantic.BaseSettings settings object, but still be able to pass standard values during development (and I guess, if I want, in prod).

I've done a couple of similar implementations before, but they have always felt clunky and involved altering the object after instantiation, or hard coding which values to take out of SSM.

@noxdafox
noxdafox / max_queue_size_pool.py
Created April 15, 2018 17:58
This code snippet shows how to wrap a concurrent.futures.Executor class to provide a limited queue size.
from threading import BoundedSemaphore
from concurrent.futures import ProcessPoolExecutor
class MaxQueuePool:
"""This Class wraps a concurrent.futures.Executor
limiting the size of its task queue.
If `max_queue_size` tasks are submitted, the next call to submit will block
until a previously submitted one is completed.
@tobywf
tobywf / boto3-gzip.py
Last active October 18, 2023 17:32
GZIP compressing files for S3 uploads with boto3
from io import BytesIO
import gzip
import shutil
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'):
"""Compress and upload the contents from fp to S3.
If compressed_fp is None, the compression is performed in memory.
"""
@oldo
oldo / video-metada-finder.py
Last active March 2, 2023 22:33
A python function utilising `ffprobe` to find any metadata related to a video file. Examples of what it can find include bitrate, fps, codec details, duration and many more. This gist returns the video height and width as an example.
#!/usr/local/bin/python3
import subprocess
import shlex
import json
# function to find the resolution of the input video file
def findVideoMetada(pathToInputVideo):
cmd = "ffprobe -v quiet -print_format json -show_streams"
args = shlex.split(cmd)
args.append(pathToInputVideo)
@veselosky
veselosky / s3gzip.py
Last active May 8, 2023 21:42
How to store and retrieve gzip-compressed objects in AWS S3
# vim: set fileencoding=utf-8 :
#
# How to store and retrieve gzip-compressed objects in AWS S3
###########################################################################
#
# Copyright 2015 Vince Veselosky and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# www.fduran.com
# exclude a process from being killed by oom killer
echo -17 > /proc/$PID/oom_adj
# The possible values of oom_adj range from -17 to +15. The higher the score, more likely the associated process is to be killed by OOM-killer: https://lwn.net/Articles/317814/