Skip to content

Instantly share code, notes, and snippets.

View vladbatushkov's full-sized avatar
🥥
Sabai sabai

Vlad Batushkov vladbatushkov

🥥
Sabai sabai
View GitHub Profile
@vladbatushkov
vladbatushkov / omgc-may-4-7.cypher
Created May 5, 2019 07:50
Species to planet as a homewolrd relationship.
WITH "https://vbatushkov.bitbucket.io/swapi.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.species as species
MATCH (spec:Species { url: species.url })
MATCH (p:Planet { url: species.homeworld })
MERGE (spec)-[:HOMEWORLD]->(p)
@vladbatushkov
vladbatushkov / omgc-may-6-1.cypher
Last active May 6, 2019 16:36
create timetable for one month.
MERGE (c1:City { name: "Folkestone" })
MERGE (c2:City { name: "Calais" })
WITH c1, c2
UNWIND range(1, 31) as day
WITH CASE WHEN date({ year: 2019, month: 5, day: day }).dayOfWeek > 5 THEN 9 ELSE 7 END as morningH, CASE WHEN date({ year: 2019, month: 5, day: day }).dayOfWeek > 5 THEN 21 ELSE 20 END as eveningH, c1, c2, day
MERGE (t1:Trip { code: "1_" + day, departure: DateTime({ year: 2019, month: 5, day: day, hour: morningH }), arrival: DateTime({ year: 2019, month: 5, day: day, hour: morningH, minute: 35 }) })
MERGE (t2:Trip { code: "2_" + day, departure: DateTime({ year: 2019, month: 5, day: day, hour: eveningH }), arrival: DateTime({ year: 2019, month: 5, day: day, hour: eveningH, minute: 35 }) })
MERGE (t3:Trip { code: "3_" + day, departure: DateTime({ year: 2019, month: 5, day: day, hour: morningH }), arrival: DateTime({ year: 2019, month: 5, day: day, hour: morningH, minute: 35 }) })
MERGE (t4:Trip { code: "4_" + day, departure: DateTime({ year: 2019, month: 5, day: day, hour: eveningH }), arrival: Date
@vladbatushkov
vladbatushkov / omgc-may-6-2.cypher
Created May 6, 2019 16:37
Trips for today in all directions.
MATCH (t:Trip)--(c:City)
WHERE t.departure.day = 6
RETURN t, c
@vladbatushkov
vladbatushkov / omgc-may-6-3.cypher
Created May 6, 2019 16:38
Search for trips for appropriate days.
MATCH (c1:City { name: "Calais" })<-[:FROM]-(t1:Trip)
MATCH (c2:City { name: "Folkestone" })<-[:FROM]-(t2:Trip)
WHERE t1.departure.day = 6 AND t1.departure.hour = 7 AND t2.departure.day = 12 AND t2.departure.hour = 21
RETURN t1, t2, c1, c2
MATCH (tr1:Trip { code: "3_7" })
MATCH (tr2:Trip { code: "2_12" })
MERGE (p1:Passenger { name: "Vlad Batushkov", passport: "XXX" })
MERGE (p2:Passenger { name: "Katerina Batushkova", passport: "XXX" })
MERGE (t1:Ticket { sitNo: 7, wagon: 3 })
MERGE (t2:Ticket { sitNo: 8, wagon: 3 })
MERGE (t3:Ticket { sitNo: 1, wagon: 1 })
MERGE (t4:Ticket { sitNo: 2, wagon: 1 })
MERGE (b:Booking { createdAt: localdatetime() })
MERGE (p:Payment { createdAt: localdatetime(), status: "Paid", amount: 400, transactionCode: "XXX" })
@vladbatushkov
vladbatushkov / omgc-may-7-1.cypher
Created May 7, 2019 16:27
Grab FM frequency of Moscow radio stations.
WITH ("http://www.morze.ru/radio_tv/radio_tv1.htm") as url
CALL apoc.load.html(url, { waves: "td.boldtabl"}) YIELD value
WITH apoc.coll.pairsMin(value.waves)[0..50] as val
UNWIND val as v
WITH toFloat(apoc.text.replace(v[0].text, ",", ".")) as fm1, toFloat(apoc.text.replace(v[1].text, ",", ".")) as fm2
WITH apoc.math.round(fm2 - fm1, 1) as diff, fm1, fm2
MERGE (w1:Wave { fm: toString(fm1) + " FM" })
MERGE (w2:Wave { fm: toString(fm2) + " FM" })
MERGE (w1)-[:NEXT { diff: diff }]->(w2)
@vladbatushkov
vladbatushkov / omgc-may-7-2.cypher
Created May 7, 2019 16:28
Top 3 of longest difference of 2 stations.
MATCH (w1:Wave)-[d:NEXT*2]->(w2:Wave)
WITH w1, w2, reduce(result = 0, x in d | result + x.diff) as diff
RETURN w1, w2, max(diff) as max_diff
ORDER BY max_diff DESC
LIMIT 3
@vladbatushkov
vladbatushkov / omgc-may-5-1.cypher
Created May 7, 2019 16:31
Grab perfume brands.
WITH "https://www.fragranceoutlet.com/pages/brands" as url
CALL apoc.load.html(url, { data: "li.brand a" }) YIELD value
UNWIND value.data as brand
MERGE (b:Brand { name: brand.text, url: brand.attributes.href })
@vladbatushkov
vladbatushkov / omgc-may-5-2.cypher
Created May 7, 2019 16:32
Grab perfume products of brands starts from 4, I, O.
WITH ["4", "I", "O"] as list
MATCH (b:Brand)
WHERE apoc.coll.contains(list, left(b.name, 1)) = true
WITH "https://www.fragranceoutlet.com" + b.url as url, b
CALL apoc.load.html(url, { products: "a.product-grid-item p.product-title" }) YIELD value
UNWIND value.products as product
MERGE (p:Product { name: product.text })
MERGE (p)-[:PRODUCED_BY]->(b)
@vladbatushkov
vladbatushkov / omgc-may-9-1.cypher
Created May 9, 2019 15:59
Grab data of Immortal Regiment.
WITH ("https://ru.wikipedia.org/wiki/%D0%91%D0%B5%D1%81%D1%81%D0%BC%D0%B5%D1%80%D1%82%D0%BD%D1%8B%D0%B9_%D0%BF%D0%BE%D0%BB%D0%BA") as url
CALL apoc.load.html(url, { list: "table:not([class]) ul li" }) YIELD value
UNWIND value.list as item
WITH split(replace(item.text, ' - ', ' - '), '-') as arr
WITH trim(arr[0]) as countryName, apoc.text.regexGroups(trim(arr[1]), "[0-9]{4}")[0][0] as year
WITH length(countryName) / 2 as middle, countryName, year
WITH CASE WHEN left(countryName, middle) = right(countryName, middle) THEN left(countryName, middle) ELSE countryName END as cn, year
MERGE (y:Year { value: year })
MERGE (c:Country { name: cn })
MERGE (c)-[:JOINED_AT]->(y)