Skip to content

Instantly share code, notes, and snippets.

View jrosell's full-sized avatar

Jordi Rosell jrosell

View GitHub Profile

terra extract points in time efficiently from (xy-regular) zarr.

## Point-in-time (x, y, t) lookup from a cloud Zarr with terra's
## multidimensional reader (GDAL Zarr driver), grouped by chunk.
##
## Each point wants one value: the cell containing (x, y) at the time step
## nearest t. The cost is set by how many distinct Zarr chunks those values
## live in, not by the number of points. So:
##
@CEXT-Dan
CEXT-Dan / OBRC.CPP
Last active April 24, 2026 09:26
The One Billion Row Challenge
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
#include "tchar.h"
#include <iostream>
#include <string>
#include <format>
#include <mutex>
#include <unordered_map>
#include <execution>
library(ggplot2)
all_plots <- list()
m <- as.matrix(penguins[,3:6])
for (i in 1:ncol(m)) {
gg <- ggplot(penguins, aes(bill_len, m[,i])) +
geom_point() +
labs(title = sprintf("Column %i", i))
@jrosell
jrosell / compute-risk-ratio-risk-difference.R
Last active September 26, 2025 07:36
Methods for computing Risk Ratio and Risk Difference.
stopifnot(requireNamespace("rlang"))
rlang::check_installed("pak")
pkgs <- rlang::chr(
"tidymodels",
"marginaleffects",
"parameters",
"modelbased",
"dplyr",
"stringr",
"tibble",
@dgkf
dgkf / cols.R
Last active September 12, 2025 18:26
dplyr at home
#' Column selector for `[` and `[[`
#'
#' @param ... Column names provided as `character` or `symbol` (could be
#' extended to allow other inputs!)
#' @return A `numeric` vector of column indices to select
#'
#' @examples
#' mtcars[cols(cyl, wt)] |> head()
#'
#' mtcars[cols(mpg:wt)] |> head()
@thyngster
thyngster / ga4CookieParser.js
Created April 12, 2025 06:01
GA4 COOKIES PARSER
/**
* Parses GA4 cookies using a measurement ID without polluting the global namespace
* @param {string} measurementId - GA4 measurement ID (e.g., 'G-XXXXXXXX')
* @returns {Object|null} Parsed GA4 cookie data or null if cookies not found
*/
function parseGA4Cookies(measurementId) {
function getCookieValue(name) {
const match = document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)');
return match ? match.pop() : null;
}
library(tidyverse)
library(gutenbergr)
constitution_raw <- gutenberg_download(5)
constitution <- constitution_raw |>
slice(36:546) |>
filter(text != "") |>
mutate(text_lc = str_to_lower(text)) |>
mutate(is_article = str_starts(text_lc, "article")) |>
@jrosell
jrosell / install_and_load.R
Last active November 13, 2026 21:56
This is how I like to check for required installed versions and load packages in my R scripts, including non-CRAN packages. It requires {rlang} and {pak} packages.
if (!requireNamespace('rlang')) stop("Please, run install.packages('rlang')")
rlang::check_required("pak")
pkgs <- rlang::chr(
rlang = "r-lib/rlang@1.1.6.9000",
purrr = "purrr",
tidyverse = "tidyverse/tidyverse",
tidymodels = "tidymodels/tidymodels",
jrrosell = "jrosell/jrrosell@main",
)
pak::pak(pkgs)
@skkzsh
skkzsh / alert.org
Last active November 19, 2024 16:59
org-mode syntax

Note

Note

Tip

Tip

@dceddia
dceddia / bench.sh
Created November 15, 2024 18:30
Language benchmarks
#!/bin/bash
# Function to measure execution time
measure_time() {
start_time=$(date +%s.%N)
"$@"
end_time=$(date +%s.%N)
execution_time=$(echo "$end_time - $start_time" | bc)
echo "Execution time: $execution_time seconds"
}