This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useEffect} from "react"; | |
/** | |
* A hook that runs an async function on mount with support for cancellation. | |
* | |
* If unmounting before the async function completes, the cleanup function will be called. | |
* @param fn {function} A function that takes a 'cancelled' function as its only argument. | |
* @param inputs {array?} An optional array of inputs to pass to useEffect. | |
* @param cleanup {function?} An optional cleanup function to run on unmount. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generate a UUIDv7 as a string (see also: https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/) | |
* | |
* This function was translated to javascript from the python implementation here: https://github.com/oittaa/uuid6-python | |
* | |
* The UUIDv7 format is designed to encode a Unix timestamp with | |
* arbitrary sub-second precision. The key property provided by UUIDv7 | |
* is that timestamp values generated by one system and parsed by | |
* another are guaranteed to have sub-second precision of either the | |
* generator or the parser, whichever is less. Additionally, the system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An example of how to use boto3 and a concurrent.futures process pool to upload files in parallel. | |
Bonus: when uploading files ending in .gz, the Content-Encoding metadata will be set automatically. | |
""" | |
import os | |
from concurrent.futures import ProcessPoolExecutor, as_completed | |
import boto3 | |
def concurrent_s3_upload(files, bucket, prefix, metadata, remove_gz_extension=True): |