Skip to content

Instantly share code, notes, and snippets.

View vladbatushkov's full-sized avatar
🇺🇦
Pray for Ukraine

Vlad Batushkov vladbatushkov

🇺🇦
Pray for Ukraine
View GitHub Profile
@vladbatushkov
vladbatushkov / eatnoteat-model.elm
Last active November 28, 2020 14:00
eatnoteat model
type alias Model =
{ screen : Screen
, hero : Hero
, foodPanel : FoodPanel
, hp : Hp
, score : Int
, bestResults : List BestResult
}
@vladbatushkov
vladbatushkov / social-network.cql
Created September 13, 2020 14:12
People like posted posts
MATCH (n) DETACH DELETE n;
//DROP INDEX person_name;
CREATE (me:Person { name: "Vlad" })
CREATE (p1:Person { name: "Max" })
CREATE (p2:Person { name: "Peter" })
CREATE (p3:Person { name: "Alex" })
CREATE (po1:Post { content: "What a lovely day." })
CREATE (po2:Post { content: "New challenge - new learnings." })
CREATE (po3:Post { content: "Never give up!" })
CREATE (p1)-[:POSTED]->(po1)
@vladbatushkov
vladbatushkov / rels.md
Last active June 30, 2020 16:33
Explore rels same-name issue on query performance.

Relationships

10k Posts, 2 Tags, 1 Emoji. Explore impact of :CONTAINS rel on query.

Option 1

Schema: (:Emoji)<-[:CONTAINS]-(:Post)-[:CONTAINS]->(:Tag)

@vladbatushkov
vladbatushkov / neo4j-modeling-guide.md
Last active June 25, 2020 15:00
Follow this guideline tips to mastering in Neo4j graph data modeling.

Max De Marzi Modeling Guidelines:

  1. Don’t use the same Relationship Type for everything
  2. Don’t use two relationships when one will do
  3. Keep the same Direction for paths
  4. Use different Relationship Types between label pairs
  5. Pre-Split densely related nodes by relationship types
  6. Try to stick to One Label per Node
  7. Create Indexes on any properties used to Find a Node
@vladbatushkov
vladbatushkov / neo4j-like-a-boss.md
Last active June 25, 2020 14:42
Start explore your Neo4j graph with next queries.

Database Schema

CALL db.schema.visualization();

Graph Size

CALL apoc.meta.stats();
@vladbatushkov
vladbatushkov / tx-address.cql
Last active June 21, 2020 12:56
Find txs chain with addresses
PROFILE MATCH (:Address {address: "addr1-2"})-[:OUT]->(:Output)<-[:OUT]-(t:Transaction)
CALL apoc.path.expandConfig(t, { sequence:'Transaction, <IN, Input, <UNLOCK, Output, <OUT' })
YIELD path
UNWIND nodes(path) as tx
MATCH (tx:Transaction)-[:OUT]->(o:Output)<-[:OUT]-(a:Address)
WHERE (o)-[:UNLOCK]->(:Input)
RETURN DISTINCT *
// check tx chain, 3 - min number of hops in the chain, 6 - max
// where is no chains longer than 3 hops = 2 tx. (each (tx)-to->(tx) step required 3 hops).
@vladbatushkov
vladbatushkov / blockchain-gen.cql
Last active June 15, 2020 13:51
blockchain generation script
MATCH (n) DETACH DELETE n;
CREATE (b:Block {hash: 'block1'});
// Coinbase 1
MATCH (b:Block {hash: 'block1'})
CREATE
(i:Input {coinbase: 'coinbase1'}),
(tx:Transaction {id: 'tx1-1'}),
(o:Output {n: 0, value: 11}),
(a:Address {address: 'addr1-1'})
@vladbatushkov
vladbatushkov / neo4j-apoc-gds.dockerfile
Last active September 1, 2020 08:22
Neo4j 4.0.0 + APOC + GDS
FROM neo4j:4.0.0
ENV APOC_VERSION=4.0.0.4
ENV APOC_URI=https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/${APOC_VERSION}/apoc-${APOC_VERSION}-all.jar
ENV GDS_VERSION=1.0.0
ENV GDS_URI=https://github.com/neo4j/graph-data-science/releases/download/${GDS_VERSION}/neo4j-graph-data-science-${GDS_VERSION}-standalone.jar
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
RUN wget $APOC_URI && mv apoc-${APOC_VERSION}-all.jar plugins/apoc-${APOC_VERSION}-all.jar
@vladbatushkov
vladbatushkov / money-query.cql
Last active May 30, 2020 06:21
Find circular money flow in financial graph
PROFILE MATCH path = (t1:Transaction)-[:HOP*3..10]->(t2:Transaction)
WHERE (t1)<-[:OUT]-(:Client)-[:IN]->(t2)
AND t1.timestamp < t2.timestamp
AND (t1.amount - t2.amount) / t1.amount < 0.25
UNWIND nodes(path) as t
MATCH (e)-[:OUT]->(t)
WHERE e:Client OR e:Company
RETURN e, t
@vladbatushkov
vladbatushkov / money-sub.cql
Last active May 30, 2020 06:18
Sub-graph for money graph, that connects Transactions via HOPs
// clean up HOPS
CALL apoc.periodic.iterate(
"MATCH (:Transaction)-[r:HOP]->(:Transaction) RETURN r",
"DETACH DELETE r",
{ batchSize: 10000, parallel: false });
// generate HOP relationships
CALL apoc.periodic.iterate(
"MATCH (t1:Transaction)<-[:IN]-(e)-[:OUT]->(t2:Transaction)
WHERE (e:Client OR e:Company)
AND t1.timestamp < t2.timestamp