Skip to content

Instantly share code, notes, and snippets.

View nicolewhite's full-sized avatar

Nicole White nicolewhite

  • Autoblocks
  • Washington, DC
View GitHub Profile
@nicolewhite
nicolewhite / widest_path.adoc
Last active August 29, 2015 14:02
Solve the Widest Path Problem in Cypher

Solve the Widest Path Problem in Cypher

The widest path problem has a number of applications in many domains, including networking, shipping, and emergency response. Assuming the relationships between nodes in a graph are weighted by a capacity of some sort, the widest path problem involves finding the path between two nodes that maximizes the minimum capacity in the path.

Below, each node is a router in a city and the relationships between the routers have a bandwidth property indicating the bandwidth capacity of the two routers' connection. The direction of the connection is arbitrary.

Wiki graph
@nicolewhite
nicolewhite / community_detection.r
Created June 9, 2014 11:57
Community detection in R.
library(RNeo4j)
library(igraph)
graph = startGraph("http://localhost:7474/db/data/")
clear(graph)
create_users = "FOREACH (i IN RANGE(1,50) | CREATE (:User {id:i, name:'name ' + i}))
WITH 1 AS dummy
@nicolewhite
nicolewhite / weekdays.r
Created July 7, 2014 03:53
Add weekdays to a neo4j time tree.
library(RNeo4j)
graph = startGraph("http://localhost:7474/db/data/")
# Create time tree.
# Copied from http://www.markhneedham.com/blog/2014/04/19/neo4j-cypher-creating-a-time-tree-down-to-the-day/
timetree = "WITH range(2011, 2014) AS years, range(1,12) as months
FOREACH(year IN years |
MERGE (y:Year {year: year})
FOREACH(month IN months |

OSCON Twitter Graph

During the OSCON conference, the Neo4j team will be collecting tweets and adding them to a graph. Below is an example database of 15 tweets.

create (_0:`Tweet` {`text`:"RT @BrentVukmer: The worst things so far about @oscon - too many choices, not enough time."})
create (_1:`User` {`username`:"oscon"})
import requests
import os
import time
from py2neo import neo4j
# Connect to graph and add constraints.
url = os.environ['NEO4J_URL']
# url = "http://localhost:7474/db/data/"
graph = neo4j.GraphDatabaseService(url)

For Nick

Sample Data

I tried to copy your data model as I understood it. I created two User nodes each with five View nodes. User 1’s sequence of views touches a distinct set of Page nodes; User 2’s sequence of views is not a distinct set; User 2 visits the analytics page twice.

@nicolewhite
nicolewhite / terran.cypher
Created November 25, 2015 13:58
Terran build tree in Neo4j
CREATE (depot:Building {name:"Supply Depot", minerals:100, gas:0}),
(command:Building {name:"Command Center", minerals:400, gas:0}),
(orbital:Building {name:"Orbital Command", minerals:150, gas:0}),
(planetary:Building {name:"Planetary Fortress", minerals:150, gas:150}),
(barracks:Building {name:"Barracks", minerals:150, gas:0}),
(ebay:Building {name:"Engineering Bay", minerals:125, gas:0}),
(turret:Building {name:"Missile Turret", minerals:100, gas:0}),
(sensor:Building {name:"Sensor Tower", minerals:125, gas:100}),
(refinery:Building {name:"Refinery", minerals:75}),
(factory:Building {name:"Factory", minerals:150, gas:100}),

US Flights & Airports: Delays, Cancellations, & Diversions


Table of Contents

Pokémon X & Y


Inspiration

@nicolewhite
nicolewhite / import.txt
Last active June 29, 2016 21:35
Cypher query for importing DFW data into Neo4j.
create (_0:`Gate` {`number`:1})
create (_1:`Gate` {`number`:2})
create (_2:`Gate` {`number`:3})
create (_3:`Gate` {`number`:4})
create (_4:`Gate` {`number`:5})
create (_5:`Gate` {`number`:6})
create (_6:`Gate` {`number`:7})
create (_7:`Gate` {`number`:8})
create (_8:`Gate` {`number`:9})
create (_9:`Gate` {`number`:10})