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 / omgc-may-1-1.cypher
Last active May 2, 2019 04:08
Generate a graph with nodes of working days and weekends.
WITH date({ year: 2019, month: 12, day: 31 }) as lastDay
UNWIND range(1, lastDay.ordinalDay) as iterator
WITH date(toString(lastDay.year) + CASE WHEN iterator <= 9 THEN "00" WHEN iterator > 9 AND iterator <= 99 THEN "0" ELSE "" END + toString(iterator)) as day
FOREACH(day IN CASE WHEN (day.dayOfWeek > 5) THEN [day] ELSE [] END |
CREATE (:Weekend { day: day, workingHours: 0 })
)
FOREACH(day IN CASE WHEN (day.dayOfWeek < 6) THEN [day] ELSE [] END |
CREATE (:WorkingDay { day: day, workingHours: 8 })
)
@vladbatushkov
vladbatushkov / omgc-may-1-2.cypher
Last active May 3, 2019 16:36
Join working days and weekends into year day by day.
UNWIND apoc.coll.pairsMin(range(1, 365)) as pair
MATCH (w1)
WHERE (w1:WorkingDay OR w1:Weekend) AND w1.day.ordinalDay = pair[0]
MATCH (w2)
WHERE (w2:WorkingDay OR w2:Weekend) AND w2.day.ordinalDay = pair[1]
MERGE (w1)-[:NEXT]->(w2)
RETURN w1, w2
MERGE (g:Genius { name: "Leonardo da Vinci" })
@vladbatushkov
vladbatushkov / omgc-may-2-2.cypher
Created May 2, 2019 16:50
Update with dates of birth and death.
MATCH (g:Genius)
SET g.dateOfBirth = date({ year: 1452, month: 4, day: 15 }), g.dateOfDeath = date({ year: 1519, month: 5, day: 2 })
MATCH (g:Genius)
MERGE (mom:Person { name: "Caterina", occupation: "peasant woman" })
MERGE (dad:Person { name: "Messer Piero", occupation: "notary" })
MERGE (mom)-[:MOTHER_OF]->(g)<-[:FATHER_OF]-(dad)
@vladbatushkov
vladbatushkov / omgc-may-2-4.cypher
Created May 2, 2019 16:51
Create a birth place.
MATCH (g:Genius)
MERGE (v:Region { name: "Vinci" })
MERGE (f:City { name: "Florence" })
MERGE (g)-[:BIRTH_PLACE]->(v)-[:NEAR_BY]->(f)
@vladbatushkov
vladbatushkov / omgc-may-2-5.cypher
Created May 2, 2019 16:52
Leonardo da Vinci known for.
MATCH (g:Genius)
WITH ['Painter', 'Sculptor', 'Architect', 'Musician', 'Scientist', 'Mathematician', 'Engineer', 'Inventor', 'Anatomist', 'Geologist', 'Cartographer', 'Botanist', 'Writer'] as knowns, g
UNWIND knowns as known
MERGE (g)-[:KNOWN_FOR]->(o:Occupation { name: known })
@vladbatushkov
vladbatushkov / omgc-may-2-6.cypher
Last active May 2, 2019 16:55
Well known artworks.
MATCH (o:Occupation { name: "Painter" })
WITH ['The Annunciation', 'The Baptism of Christ', 'Madonna of the Carnation', 'Ginevra de\' Benci', 'Benois Madonna', 'The Adoration of the Magi', 'Saint Jerome in the Wilderness', 'Madonna Litta', 'Virgin of the Rocks', 'Portrait of a Musician', 'Lady with an Ermine', 'The Last Supper', 'La belle ferronnière', 'Sala delle Asse', 'The Virgin and Child with St Anne and St John the Baptist', 'Portrait of Isabella d\'Este', 'The Madonna of the Yarnwinder', 'The Madonna of the Yarnwinder', 'The Virgin and Child with St. Anne', 'Mona Lisa', 'Salvator Mundi', 'Head of a Woman', 'St. John the Baptist'] as artworks, o
UNWIND artworks as artwork
MERGE (o)-[:CREATE]->(a:Artwork { name: artwork })
MATCH (a:Artwork)
WHERE a.name = 'The Last Supper' OR a.name = 'Mona Lisa'
SET a:Masterpiece
@vladbatushkov
vladbatushkov / omgc-may-2-8.cypher
Last active May 2, 2019 16:54
Some of famous inventions.
MATCH (o:Occupation { name: "Inventor" })
WITH ['Parachute', 'Aerial Screw', 'Ornithopter', 'Robots', 'Machine Gun', 'Viola Organista', 'Diving Suit', 'Self-Propelled Cart', 'Armored Vehicle', 'Cannons'] as inventions, o
UNWIND inventions as invention
MERGE (o)-[:INVENT]->(i:Invention { name: invention })