Skip to content

Instantly share code, notes, and snippets.

View stoerr's full-sized avatar

Dr. Hans-Peter Störr stoerr

View GitHub Profile
@stoerr
stoerr / mvn
Created January 10, 2025 16:50
Mvn wrapper that searches a .m2/settings.xml upwards from the current directory - if you have to use different maven installations for different projects at the same time
#!/bin/bash
# This script calls Maven with settings depending on the directory it's started.
# It searches for .m2/settings.xml in the current directory and parent directories and takes the first it finds.
# This is not done if the command line contains an argument -s or --settings.
# This is useful if you have different settings for different projects.
# In the end it expects the real mvn executable (or probably a link to it) to be named _mvn and in the PATH.
settings_file=".m2/settings.xml"
settings_dir="$(realpath .)"
use_custom_settings=true
@stoerr
stoerr / deploy
Last active January 1, 2025 10:58
Helper script that lets you choose and execute configurable directory specific command lines you need to execute again and again. Compare https://www.stoerr.net/blog/deployScript
#!/usr/bin/env bash
# requires bash > 4, so no /bin/bash on MacOS
function usage() {
cat <<EOF
Usage: $0 [-h] [-l] [-v] [tag]
Execute a deployment or other command selected from the configured commands for the directory.
The script looks for files called .deploycmds in the current directory and the parent directories up to $HOME.
Those files can contain a tagged list of commands for different deployment / command types. E.g.
@stoerr
stoerr / deployit.sh
Created February 2, 2024 11:28
Script zum leichteren Aufrufen von Deployment-Kommandos - vergleiche https://youtu.be/CMB1HEr5MnM
#!/usr/bin/env bash
# Demoscript erzeugt mit Github Copilot, vergleiche https://youtu.be/CMB1HEr5MnM
# Ist auch durchaus verwendbar. :-)
function usage() {
cat <<EOF
Verwendung: $0 [-h] [-l] [-v] [tag]
Führt einen Build / ein Deployment mit einem für das aktuelle Verzeichnis konfigurierten Befehle aus.
Der Script sucht nach einer Konfigurationsdatei mit dem Namen .deploycmds im aktuellen Verzeichnis
@stoerr
stoerr / bookmarklets.js
Created March 19, 2023 18:08
A couple of ChatGPT bookmarklets to summarize text from the current page, or generate text
/* jshint -W028 */
// bookmarklets to summarize the shown webpage.
// replace XXXInsertAPIKeyHereXXX with your API key to use these bookmarklets.
// this summarizes the text on the page. (We might have to cut it down to 3000 words, because the API has a limit of 3000 words.)
javascript:(async () => {
var apikey = "XXXInsertAPIKeyHereXXX";
const maxwordcount = 2500;
try {
@stoerr
stoerr / suggestCommand.js
Created March 7, 2023 17:18
A little script to access ChatGPT from the command line
// see also https://platform.openai.com/playground?mode=complete
// command line example:
// node suggestCommand.js "Write a bash command line to do the following: log the last 3 git commits"
// Needs an API key in ~/.openaiapi , see https://beta.openai.com/docs/api-reference/authentication
// Idea for a shellscript calling that. You could also add things to the prompt there.
// #!/bin/bash
// node "$(dirname "$(readlink -f "$0")")/suggestCommand.js" "$*"
const axios = require('axios');
const fs = require('fs');
@stoerr
stoerr / getpackage.java
Last active March 11, 2021 08:38
Servlet to download a resource subtree from AEM as a content-package
/**
* This is a servlet that enables to download a package of a JCR subtree without
* having to create a package in the package manager. The package is
* created on the fly, and not saved to disk / the repository, so this is
* better suited to large content trees, but valuable also for quickly downloading
* a page.
*
* CAUTION: not suitable for production, only for internal testing systems!
*
* Usage with curl e.g.
@stoerr
stoerr / AutoEncoderDemo.ipynb
Last active March 3, 2020 19:20
Pre-training with autoencoder
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stoerr
stoerr / PredictVariability.ipynb
Last active February 20, 2020 21:48
Estimation of mean and variance / standard deviation of a stochastic process with a neural network
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stoerr
stoerr / CharsetStress.java
Last active February 12, 2020 10:56
For testing purposes: generates various test strings with unusual characters which can be used to detect character encoding problems. Caution: this currently covers only relatively common stuff - it does not yet lead into the deeper realms of UTF like substitutes, right to left, Kanji, characters outside of 16 bit.
package net.stoerr.testing;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
/**
* Returns a couple of teststrings to detect character escaping problems. This file encodes all chars numerically to
* make sure we are independent of the encoding of this file. Caution: this currently covers only relatively common
* stuff - it does not yet lead into the deeper realms of UTF like substitutes, right to left, Kanji, characters
@stoerr
stoerr / LockAsAutoCloseable.java
Last active November 6, 2019 15:39
Allows using a java.util.concurrent.lock in a Java try-with-resources statement
import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
/**
* Allows using a {@link java.util.concurrent.locks.Lock} with a try with resources, e.g.:
* <code> try (LockAsAutoCloseable locked = LockAsAutoCloseable.lock(lock)) { ... } </code> .
*/
@SuppressWarnings("LockAcquiredButNotSafelyReleased")
public class LockAsAutoCloseable implements AutoCloseable {