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 / GoL.java
Last active February 21, 2025 12:54
Cypher based Game of Life implementation meets Java meets the terminal. xkcd 356 applies.
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 24
//PREVIEW
//DEPS org.neo4j:neo4j-jdbc:6.1.3
import java.sql.DriverManager;
import org.neo4j.jdbc.Neo4jPreparedStatement;
/**
@michael-simons
michael-simons / Neo4jWithApoc.java
Last active February 21, 2025 12:49
How to run Neo4j embedded with Apoc installed. Using Java 23 preview to avoid the ceremony of an empty class holding main (See JEP 477).
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 23
//PREVIEW
//DEPS org.neo4j:neo4j:2025.01.0
//DEPS org.neo4j.procedure:apoc-common:2025.01.0
//DEPS org.neo4j.procedure:apoc-core:2025.01.0
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
@michael-simons
michael-simons / copy_to_mermaid.sql
Created November 21, 2024 11:21
Quickly create Mermaid ER-Diagrams for DuckDB Tables
-- Inspired by https://gist.github.com/Bilbottom/e1d3d677d2479e0602132327703ff15d
-- Fixed datatypes that don't render in mermaid (structs, decimal etc.)
-- Uses 1:n as base, cardinalities are hard to derive
-- Looks for column comments
-- Avoids regex.
COPY (
WITH hlp AS (
SELECT referenced_table, c.table_name,
trim(string_agg(d.comment, ' ')) AS comment,
@michael-simons
michael-simons / gist:6667018c883738bc22502b2d269e678f
Created November 9, 2024 11:31
Use duckdb with twitter gdpr archive
sed '1s/.*= //' tweets.js |
duckdb -s "
SELECT strptime(t->'tweet'->>'created_at', '%a %b %d %H:%M:%S %z %Y') AS created_at,
t->'tweet'->>'full_text' AS text,
NULLIF(t->'tweet'->>'in_reply_to_status_id', 'null') IS NOT NULL AS is_reply,
t->'tweet'->>'in_reply_to_screen_name' AS in_reply_to_screen_name,
(t->'tweet'->>'in_reply_to_user_id_str')::bigint AS in_reply_to_user_id_str,
(t->'tweet'->>'in_reply_to_status_id')::bigint AS in_reply_to_status_id
FROM read_json('/dev/stdin') t
WHERE text NOT LIKE 'RT @'
@michael-simons
michael-simons / GoCyclingWithNeo4j.java
Last active October 11, 2024 19:02
Parses a jvm.log file created with -Xlog:class+resolve=trace:file=jvm.log, to find cycling initialisation of classes (inspired by https://www.youtube.com/watch?v=vWmzHnuMXHY)
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS org.neo4j:neo4j:5.24.1
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Map;
@michael-simons
michael-simons / newkm.sql
Created August 14, 2024 12:56
new kilometers from Strava x wanderer.earth on a german GDPR export with duckdb
select year(strptime("Aktivitätsdatum", '%d.%m.%Y, %H:%M:%S')) as year, round(sum(regexp_extract("Aktivitätsbeschreibung", '(\d+(?:\.\d+)*) new kilometer', 1)::double), 2) as new from 'activities.csv' where "Aktivitätsbeschreibung" like '%new kilometers%' group by all order by year;
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS info.picocli:picocli:4.7.5
//DEPS info.picocli:picocli-codegen:4.7.5
//DEPS org.neo4j:neo4j-cypher-dsl-parser:2023.9.7
//DEPS com.opencsv:opencsv:5.9
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
@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;