Skip to content

Instantly share code, notes, and snippets.

View jrosell's full-sized avatar

Jordi Rosell jrosell

View GitHub Profile

commonkmark's markdown nested tags alternatives

What if we don't want to use raw html?

<div>What's <div>There</div></div>

What other tags can we nest using commonkmark without raw html?

library(ggplot2)
# expected plot gg_manual
manual_plots <- list()
manual_plots[[1]] <- ggplot(penguins, aes(bill_len, m[,1])) +
geom_point() +
labs(title = "Column 1")
manual_plots[[2]] <- ggplot(penguins, aes(bill_len, m[,2])) +
geom_point() +
labs(title = "Column 2")
@jrosell
jrosell / cloudflare-crawl.sh
Last active March 13, 2026 09:03
Crawl an entire site using cloudflare. Keep in mind, that the free tier only gets 100 pages. You can read more info than the official docs here: https://github.com/jbobbink/seo-and-crawling-skills/blob/main/cloudflare-crawl/SKILL.md
# Get your API Key with Broser rendering permissions here: https://dash.cloudflare.com/profile/api-tokens
CLOUDFLARE_ACCOUNT_ID="<your_cloudflare_account_id>"
CLOUDFLARE_API_TOKEN="<your_cloudflare_api_token>"
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/browser-rendering/crawl" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"url": "https://www.thediar.com/"
# Reference: By Josh Goldstein from Dirk Eddelbuettel on https://mastodon.social/@eddelbuettel/116132645744985793
library(data.table)
cw <- data.table(ChickWeight)
# fmt: skip
cw21 <- (
cw[Time %in% c(0, 21)]
[, Weight := weight]
[, Group := factor(paste0("Diet_", Diet))]
@jrosell
jrosell / sse.R
Created March 2, 2026 20:43
HTTP streaming and Server-Sent Events in R with nanonext
# pak::pak("r-lib/nanonext")
library(nanonext)
conns <- list()
handlers <- list(
handler_stream("/stream",
on_request = function(conn, req) {
conn$set_header("Content-Type", "application/x-ndjson")
conns[[as.character(conn$id)]] <<- conn
conn$send('{"status":"connected"}\n')
@jrosell
jrosell / dictionaries.md
Last active February 12, 2026 13:53
Do you want to merging R objects like dictionaries in R? It seems like using base vectors are the fastest of the explored options to merge like dictionaries in R. 15 times faster than purrr::list_modify, fastmap or collections::dict
title Merging R objects like dictionaries in R
format html

Let's explore how to merge lists, enviroments or vectors like dictionaries in R.

pak::pak(c(
  "purrr",
@jrosell
jrosell / image-embeddings.qmd
Last active February 3, 2026 16:44
Create and search image embeddings using torch, mobilenet v3, rchroma and R
---
title: "Create and search image embeddings using torch, mobilenet v3, rchroma and R"
---
Prepare torch, and mobilenet v3 embeddings.
```{r}
if (!rlang::is_installed("torch")) {
# https://torch.mlverse.org/docs/articles/installation#pre-built
options(timeout = 90000)
@jrosell
jrosell / r.json
Created January 9, 2026 09:02
R snippets for code autocompletion. Copy-paste-modify cases are good snippets candidates.
{
"lib": {
"prefix": "lib",
"body": "library(${1:package})",
"description": "Attach an R package"
},
"src": {
"prefix": "src",
"body": "source(\"${1:file.R}\")",
"description": "Source an R file"
@jrosell
jrosell / reduce-loop-using-pipes.R
Last active December 19, 2025 12:31
Reduce loops using purrr base R pipe. Inspired by https://masalmon.eu/2023/07/26/reduce/
library(purrr)
# The intial information
elements <- tibble::tribble(
~key , ~values ,
"Barbie" , "shoes" ,
"Oppenheimer" , "history"
)
# Aditional values we want to proces
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.