Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Simons michael-simons

View GitHub Profile
@michael-simons
michael-simons / format_java.java
Created December 23, 2022 13:14
Formats Java source files with Google Formats.
View format_java.java
//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;
View Neo4jAndJDK17Records.java
//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;
View twitter_archive_fun.sh
# 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.
View checkstyle.xml
<?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+.*""";'/>
View SimpleDisplayNameGeneratorWithTags.java
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.
View format_cypher.java
///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;
View RenderMonths.java
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS info.picocli:picocli:4.6.3
package df;
import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParameterException;
import picocli.CommandLine.Spec;
View foo.sql
WITH duplicate_checksums AS (
SELECT MD5 FROM file_duplicates_develop.files
GROUP BY MD5 HAVING COUNT(*) > 1
)
SELECT * FROM file_duplicates_develop.files
WHERE MD5 = duplicate_checksums.MD5
ORDER BY -Size, MD5;
View how-to-handle-cyclomatic-object-references-in-jackson.adoc

Howto serialize and deserialize cyclomatic references in Java objects with Jacksons to and from JSON

@michael-simons
michael-simons / README.md
Created March 23, 2022 11:37
Filtering contents of fileB.json with information from fileA.json
View README.md