Sunday, December 4, 2011

Neo4j Labs: Heroku, Neo4j and Google Spreadsheet in 10min. Flat.

Hi all,

Last Friday, we were all labbing again - the best day of the week.

I didn't have much time so I decided to try to produce a screencast that would measure the time required to go from nothing to flash using some of our tools.

What I came up with demonstrates the process required to set up a Neo4j instance via Heroku, then connect to it from within a Google Spreadsheet (which your managers will like) using appscript.
Simple, yet pretty cool.

Note: Please make sure that you are part of the Heroku private beta program, before trying this yourself.  Alternatively send an email to heroku at neo4j.org for getting registered.
The addon-documentation is also available at heroku (protected).

 The basic steps are:
  • Register at Heroku and install the heroku gem
  • Create and install a Heroku app (heroku apps:create)
  • Add a Neo4j addon instance to it (heroku addons:add neo4j)
  • Upload existing Twitter data to the graph
  • Create a custom Ruby app (code below, GitHub)
  • Execute Cypher queries (queries below) 
  • Connect to the app using a Google Spreadsheet 
  • Build a small bar chart from a Cypher query.
Watch the screencast to see it in action:

Heroku, Neo4j and Google Spreadsheet in 10min. Flat.

What do you think, both about the content and the screencast itself? Some thoughts:
  • quality is not stellar but acceptable with IShowU and built-in MacBookPro Mic
  • probably a transcript of the commands used in the cast would be good, as suggested by Patrick Durusau
  • YouTube seems to have a problem accepting my login via iMovie, which I used for putting together the pieces.
  • All in all, it will take about 2h to produce this kind of casts, hope to get that down to 1h for 5 minutes.
Create and launch Heroku Application
# Register at Heroku and for the beta program
> git init
> heroku apps:create <app-name>
> heroku addons:add neo4j
> add the files below
> git add *; git commit -m"neo4j demo"
> git push heroku master
# Gemfile
source :rubygems

gem 'sinatra'
gem 'json'
gem 'rest-client'

#config.ru
require './cypher-endpoint'
run Sinatra::Application

#cypher-endpoint.rb
require 'sinatra'
require 'rest-client'
require 'json'

rest = RestClient::Resource.new(ENV['NEO4J_URL'])

post '/raw-cypher' do
    data = {:query=>request.body.read }
    rest["/db/data/ext/CypherPlugin/graphdb/execute_query"].post data.to_json, 
                 {:accept=>"application/json",:content_type=>"application/json"}
end

Cypher Queries
start user=node(212) match user-[:USED]->tag return tag.name
start user=node:users(twid:*)
  match user-[:TWEETED]->tweet
  return user.twid, count(*)
curl -d'start user=node:users("twid:*")
  match user-[:TWEETED]-> tweet -[:TAGGED]-> tag
  return user.twid, tag.name, count(*)
  order by count(*)
  desc limit 10' http://heroku-neo4j-appscript-demo.heroku.com/raw-cypher


For the next screencasts, please suggest topics that you are interested in!
Even better - create a screencast about a Neo4j topic yourself.

Enjoy!

/peter

PS: The front picture is my son Kalle during a tour around the beautiful island of Nordkoster.

6 comments:

Anonymous said...

Now *that* was cool :).

What was exactly in that zip file containing the data and how did it get into Neo4j?

Peter Neubauer said...

Oh, that could be any neo4j datastore, zipped up. This one came from an installation of Michael Hungers Birdies project, see http://birdies.heroku.com/

Hope you enjoy it!

/peter

Andreas Ronge said...

Really great demo !
The rest of my team in China can't watch this because of the great firewall. Where can I download this ?

Peter Neubauer said...

Argh,
I deleted the files from my computer, it's only at Vimeo :/ maybe screen capture?

negarnil said...

Neo4j Heroku addon rocks! how can I deploy my server plugins to my Neo4j instance in Heroku?

Michael Hunger said...

You can't yet, this is something that will come with the paid plans of Neo4j. What you can use right now is the JRuby Script extension.