This gist contains some useful stuff for profiles.
Currently:
- bash
- R
- Visual Studio code
library(rvest) | |
library(stringr) | |
webpage <- read_html("https://en.wikipedia.org/wiki/Magic_8-Ball") | |
# Find the answers | |
answers <- | |
webpage %>% | |
html_nodes("dd") %>% | |
html_text() %>% |
(defn print-log | |
[x] | |
(do | |
(if (not (nil? x)) (println x)) | |
x)) |
tau <- function(hg, ag, home_rates, away_rates, rho) { | |
case_when( | |
(hg == 0) && (ag == 0) ~ 1 - home_rates * away_rates * rho, | |
(hg == 0) && (ag == 1) ~ 1 + home_rates * rho, | |
(hg == 1) && (ag == 0) ~ 1 + away_rates * rho, | |
(hg == 1) && (ag == 1) ~ 1 - rho, | |
TRUE ~ 1 | |
) | |
} |
# CF: www.coursera.org/learn/ml-clustering-and-retrieval/lecture/aZCHX/optional-improving-efficiency-through-multiple-tables | |
tibble(x = seq(0, 0.20, 0.001)) %>% | |
crossing(h = 1:4) %>% | |
mutate(single = 1 - (1-x)^h -h*x*(1-x)^(h-1), | |
multiple = (1 - (1-x)^h)^(h+1), | |
n_lines = h + 1) %>% | |
gather(key, value, -x, -h, -n_lines) %>% | |
ggplot(aes(x = x, y = value, | |
colour = key, group = key)) + | |
geom_path() + |
library(tidyverse) | |
library(rgdal) | |
library(plotKML) | |
#Set input and output directories | |
os50_contours_dir <- here::here("~/Downloads/contours/") | |
output_dir <- here::here("~/Downloads/kml/") | |
#Load all shapefiles in input directory | |
shape_filenames <- list.files(os50_contours_dir, "*line.shp") |
library(tidyverse) | |
shot_counts <- read_csv(here::here("data/shot_counts.csv")) | |
# Interpolate points | |
shot_counts_tween <- shot_counts %>% | |
filter(season < 2018) %>% | |
group_by(season) %>% | |
arrange(desc(count)) %>% | |
mutate(rank = row_number()) %>% |
This gist contains some useful stuff for profiles.
Currently:
library(tidyverse) | |
stirling_formula <- function(n) sqrt(2*pi*n)*(n / exp(1))^n | |
x <- 1:10 | |
breaks_log10 <- 1:10 %>% | |
map_dbl(~ 10^.x) %>% | |
map(~ .x*(1:10)) %>% | |
unlist() |
log <- function(f, ...) { | |
function_name <- as.character(substitute(f)) | |
dots <- list(...) | |
args <- paste0(dots, collapse = ",") | |
function_result <- f(...) | |
print(stringr::str_glue("{function_name}({args}) -> {function_result}")) | |
function_result |