Skip to content

Instantly share code, notes, and snippets.

View BerriJ's full-sized avatar
🌞

Jonathan Berrisch BerriJ

🌞
View GitHub Profile
@BerriJ
BerriJ / awtrix_spotifiy.yaml
Created August 29, 2023 07:16
Awtrix Spotify
alias: pixelclock_spotify
description: ""
trigger:
- platform: state
entity_id: media_player.spotify_vistagamer
condition: []
action:
- choose:
- conditions:
- condition: state
@BerriJ
BerriJ / periodic_bsplines.cpp
Last active April 5, 2023 13:29
Create periodic B-Splines using Spline2 R-Package
#include <RcppArmadillo.h>
// include header file from splines2 package
#include <splines2Armadillo.h>
// [[Rcpp::export]]
arma::mat splines2_periodic(const arma::vec &x,
const arma::vec &knots,
const unsigned int deg,
const bool &intercept = true)
{
@BerriJ
BerriJ / expose_r_function.cpp
Created January 13, 2023 15:06
Expose R function splines::splineDesign to Rcpp
#include <RcppArmadillo.h>
// Expose splines::splineDesign to Rcpp
mat splineDesign_rcpp(const vec &x, const vec &knots, const int &deg)
{
Rcpp::Environment pkg = Rcpp::Environment::namespace_env("splines");
Rcpp::Function f = pkg["splineDesign"];
mat y = Rcpp::as<arma::mat>(f(knots, x, deg + 1, 0, true));
return y;
}
@BerriJ
BerriJ / efficient_grid_sample.R
Created November 25, 2022 08:29
In R: Draw sample from a grid without creating it (without replacement)
library(microbenchmark)
library(Rcpp)
library(inline)
src <- "int n = as<int>(N);
std::vector<int> s = as< std::vector<int> >(sizes);
std::vector<int> epsilon (s.size());
std::vector<int>::iterator it;
it = s.begin();
it = s.insert ( it , 1 );
@BerriJ
BerriJ / material_cols.R
Last active January 19, 2023 11:58
Snippets for plotting with R
library(dplyr)
library(ggplot2)
library(ggsci)
library(tidyr)
material_pals <- c(
"red", "pink", "purple", "deep-purple", "indigo",
"blue", "light-blue", "cyan", "teal", "green", "light-green", "lime",
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey"
)
@BerriJ
BerriJ / fielddemo.R
Created November 3, 2021 19:42
Demo of handling fields of different dimensions between C++ (via RcppArmadillo) and R
field1 <- fieldtest1()
dim(field1)
field2 <- fieldtest2()
dim(field2)
field3 <- fieldtest3()
dim(field3)
field1out <- FieldInfieldOut(field1)
@BerriJ
BerriJ / Dockerfile
Created August 18, 2021 10:30
Dockerfile vscDebugger Problem
FROM ubuntu:focal
SHELL ["/bin/bash", "-c"]
ENV R_VERSION=4.1.1 \
# See https://packagemanager.rstudio.com/client/#/repos/1/overview
R_REPOS=https://packagemanager.rstudio.com/all/__linux__/focal/4526215 \
DISPLAY=:0 \
TZ=Europe/Berlin
@BerriJ
BerriJ / test.cpp
Created January 7, 2021 16:01
Example Rcpp armadillo comparison double to vec
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace arma;
// [[Rcpp::export]]
vec testfun(const vec &x,
const double &y,
const double &z)
{
vec out = ((y < x) - z) % (x - y);
@BerriJ
BerriJ / Main.tex
Last active September 29, 2020 07:18
latexmk_reprex_files
% !TEX root = Main.tex
\documentclass{article}
\usepackage[round]{natbib}
\bibliographystyle{abbrvnat}
\begin{document}
\cite{geng2017relationship}
@BerriJ
BerriJ / app.R
Created August 28, 2019 08:13 — forked from PaulC91/app.R
return key trigger actionButton click in shiny example
library(shiny)
ui <- fluidPage(
tags$head(includeScript("returnClick.js")),
textInput("myText", "", placeholder = "Enter text then hit return", width = "100%"),
actionButton("myButton", "Go!"),
verbatimTextOutput("textOutput")