Skip to content

Instantly share code, notes, and snippets.


Kenny Bastani kbastani

View GitHub Profile
kbastani / gist:6c3df0418d9d61a1a994
Last active Aug 29, 2015
The Oregon Brewers Festival is the quintessential celebration of craft beer!
View gist:6c3df0418d9d61a1a994
= Craft Beers Are Everywhere in Portland =
:neo4j-version: 2.1.2
:author: Kenny Bastani
:twitter: @kennybastani
This GraphGist tells a story about why relationships matter and how craft beers seem to be everywhere in Portland.
== Like Graphs, Craft Beers Are Everywhere
Let me first start out by stating that I ([@kennybastani]) am a happy evangelist for the[Neo4j Graph Database].
kbastani / graph-art-1
Last active Aug 29, 2015
Run these Cypher scripts sequentially to generate graph art in Neo4j
View graph-art-1
MATCH (a), (b)
WHERE id(a) = 10484 AND id(b) = 10546
MATCH p=shortestPath((a)-[*]-(b))

Prim’s algorithm generates a minimum spanning tree from a graph with weighted edges. Starting in the bottom-left corner, the algorithm keeps a heap of the possible directions the maze could be extended (shown in pink). At each step, the maze is extended in the direction with the lowest weight, as long as doing so does not reconnect with another part of the maze. Here the edges are initialized with random weights.

Unlike Wilson’s algorithm, this does not result in a uniform spanning tree. Sometimes, random traversal is misleadingly referred to as randomized Prim’s algorithm; however, the two algorithms exhibit radically different behavior! The global structure of the maze can be more easily seen by flooding it with color.


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.

View gist:588d53ffc824da4c8b1d

= What is the Neo4j GraphGist project?

:neo4j-version: 2.1.0 :author: Anders Nawroth :twitter: @nawroth :tags: domain:example[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[Cypher].

View einstein-riddle-cypher
= Logical Graphs =
:neo4j-version: 2.0.3
:author: Kenny Bastani
:twitter: @kennybastani
image::[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
View Interpolate-Missing-Data-Points
// 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 / Neo4jTransactionalEndpointUtility.cs
Last active Mar 6, 2018
Neo4j Transactional Endpoint Implementation for C# .NET
View Neo4jTransactionalEndpointUtility.cs
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;
kbastani / Reify relationships
Last active Aug 29, 2015
Data Modeling Training San Francisco
View Reify relationships
MATCH (n1:node { = "1234" })
MATCH (n0)-[r1]->(n1)-[r2]->(n2)
DELETE r1, n1, r2
MERGE (n0)-[:NEXT]->(n2)