Skip to content

Instantly share code, notes, and snippets.

View knbknb's full-sized avatar
💭
🙅‍♀️💡💤😴🛌🤪🧔

Knut Behrends knbknb

💭
🙅‍♀️💡💤😴🛌🤪🧔
View GitHub Profile
@knbknb
knbknb / cleanup-gitlab-pipelines.sh
Created February 20, 2023 17:18 — forked from chrishoerl/cleanup-gitlab-pipelines.sh
Bulk delete gitlab pipelines older than a given date
#!/bin/bash
# Purpose: Bulk-delete GitLab pipelines older than a given date
# Author: github.com/chrishoerl
# GitLab API: v4
# Requirements: jq must be instaled ($ sudo apt install jq)
# API example: https://gitlab.example.com/api/v4/projects
# API example: https://gitlab.example.com/api/v4/projects/<projectid>/pipelines
#
# NOTE: Script is just a dryrun. To really delete pipelines, simply uncomment line 49 to activate
#
@knbknb
knbknb / ubuntu-custom-setup.sh
Last active March 8, 2023 14:13 — forked from riccardopedrielli/ubuntu-workstation-setup.sh
Ubuntu workstation setup
#!/usr/bin/env bash
set -Eeu
trap 'STATUS=${?}; echo "${0}: Error on line ${LINENO}: ${BASH_COMMAND}"; exit ${STATUS}' ERR
trap 'rm -rf ${tempDir}' EXIT
readonly supportedUbuntuVersion="22.04"
readonly tempDir="/tmp/setup"
readonly devDir="${HOME}/dev"
readonly scriptsDir="${devDir}/scripts"
@knbknb
knbknb / snaps-list-updates-recent.sh
Last active May 18, 2023 10:05
bash: snaps-list-updates-recent.sh
#!/usr/bin/env bash
# snaps-list-updates-recent.sh
# checks all installed snaps by name,
# lists them by latest update date.
tempfile=/tmp/snaps-$(date +%Y+%m-%d).txt
rm -f $tempfile
# can take a few seconds to run.
# therefore write to temp file.
snap_names=$(snap list \
@knbknb
knbknb / perl-html-parser-snippets-01.sh
Last active January 19, 2024 08:02
perl: HTML::Parser from command line
#!/usr/bin/env bash
# HTML::Parser has a convenient option to strip Declarations
# by adding a handler.
# (from Stackoverflow q 16358962)
perl -MHTML::Parser -we '
$p = HTML::Parser->new(default_h => [sub {print @_},"text"] );
$p->handler(declaration => "");
$p->parse_file(shift) or die "Cannot parse: $!"; ' infile.html
# HTML::TreeBuilder module is also useful to remove elements and attributes
@knbknb
knbknb / hackernews_comment_collapser.userscript.js
Last active November 30, 2023 19:17
(JS, defunct) Sketch of a Browser userscript for news.ycombinator.com
// ==UserScript==
// @name HN Comment Collapse/Expd Button Injector
// @version 1
// @grant none
// @namespace http://userscripts.org/people/14536
// @description Toggle all comments from collapsed to expanded state
// @match https://news.ycombinator.com/*
// @author Knut Behrends, ChatGPT
// ==/UserScript==
(function() {
# benchmarking the new parsnip release 1.0.3 vs previous 1.0.2
#
# forked from: @simonpcouch
# https://gist.github.com/simonpcouch/651d0ea4d968b455ded8194578dabf52
# gist name:simonpcouch/parsnip_speedup.R
# 2022-11-22
#
library(tidymodels)
# with v1.0.2 ------------------------------------------------------------
@knbknb
knbknb / save-ggplot-as-svg.R
Last active October 24, 2022 10:07
R: save plot as SVG
library(ggplot2)
# save an image object created with "ggplot2" to svg file
# runs on linux
myplot_svg <- "myplot.svg"
image <- ggplot() +
geom_col(aes(x= symb,y=v,fill=symb))+
theme(axis.text.x = element_text(angle=90)) +
labs(title='Some title', subtitle=sprintf('%s',date())) +
facet_wrap(~ k, scales='free');
@knbknb
knbknb / R-snippet-download-file-ifnot-exists-locally.R
Last active October 23, 2022 08:42
R: download file if not exist locally
# download remote file (potentially very big)
# only if it does not exist locally
# assumes tidyverse is already loaded
inurl <- 'https://'
infile <- 'data_infiles/.csv'
if (! file.exists(infile)){
sprintf("downloading: '%s'", inurl)
try(download.file(url = inurl, destfile = infile
#, mode = "wb",
), silent = TRUE)
@knbknb
knbknb / command-line-piping.R
Last active September 22, 2022 10:26 — forked from chasemc/skimr.r
R: data.table::fread's ability to use unix-cmdtool to "stream in" data
# see: https://www.youtube.com/watch?v=RYhwZW6ofbI&t=6s
# R tip #3: use pipe connections
# by jim Hester
library(data.table) # for files < ~10GB
library(skimr) # another summary()
# filter a file: get only lines containing word UNK
@knbknb
knbknb / R-code-snippets-2022.md
Last active August 12, 2022 11:39
R code snippets

R code snippets

Installing older versions of packages

from RStudio website

# easiest if pkg version number is known
require(devtools)
install_version("emmeans", version = "1.7.5")