Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrick Schratz pat-s

View GitHub Profile
@pat-s
pat-s / github-migrate.sh
Created Aug 23, 2022
Migrate GH repo via API
View github-migrate.sh
### DEPENDENCIES
# - curl
# - jq
### VARIABLES
export REPO_NAME=FIXME
export ORG_NAME=FIXME
export SLEEP_TIME=15
export TOKEN=FIXME # empty scopes are sufficient
View gist:b0cb9a11e6f3fabe50e05b89915180cf
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 \
View install-cluto.R
# 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
Collects all mlr3 packages updates in the last quarter
View collect-mlr3-updates.R
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 Sep 10, 2021
OpenDataScience Europe 2021 talk - Patrick Schratz
View code.R
## ----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
View rcli.json
{
"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"
}
View git-startup-rstudio
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()
View git-pull-rstudio
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()
}
}
View gist:529d386d2e1e9e6ae068db73431f8866
Jun 12 01:03:00 charge2 kernel: [762622.063494] testing the buffer
Jun 12 01:03:00 charge2 kernel: [762622.063505] testing the buffer
Jun 12 01:03:00 charge2 kernel: [762622.063592] testing the buffer
Jun 12 01:03:00 charge2 kernel: [762622.063604] testing the buffer
Jun 12 01:03:01 charge2 CRON[58247]: (ursmaendli) CMD (/home/ursmaendli/charge2/run.sh >> /home/ursmaendli/run-sh.log 2>&1)
Jun 12 01:03:01 charge2 CRON[58248]: (ursmaendli) CMD (/home/ursmaendli/charge2/run-static.sh >> /home/ursmaendli/run-static-sh.log 2>&1)
Jun 12 01:03:02 charge2 containerd[80521]: time="2020-06-12T01:03:02.341916576Z" level=info msg="shim containerd-shim started" address=/containerd-shim/355a87ba8742cd32cd0d779d231a254f64410b04ae06fd07a1616efb84c2781f.sock debug=false pid=58266
Jun 12 01:03:02 charge2 containerd[80521]: time="2020-06-12T01:03:02.397109845Z" level=info msg="shim containerd-shim started" address=/containerd-shim/ef6ccfec1e235dab150e0ec0e1409e821985432e28a324418737a76f1c85f8a3.sock debug=false pid=58300
Jun 12
View RStudio_usethis_selection_browse.R
browse_news <- function(package = NULL) {
# check for pkgdown url
field_url <- desc::desc_get_urls(file = system.file("DESCRIPTION", package = package))[1]
# check if a news site exists for the given url
has_pkgdown <- httr::status_code(httr::GET(paste0(field_url, "/news"))) == 200
if (has_pkgdown) {
view_url((paste0(field_url, "/news")))
return(invisible())
}