Skip to content

Instantly share code, notes, and snippets.

View andreasronge's full-sized avatar

Andreas Ronge andreasronge

View GitHub Profile
require 'rubygems'
require 'neo4j-core'
def connect(d)
d.each{|i| Neo4j::Relationship.new(:flies_to, i[:from], i[:to])}
end
tx = Neo4j::Transaction.new
@a, @b, @c, @z = %w[A B C D].map{|name| Neo4j::Node.new(:name => name)}
connect([ {:from=>@a, :to=>@b}, {:from=>@a, :to=>@c}, {:from=>@b, :to=>@c},
@andreasronge
andreasronge / StackTrace
Created August 17, 2012 10:16
JVM Crash using JRuby 1.7.preview2
Environment
===========
Mac OSX
jruby 1.7.0.preview2
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
How to Reproduce
me = lookup('node_auto_index', 'name', "Joe").as(:me)
me > rel(:favorite) > node(:myFavorites) > rel(:tagged) > node(:tag) < rel(:tagged) < node(:theirFavorites) < rel(:favorite) < node(:people)
me != node(:people)
ret node(:people)[:name].as(:name), count.desc.as(:similar_favs)
@andreasronge
andreasronge / Gemfile
Last active December 10, 2015 08:28
Complete Ha Example
source 'https://rubygems.org'
gem 'rails', '3.2.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'jruby-openssl'
class TransactionalExec
attr_accessor :commit_every, :block
def initialize(commit_every, max_lines = nil, verbose = true, &block)
@commit_every = commit_every
@block = block
@max_lines = max_lines
@verbose = verbose
end
@andreasronge
andreasronge / show.rb
Created April 22, 2013 07:34
Working with relstionships
require 'neo4j'
class Show < Neo4j::Rails::Model
property :show_name, type: String, index: :exact
has_n :booked_bands
end
#I have another model, band.rb
class Band < Neo4j::Rails::Model
@andreasronge
andreasronge / neo4j.rb
Created July 6, 2013 09:47
Spike on neo4j 2.0 featrues
require 'java'
require 'forwardable'
require 'fileutils'
# Load Neo4j Jars for the jars folder
# Put the neo4j 2.0 jars there
jar_folder = File.expand_path('../jars', __FILE__)
jars = Dir.new(jar_folder).entries.find_all { |x| x =~ /\.jar$/ }
jars.each { |jar| require File.expand_path(jar, jar_folder) }
@andreasronge
andreasronge / Gemfile
Last active August 29, 2015 14:00
Example how to deploy Neo4j.rb / neo4j-core app on heroku
source "https://rubygems.org"
ruby "2.1.1"
gem 'sinatra', '1.1.0'
gem 'neo4j-core', '3.0.0.alpha.11'
# Create a node with on property name='andreas', and one label 'Human'
andreas = Neo4j::Node.create({name: 'andreas'}, :Human)
duchess = Neo4j::Node.create({name: 'duchess', character: 'posh'}, :Animal, :Cat)
kim = Neo4j::Node.create({name: 'kim', age: 1}, :Animal, :Cat)
# Create a relationship of type pets between andreas and duchess
# Relationships can also have properties
andreas.create_rel(:pets, duchess, since: 2014)
andreas.create_rel(:pets, kim, since: 2014)
duchess.create_rel(:kittens, kim)
cats = Neo4j::Session.query.match('(h:Human)-[:pets]->(p)').where(h: {name: 'andreas'}).pluck(:p)
# print the name of the cats
puts cats[0][:name]
puts cats[1][:name]