Skip to content

Instantly share code, notes, and snippets.

View jexp's full-sized avatar
🐉
Watching the chamaeleon.

Michael Hunger jexp

🐉
Watching the chamaeleon.
View GitHub Profile

LOAD CSV into Neo4j quickly and successfully

Since version 2.1 Neo4j provides out-of-the box support for CSV ingestion. The LOAD CSV command that was added to the Cypher Query language is a versatile and powerful ETL tool. It allows you to ingest CSV data from any URL into a friendly parameter stream for your simple or complex graph update operation, that …​ conversion.

# english output for tools
export JAVA_TOOL_OPTIONS=-Duser.language=en
# sdkman
sdk list
sdk list java
#sdk install java 20-open
sdk use java 20-open
java -version
@jexp
jexp / bsky_jazco_import.cypher
Last active May 8, 2023 09:30
BlueSky User Interactions Neo4j Import, data collection courtesy https://bsky.jazco.dev/
create constraint user_key if not exists for (u:User) require (u.key) is unique;
// add nodes
call apoc.load.json("https://bsky.jazco.dev/exported_graph_minified.json","$.nodes")
yield value as nv
call { with nv
merge (n:User {key:nv.key})
on create set n += apoc.map.clean(nv.attributes,["key"],[])
} in transactions of 10000 rows;
// sdk install java 20-open
// java -version
/*
openjdk version "20" 2023-03-21
OpenJDK Runtime Environment (build 20+36-2344)
OpenJDK 64-Bit Server VM (build 20+36-2344, mixed mode, sharing)
*/
// jshell --enable-preview --add-exports java.base/jdk.internal.vm=ALL-UNNAMED --add-modules=jdk.incubator.concurrent
@jexp
jexp / guide-create-neo4j-browser-guide.adoc
Last active March 2, 2023 15:33
Create a Custom Neo4j Browser Guide

Create a Custom Neo4j Browser Guide

@jexp
jexp / stackoverflow-schema.graphql
Created June 24, 2019 20:27
StackOverflow GraphQL Schema
type Tag {
name: String!
questions: [Question] @relation(name: "TAGGED", direction: "IN")
}
type Answer {
createdAt: DateTime
downVotes: Int
id: Int!
link: String
@jexp
jexp / dependencies.cypher
Last active January 5, 2023 13:09
Google deps.dev to #Neo4j graph on dev.neo4j.com/sandbox
// load initial package, adjust your name and version
with "org.neo4j:neo4j-kernel" as name, '4.2.6' as version
call apoc.load.json("https://deps.dev/_/s/maven/p/"+name+"/v/"+version+"/dependencies") yield value
where value.package.system = 'MAVEN'
merge (p:Package:Maven {name:value.package.name, version:value.version})
with *
unwind value.dependencies as dep
with p, dep where dep.package.system = 'MAVEN'
merge (d:Package:Maven {name:dep.package.name, version:dep.version})
This file has been truncated, but you can view the full file.
{
"laureates": [
{
"id": "745",
"knownName": {
"en": "A. Michael Spence",
"se": "A. Michael Spence"
},
"givenName": {
"en": "A. Michael",
@jexp
jexp / aoc_day1.cypher
Last active December 4, 2022 12:15
Advent of Code 2022 in some languages
with split($input, "\n\n") as elves
unwind elves as elf
return reduce(s=0, c in split(elf,"\n") | s + toInteger(c)) as total
order by total desc limit 1;
with split($input, "\n\n") as elves
unwind elves as elf
with reduce(s=0, c in split(elf,"\n") | s + toInteger(c)) as total
order by total desc limit 3
@jexp
jexp / test-db
Created December 1, 2022 16:45
Neo4j single transaction testing using java core api and drivers, using https://jbang.dev
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS org.neo4j:neo4j:5.2.0
import static java.lang.System.*;
import org.neo4j.dbms.api.*;
import org.neo4j.graphdb.*;
import java.nio.file.Path;
import java.util.Map;