Skip to content

Instantly share code, notes, and snippets.

View jmcastagnetto's full-sized avatar
🇵🇪
Focusing

Jesus M. Castagnetto jmcastagnetto

🇵🇪
Focusing
View GitHub Profile
@jmcastagnetto
jmcastagnetto / README.md
Last active April 3, 2025 12:26
2025-04-02: New USA tariffs
@jmcastagnetto
jmcastagnetto / rag_duckdb_helper.md
Created March 17, 2025 16:37
Quick notes on creating a local duckdb helper using RAG with aichat and ollama

DIY - build your own dudckdb local helper with aichat and ollama using RAG

Caveat: The following "works for me"™, and it is kept simple because I implemented in on my 2016 refurbished Thinkpad P50. Also, I've done very minor testing of prompts, and the majority have worked, but YMMV.

This recipe assumes that you have already have ollama and aichat installed on your local machine. If you don't have them installed, you can follow the instructions in the following links:

There are different ways to install those two, so pick the one you are most comfortable with. I installed them on my laptop directly, but you might like to use docker instead.

@jmcastagnetto
jmcastagnetto / README.md
Last active April 25, 2024 14:22
Example showing the truncation in rio::import() with malformed CSV files
@jmcastagnetto
jmcastagnetto / if_else_ejemplos.R
Created November 20, 2023 15:05
Ejemplo de uso de "if ... else ..." en R
library(tidyverse)
v1 <- LETTERS[1:20]
v1
for (i in 1:length(v1)) {
if (i %% 2 == 0) {
v1[i] <- tolower(v1[i])
} else {
v1[i] <- "-"
}
@jmcastagnetto
jmcastagnetto / barplot-with-labels-on-top.R
Created September 29, 2022 15:45
Simple barplot with labels on top (ggplot2)
library(tidyverse)
library(palmerpenguins)
ggplot(
penguins,
aes(y = species, group = sex, fill = sex)
) +
geom_bar(width = .4) +
geom_text(aes(label = paste("Penguin species:", species), x = 0), nudge_y = .3, hjust = 0, size = 6) +
theme_void() +
@jmcastagnetto
jmcastagnetto / test-pivot-wider.R
Created March 24, 2022 17:53
pivot_wider() on a char column
library(tidyverse)
d <- tibble(
id = c(1, 1, 2, 2),
foo = c("oh", "no", "oh", "no"),
bar = c("hmmm", "ok", "right", "sure?")
)
d %>%
pivot_wider(
@jmcastagnetto
jmcastagnetto / plot-map.R
Created March 11, 2022 21:17
Map showing the asymmetric distribution of the ratio of excess deaths to COVID-19 deaths (2020-2021)
# Data source: http://ghdx.healthdata.org/record/ihme-data/covid_19_excess_mortality
library(tidyverse)
library(sf)
library(rnaturalearth)
library(ggridges)
library(patchwork)
world_map <- ne_countries(type = "countries", returnclass = "sf")
@jmcastagnetto
jmcastagnetto / map-peru-commuting-zones-provinces.R
Last active January 13, 2022 13:33
Plot map of Peru's Commuting Zones and of its provinces as comparison
# Using data from https://data.humdata.org/dataset/commuting-zones
library(tidyverse)
library(sf)
library(geodata)
library(patchwork)
peru_map <- gadm("Peru", level = 2, path = ".") %>%
st_as_sf()
csv <- "~/Downloads/data-for-good-at-meta-commuting-zones-july-2021.csv"
@jmcastagnetto
jmcastagnetto / preproc-data.R
Created January 12, 2022 15:48
Cruzar datos de positivos con vacunados (COVID-19, Peru - basado en datos abiertos del MINSA")
library(tidyverse)
library(arrow)
# RDS de https://github.com/jmcastagnetto/covid-19-peru-limpiar-datos-minsa
positivos <- readRDS("tmp/positivos_covid_aumentado.rds") %>%
select(id_persona, fecha_resultado, metododx) %>%
distinct() %>%
mutate(
id_persona = as.integer(id_persona)
)
@jmcastagnetto
jmcastagnetto / covid19-new-cases-nyt-spiral-graph.R
Created January 10, 2022 20:29
Una versión del gráfico espiral del NYT para los nuevos casos COVID-19 del Perú
# Ref: https://bydata.github.io/nyt-corona-spiral-chart/
# https://github.com/bydata/nyt-corona-spiral-chart/blob/main/spiral-chart.R
library(tidyverse)
library(lubridate)
library(ggtext)
library(patchwork)
owid_url <- "https://github.com/owid/covid-19-data/blob/master/public/data/owid-covid-data.csv?raw=true"
country <- "Peru"