Skip to content

Instantly share code, notes, and snippets.

@reitzig
reitzig / Jenkinsfile_snippet
Created April 11, 2023 10:10
Jenkins: stash-like helper functions that use artifacts
// "Stash" in one stage ...
script {
stashAsArtifact(this, 'node-dependencies', '**/node_modules/')
}
// ... and "unstash" in another
script {
unstashFromArtifact(this, 'node-dependencies')
}
@reitzig
reitzig / Dockerfile
Last active March 13, 2024 02:54
Run whisper.cpp as Container
FROM debian:11 AS build
RUN apt-get update \
&& apt-get install -y libsdl2-dev alsa-utils g++ make wget
RUN mkdir /whisper && \
wget -q https://github.com/ggerganov/whisper.cpp/tarball/master -O - | \
tar -xz -C /whisper --strip-components 1
WORKDIR /whisper
@reitzig
reitzig / Dockerfile
Last active January 9, 2023 11:02
Minimal nginx Docker image with antora redirects
FROM nginxinc/nginx-unprivileged:alpine
COPY build/site /usr/share/nginx/html/
# Inject the rewrite rules antora generates into the nginx config:
# 1. Add \ to the end of every line (to make the multi-line sed command in 3. work), and
# indent all lines (cosmetics).
# 2. Append another ("escaped") empty line (cosmetics).
# 3. Insert what we got before the final closing brace in the default config file.
# NB: Using % as separator for the replace command because rewrite.conf contains many /
@reitzig
reitzig / Dockerfile
Last active January 27, 2024 00:57
MWE: docker-compose.yaml with build arguments
FROM ubuntu
ARG foo="setme"
# Available at build time:
RUN echo foo=${foo} > foo
# Need to "convert" into environment variable so it's available at runtime:
ENV FOO ${foo}
@reitzig
reitzig / common.schema.json
Last active February 24, 2022 15:40
jsonschema 4.4.0 RefResolver reproduction
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"shared-def": {
"type": "string",
"pattern": "^shared-"
}
}
}
@reitzig
reitzig / LazyJdbcConnection.java
Created January 5, 2022 09:10
Sketch: JDBC ResultSet -> Java Stream
public class LazyJdbcConnection extends JdbcConnection {
public LazyJdbcConnection(JdbcTemplate jdbcTemplate) {
super(jdbcTemplate);
}
public <T> T executeQueryLazily(final String sqlQuery, final LazyResultSetExtractor<T> resultSetExtractor) throws SQLException {
log.debug("Executing query: {}", sqlQuery);
if (jdbcTemplate.getDataSource() == null) {
throw new SQLException("Data source not available via JdbcTemplate");
@reitzig
reitzig / puzzle_shelves.kts
Created November 20, 2020 17:49
Determine how to fill a wall with shelves of certain widths
fun maximalSplits(pieces: List<Int>, width: Int): List<Pair<Map<Int, Int>, Int>> {
fun maximalSplits(partial: List<Int>): List<List<Int>> {
val longerSplits = pieces
.filter { partial.sum() + it < width }
.map { (partial + it).sorted() }
.flatMap { maximalSplits(it) }
.distinct()
if (longerSplits.isEmpty()) {
return listOf(partial)
@reitzig
reitzig / logger_dev.go
Created June 15, 2020 20:18
Go logging with Zap
// +build test
package main
import "go.uber.org/zap"
func makeLogger() (*zap.Logger, error) {
return zap.NewDevelopment()
}
@reitzig
reitzig / $
Last active June 15, 2020 20:22
Docker-based wrapper for npm and friends
#!/usr/bin/env bash
# Usage:
#
# - Run something: ./$ npm --version
# - Setup something: Add a suitable `prepare` script to your `package.json`, e.g.
#
# "scripts": {
# "prepare": "npm i -g @zeit/ncc"
# }
@reitzig
reitzig / Dockerfile
Created May 20, 2020 08:41
UBI Minimial with Kotlin Native
FROM registry.access.redhat.com/ubi7/ubi:latest AS build
RUN yum -y install --disableplugin=subscription-manager \
java-11-openjdk
ARG kotlin_version=1.3.72
RUN curl -LO https://github.com/JetBrains/kotlin/releases/download/v${kotlin_version}/kotlin-native-linux-${kotlin_version}.tar.gz \
&& tar -xzf kotlin-native-linux-${kotlin_version}.tar.gz \
&& rm kotlin-native-linux-${kotlin_version}.tar.gz