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 / politician_tweets.py
Created August 29, 2014 16:42
Get politicians' tweets and put into csv.
import tweepy
from tweepy import Cursor
import unicodecsv
from unidecode import unidecode
# Authentication and connection to Twitter API.
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
@nicolewhite
nicolewhite / file.md
Last active April 7, 2019 16:34
Datasets for Graph Hack.

Datasets for Graph Hack 2014.

All stores are Neo4j 2.1.3.

Transportation

What is related, and how?

Flight	ORIGIN Airport
@nicolewhite
nicolewhite / userDefineLang_Cypher.xml
Last active June 15, 2022 17:17
A Cypher syntax highlighter for Notepad ++.
<NotepadPlus>
<UserLang name="Cypher" ext="cypher" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="yes" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 01 02 03// 04</Keywords>
<Keywords name="Operators1">( ) , = :</Keywords>
<Keywords name="Folders in comment, open">CASE</Keywords>
@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})