Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Coding

Kenny Bastani kbastani

💭
Coding
View GitHub Profile
@kbastani
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 (http://www.twitter.com/kennybastani[@kennybastani]) am a happy evangelist for the http://www.neo4j.com[Neo4j Graph Database].
@kbastani
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))
RETURN p
View README.md

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.

View README.md

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

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].

View einstein-riddle-cypher
= 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
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
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
kbastani / Reify relationships
Last active Aug 29, 2015
Data Modeling Training San Francisco
View Reify relationships
MATCH (n1:node { n.id = "1234" })
MATCH (n0)-[r1]->(n1)-[r2]->(n2)
DELETE r1, n1, r2
MERGE (n0)-[:NEXT]->(n2)