Skip to content

Instantly share code, notes, and snippets.

@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 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 / 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 / Camelizer.swift
Created February 22, 2018 17:26
Convert Swift strings to camel case
fileprivate let badChars = CharacterSet.alphanumerics.inverted
extension String {
var uppercasingFirst: String {
return prefix(1).uppercased() + dropFirst()
}
var lowercasingFirst: String {
return prefix(1).lowercased() + dropFirst()
}
@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 / Data.swift
Last active April 15, 2022 03:47
Reading InputStream into Data
extension Data {
/**
Consumes the specified input stream, creating a new Data object
with its content.
- Parameter reading: The input stream to read data from.
- Note: Closes the specified stream.
*/
init(reading input: InputStream) {
self.init()
input.open()
@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 / Jenkinsfile
Created July 17, 2018 16:55
Report Jenkins build status to Upsource
pipeline {
agent any
environment {
UPSOURCE_URL = "http://your.upsource"
UPSOURCE_PROJECT = "your-project"
UPSOURCE_AUTH = credentials('upsource-auth')
// ^^ set this up as "secret text" credential in Jenkins;
// use the authentication token from Upsource project settings > integration
}
@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)