Skip to content

Instantly share code, notes, and snippets.

View jfuerth's full-sized avatar

Jonathan Fuerth jfuerth

View GitHub Profile
@jfuerth
jfuerth / GlobToRegex.java
Created May 20, 2024 15:45
Convert shell-like glob/wildcard to regex and match a string
private boolean matchesAnyGlob(String value, Collection<String> globs) {
// convert globs to regex
StringBuilder sb = new StringBuilder();
sb.append("(");
for (String glob : globs) {
if (sb.length() > 1) {
sb.append("|");
}
String[] parts = glob.splitWithDelimiters("[*?]", 0);
for (int i = 0; i < parts.length; i++) {
@jfuerth
jfuerth / drs-concepts.schema.json
Created March 15, 2023 22:22
Example schema for references to DRS objects
{
"$id": "https://drs-concepts.example.com/drs-concepts.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
{ "$ref": "#/$defs/url" },
{ "$ref": "#/$defs/curie" },
],
"$defs": {
"url": {
"title": "DrsObject URL",
@jfuerth
jfuerth / Dockerfile
Last active January 13, 2022 16:32
Docker packaging for running the Cloud Foundry Java Buildpack Memory calculator on MacOS or Windows via Docker
FROM alpine:3.15
RUN echo "This Docker image exists so you can run the prebuilt memory calculator on MacOS and Windows.\n\
There is no sense in using it on a Linux system.\n\
You can find the Dockerfile at https://gist.github.com/jfuerth/f002f3dde9b54e5be67b43f0a85d59d7" \
> /etc/motd
# Grab the pre-compiled release binary
RUN wget -O - https://github.com/cloudfoundry/java-buildpack-memory-calculator/releases/download/v4.1.0/memory-calculator-4.1.0.tgz \
| tar zxv
@jfuerth
jfuerth / embedded-json-schema-no-allof.yaml
Last active April 21, 2021 21:53
An OpenAPI spec for a type that has an which is a JSON Schema
openapi: "3.0.2"
paths:
/table/{tableName}:
get:
responses:
'200':
content:
application/json:
schema:
$ref: "#/components/schemas/Table"
@jfuerth
jfuerth / egl_bar.c
Last active December 26, 2023 08:01
Self-contained example of an EGL + X11 OpenGL ES 2.0 rectangle moving across the screen
// egl_bar.c - self-contained example of a vertical bar moving across the screen.
// compile with gcc -Wall -O0 -g -o egl_bar egl_bar.c log.c -lX11 -lEGL -lGLESv2 -lm
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@jfuerth
jfuerth / xorg.conf
Last active May 12, 2024 22:01
Separate X11 screens on dual-head Raspberry Pi
# Sets up Xorg on Raspberry Pi 3b in FKMS mode for two screens.
#
# To put the Pi into FKMS mode, add one of the following lines to /boot/config.txt:
# 1. "fake" KMS mode (exposes the proprietary vc4 firmware driver via KMS API):
# dtoverlay=vc4-fkms-v3d
# If you wanted "full" KMS mode, fully open source "vc4" driver in the Linux kernel, you
# would use `dtoverlay=vc4-kms-v3d` instead, but then the identifiers in the Driver section
# need to be different.
#
# To run X clients on one screen or another:
@jfuerth
jfuerth / log-wedge.js
Created April 24, 2018 14:24
Javascript console wedge for embedded browsers that don't support remote dev tools
if (!console.olog) { // eslint-disable-line no-console
const escapeHtml = str => `${str}`.replace('&', '&amp;').replace('<', '&lt;');
console.olog = console.log; // eslint-disable-line no-console
console.log = (msg, ...args) => { // eslint-disable-line no-console
console.olog(msg, ...args); // eslint-disable-line no-console
document.getElementById('debugDiv').innerHTML += `<p>${escapeHtml(msg)} ${escapeHtml(args)}</p>`;
};
console.debug = console.log; // eslint-disable-line no-console
console.info = console.log; // eslint-disable-line no-console
console.warn = console.log; // eslint-disable-line no-console
@jfuerth
jfuerth / TraceLogger.java
Created March 12, 2018 14:53
Recipe for adding an SLF4J TRACE-level logger to a Feign-OkHttp3 client
private static class TraceLogger implements okhttp3.logging.HttpLoggingInterceptor.Logger {
/*
.client(new OkHttpClient(new okhttp3.OkHttpClient.Builder()
.addInterceptor(new okhttp3.logging.HttpLoggingInterceptor(
new TraceLogger(LoggerFactory.getLogger(FEIGN_TARGET)))
.setLevel(HttpLoggingInterceptor.Level.BODY))
.build()))
*/
@jfuerth
jfuerth / logviewer.html
Created July 12, 2016 14:57
View CF logs with line height proportional to time
<!DOCTYPE html>
<html>
<head>
<title>Log visualizer</title>
<style type="text/css">
div.logEntry {
border-bottom: 1px;
border-bottom-color: black;
border-bottom-style: solid;
position: relative;
@jfuerth
jfuerth / tracker-bookmarklet.html
Last active December 22, 2016 15:45
Enhanced Pivotal Tracker Story Links!
<!DOCTYPE html>
<body style="width: 100%; font-family: helvetica,arial,sans-serif">
<h1>Enhanced Pivotal Tracker Story Links!</h1>
<a style="align:center; font-size:40pt; text-decoration: none" href='javascript:void(function(){storyIdPattern = /.*\/([0-9]+)/;storyInternalIdPattern = /story_copy_link_(.*)/;var buttons=document.querySelectorAll("button.link[data-clipboard-text]");for (i = 0; i < buttons.length; i++) {var b=buttons[i];var textAttr=b.attributes.getNamedItem("data-clipboard-text");var storyId=storyIdPattern.exec(textAttr.value)[1];var idAttr=b.attributes.getNamedItem("id");var storyInternalId=storyInternalIdPattern.exec(idAttr.value)[1];var storyTitle=document.getElementById("story_name_"+storyInternalId).value;var idButton=document.getElementById("story_copy_id_"+storyInternalId);idButton.attributes.getNamedItem("data-clipboard-text").value=storyTitle + " [#"+storyId+"]"}}())'>Enhance Story Links</a>
<p>To use it:
<ol>
<li>Drag the above link to your bookmarks bar!
<li>Expand one or more stor