Skip to content

Instantly share code, notes, and snippets.

View apcj's full-sized avatar

Alistair Jones apcj

  • Neo Technology
  • London
View GitHub Profile
@apcj
apcj / machine.js
Created December 5, 2019 21:57
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
MERGE (person:Person{name:"Alistair"})
MERGE (role:Role{name:"Software Engineer"})
MERGE (company:Company{name:"Neo Technology"})
CREATE (empl:Employment{from: 2011})
MERGE (person)-[:CURRENT]->(empl)
MERGE (empl)-[:WORKS_AT]->(company)
MERGE (empl)-[:ROLE]->(role)
// Determine whether first story already exists
@apcj
apcj / README.md
Last active August 29, 2015 14:24 — forked from mbostock/.block

This simple force-directed graph shows character co-occurence in Les Misérables. A physical simulation of charged particles and springs places related characters in closer proximity, while unrelated characters are farther apart. Layout algorithm inspired by Tim Dwyer and Thomas Jakobsen. Data based on character coappearence in Victor Hugo's Les Misérables, compiled by Donald Knuth.

Compare this display to a force layout with curved links, a force layout with fisheye distortion and a matrix diagram.

@apcj
apcj / README.md
Last active August 29, 2015 14:06
Cypher HTTP
@apcj
apcj / poms2cypher.py
Created July 1, 2014 14:00
Emit cypher statements to express maven module structure
#!/usr/bin/python
import os
import xml.etree.ElementTree as xml
ns = '{http://maven.apache.org/POM/4.0.0}'
print 'MATCH (n) OPTIONAL MATCH (n) -[r]-> () DELETE n, r;'
def mergeProject(domElement, variableName):
@apcj
apcj / results.txt
Last active August 29, 2015 14:02
World cup revenge
In 2010, Mexico gained revenge over France for beating them in 1930 after a wait of 80 years
In 1986, Argentina gained revenge over Uruguay for beating them in 1930 after a wait of 56 years
In 2010, Mexico gained revenge over France for beating them in 1954 after a wait of 56 years
In 1986, Brazil gained revenge over Spain for beating them in 1934 after a wait of 52 years
In 1982, France gained revenge over Austria for beating them in 1934 after a wait of 48 years
In 1986, France gained revenge over Italy for beating them in 1938 after a wait of 48 years
In 2006, France gained revenge over Brazil for beating them in 1958 after a wait of 48 years
In 2010, Switzerland gained revenge over Spain for beating them in 1966 after a wait of 44 years
In 1978, Brazil gained revenge over Italy for beating them in 1938 after a wait of 40 years
In 1998, France gained revenge over Brazil for beating them in 1958 after a wait of 40 years
@apcj
apcj / country_distance.cyp
Last active August 29, 2015 14:02
World cup country Geo location
MATCH (c1:Country)
MATCH (c2:Country)
WHERE c1 <> c2
WITH c1, c2, 2 * 6371 * asin(sqrt(haversin(radians(c1.lat - c2.lat))+ cos(radians(c1.lat))*
cos(radians(c2.lat))* haversin(radians(c1.lon - c2.lon)))) AS dist
WHERE dist > 0
RETURN c1.name, c2.name, dist
ORDER BY dist
LIMIT 1000
@apcj
apcj / gist:361a759dabfb1dc608f9
Created June 18, 2014 19:27
Squads that beat each other in the same world cup
MATCH (s:Squad) -[:BEAT]-> () -[:BEAT]-> (s)
RETURN s
@apcj
apcj / .gitignore
Last active January 4, 2016 18:19 — forked from mbostock/.block
data.tsv
@apcj
apcj / README.md
Last active December 19, 2015 13:28 — forked from mbostock/.block

Smooth graph exploration

D3 force layout keeps track of node positions by setting x and y properties on the underlying data. By default it chooses starting positions at random, which is convenient, but leads to high-velocity, distracting movements when force calculations begin.

For many graph structures, it's easy to do better than random for starting positions. We can set specific start positions on the data before handing over control to force layout.

In this example, clicking on a node expands its 10 immediate neighbours. For a short period