Skip to content

Instantly share code, notes, and snippets.

Neo4j rb finding connectivity between 2 nodes

Question

I am using neo4j.rb in my rails application. I already have two nodes n1 and n2 retrieved from the database. Now i need to check if they have a path between them, i was thinking of using cypher queries using Neo4j::Session.query But since i already have the two nodes i do not want to retrieve them again inside the query,(does it affect performance?) is there a way to do it? I know i can use query1 = n1.query_as(:node1) and use it as the node identifier but how can i introduce n2 within the same query object so that i can check connectivity between them. I want something equivalent to the query

Devise - Authentication

Cancancan - Authorization

Omniauth - Social

Paperclip - Upload

Parrierwave - Upload

@WanderGink
WanderGink / uniqueId.adoc
Created April 10, 2017 04:39 — forked from tekiegirl/uniqueId.adoc
Using the graph to control unique id generation.

Using the graph to control unique id generation

Introduction

This gist was prompted by Nigel Small’s tweet of a query to generate a unique id for a node (and is posted here with his agreement). It inspired me to think about how it could be used in a full example, unrestricted by Twitter’s 140 characters. I have also looked at how we could generate different sets of unique ids for different labels.

Auto-incrementing #Neo4j counter MERGE (x:Counter {name:'foo'}) ON CREATE SET x.count = 0 ON MATCH SET x.count = x.count + 1 RETURN x.count

— Nigel Small (@technige) December 16, 2013

If you are using ZSH and trying to pass a parameter into a task

rake task['param']

or

rake task[param]

you may be getting an error that says

@WanderGink
WanderGink / postgres-cheatsheet.md
Created March 12, 2017 09:04 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@WanderGink
WanderGink / ActiveRecord Cheat Sheet v1
Created March 4, 2017 10:51 — forked from jessieay/ActiveRecord Cheat Sheet v1
Active Record cheat sheet with examples of queries I've needed most so far
ActiveRecord cheat sheet / EXAMPLES
INSTALL
=======
$ gem install activerecord
in GEMFILE: gem ‘activerecord’
REQUIRE
=======
require ‘active_record’
@WanderGink
WanderGink / gist:d7e146ebbc610f365927a87eb01a75d4
Created February 25, 2017 08:25 — forked from cheerfulstoic/gist:3142ed2e15ad08ef6631
Script for "Neo4j.rb Screencast #1 - Create a Neo4j Rails Application"

Welcome to the first episode in a series of short screencasts for the Ruby neo4j gem. Each episode will describe a different aspect of the gem. In this first episode, we will start by discussing how to set up a new Ruby on Rails app using Neo4j. The neo4j gem is not Rails specific so you can use other frameworks like Sinatra or Lotus, but because of the popularity of Ruby on Rails we will be using it for this screencast series.

In this series we’re going to create an application to host digital assets which we’ll call "asset_portal". To create your Rails app you can run a rails new command as usual. To use Neo4j instead of ActiveRecord you can give arguments which will set up a new Rails app using Neo4j models.

rails new asset_portal -m http://neo4jrb.io/neo4j/neo4j.rb -O

The dash-m argument runs a script from the neo4j gem project and the dash-capital-O argument says to exclude ActiveRecord. There aren’t any restrictions on using Neo4j with other ORMs like ActiveRecord, but you will need to conf

@WanderGink
WanderGink / web-fonts-asset-pipeline.md
Created February 14, 2017 11:47 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@WanderGink
WanderGink / Rake Database.md
Created January 7, 2017 14:45 — forked from stevenyap/Rake Database.md
List of rake commands to manage database

Create database

rake db:create

Create database table

This will creates a migration file in /db/migrate without table definition.

rails g migration create_<TABLE>
@WanderGink
WanderGink / zsh.md
Created December 22, 2016 07:49 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu