Skip to content

Instantly share code, notes, and snippets.

View epeters3's full-sized avatar

Evan Peterson epeters3

View GitHub Profile
@epeters3
epeters3 / .bash_profile
Created August 28, 2018 15:14
My .bash_profile that I like to use
### VISUAL TERMINAL SETTINGS
############################
# Configure prompt
EMOJIS=("🌮" "🍍" "🎉" "🚀")
DEFAULT_EMOJI=${EMOJIS[$RANDOM % ${#EMOJIS[@]} ]}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
@epeters3
epeters3 / embeddings_playground.py
Last active February 3, 2020 19:11
Fast Querying of Word Embeddings Using `sklearn.neighbors.BallTree`
import io
import typing as t
import pickle
import os
import numpy as np
from tqdm import tqdm
from sklearn.neighbors import BallTree
# The embedded word vectors that work with this gist can be downloaded at
@epeters3
epeters3 / recognize_intent.py
Last active March 6, 2020 23:06
This is a naive system for intent recognition, for use in dialogue systems. Other intents can be added. This system is naive because it makes the assumption that the sentence embeddings of all natural language instantiations of an intent will be within two standard deviations of the intent's examples centroid. This is a heuristic.
from statistics import mean
from math import sqrt
from functools import reduce
from sentence_transformers import SentenceTransformer
import numpy as np
from scipy.spatial.distance import cosine
model = SentenceTransformer("distilbert-base-nli-stsb-mean-tokens")
@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
@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 / 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 / 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 / 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-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 / 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"