Skip to content

Instantly share code, notes, and snippets.

View andreasronge's full-sized avatar

Andreas Ronge andreasronge

View GitHub Profile
# This SPIKE is now commited in branch rest: http://github.com/andreasronge/neo4j/tree/restful
# This is a old, see branch for new code, example and a spike of how RESTful Neo4j API would work
require 'rubygems'
require 'json'
require 'sinatra/base'
require 'neo4j'
# This mixin creates the following restful resources
@andreasronge
andreasronge / gist:217094
Created October 23, 2009 18:35
How do I find All actors that acted in these 2 movies, or 3 movies?
require 'model' # from the example/imdb neo4j.rb example
class Actor
def acted_in_cool_movies
traverse.outgoing(:acted_in).find_all {|movie| movie.relationship?(:cool_movies, :incoming)}
end
end
cool_movies = Node.new
all_cool_movies = [m1,m2] # m1,m2 are two movies - defined somewhere else
require "rubygems"
require "neo4j"
class Person
include Neo4j::NodeMixin
# define Neo4j properties
property :name
# define an one way relationship to any other node
require 'rubygems'
require 'neo4j'
# include the Module so we can skip the Neo4j:: prefix
include Neo4j
# this node is accessible from Neo4j.ref_node
# add a relationship to the top principal = All principals
class Neo4j::ReferenceNode
has_one :top_principal
require 'rubygems'
require 'neo4j'
include Neo4j
Transaction.new
# create some people
andreas = Node.new :name => 'andreas'
peter = Node.new :name => 'peter'
kalle = Node.new :name => 'kalle'
@andreasronge
andreasronge / inserter.rb
Created January 24, 2011 18:33
Batch Inserter API
module Neo4j
module Batch
# == Usage
#
# === Nodes/Properties and Relationships
#
# Example:
#
# inserter = Neo4j::Batch::Inserter.new(config, storage)
@andreasronge
andreasronge / JVM_jruby_crash
Created June 16, 2011 09:12
JVM/JRuby crash
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xb3746cdd, pid=9500, tid=2348546928
#
# JRE version: 6.0_24-b07
# Java VM: Java HotSpot(TM) Server VM (19.1-b02 mixed mode linux-x86 )
# Problematic frame:
# J org.jruby.RubyBasicObject.getRuntime()Lorg/jruby/Ruby;
#
@andreasronge
andreasronge / InvokeDynamicBug
Created August 15, 2011 11:51
JRuby InvokeDynamicSupport bug ?
InvokeDynamicSupport.java:2541:in `findVirtual': java.lang.RuntimeException: java.lang.IllegalAccessException: symbolic reference class is not public: class org.neo4j.kernel.impl.core.RelationshipProxy, from org.jruby.runtime.invokedyna$
from InvokeDynamicSupport.java:1603:in `createJavaHandle'
from InvokeDynamicSupport.java:1103:in `handleForMethod'
from InvokeDynamicSupport.java:1059:in `tryDispatchDirect'
from InvokeDynamicSupport.java:1065:in `getTarget'
from InvokeDynamicSupport.java:441:in `invocationFallback'
from jruby.rb:28:in `method__2$RUBY$visit_ref_node'
from jruby$method__2$RUBY$visit_ref_node:65535:in `call'
from jruby$method__2$RUBY$visit_ref_node:65535:in `call'
from InvokeDynamicSupport.java:1244:in `fail'
@andreasronge
andreasronge / cypher.rb
Created January 5, 2012 10:19
recommendation example
recommend = Neo4j.query do
node(alice).where_not{|me| me > ':follows' > :user} > ':used_tag' > :tag < ':used_tag' < :user
ret(node(:user), count(:tag).desc(count(:tag)))
end.first[:user]
@andreasronge
andreasronge / basic_test.rb
Created January 5, 2012 13:42
Domain Example
# load 'nodes.rb'
require 'rubygems'
require 'neo4j'
alice = Neo4j::Transaction.run { Neo4j::Node.new }
bob = Neo4j::Transaction.run { Neo4j::Node.new }
Neo4j::Transaction.run do
alice[:name] = "alice"
alice[:score] = [42,4]