Skip to content

Instantly share code, notes, and snippets.

View kleinlennart's full-sized avatar
💭

Lennart Klein kleinlennart

💭
  • United Nations | Executive Office of the Secretary-General (EOSG)
  • New York
  • LinkedIn in/lennart-klein
View GitHub Profile
@kleinlennart
kleinlennart / structured_output_prompt.py
Last active February 28, 2025 18:19
Snippet for Structured Output Prompt OpenAI API, Loop over DataFrame
import json
from pathlib import Path
import pandas as pd
from dotenv import load_dotenv
from openai import OpenAI
from tqdm import tqdm
# .env
# OPENAI_API_KEY=<API-Key>
@kleinlennart
kleinlennart / ggplot2_map.R
Created January 9, 2025 21:30
Data Visualization Snippets | World Map with Country Dots
library(tidyverse)
library(sf)
# Data --------------------------------------------------------------------
raw_survey <- read_csv(here::here("data", "input", "Survey", "Crisis+Data+Ecosystem+Survey_RAW.csv"))
# Wrangle -----------------------------------------------------------------
# remove the variable descriptions row, only useful for new colnames
@kleinlennart
kleinlennart / snippets.R
Created January 8, 2025 19:09
RStudio Snippets
snippet pak
pak::pak("${1}")
@kleinlennart
kleinlennart / zotero_remove_eprint_extra.ipynb
Created May 26, 2024 17:56
zotero_remove_eprint_extra.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kleinlennart
kleinlennart / .quartoignore
Created January 16, 2024 15:25
.quartoignore Recommended Defaults for Quarto Extensions
template.Rproj
template.html
*_files/
*_cache/

Lennart's Dotfiles

GitHub Gist last commit

@kleinlennart
kleinlennart / .Rprofile
Last active January 29, 2024 09:23
.Rprofile
if (interactive()) {
suppressMessages(require(usethis))
}
if (interactive()) {
suppressMessages(require(devtools))
}
if (interactive()) {
suppressMessages(require(cput))
@kleinlennart
kleinlennart / markdown.md
Created February 17, 2021 19:10
Markdown Snippets
expand stuff
@kleinlennart
kleinlennart / sorting.R
Last active January 27, 2021 20:50
R Sort Columns alphabetically
# Sort all columns alphabetically
dat <- dat[,order(colnames(dat))]
dat <- dat %>% select(sort(current_vars())) # Alternatively
# Reorder each column alphabetically
dat <- map_df(dat, function(x) {sort(x, na.last = TRUE)})