Skip to content

Instantly share code, notes, and snippets.

@jmini
jmini / example.java
Created July 16, 2020 05:24
Write an OpenAPI spec with Java code (instead of YAML or JSON directly)
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.smallrye:smallrye-open-api-core:2.0.3
import static org.eclipse.microprofile.openapi.OASFactory.*;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import io.smallrye.openapi.runtime.io.Format;
import io.smallrye.openapi.runtime.io.OpenApiSerializer;
@jmini
jmini / SpoonMain.java
Created March 25, 2021 08:13
Spoon test with compile errors
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS fr.inria.gforge.spoon:spoon-core:8.4.0
//DEPS org.slf4j:slf4j-simple:1.7.30
import java.util.List;
import java.util.Set;
import spoon.Launcher;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtField;
@jmini
jmini / pom.xml
Created December 7, 2021 21:11
Maven file to download some Gradle dependencies
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mvntmp</groupId>
<artifactId>mvntmp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
@jmini
jmini / CreateWebserver.java
Created December 28, 2021 11:53
Create a docker image with Jib
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.google.cloud.tools:jib-core:0.20.0
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import com.google.cloud.tools.jib.api.Containerizer;
import com.google.cloud.tools.jib.api.DockerDaemonImage;
@jmini
jmini / runTests.java
Created January 27, 2022 22:14
Re-run Junit 5 tests present in a Jar
///usr/bin/env jbang "$0" "$@" ; exit $?
// jar containing the Junit5 tests:
//DEPS com.company.test:lib:1.3.2
// Junit console to start the test engine:
//DEPS org.junit.platform:junit-platform-console:1.8.2
// engine to run the tests (tests are written with Junit5):
//DEPS org.junit.jupiter:junit-jupiter-engine:5.8.2
@jmini
jmini / runTests.java
Created March 8, 2022 06:53
Write and execute Junit 5 unit tests directly in Jbang
///usr/bin/env jbang "$0" "$@" ; exit $?
// Junit console to start the test engine:
//DEPS org.junit.platform:junit-platform-console:1.8.2
// engine to run the tests (tests are written with Junit5):
//DEPS org.junit.jupiter:junit-jupiter-engine:5.8.2
import static org.junit.jupiter.api.Assertions.fail;
@jmini
jmini / decodeDiagram.java
Created May 9, 2022 22:02
Decode drawio compressed xml
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.github.vlsi.mxgraph:jgraphx:4.2.2
//JAVA 8
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URLDecoder;
@jmini
jmini / listProjectDirectories.java
Created May 10, 2022 21:28
Use the Gradle tooling API in a Jbang script
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.gradle:gradle-tooling-api:7.4.2
//DEPS org.slf4j:slf4j-simple:1.7.10
//REPOS gradle-releases=https://repo.gradle.org/gradle/libs-releases
import java.io.File;
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;
@jmini
jmini / DisplayTree.java
Last active August 10, 2022 14:47
Display ASCII Art tree
import java.util.ArrayList;
import java.util.List;
public class DisplayTree {
private static final boolean USE_UNICODE = false;
public static void main(final String[] args) {
final DisplayTree.Node node = new DisplayTree.Node("example")
.addChild(new Node("a"))
@jmini
jmini / ListPermutations.java
Created October 19, 2022 06:29
Compute all permutations of a list
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.junit.jupiter:junit-jupiter-api:5.7.2
//DEPS org.assertj:assertj-core:3.11.1
//JAVA 17
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;