Skip to content

Instantly share code, notes, and snippets.

@dmi3kno
dmi3kno / USReciprocalTariffs.csv
Created April 3, 2025 09:42
USReciprocalTariffs
CountryRegion alpha2 alpha3 CountryRegionTariff USReciprocalTariffs
Afghanistan AF AFG 0.49 0.1
Albania AL ALB 0.1 0.1
Algeria DZ DZA 0.59 0.3
Andorra AD AND 0.1 0.1
Angola AO AGO 0.63 0.32
Anguilla AI AIA 0.1 0.1
Antigua and Barbuda AG ATG 0.1 0.1
Argentina AR ARG 0.1 0.1
Armenia AM ARM 0.1 0.1
@dmi3kno
dmi3kno / _brand.yml
Created December 3, 2024 09:14
Quarto branding for Lund University
meta:
name: "Lund Univerisy brand"
link: "https://www.medarbetarwebben.lu.se/grafiskprofil"
color:
palette:
lu-blue: "#000080"
lu-gold: "#9C6114"
bg-pink: "#E9C4C7"
bg-pink-50: "#E9C4C780"
@dmi3kno
dmi3kno / funfactory_arg.R
Created January 17, 2023 19:44
Function factory with changeable argument name
library(magrittr)
logit <- function(u) log(u)-log(1-u)
raise_to_pow <- function(fun, pname_pow=".pow"){
eval(parse(text=gsub(pattern=".pow", replacement=pname_pow,
"function(u, .pow=1, ...) fun(u,...)^(.pow)")))
}
powlogit <- logit %>% raise_to_pow(pname_pow="e")
@dmi3kno
dmi3kno / Gamma_Exponential_Stan.R
Created May 30, 2021 17:39 — forked from mages/Gamma_Exponential_Stan.R
Gamma Exponential with Stan
library(rstan)
stanmodelcode <- "
data {
int<lower=0> N;
int<lower=0> y[N];
}
parameters {
real<lower=0.00001> Theta;
}
model {
@dmi3kno
dmi3kno / rillusion_23.R
Created November 8, 2020 11:33
Optical illusion 23
library(minisvg)
lightpurple <- "#c0c0f2"
darkpurple <- "#9596ce"
x <- 5
s <- x*10
a <- x*sqrt(2)
chkrs_pat <- stag$pattern(width=2*s, height=2*s, id = 'chkrs_pattern',
patternUnits = 'userSpaceOnUse',
stag$rect(x=0, y=0, width =s, height = s, fill=lightpurple),
stag$rect(x=s, y=0, width =s, height = s, fill=darkpurple),
library(tidybayes)
library(ggplot2)
library(hrbrthemes)
m <- 100
s <- 10
dist_df <- tibble::tibble(y=seq.int(0.01,0.99, by=0.05),
arg1_mean=qlnorm(p=y,meanlog=log(m), sdlog=log(s)),
arg2_sd=abs(0.5-y+0.1)*400+100)
@dmi3kno
dmi3kno / match_to_formals.R
Last active June 13, 2020 17:02
Example of formals-aware decorator
is.unset<-function(x)
x==as.list(alist(a=))[[1]]
is.nameempty <- function(x){
nx <- names(x)
if(is.null(nx))
return(rep(TRUE, length(x)))
is.na(nx) | nx==""
}
---
title: 'Tables with references'
author: dmi3kno
date: '2018-01-25'
abstract: |
My goal was to prepare a minimum reproducible example.
output:
pdf_document:
citation_package: natbib
keep_md: yes
library(magick)
library(hocr)
library(bunny)
library(bbx)
library(dplyr)
img <- image_read("https://pbs.twimg.com/media/EXKzsiAWoAYH9Pv?format=png")
img_bw <- img %>%
image_threshold("white", threshold = "5%") %>%
@dmi3kno
dmi3kno / centered_text_minisvg.R
Last active April 30, 2020 21:49
Text centering within different containers
# tips and ideas from
# https://stackoverflow.com/questions/5546346/how-to-place-and-center-text-in-an-svg-rectangle
library(minisvg)
doc <- svg_doc(width = 600, height = 600)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Centered text in circle
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~