Skip to content

Instantly share code, notes, and snippets.

View Iknewthisguy's full-sized avatar

Chris Bolton Iknewthisguy

View GitHub Profile
=> [#<User:0xfb4
@_java_node=#<Java::OrgNeo4jKernelImplCore::NodeProxy:0x2821e44d>,
@_properties={"first_and_last"=>"Black Panther", "deleted_at"=>nil},
@_properties_before_type_cast={},
@_relationships={}>,
#<User:0xfc4
@_java_node=#<Java::OrgNeo4jKernelImplCore::NodeProxy:0x2346c62b>,
@_properties={"first_and_last"=>"Bat Man", "deleted_at"=>nil},
@_properties_before_type_cast={},
@_relationships={}>]
@Iknewthisguy
Iknewthisguy / gist_cypher_query_limiting
Created July 26, 2012 21:20
Limiting Cypher Query Results
neo4j-sh (0)$ START n=node (4) MATCH (n)-[:`friends`]->(x) WHERE (NOT(n.blocked_friends)) OR (NOT(n.pending_inner)) RETURN x
==> SyntaxException: unknown function
==> "START n=node (4) MATCH (n)-[:`friends`]->(x) WHERE (NOT(n.blocked_friends)) OR (NOT(n.pending_inner)) RETURN x"
==> ^
neo4j-sh (0)$ START n=node (4) MATCH (n)-[:`friends`]->(x) WHERE NOT(n.blocked_friends) OR NOT(n.pending_inner) RETURN x
==> SyntaxException: unknown function
==> "START n=node (4) MATCH (n)-[:`friends`]->(x) WHERE NOT(n.blocked_friends) OR NOT(n.pending_inner) RETURN x"
==> ^
neo4j-sh (0)$ START n=node (4) MATCH (n)-[:`friends`]->(x) WHERE NOT(n.blocked_friends) RETURN x
==> SyntaxException: unknown function
@Iknewthisguy
Iknewthisguy / module_refactoring
Created August 7, 2012 15:01
Module Refactoring - Sample Model
class User < < ActiveRecord::Base
def self.find_by_vanity(vname)
#m = User.find vname
v = Vanity.find_by_name(vname)
m = v.try(:vanity)
#if we couldnt find by Vanity, lets try finding by regular id:
unless v and m
begin
m = User.find!(vname)
@Iknewthisguy
Iknewthisguy / gist:3743800
Created September 18, 2012 15:35
Filter in Cypher
def match
criteria_matched = params[:quantity]
case criteria_matched
when criteria_matched == 4
results = Neo4j._query("START n=node(13626) MATCH(n)-[:_all]->(x) WHERE x.city == #{Resume.city} AND x.school == #{Resume.school} AND x.sport == #{Resume.sport} AND x.skill =~ /(?i-mx:.*#{Resume.skill}.*)/ RETURN x")
when criteria_matched == 5
results = Neo4j._query("START n=node(13626) MATCH(n)-[:_all]->(x) WHERE x.city == #{Resume.city} AND x.school == #{Resume.school} AND x.sport == #{Resume.sport} AND x.skill =~ /(?i-mx:.*#{Resume.skill}.*)/ AND x.history == #{Resume.history} RETURN x")
when criteria_matched == 6
results = Neo4j._query("START n=node(13626) MATCH(n)-[:_all]->(x) WHERE x.city == #{Resume.city} AND x.school == #{Resume.school} AND x.sport == #{Resume.sport} AND x.skill =~ /(?i-mx:.*#{Resume.skill}.*)/ AND x.history == #{Resume.history} AND x.pets == #{Resume.pets} RETURN x")
@Iknewthisguy
Iknewthisguy / gist:3746578
Created September 18, 2012 23:01
Full query
START n=node(#{self.id})
MATCH
(n)-[:friends]->(y)-[:friends]->(z)<-[:`OfferJobResume#resumeuser`]-(t)
WHERE
(z-[:friends]->y-[:friends]->n)
AND NOT(n-[:friends]->z-[:friends]->n)
AND NOT(n-[:blocked_friends]->y-[:blocked_friends|friends]->z)
AND NOT(n-[:blocked_friends|friends]->y-[:blocked_friends]->z)
AND NOT(n-[:blocked_friends]->z)
AND NOT(has(z.deleted_at))
@Iknewthisguy
Iknewthisguy / gist:3778946
Created September 24, 2012 22:54
CoffeeScript Regex
listingSkills = (/\w\S.*/).exec($('div#search-sidebar.contentBox.clearfix div.pa20 div.skills').text())
words = ["the", "and", "but", "a", "an", "some", "or", "yet", "for", "so", "did"]
console.log(listingSkills)
listingSkills.split " "
console.log(listingSkills)
words.forEach (word) ->
listingSkills.replace /word/, ""
@Iknewthisguy
Iknewthisguy / gist:3783558
Created September 25, 2012 18:23
Text Scrubbing
listingSkills = $('div#search-sidebar.contentBox.clearfix div.pa20 div.skills').text().replace /[,\/.()""'']+ ?/g, " "
listingSkills = listingSkills.replace /\b(\s+|and|or|deflect|an|a|etc)\b/g, " "
listingSkills = listingSkills.replace /^\s+|\s+$/g, ""
listingSkills = listingSkills.split /\s+/g
@Iknewthisguy
Iknewthisguy / gist:3912715
Created October 18, 2012 15:50
Sorting across multiple property types
@users.sort! { |a,b| a.name.downcase <=> b.name.downcase }
@Iknewthisguy
Iknewthisguy / gist:3933226
Created October 22, 2012 18:29
Link_to trickiness
%li.search-business
= link_to '#', searches_path(:t => "1") do
%i.icon-star
Business
@Iknewthisguy
Iknewthisguy / gist:4081444
Created November 15, 2012 21:34
Outer_circle
START n=node(127)
MATCH
(n)-[:friends]->(y)-[:friends]->(z)
WHERE
(z<>n)
AND(z-[:friends]->y-[:friends]->n)
AND NOT(n-[:friends]->z-[:friends]->n)
AND NOT(n-[:blocked_friends]->y-[:blocked_friends|friends]->z)
AND NOT(n-[:blocked_friends|friends]->y-[:blocked_friends]->z)
AND NOT(n-[:blocked_friends]->z)