This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:80> | |
ServerAdmin [email protected] | |
ServerName api.domain.com | |
ProxyPass / http://127.0.0.1:8000/ | |
ProxyPassReverse / http://127.0.0.1:8000/ | |
</VirtualHost> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# plumber::plumb("country_from_coordinates_api.R")$run(port = 8000) | |
library(plumber) | |
library(httr2) | |
library(rlang) | |
#* @serializer html | |
#* @get / | |
function() { | |
html_content <- '<!DOCTYPE html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
suppressPackageStartupMessages({ | |
library(dplyr) | |
library(tidyr) | |
}) | |
click_data <- tibble( | |
click_id = c("u1", "u1", "u1", "u1", "u1", "u1", "u1", "u1", "u1", "u2", "u2", "u2", "u3", "u3", "u2"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!requireNamespace('pak')) stop("Please, run install.packages('pak')") | |
pkgs <- c( | |
rlang = "rlang", | |
tidyverse = "tidyverse/tidyverse", | |
tidymodels = "tidymodels/tidymodels", | |
jrrosell = "jrosell/jrrosell@main" | |
) | |
pak::pak(pkgs) | |
suppressPackageStartupMessages(purrr::walk(names(pkgs), \(p) { | |
library(p, character.only = TRUE, quietly = TRUE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Level 2 | |
minimal_character_positions <- \(s) { | |
max_len <- max(nchar(s)) | |
for (i in seq_len(max_len)) { | |
for (indices in combn(seq_len(max_len), i, simplify = FALSE)) { | |
char_vectors <- | |
purrr::map(s, \(str, idx = indices) { | |
purrr::map_chr(idx, \(ii) { | |
if (ii <= nchar(str)) substr(str, ii, ii) else NA | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidychatmodels) | |
ollama_llama31 <- | |
create_chat('ollama') |> | |
add_model('llama3.1') | |
chat <- | |
ollama_llama31 |> | |
add_message('What is love? IN 10 WORDS.') |> | |
perform_chat() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Thanks to @koaning for pointing out this visualization in Stack Overflow https://stackoverflow.com/a/49535509/481463 in this video https://www.youtube.com/watch?v=3M2Gmuh5mtI | |
library(tidyverse) | |
library(rayshader) | |
library(viridis) | |
df <- | |
expand_grid( | |
precision = 1:100 / 100, | |
recall = 1:100 / 100, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(magick) | |
library(purrr) | |
library(ggplot2) | |
# Define variables | |
FRAMES <- 30 | |
MEAN1 <- 0 # Mean of the first group | |
MEAN2 <- 0.2 # Mean of the second group | |
FROM <- 2 | |
TO <- 1500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @jrosell: Calculate shortest distance to fuel station from all interest points (useful for feature engineering!) | |
# @jrosell: Use setNames to be sure distance works. | |
# @jrosell: Use rowwise() |> group_split() |> map() |> list_rbind() to be able to get ETA with .progress = TRUE | |
# Original source by @milos-agathon: https://www.youtube.com/watch?v=jmImC0v6qmU | |
# ============================================================================== | |
# Preparations | |
libs <- c( | |
"tidyverse", # Data wrangling and visualization |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(testthat) | |
expected <- c(0L, 8L, 15L, 0L, 5L, 9L, 0L, 2L) | |
cumsum_cut_base <- function(x, cuts = NULL) { | |
g <- rep(0, length(x)) | |
if (!is.null(cuts)) g[cuts] <- 1 | |
unlist(unname(lapply(split(x, cumsum(g)), \(.x) head(c(0, cumsum(.x)), -1)))) | |
} | |
cumsum_cut_rlang <- function(x, cuts) { |
NewerOlder