Skip to content

Instantly share code, notes, and snippets.

View pat-s's full-sized avatar

Patrick Schratz pat-s

View GitHub Profile
@pat-s
pat-s / test.R
Last active March 29, 2023 08:05
blockCV: raster -> terra
#### blockCV old
library(raster)
x <- raster(system.file("external/rlogo.grd", package="raster"))
resolution = 10000
ybin = 3
xbin = 3
@pat-s
pat-s / migrate.sh
Created February 7, 2023 18:47
Migrate from Terraform Cloud to "Remote" storage backend
export TFC_TOKEN=<CHANGEME> # TF cloud token
export WORKSPACE_ID=<CHANGEME> # old TF cloud Workspace ID
export WORKSPACE_ID_NEW=<CHANGEME> # new OTF workspace ID
export TOKEN_REMOTE_BACKEND=<CHANGEME> # OTF token
export REMOTE_BACKEND_URL=<CHANGEME> # OTF URL
### START
HTTP_RESPONSE=$(curl \
--header "Authorization: Bearer "$TFC_TOKEN"" \
@pat-s
pat-s / github-migrate.sh
Created August 23, 2022 21:58
Migrate GH repo via API
### DEPENDENCIES
# - curl
# - jq
### VARIABLES
export REPO_NAME=FIXME
export ORG_NAME=FIXME
export SLEEP_TIME=15
export TOKEN=FIXME # empty scopes are sufficient
@pat-s
pat-s / gist:b0cb9a11e6f3fabe50e05b89915180cf
Created July 18, 2022 08:05
Stripped RSW server image
FROM ubuntu:focal
# set ENV variables
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV TERM=xterm
ENV DEBIAN_FRONTEND=noninteractive
# locale ----------------------------------------------------------------------#
RUN apt update \
# because base::file.rename() is a pain across OS
requireNamespace("fs", quietly = TRUE)
# download cluto zip file
temp = tempfile()
utils::download.file("http://glaros.dtc.umn.edu/gkhome/fetch/sw/cluto/cluto-2.1.2a.zip", temp, quiet = TRUE)
utils::unzip(temp, files = c("cluto-2.1.2/Linux-x86_64/vcluster", "cluto-2.1.2/MSWIN-x86_64/vcluster.exe"))
unlink(temp)
@pat-s
pat-s / collect-mlr3-updates.R
Last active May 16, 2022 00:46
Collects all mlr3 packages updates in the last quarter
library(tidyverse)
library(htmltab)
library(lubridate)
library(pkgsearch)
list_repos = httr::content(httr::GET("https://api.github.com/orgs/mlr-org/repos?per_page=100"))
list_repos_v = unlist(lapply(list_repos, function(x) x$name))
repos_mlr3 = grep("mlr3", list_repos_v, value = TRUE)
# add non-mlr3 repos
@pat-s
pat-s / code.R
Created September 10, 2021 06:35
OpenDataScience Europe 2021 talk - Patrick Schratz
## ----mlr3-config, echo = FALSE---------------------------------------------------------------------------
lgr::get_logger("bbotk")$set_threshold("warn")
lgr::get_logger("mlr3")$set_threshold("warn")
## ----example, fig.show="hide"----------------------------------------------------------------------------
library("mlr3verse", quietly = TRUE)
set.seed(42)
# example tasks
{
"version": "0.9.0",
"description": "The R installation manage: Install, remove, configure R versions.",
"homepage": "https://github.com/pat-s/rcli",
"license": "LGPL-3",
"url": "https://github.com/pat-s/rcli/releases/download/0.9.0/rcli",
"bin": "rcli",
"checkver": "github"
}
if (requireNamespace(c("callr", "git2r", "gert", "cli"), quietly = TRUE)) {
has_git = git2r::in_repository()
if (has_git && Sys.getenv("RSTUDIO") == 1) {
cli::cli_text("Running
{.code gert::git_pull(verbose = FALSE, prune = TRUE, rebase = TRUE)}
in the background.")
callr::r_bg(function() {
gert::git_pull(verbose = FALSE, prune = TRUE, rebase = TRUE)
},
stdout = out <- tempfile(), stderr = err <- tempfile())$wait()
if (requireNamespace(c("callr", "git2r"), quietly = TRUE)) {
has_git = git2r::in_repository()
if (has_git) {
message("Running `git2r::pull()` in the background.")
callr::r_bg(function() {git2r::pull()})$wait()$get_result()
}
}