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 / gist:1f278795b122cff09fd2
Last active August 29, 2015 14:04
graphgist-sharaton
= Neo4j GraphDays =
:neo4j-version: 2.0.1
:author: Kenny Bastani
:twitter: @kennybastani
== Create sample dataset
//setup
//hide
[source,cypher]
----

== This is a test

@kbastani
kbastani / gist:6c3df0418d9d61a1a994
Last active August 29, 2015 14:04
The Oregon Brewers Festival is the quintessential celebration of craft beer!
= 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 August 29, 2015 14:04
Run these Cypher scripts sequentially to generate graph art in Neo4j
MATCH (a), (b)
WHERE id(a) = 10484 AND id(b) = 10546
MATCH p=shortestPath((a)-[*]-(b))
RETURN p
@kbastani
kbastani / README.md
Last active August 29, 2015 14:03 — forked from mbostock/.block

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.

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

@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
// 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 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;