Skip to content

Instantly share code, notes, and snippets.

View epeters3's full-sized avatar

Evan Peterson epeters3

View GitHub Profile
@epeters3
epeters3 / cloudwatch-log-events-with-metadata.ts
Last active July 5, 2023 21:57
CloudWatch Log Events With Metadata
type JSONValue =
| string
| number
| boolean
| { [x: string]: JSONValue }
| Array<JSONValue>;
/**
* A CloudWatch Logs type.
*/
@epeters3
epeters3 / gpt4all_j.py
Last active May 1, 2023 22:29
A bare-bones CLI for interacting with the `GPT4All-J@v1.2-jazzy` LLM.
from fire import Fire
import torch
from transformers import pipeline
def main():
generate_text = pipeline(
model="nomic-ai/gpt4all-j",
revision="v1.2-jazzy",
torch_dtype=torch.bfloat16,
@epeters3
epeters3 / aliases.sh
Last active February 20, 2024 22:15
My Favorite Bash Aliases ❤️
# Allows executing `watch` on an alias. Source: https://unix.stackexchange.com/a/25329
alias watch="watch "
# GIT
alias glol="git log --oneline"
alias gri="git rebase --interactive"
# Push the current branch to the remote origin.
alias gpo="git push origin $(git rev-parse --abbrev-ref HEAD)"
alias gpfo="git push --force-with-lease origin $(git rev-parse --abbrev-ref HEAD)"
@epeters3
epeters3 / upload-signed-gcs-url.ts
Last active September 2, 2021 19:33
Upload file using GCS singed URL in Typescript
import axios from "axios";
const uploadFile = async (
file: File,
signedUrl: string
): Promise<void> => {
await axios.put(signedUrl.replace(/"/g, ""), file, {
headers: {
"Content-Type": "application/octet-stream",
"X-Goog-Content-Length-Range": "1,1000000"
@epeters3
epeters3 / python-gcs-signed-urls-code.py
Last active September 2, 2021 19:35
Generating signed GCS upload URLs in Python.
from typing import Optional
from datetime import timedelta
from google import auth
from google.auth.transport import requests
from google.cloud.storage import Client
def make_signed_upload_url(
bucket: str,
@epeters3
epeters3 / python-gcs-signed-urls-service-account.tf
Last active September 2, 2021 18:17
Service account config for Cloud Run service which can generate signed GCS upload URLs.
resource "google_storage_bucket_iam_member" "bucket_admin" {
bucket = google_storage_bucket.my_bucket.name
role = "roles/storage.admin" # this includes the `roles/storage.objectCreator` role
member = "serviceAccount:${google_service_account.my_service_account.email}"
}
resource "google_project_iam_member" "token_creator" {
project = "my-gcp-project"
role = "roles/iam.serviceAccountTokenCreator"
member = "serviceAccount:${google_service_account.my_service_account.email}"
@epeters3
epeters3 / python-gcs-signed-urls-bucket.tf
Last active September 2, 2021 18:16
Terraform config for GCS bucket which will support signed upload URLs
resource "google_storage_bucket" "my_bucket" {
name = "my-unique-bucket-name"
cors {
origin = ["*"]
method = ["*"]
response_header = [
"Content-Type",
"Access-Control-Allow-Origin",
"X-Goog-Content-Length-Range"
]
@epeters3
epeters3 / docker-compose-shield.py
Last active July 1, 2021 16:37
Error-handling middleware for the docker-compose CLI. Greps through the stdout of a docker-compose command, finding the highest exit code produced by any services that exited prematurely. After docker-compose exits, prints the message associated with that highest code then exits with that code. Useful when you want to exit with an error code if …
"""
Error-handling middleware for the docker-compose CLI. Greps through the stdout of a docker-compose command,
finding the highest exit code produced by any services that exited prematurely. After docker-compose
exits, prints the message associated with that highest code then exits with that code. Useful
when you want to exit with an error code if *any* of your containers fail, and not just if the one
specified by `--exit-code-from` fails.
Example usage:
```
@epeters3
epeters3 / ubuntu-gpu-post-install-setup.sh
Last active May 24, 2023 15:39
Ubuntu Clean Install Post-Setup (w/GPU)
# ENVIRONMENT
#############
cd ~
mkdir code
mkdir code/sandbox
# Make desktop environment clock be AM/PM instead of 24h.
gsettings set org.gnome.desktop.interface clock-format '12h'
# DEVELOPER ESSENTIALS
@epeters3
epeters3 / install_cuda.sh
Last active May 29, 2020 17:19
Install latest CUDA toolkit and drivers on Ubuntu
# Register the Ubuntu Nvidia PPA
add-apt-repository ppa:graphics-driver/ppa
apt update
ubuntu-drivers autoinstall
# Restart the machine
reboot
# Then, once rebooted...
# Install the latest toolkit