Skip to content

Instantly share code, notes, and snippets.

View moxious's full-sized avatar

David Allen moxious

View GitHub Profile
/* From GraphConnect 2022 Presentation: Node Art by M. David Allen
* Each Neo4j browser "favorite" query starts with //XX-Query Name
*/
//01-Make a Snake
WITH 100 as snakeSize, 3 as snakeLinkage
/* Create the nodes... */
FOREACH (id IN range(0,snakeSize) | CREATE (:SnakeNode {id:id}))
/* Link each node to the previous {snakeLinkage} nodes, creating a lattice */
WITH ['A', 'B', 'C'] as labels, snakeSize, snakeLinkage
@moxious
moxious / components.cypher
Created January 22, 2022 14:14
Node art component cypher
/* Create a snake */
WITH 500 as snakeSize, 3 as snakeLinkage
/* Create the nodes... */
FOREACH (id IN range(0,snakeSize) | CREATE (:SnakeNode {id:id}))
/* Link each node to the previous {snakeLinkage} nodes, creating a lattice */
WITH ['A', 'B', 'C'] as labels, snakeSize, snakeLinkage
MATCH (n:SnakeNode), (n2:SnakeNode)
WHERE n2.id > n.id and n2.id < n.id + snakeLinkage
with n, n2, labels
@moxious
moxious / hierarchy.md
Created November 2, 2021 16:12
hierarchy traversal with cypher
CALL {
USE fabric.db1
MATCH (p:Person)
RETURN { id: p.id, name: p.name, age: p.age } as result
}
CALL {
USE fabric.db2
WITH result
MERGE (p:Person { id: result.id })
SET p += result
@moxious
moxious / gist:9924090e05be42a59820825f1c91252e
Created November 4, 2020 13:08
Ghengis Khan's Family Tree in Neo4j
WITH 'https://storage.googleapis.com/meetup-data/ghengis-khan-family-tree.csv' as data
LOAD CSV WITH HEADERS FROM data AS line
MERGE (p:Person { id: line.id })
SET
p.name = line.name,
p.born = coalesce(line.born, 'Unknown'),
p.died = coalesce(line.died, 'Unknown')
WITH p, line
MERGE (father:Person { id: coalesce(line.father_id, apoc.create.uuid()) })
@moxious
moxious / JDBCExample.java
Created October 13, 2020 18:06
Java JDBC Access to Neo4j Example
public class JDBCExample {
public static void main(String[] args) throws Exception {
Connection conn = null;
Statement stmt = null;
try {
//STEP 2: Register JDBC driver
Class.forName(JDBC_DRIVER);
//STEP 3: Open a connection
@moxious
moxious / gist:b7f28c3d439a062c4dfee95f92bb68ec
Created October 13, 2020 18:04
Data Access Permissions Scenario for Neo4j 4.0+
/* Sample Data */
CREATE (mark:User { name: 'Mark' })
WITH mark
CREATE (mark)-[:PHONE]->(:Phone { number: '555-123-456' })
CREATE (mark)-[:SSN]->(:SSN { ssn: 'XYZ-ABC-DEFG' })
CREATE (mark)-[:ADDRESS]->(:Address {
street: '123 Elm St',
state: 'VA',
zip: '23226'
})
1.0.3 ========================================================================
Released 2020-05-06
Enhancements & New Features
* [NEOJ-66] Java driver logging
You can now log Neo4j Java driver activity by using the
EnableJavaDriverLogging connection URL option. The driver uses the
CREATE INDEX ON :Emoji(name);
CREATE INDEX ON :Emoji(column_a);
CREATE INDEX ON :Emoji(browser);
CREATE INDEX ON :Emoji(code);
CREATE INDEX ON :Category(name);
LOAD CSV WITH HEADERS FROM 'https://storage.googleapis.com/meetup-data/emojis/all-emojis.csv' as line
WITH line
WHERE line.code is not null
MERGE (e:Emoji { code: line.code })
@moxious
moxious / gist:05571dee9102dada42ace8ac4116a11f
Created April 9, 2020 13:11
How to list transactions in Neo4j for 3.5 vs. 4.0
== 3.5 ==
CALL dbms.queryJmx("org.neo4j:instance=kernel#0,name=Transactions")
YIELD attributes WITH attributes as a
RETURN
a.NumberOfRolledBackTransactions.value as rolledBack,
a.NumberOfOpenTransactions.value as open,
a.LastCommittedTxId.value as lastCommittedId,
a.NumberOfOpenedTransactions.value as opened,
a.PeakNumberOfConcurrentTransactions.value as concurrent,