This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inversionCount = array => { | |
return array.reduce((accumulator, current, index, array) => { | |
return array | |
.slice(index) | |
.filter(item => { | |
return item < current; | |
}) | |
.map(item => { | |
return [current, item]; | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const areaKeys = { | |
A: ["B", "D"], | |
B: ["A", "C", "E"], | |
C: ["B", "F"], | |
D: ["A", "E", "G"], | |
E: ["B", "D", "F", "H"], | |
F: ["C", "E", "I"], | |
G: ["D", "H"], | |
H: ["E", "G", "I"], | |
I: ["F", "H"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tiles.map(tile => { | |
tile.addEventListener("click", event => { | |
const tileArea = tile.style.getPropertyValue("--area"); | |
const emptyTileArea = emptyTile.style.getPropertyValue("--area"); | |
emptyTile.style.setProperty("--area", tileArea); | |
tile.style.setProperty("--area", emptyTileArea); | |
forceGridAnimation(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.tile { | |
background: url(https://source.unsplash.com/900x900/?christmas,holiday,festive); | |
background-size: 300%; | |
} | |
.tile--empty { | |
background: transparent; | |
} | |
.tile--1 { | |
background-position: top left; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
.grid { | |
grid-column-end: span 3; | |
display: grid; | |
grid-gap: 2px; | |
grid-template-areas: | |
"A B C" | |
"D E F" | |
"G H I"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select("timeline_items.*") | |
.from("(#{union_query}) AS timeline_items") | |
.where("timeline_items.date <= ?", Time.current) | |
.order("timeline_items.date DESC") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lead_alerts_query = LeadAlert.timeline_subquery(lead) | |
completed_lead_alerts_query = CompletedLeadAlert.timeline_subquery(lead) | |
notes_query = Note.timeline_subquery(lead) | |
transitions_query = LeadTransition.timeline_subquery(lead) | |
union_query = [lead_alerts_query, completed_lead_alerts_query, notes_query, transitions_query].map(&:to_sql).join(" UNION ALL ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.timeline_subquery(lead) | |
select('lead_alerts.id AS id', 'lead_alerts.action AS body', 'users.first_name AS first_name', 'users.last_name AS last_name', 'lead_alerts.due_on AS date', '"lead_alerts" AS model') | |
.left_joins(:author) | |
.where(lead_id: lead) | |
End |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT timeline_items.* FROM ( | |
# Query 1 | |
SELECT lead_alerts.id AS id, lead_alerts.action AS body, users.first_name AS first_name, users.last_name AS last_name, lead_alerts.due_on AS date, "lead_alerts" AS model | |
FROM `lead_alerts` LEFT OUTER JOIN `users` ON `users`.`id` = `lead_alerts`.`author_id` | |
WHERE `lead_alerts`.`lead_id` = 1 | |
UNION ALL | |
# Query 2 | |
SELECT completed_lead_alerts.id AS id, lead_alerts.action AS body, users.first_name AS first_name, users.last_name AS last_name, completed_lead_alerts.completed_on AS date, "completed_lead_alerts" AS model |
NewerOlder