Skip to content

Instantly share code, notes, and snippets.

View GarrettMooney's full-sized avatar

Garrett Mooney GarrettMooney

View GitHub Profile
@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
@GarrettMooney
GarrettMooney / parallel.h
Created October 21, 2019 03:41
parallel for loop in C++
#pragma once
#include <algorithm>
#include <functional>
#include <future>
#include <thread>
#include <vector>
// adapted from https://stackoverflow.com/a/49188371/2055486
@GarrettMooney
GarrettMooney / kl_entropy.R
Created September 28, 2018 04:29
Entropy, KL Divergence, & Rcpp
library(ggplot2)
theme_set(theme_classic())
# Visualizing entropy ---------------------------------------------------------
entropy <- function(p) -sum(p * log(p))
n <- 1e6
p <- runif(n)
q <- 1 - p
z <- matrix(c(p, q), ncol = 2)
ent <- apply(z, 1, entropy)
@GarrettMooney
GarrettMooney / entropy_example.R
Created September 28, 2018 04:22
Entropy & Rcpp
li(ggplot2)
theme_set(theme_classic())
entropy <- function(p) -sum(p * log(p))
n <- 1e6
p <- runif(n)
q <- 1 - p
z <- matrix(c(p, q), ncol = 2)
ent <- apply(z, 1, entropy)
qplot(q, ent, geom = "line") +
@GarrettMooney
GarrettMooney / kl_divergence_example.R
Created September 28, 2018 04:21
KL Divergence & Rcpp
li(ggplot2)
theme_set(theme_classic())
kld <- function(p, q) sum(p * log(p / q))
n <- 1e6
p <- c(0.6, 0.4)
q1 <- runif(n)
q2 <- 1 - q1
z <- matrix(c(q1, q2), ncol = 2)
kl <- apply(z, 1, kld, p = p)