Skip to content

Instantly share code, notes, and snippets.

View tanho63's full-sized avatar
🏈

Tan Ho tanho63

🏈
View GitHub Profile
@tanho63
tanho63 / graph_upload.R
Last active January 29, 2021 20:49
Upload file to Microsoft Graph/Sharepoint API
# I struggled with uploading things to Microsoft Graph API/Sharepoint/OneDrive for business - here's the code that finally worked for me.
library(AzureGraph)
library(httr)
# Creates authentication token via browser
graph_token <- AzureGraph::create_graph_login()$token
# Send a PUT request to the Microsoft Graph API
#### Snippet where I write csv files to https://github.com/DynastyProcess/data each week ####
write.csv(values_players,'../data/files/values-players.csv',row.names = FALSE)
write.csv(values_picks,'../data/files/values-picks.csv',row.names = FALSE)
write.csv(values,'../data/files/values.csv',row.names = FALSE)
write.csv(dp_playerids,'../data/files/db_playerids.csv',row.names = FALSE)
data_repo <- git2r::repository('../data') # Set up connection to repository folder
git2r::add(data_repo,'files/value*') # add specific files to staging of commit
git2r::add(data_repo,'files/db_*')
@tanho63
tanho63 / script.R
Last active August 4, 2020 12:51
Build bookdown as epub
#### Convert bookdown to epub ####
library(devtools)
## Clone to folder
book_repo <- "hadley/adv-r"
dest_folder <- "~/documents/github"
@tanho63
tanho63 / pfr-drafted.R
Created August 13, 2020 03:07
PFR while loop
library(rvest)
library(tidyverse)
library(glue)
library(ratelimitr)
library(DBI)
# Ratelimit read_html to 100 pages per minute
lim_readhtml<-limit_rate(read_html,rate(n = 100,period = 60))
# Set parameters of loop
@tanho63
tanho63 / ShinyErrorModals.R
Last active September 5, 2020 12:16
Applying Adv-R, 1: Shiny Error Modals
observeEvent(input$run_main, {
showModal(modalDialog(title = "Please wait", "Loading Data!"))
df_reactivevalues <- tryCatch(
fn_loaddata(df_reactivevalues),
error = function(e) {
Sys.sleep(2)
showModal(modalDialog(title = "Oh no, we've found an error!", e$message))},
warning = function(e) {
@tanho63
tanho63 / sfb_w1.R
Created September 15, 2020 14:25
SFB week 1 matchups
library(ffscrapr) # on CRAN, woop woop!
library(tidyverse)
base_conn <- mfl_connect(2020,
rate_limit_number = 2,
rate_limit_seconds = 3)
sfb_leagues <- mfl_getendpoint(base_conn,
endpoint = "leagueSearch",
SEARCH = "#SFBX Conference") %>%
@tanho63
tanho63 / parse_sportradar_participation.R
Last active November 23, 2021 04:37
one-pipeline parsing of participation data
json_list <- readRDS(url("https://github.com/guga31bb/sport_radar/blob/master/data/participation/c2b24b1a-98c5-465c-8f83-b82e746b4fcf.rds?raw=true"))
plays <- json_list %>%
list() %>%
map(`[`,c("summary","plays")) %>%
tibble() %>%
unnest_wider(1) %>%
hoist('summary','season','week') %>%
mutate(
season = map_dbl(season,pluck,"year"),
@tanho63
tanho63 / position-picker-input.R
Last active November 9, 2022 08:26
pickerInput example
positions <- data.frame(pos = c("QB","RB","WR","TE"),
posdesc = c("Quarterback","Running Back","Wide Receiver","Tight End"))
shinyWidgets::pickerInput(
inputId = 'positions',
label = 'position',
choices = positions$pos,
selected = positions$pos,
multiple = TRUE,
options = list(
@tanho63
tanho63 / scoobydoo_pivot.R
Last active September 25, 2023 19:19
pivot_longer sentinel .value - scoobydoo tidy tuesday
library(tidyverse)
scooby_data <- read.csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-07-13/scoobydoo.csv")
x <-
scooby_data %>%
select(season, title,
starts_with("caught"),
starts_with("captured"),
starts_with("unmask"),
@tanho63
tanho63 / scrape_stream_notes.md
Last active July 22, 2021 00:58
scraping stream questions