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 / 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;
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;