Skip to content

Instantly share code, notes, and snippets.

View jcary741's full-sized avatar
👾
New challenges

Jay Cary jcary741

👾
New challenges
  • Chloris Geospatial
View GitHub Profile
@jcary741
jcary741 / useEffectAsync.js
Created June 13, 2023 15:03
useEffectAsync: a cancellable and async version of the React useEffect hook
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.
*
@jcary741
jcary741 / uuid7.js
Created September 6, 2022 16:30
UUIDv7 in Javascript
/**
* 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
@jcary741
jcary741 / concurrent_s3_upload.py
Created August 16, 2022 17:55
Python upload files to S3 in parallel using concurrent.futures and boto3
"""
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):