Skip to content

Instantly share code, notes, and snippets.

View GarrettMooney's full-sized avatar

Garrett Mooney GarrettMooney

View GitHub Profile
@GarrettMooney
GarrettMooney / queries.md
Last active October 29, 2024 23:57
Useful snowflake queries

Schemas in QA but not in Prod

WITH qa AS (
    SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME
    FROM qa_edw_pstg.information_schema.tables
),
prod AS (
    SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME
    FROM prd_edw_pstg.information_schema.tables
@GarrettMooney
GarrettMooney / ui.py
Created October 8, 2024 19:57
Streamlit chatbot template
import uuid
import streamlit as st
#########
# Helpers
#########
def get_completion(question, session_id):
@GarrettMooney
GarrettMooney / create_sagemaker_endpoint.py
Created October 7, 2024 15:29
Create sagemaker endpoint from local artifact and inference.py
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "boto3",
# "sagemaker",
# ]
# ///
import subprocess
import time
from time import gmtime, strftime
@GarrettMooney
GarrettMooney / etl.py
Last active September 30, 2024 21:11
Query athena, return a polars dataframe, subquery via duckdb
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "duckdb",
# "polars",
# "pyarrow",
# "pyathena",
# "s3fs",
# ]
# ///
@GarrettMooney
GarrettMooney / linkedin.py
Created May 2, 2024 15:25
linkedin search
"""View remote jobs in a 3 day interval."""
BASE_URL = "https://www.linkedin.com/jobs/search/"
def get_linkedin_jobs(search, n_days=3, remote=True):
# time
seconds_in_day = 86400
n_seconds = n_days * seconds_in_day
query = BASE_URL + "?f_TPR=r" + str(n_seconds)
from typing import Union
import numpy as np
import pandas as pd
def create_sample_weights(
y_train: np.ndarray,
X_train: Union[np.ndarray, pd.DataFrame]
) -> pd.Series:
y_series = pd.DataFrame({"y": y_train})["y"]
@GarrettMooney
GarrettMooney / binary_outcomes.py
Created January 24, 2023 20:42
Closed form A/B/C/D tests
from numpy import log, exp
from scipy.special import betaln as logbeta
def probability_B_beats_A(α_A, β_A, α_B, β_B):
total = 0.0
for i in range(α_B):
total += exp(
logbeta(α_A + i, β_B + β_A)
- log(β_B + i)
%pip install "whatlies[sentence_tfm]"  # quotes for my fellow zsh users

import numpy as np
from whatlies.language import SentenceTFMLanguage
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression

pipe = Pipeline([
 ("embed", SentenceTFMLanguage('distilbert-base-nli-stsb-mean-tokens')),
@GarrettMooney
GarrettMooney / venv.zsh
Last active November 12, 2020 18:16 — forked from ines/.zshrc
Command to activate / create Python virtual environmment
# venv
# usage:
# $ venv .recsys
function venv {
default_envdir=".env"
envdir=${1:-$default_envdir}
if [ ! -d $envdir ]; then
python3.7 -m virtualenv -p python3.7 $envdir
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m"
@GarrettMooney
GarrettMooney / gpu_toggle.sh
Created May 3, 2020 01:29
Toggle between using GPU for Deep Learning and Video Games.
#!/bin/bash
flag=$1
if [[ $flag == 'DL' ]]; then
# -------------
# Deep Learning
# -------------
echo "Configuring GPU for Deep Learning..."
sudo apt-get install -y libnvidia-common-440
sudo apt-get install -y cuda
sudo apt-get install -y cuda-drivers