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 / MoviesController.java
Created December 18, 2020 11:39
A streaming controller providing tailable queries, result sets…
package com.example.demo.movies;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicReference;
import org.springframework.data.domain.Sort;
CREATE CONSTRAINT ON (n:Region) ASSERT n.id IS UNIQUE;
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/gvenzl/sample-data/master/countries-cities-currencies/regions.csv' AS row
MERGE (r:Region {id: row['REGION_ID'], name: row['NAME']})
RETURN count(r);
CREATE CONSTRAINT ON (n:Country) ASSERT n.id IS UNIQUE;
LOAD CSV WITH HEADERS FROM 'https://raw.githubusercontent.com/gvenzl/sample-data/master/countries-cities-currencies/countries.csv' AS row
MATCH (r:Region {id: row['REGION_ID']})
MERGE (c:Country {id: row['COUNTRY_ID']}) ON CREATE
SET c.officialName = row['OFFICIAL_NAME'],
with recursive factorial (n, factorial) AS (
SELECT 1, 1
UNION ALL
SELECT n + 1, ( n + 1 ) * factorial
FROM factorial
WHERE n <= 10
)
select * from factorial;
@michael-simons
michael-simons / ApplicationTest2.java
Last active November 19, 2020 16:45
A couple of ways to load data into Neo4j (4) test container
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.GraphDatabase;
import org.testcontainers.containers.Neo4jContainer;
/**
* Creates everything from the test itself.
*
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@michael-simons
michael-simons / Server.java
Created October 12, 2020 09:38 — forked from nigjo/Server.java
A simple, insecure One-File-Java-Server to serve static pages. Main purpose is to have a simple server to locally test some github pages.
/*
* Copyright 2020 Jens "Nigjo" Hofschröer.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
public static void main(String... a) throws Exception {
var driver = GraphDatabase.driver(
"bolt://localhost:7687",
AuthTokens.basic("neo4j", "secret"),
Config.builder().withLogging(Logging.console(Level.INFO)).build()
);
System.out.println("\nImperative transaction functions\n---");
Function<Record, String> getNameFromRecord = record -> record.get("name").asString();
#!/bin/bash
git filter-repo --force \
--message-callback '
import re
return re.sub(rb"GH-\d+ - ", b"", message)
' \
--path .editorconfig \
--path .gitignore \
--path .mvn \
@michael-simons
michael-simons / wait_for_bolt.sh
Last active July 1, 2020 13:28
A bash script waiting for port 7687 to become available without netcat or similar.
#!/bin/bash
until (exec 3<>/dev/tcp/127.0.0.1/7687) &>/dev/null; do
echo "Try again"
sleep 1s
done
package ac.simons.neo4j.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import org.neo4j.configuration.connectors.BoltConnector;
import org.neo4j.configuration.helpers.SocketAddress;
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;