Skip to content

Instantly share code, notes, and snippets.

@sarmbruster
sarmbruster / neo4j.sh
Last active June 6, 2023 13:22
neo4j with self signed certificates
#!/bin/sh
#!/bin/bash
# Generate a private key
openssl genpkey -algorithm RSA -out private.key
# Generate a certificate signing request (CSR)
openssl req -new -key private.key -subj "/C=DE/L=Munich/O=Company/CN=www.myurl.com" -out certificate.csr
@sarmbruster
sarmbruster / run_docker_neo4j_bloom.sh
Last active February 27, 2024 17:56
Run Neo4j in a docker container together with apoc and Bloom installed.
#!/bin/sh
# start a neo4j docker container with apoc and bloom (server variant) configured
# this requires to have
# * curl, unzip and jq being installed
# * having a valid bloom license file
# released under the WTFPL (http://www.wtfpl.net/)
# (c) Stefan Armbruster
= Soft drinks Stefan variant
This graph contains the top 15 leading brands of soft drinks as of 2013 according to brand value (in million USD).
It will serve as a classification system based on the qualities of the drink as well as the company manufacturing it.
We will also have access to the brand value statistics, allowing us to make certain queries pertaining to tendencies in the market.
It uses a simple domain model that will nevertheless allow for some interesting queries.
image::https://dl.dropboxusercontent.com/u/47527342/drinks.jpg[DataModel]

neo4j installation

  • Install Neo4j 3.1.0-M12-beta2

  • copy APOC library to plugins folder

  • drop Node.txt and Link.txt to import folder

prepare data files

Node.txt and Link.txt do have couple of header lines we should get rid of to make it more easy to process them with LOAD CSV. Be aware the following sed commands do inplace editing.

@sarmbruster
sarmbruster / beergist.adoc
Created September 21, 2016 11:52 — forked from rvanbruggen/beergist.adoc
Creating a beergraph straight from wikipedia

Belgian Beer Graph - straight from Wikipedia into a GraphGist

For the past couple of years, I have been preaching the Neo4j gospel in many different places, meetups, conferences, and what have you. For the most part, I have been using a very specific demo that has been super well-received: The Belgian Beer Graph. It started out as a learning experience for me personally back in the day when Neo4j did not have any proper data import functionality - and I had to load the graph by jumping through all kinds of hoops.

belgian beers
@sarmbruster
sarmbruster / mergeConnectedNodes.java
Last active August 25, 2016 15:56
sample code for simulating merging two nodes and a relationship in between in a concurrent safe way
private void mergeConnectedNodes(Label myLabel, RelationshipType relationshipType, String propertyKey, String valueA, String valueB) {
try (Transaction tx = db.beginTx()) {
// get or create start end node
Node a = mergeAndLockNode(myLabel, propertyKey, valueA);
Node b = mergeAndLockNode(myLabel, propertyKey, valueB);
grabLocksInConsistentOrder(tx, a,b);
boolean aIsCheaper = a.getDegree(relationshipType) < b.getDegree(relationshipType);
@sarmbruster
sarmbruster / panama_papers_azerbaijan.adoc
Last active May 3, 2016 14:47 — forked from jexp/panama_papers_azerbaijan.adoc
ICIJ Panama Papers Graph Model Exploration

The #PanamaPapers - Example Dataset President of Azerbaijan my changes

Let’s look at the family of the Azerbaijan’s President Ilham Aliyev who was already the topic of a GraphGist by Linkurious in the past. We see his wife, two daughters and son depicted.

Source

@sarmbruster
sarmbruster / rotate.sh
Created April 14, 2016 11:26
script for Thinkpad X1 Yoga to rotate screen and input devices
#!/bin/sh
# screen and input device rotation for e.g. a Thinkpad X1 Yoga
# adopted from by the script from http://ubuntuforums.org/showthread.php?t=996830&p=6274392#post6274392
#
# Usage:
# ./rotate.sh
# will rotate both the screen and input device either to right or normal setting depending on previous state. Additionally:
# * in "right" layout, a on screen keyboard (onboard) is started or stopped in normal mode
# * the touchpad is switched off in "right" mode
@sarmbruster
sarmbruster / BatchDeleteSpec.groovy
Created April 5, 2016 12:19
code sample for batch deletions in groovy
package org.neo4j.extension.tei
import org.junit.Rule
import org.neo4j.extension.spock.Neo4jResource
import org.neo4j.graphdb.DynamicLabel
import org.neo4j.graphdb.GraphDatabaseService
import spock.lang.Specification
import java.util.concurrent.Executors
// short snippet to retrieve the type of a given property in cypher
CREATE (x {myProp: 1.2}) // create a sample node with a float property, change the value to whatever you like
RETURN
CASE x.myProp
WHEN toString(x.myProp) THEN "STRING"
WHEN toFloat(x.myProp) THEN "FLOAT"
WHEN toInt(x.myProp) THEN "INTEGER"
END