Skip to content

Instantly share code, notes, and snippets.

@mhluongo
mhluongo / gist:4645421
Last active December 11, 2015 18:58
A quick bit of Cypher demonstrating how you can change the default null-ordering in ORDER BY. Note that the trick is in the null predicate and STR cast.
START n=node({startId})
MATCH (n)-[?:DID]->(thing)
WITH thing, (thing.year? = null) AS year_is_null
WITH thing, STR(year_is_null) as null_year
ORDER BY null_year, thing.year? DESC
RETURN thing, thing.year? as year
import neo4django
from neo4django.db import models
class Preceding(models.NodeModel):
precedes_events = model.Relationship('Condition',reltype=neo4django.Outgoing.PRECEDES_CONDITION)
precedes_conditions = model.Relationship('Event', reltype=neo4django.Outgoing.PRECEDES_EVENT)
class Event(Preceding):
pass
@mhluongo
mhluongo / gist:4524548
Created January 13, 2013 15:16
One approach to integrating neo4django and django.contrib.auth.
from neo4django.db import models
class BlogPost(models.NodeModel):
def __init__(self, user, contents):
self.by_user = user.id
self.contents = contents
by_user = models.IntegerProperty(indexed=True)
contents = models.StringProperty()
@mhluongo
mhluongo / gist:4399621
Created December 28, 2012 16:52
A pymaps extension that exposes maps globally in Javascript.
from pymaps import PyMap
class MyPyMap(PyMap):
#old-style classes, unfortunately
def _mapjs(self, map):
super_js = PyMap._mapjs(self, map)
return super_js + 'PyMaps.push(%s);\n' % map.id
def _buildmaps(self):
super_js = PyMap._buildmaps(self)
@mhluongo
mhluongo / gist:4199327
Created December 4, 2012 00:22
A quick orcid-python example.
>>> import orcid
>>> cs_authors = orcid.search('computer science')
>>> print cs_authors.next()
<Author Olga Zhelenkova, ORCID 0000-0003-0028-2469>
@mhluongo
mhluongo / gist:4009325
Created November 3, 2012 23:37
another neo4django relational filtering workaround
# a hack for pete.groups.filter(created_date__gt = datetime.date(2012,1,1), type__type = "Chess Club")
import datetime
import neo4django
from neo4django.db import models
class Person(models.NodeModel):
auto_id = models.AutoProperty(indexed=True)
groups = models.Relationship('Group', related_name='people',
rel_type=neo4django.Outgoing.MEMBER_OF)
@mhluongo
mhluongo / gist:3251313
Created August 3, 2012 20:39
Attempt to replicate http://travis-ci.org/#!/mhluongo/neo4django/jobs/2013936 using the travis-php box.
vagrant@nettuno:~$ cd ~/builds
vagrant@nettuno:~/builds$ export TRAVIS_PULL_REQUEST=false
vagrant@nettuno:~/builds$ export TRAVIS_SECURE_ENV_VARS=false
vagrant@nettuno:~/builds$ export NEO4J_VERSION="1.6.3"
vagrant@nettuno:~/builds$ git clone --depth=100 --quiet git://github.com/mhluongo/neo4django.git mhluongo/neo4django
vagrant@nettuno:~/builds$ cd mhluongo/neo4django
vagrant@nettuno:~/builds/mhluongo/neo4django$ git checkout -qf 155c266129d2d587b39e5d7acff86b123c94dda7
vagrant@nettuno:~/builds/mhluongo/neo4django$ export TRAVIS_PYTHON_VERSION=2.6
vagrant@nettuno:~/builds/mhluongo/neo4django$ source ~/virtualenv/python2.6/bin/activate
vagrant@nettuno:~/builds/mhluongo/neo4django$ python --version
from neo4django.db import models
import neo4django
class Concept(models.NodeModel):
name = models.StringProperty(indexed=True)
class ContainerConcept(Concept):
class Meta:
abstract = True
@mhluongo
mhluongo / download_neo.sh
Created May 31, 2012 14:33
A bit of bash we use to download Neo and install the cleandb extension on development machines.
#!/bin/bash
VERSION='1.6'
DIR="neo4j-community-$VERSION"
FILE="$DIR-unix.tar.gz"
SERVER_PROPERTIES_FILE="lib/neo4j/conf/neo4j-server.properties"
if [[ ! -d lib/$DIR ]]; then
wget http://dist.neo4j.org/$FILE
tar xvfz $FILE &> /dev/null
@mhluongo
mhluongo / gist:2628389
Created May 7, 2012 15:24
QuerySet relational filtering workaround (as of 5/7/2012. neo4django 03b247d7911753)
# a hack for `NodeA.objects.filter(nodeb__in=nodebnodes)`
from neo4django.db import connections
from neo4django.db.models.script_utils import LazyNode
# ...
b_nodes = set([...]) #your NodeB instances
b_node_ids = [b.id for b in b_nodes]
type_node_a = NodeA._type_node()