Skip to content

Instantly share code, notes, and snippets.

View michael-simons's full-sized avatar

Michael Simons michael-simons

View GitHub Profile
@michael-simons
michael-simons / Movie.java
Created October 25, 2023 08:00
An example how to run integration tests as GraalVM native image.
package demo;
import java.util.Map;
import java.util.stream.Collectors;
import org.neo4j.driver.Driver;
public record Movie(String id, String title) {
public static final class Repository {
Moved to https://github.com/michael-simons/pv
//usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS org.neo4j.driver:neo4j-java-driver:5.7.0
//DEPS com.fasterxml.jackson.core:jackson-databind:2.14.1
package ac.simons;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
sqlite3 :memory: \
'.mode csv' \
'.import "|curl -s https://gist.githubusercontent.com/zhonglism/f146a9423e2c975de8d03c26451f841e/raw/f79e190df4225caed58bf360d8e20a9fa872b4ac/vgsales.csv" hlp' \
"
WITH vgsales AS (
SELECT name, cast(global_sales as number) * 1000000 AS sales, cast(year as number) AS year FROM hlp WHERE year != 'N/A'
),
per_year AS (
SELECT year, name, sales, dense_rank() OVER (PARTITION BY year ORDER BY sales DESC) AS rnk FROM vgsales
)
@michael-simons
michael-simons / format_java.java
Created December 23, 2022 13:14
Formats Java source files with Google Formats.
//usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17+
//DEPS com.google.googlejavaformat:google-java-format:1.15.0
//RUNTIME_OPTIONS --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
//RUNTIME_OPTIONS --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
//RUNTIME_OPTIONS --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
//RUNTIME_OPTIONS --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
//RUNTIME_OPTIONS --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
import com.google.googlejavaformat.java.Main;
//JAVA 17
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.neo4j.driver:neo4j-java-driver:5.2.0
import java.util.List;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.GraphDatabase;
// You need to import the Neo4j record, otherwise you will have ambiguous imports
import org.neo4j.driver.Record;
# Most interactions / mentions, excluding myself.
{ sed -e '1s/.*/[/' -e '$d' tweets.js && sed '1s/.*/,/' tweets-part1.js; } | \
jq '
[.[].tweet.entities.user_mentions[] | select(.screen_name != "rotnroll666") | {handle: .screen_name}] |
group_by(.handle) | map(.[0] + {"count": length}) |
sort_by(-.count,.handle|=ascii_downcase) | limit(20;.[]) |
"@\(.handle) (\(.count))"
'
@michael-simons
michael-simons / checkstyle.xml
Created September 14, 2022 08:49
Checkstyle config enforcing tabs but allowing leading spaces in text blocks.
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="SuppressWithPlainTextCommentFilter">
<property name="offCommentFormat" value='=\s+"""'/>
<property name="onCommentFormat" value='^\s+.*""";'/>
import java.lang.reflect.Method;
import java.util.stream.Collectors;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Tag;
import org.junit.platform.commons.util.AnnotationUtils;
final class SimpleDisplayNameGeneratorWithTags extends DisplayNameGenerator.Simple {
@Override
@michael-simons
michael-simons / format_cypher.java
Created June 2, 2022 19:34
A simple formatter for Cypher.
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS info.picocli:picocli:4.6.3
//DEPS org.neo4j:neo4j-cypher-dsl-parser:2022.4.0
import picocli.CommandLine;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;