Skip to content

Instantly share code, notes, and snippets.

body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd, img, form, fieldset, input, textarea, blockquote {
margin: 0; padding: 0; border: 0;
}
body {
margin: 200px;
font-family: Helvetica;
background: white;
}

The Pinterest Graph

This GraphGist is inspired by the blog Building a follower model from scratch, kudos to the Pinterest Engineers!

The model

The basic model is just users following users, something like the following.

@imranansari
imranansari / resque.py
Created February 18, 2014 06:21 — forked from defunkt/resque.py
from redis import Redis
import simplejson
class Resque(object):
"""Dirt simple Resque client in Python. Can be used to create jobs."""
redis_server = 'localhost:6379'
def __init__(self):
host, port = self.redis_server.split(':')
self.redis = Redis(host=host, port=int(port))
MATCH (n1:node { n.id = "1234" })
MATCH (n0)-[r1]->(n1)-[r2]->(n2)
DELETE r1, n1, r2
MERGE (n0)-[:NEXT]->(n2)

The Zen of Cypher

  • Write functions() in lower case, KEYWORDS in upper.
  • START each keyword clause
    ON a new line.
  • Use either camelCase or snake_case for node identifiers but be consistent.
  • Relationship type names should use UPPER_CASE_AND_UNDERSCORES.
  • Label names should use CamelCaseWithInitialCaps.
  • MATCH (clauses)-->(should)-->(always)-->(use)-->(parentheses)-->(around)-->(nodes)
  • Backticks `cân éscape odd-ch@racter$ & keyw0rd$` but should be a code smell.
= C Graph
:neo4j-version: 2.0.0-RC1
'''
//setup
//hide
== Initial Data Setup
//person1 WORKED_AT company1
//person1 WORKED_AT company2
BEARER='...'
def load_tweets(query,since_id=nil,lang="en",page=1,rpp=100)
res=RestClient.get('https://api.twitter.com/1.1/search/tweets.json',
{:params=> {:q=>query, :lang=>lang,:count=>rpp,:result_type=>:recent,:since_id=>since_id},
:accept=>:json,
:Authorization => "Bearer #{BEARER}"})
puts "query '#{query}'\n since id #{since_id} result #{res.code}"
return [] unless res.code==200
data=JSON.parse(res.to_str)

Neo4j cypher for co-favorited plus additional attribute

Answering an Stackoverflow Question.

I am learning Neo4j and decided to take one of the sample queries and add a twist to it. I took this example http://docs.neo4j.org/chunked/stable/cypher-cookbook-co-favorited-places.html and wanted to say what if there was an additional attribute that you could use to filter the results by. My test I put together was to have tags in the graph as well and then I wanted to search by overlapped favorites desc then by overlapping tags desc.

Here is the sample data I am using:

<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
</template>
<script>
@imranansari
imranansari / designer.html
Last active August 29, 2015 14:05
designer
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;