Skip to content

Instantly share code, notes, and snippets.

View adam-cowley's full-sized avatar

Adam Cowley adam-cowley

View GitHub Profile
== Northwind Graph
=== Introduction
Recently, I was asked to pitch a method for providing recommendations. Luckily, armed with the knowledge obtained from talks from Max De Marzi and [Mark Needham](https://skillsmatter.com/skillscasts/7298-modelling-a-recommendation-engine-a-worked-example) at a recent Neo4j London Meetups, I knew this could be easily achieved with Neo4j.
The key issue with recommendation engines comes from the data. Luckily, Neo4j comes bundled with the Northwind Graph Example. The Northwind database is an infamous dataset containing purchase history that has been used to teach relational databases for years and was a great place to start. You can import the Northwind database into a graph by following the ["Import Data into Neo4j"](http://neo4j.com/developer/guide-importing-data-and-etl/) post on Neo4j or type the following into Neo4j's browser at `http://localhost:7474/`
:play northwind graph
@adam-cowley
adam-cowley / queue.js
Created September 28, 2016 09:29
Run an array of promises one by one
function queue(all) {
return new Promise((resolve, reject) => {
const output = [];
next(all.splice(0, 1))
function next(go) {
go();
.then(res => {
output.push(res);
@adam-cowley
adam-cowley / neo4j-ticketmaster
Created February 17, 2017 16:27
Import Ticketmaster Classifications into Neo4j
CALL apoc.load.json('https://app.ticketmaster.com/discovery/v2/classifications?locale=en-us&apikey={key}') YIELD value AS json
UNWIND json._embedded.classifications as classification
MERGE (seg:Segment {ticketmaster_id: classification.segment.id, name: classification.segment.name})
WITH seg, classification
UNWIND classification.segment._embedded.genres as genre
MERGE (gen:Genre {ticketmaster_id: genre.id, name: genre.name})
MERGE (seg)-[:HAS_GENRE]->(gen)
WITH seg, gen, genre
UNWIND genre._embedded.subgenres as subgenre
MERGE (sub:SubGenre {ticketmaster_id: subgenre.id, name: subgenre.name})
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECUw
LjQ4OTQ2NTYxNjMgMC41NDM3OTkwNSAwLjU2MjMyMzI0NjYAEAKAAtIQERITWiRjbGFz
c25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZl
@adam-cowley
adam-cowley / index.js
Created March 2, 2018 16:24
Neo4j Driver as an Express Middleware
// Create an express app
const express = require('express');
const app = express();
// Tell it to use Neo4j middleware
app.use(require('./neo4j'));
// Example Route
app.get('/', (req, res) => {
// Create Driver session
@adam-cowley
adam-cowley / createCypher.js
Created June 4, 2018 17:34
Using Neo4j Temporal data types in Neo4j Drivers
const neo4j = require('neo4j-driver').v1
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo'))
const session = driver.session()
session.run(
'CREATE (e:Event { id: $id, title: $title, startsAt: datetime($startsAt) }) RETURN e',
{
id: 2,
title: 'Another Test Event',
@adam-cowley
adam-cowley / test.grass
Created January 30, 2020 21:03
Custom icons in Neo4j Browser
node {
diameter: 50px;
color: #A5ABB6;
border-color: #9AA1AC;
border-width: 2px;
text-color-internal: #FFFFFF;
font-size: 10px;
}
relationship {
color: #A5ABB6;
{ status: 'success', message: 'Book updated' }
{
ISBN: 1,
publication: '2020-03-13',
createdAt: '2020-03-13T17:30:20.191000000Z'
}
@adam-cowley
adam-cowley / all.cypher
Last active June 11, 2021 10:15
Euro 2020 in Neo4j
:begin
CREATE INDEX ON :Fixture(kickoff);
CREATE CONSTRAINT ON (node:Country) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:Fixture) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:Group) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:Player) ASSERT (node.id) IS UNIQUE;
CREATE CONSTRAINT ON (node:Stadium) ASSERT (node.name) IS UNIQUE;
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
CALL db.awaitIndexes(300);
@adam-cowley
adam-cowley / episodes.cypher
Last active February 3, 2022 13:32
Learn with Jason as a Graph
// Create a graph of episodes and guests
CALL apoc.load.json('https://www.learnwithjason.dev/api/episodes')
YIELD value
//
MERGE (e:Episode {
id: value._id
})
ON CREATE SET
e.createdAt = datetime(),