Skip to content

Instantly share code, notes, and snippets.

View cheerfulstoic's full-sized avatar

Brian Underwood cheerfulstoic

View GitHub Profile

The best GraphGist evahh!

This is awesome. Yaaaahhh!!

foo

@cheerfulstoic
cheerfulstoic / tinypng.rb
Created January 26, 2016 08:58
TinyPNG script
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'dotenv'
Dotenv.load
require 'tinify'
require 'json'
@cheerfulstoic
cheerfulstoic / trace_execution.rb
Last active February 27, 2018 14:07
trace_execution
def trace_execution(levels = 4)
cyan = "\e[36m"
clear = "\e[0m"
green = "\e[32m"
indent = 0
output = ''
trace = TracePoint.new(:call, :c_call, :return, :c_return) do |tp|
if [:return, :c_return].include?(tp.event) && indent.nonzero?
@cheerfulstoic
cheerfulstoic / file1.adoc
Created December 15, 2015 04:05
Test gist with multiple files

File 1

@cheerfulstoic
cheerfulstoic / graph_gist_template.adoc
Last active April 14, 2020 07:29
CHANGEME: GraphGist Template. Fork to make your own, view source to see instruction comments

TITLE OF YOUR GRAPHGIST

Open question for the Neo4j.rb community:

ActiveNode models allow for query chaining like so:

object.foo.bar.baz

This is a powerful way to traverse entities which builds Cypher queries under the covers. It is also currently possible to name your variables for later use like so:

object.foo(:f).bar.baz(:b).pluck(:f, 'collect(b)')

This is a test gist

CREATE a;
MATCH a RETURN a;
@cheerfulstoic
cheerfulstoic / gist:262412202b7f8fb283dd
Last active April 17, 2017 21:14
Script for "Neo4j.rb Screencast #6 - Deeper Querying"

Welcome to the sixth episode in a series of short screencasts about the Ruby neo4j gem. Previously we learned how to chain associations together to create queries which can hop across entities and use any part of the entire path to query records of interest. In this episode we dig deeper into the tools behind the magic. A familiarity with the Cypher query language is advised. See the show notes for a link to a Cypher tutorial.

As discussed previously, when we call associations we get a proxy object:

user.created_assets

There are two kinds of proxy objects: AssociationProxy and QueryProxy. The details aren't important for the moment, but behind the scenes both are causing a Query object to be built. We can see this Query object by calling the query method at any point:

user.created_assets.query
@cheerfulstoic
cheerfulstoic / gist:8fc7990a9b361fdfa9d0
Last active August 29, 2015 14:27
Script for "Neo4j.rb Screencast #5 - ActiveRel"

Welcome to the fifth episode in a series of short screencasts about the Ruby neo4j gem. In this episode we will discuss the ActiveRel module which allows us to define model classes for Neo4j relationships.

In previous episodes we've seen that it's possible to work with Neo4j relationships via ActiveNode associations. While associations provide a lot of power through the abstraction of relationships as ties between nodes, Neo4j often allows us to think about relationships as entities worthy of consideration by themselves. When we want a richer representation of a relationship it is useful to create a representative model with it's own structure and logic. In the neo4j gem this is done via the ActiveRel module.

Defining an ActiveRel module is only slightly more complicated than defining an ActiveNode module.

class Viewed
  include Neo4j::ActiveRel
@cheerfulstoic
cheerfulstoic / Neo4j.rb Screencast #4 - Association chaining.md
Last active August 29, 2015 14:26
Script for "Neo4j.rb Screencast #4 - Association chaining"

Welcome to the fourth episode in a series of short screencasts about the Ruby neo4j gem. In this episode we will discuss how to chain associations to create complex queries with the power of Neo4j and the ease of Ruby. You may want to be familiar with Neo4j's Cypher query language before watching this episode, but if you aren't everything should still be comprehensible.

In our asset portal application we have a User model with a created_assets association. This association represents assets which are found by traversing outgoing relationships of the type CREATED:

class User
  has_many :out, :created_assets, type: :CREATED, model_class: :Asset
end

Furthermore, on our Asset model we have a simple categories association which represents the categories for assets.