Skip to content

Instantly share code, notes, and snippets.

View kbastani's full-sized avatar
💭
Coding

Kenny Bastani kbastani

💭
Coding
View GitHub Profile
@kbastani
kbastani / neo4j-cypher-delete-id-list.txt
Created August 14, 2013 19:06
Follow the steps in this gist to find and delete duplicate nodes on property and index in Neo4j graph database web admin console.
// Delete duplicate nodes as a list collected from the output of neo4j-cypher-duplicate-get-node.txt
START n=node(1120038,1120039,1120040,1120042,1120044,1120048,1120049,1120050,1120053,1120067,1120068)
// Replace IDs above with the IDs from CommaSeparatedListOfIds in neo4j-duplicate-get-node.txt
MATCH n-[r]-()
DELETE r, n
@kbastani
kbastani / CalendarDay.cql
Last active July 14, 2020 20:36
This gist is a Neo4j Cypher query for merging a calendar graph for a specific year. This query has 4 levels of indexes, consisting of year, month, day, hour.
// Enter the day you would like to create
WITH { day: 18, month: 1, year: 2014 } as dayMap
// Merge hours in a day
MERGE (thisDay:Day { day: dayMap.day, month: dayMap.month, year: dayMap.year })
MERGE (firstHour:Hour { day: dayMap.day, month: dayMap.month, year: dayMap.year, hour: 1 })
CREATE (thisDay)-[:FIRST]->(firstHour)
FOREACH (i IN tail(range(1, 24)) |
MERGE (thishour:Hour { day: dayMap.day, month: dayMap.month, year: dayMap.year, hour: i })
MERGE (lasthour:Hour { day: dayMap.day, month: dayMap.month, year: dayMap.year, hour: i - 1 })
@kbastani
kbastani / CasinoStaff-24-7-Alice.CQL
Last active January 3, 2016 22:39
Casino staff 24/7
// Setup data for casino employee: Alice
WITH { day: 18, month: 1, year: 2014 } as dayMap
// The dayMap field acts as a parameter for this script
// Merge Alice and his skills
MERGE (baccarat:Skill { name: "Baccarat" })
MERGE (blackjack:Skill { name: "Blackjack" })
MERGE (roulette:Skill { name: "Roulette" })
MERGE (alice:Employee { firstname: "Alice", lastname: "Smith" })
@kbastani
kbastani / gist:9009200
Last active August 29, 2015 13:56
Neo4j Data Modeling Training
MERGE (pressly:Person{name:'pressly'})
MERGE (yoom:Person{name:'yoom'})
MERGE (paul:Person{name:'paul'})
MERGE (company:Company{name:'acme'})
MERGE (neo4j:Skill{name:'Neo4j'})
MERGE (rest:Skill{name:'REST'})
MERGE (java:Skill{name:'JAVA'})
MERGE (cpp:Skill{name:'C++'})
MERGE (gremlin:Skill{name:'Gremlin'})
MERGE (ruby:Skill{name:'Ruby'})
@kbastani
kbastani / Reify relationships
Last active August 29, 2015 13:56
Data Modeling Training San Francisco
MATCH (n1:node { n.id = "1234" })
MATCH (n0)-[r1]->(n1)-[r2]->(n2)
DELETE r1, n1, r2
MERGE (n0)-[:NEXT]->(n2)
@kbastani
kbastani / Neo4jTransactionalEndpointUtility.cs
Last active March 6, 2018 19:15
Neo4j Transactional Endpoint Implementation for C# .NET
using Neo4jClient;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
// Create a list of dates to use as data points
// Count the amount of days since the creation date
int dayCount = DateTime.Now.Subtract(createdDate).Days;
// Create an index of data points and calculate linear interpolation for a given point
int[] membershipPoints = new int[dayCount];
for (int i = 0; i < membershipPoints.Length; i++)
{
// Calculate membership count using linear interpolation
@kbastani
kbastani / einstein-riddle-cypher
Created May 13, 2014 21:22
Who owns the fish?
= Logical Graphs =
:neo4j-version: 2.0.3
:author: Kenny Bastani
:twitter: @kennybastani
image::https://c2.staticflickr.com/4/3034/3047586737_9ba0b25fbf.jpg[Who owns the fish?]
There are five houses in five different colours starting from left to right. In each house lives a person of a different nationality. These owners all drink a certain type of beverage, smoke a certain brand of cigarette and keep a certain type of pet. No two owners have the same pet, smoke the same brand or drink the same beverage. The question is: WHO OWNS THE FISH???
== Problem
@kbastani
kbastani / gist:588d53ffc824da4c8b1d
Created May 22, 2014 23:28
sample project page

= What is the Neo4j GraphGist project?

:neo4j-version: 2.1.0 :author: Anders Nawroth :twitter: @nawroth :tags: domain:example

http://neo4j.com[Neo4j] GraphGists are an easy way to create and share documents containing not just prose, structure and pictures but most importantly example graph models and use-cases expressed in Neo4j's query language http://docs.neo4j.org/refcard/2.1/[Cypher].

The tree layout implements the Reingold-Tilford algorithm for efficient, tidy arrangement of layered nodes. The depth of nodes is computed by distance from the root, leading to a ragged appearance. Cartesian orientations are also supported. Implementation based on work by Jeff Heer and Jason Davies using Buchheim et al.'s linear-time variant of the Reingold-Tilford algorithm. Data shows the Flare class hierarchy, also courtesy Jeff Heer.

Compare to this Cartesian layout.