Skip to content

Instantly share code, notes, and snippets.

View CoryMcCartan's full-sized avatar

Cory McCartan CoryMcCartan

View GitHub Profile
@CoryMcCartan
CoryMcCartan / expense_split.R
Last active June 23, 2025 15:55
Find a sparse set of payments to settle expenses
# vector of net paid/owed, i.e., positive means owed money
b = c(Alice=-15, Bob=130, Charlie=-125, Diane=150, Ed=20, Frank=-160)
stopifnot(sum(b) == 0)
n = length(b)
m = n * (n - 1) / 2
A = combn(n, 2, function(x) {
out = numeric(n)
out[x] = c(1, -1)
out
@CoryMcCartan
CoryMcCartan / primary_model.R
Created August 30, 2023 21:15
Replication and investigation of "What Are Trump's Chances Of Winning The GOP Primary?" <https://fivethirtyeight.com/features/trump-chances-to-win-republican-primary/>
library(tidyverse)
library(janitor)
library(rvest)
library(rstanarm)
library(posterior)
# load data, add 2024 candidates
page <- read_html("https://fivethirtyeight.com/features/trump-chances-to-win-republican-primary/")
d <- html_table(page) |>
@CoryMcCartan
CoryMcCartan / fix_rstudio_macos.sh
Created March 17, 2023 19:56
Simple script to run after reinstalling Rstudio on new Macs.
#!/usr/bin/env bash
RSTUDIO=/Applications/RStudio.app/Contents
# find Quarto and give instructions for putting it and pandoc on the path
QUARTO_PATH=$(find $RSTUDIO -name "quarto" -type d | head -n 1)
echo 'Add the following to your $PATH:'
echo "PATH=\$PATH:$QUARTO_PATH/bin/"
echo "PATH=\$PATH:$QUARTO_PATH/bin/tools"