This file contains 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 shuffle = (arr, mixed = [], pool = arr.slice()) => { | |
const remaining = pool.length; | |
if (!remaining) return mixed; | |
const index = Math.floor(Math.random() * remaining); | |
const el = pool.splice(index, 1).pop(); | |
mixed.push(el); | |
return shuffle(arr, mixed, pool); | |
}; |
This file contains 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 scrollRoot = (() => { | |
if ("scrollingElement" in document) | |
return document.scrollingElement; | |
const initial = document.documentElement.scrollTop; | |
document.documentElement.scrollTop = initial + 1; | |
const updated = document.documentElement.scrollTop; | |
document.documentElement.scrollTop = initial; | |
return updated > initial |
This file contains 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 isObject = obj => Object(obj) === obj; |
This file contains 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 immutable = (() => { | |
const getValue = obj => key => obj[key]; | |
const isObject = obj => Object(obj) === obj; | |
const isMutable = obj => isObject(obj) && !Object.isFrozen(obj); | |
return obj => { | |
Object.keys(obj).map(getValue(obj)).filter(isMutable).forEach(immutable); | |
return Object.freeze(obj); | |
}; | |
})(); |
This file contains 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 iterable = function* (obj) { | |
yield* Object.keys(obj).map(key => [key, obj[key]]); | |
}; |
This file contains 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
<!doctype html> | |
<title>Holy Grail Layout</title> | |
<style> | |
body { | |
display: grid; | |
grid-template-rows: 100px 1fr 100px; | |
grid-template-columns: 200px 1fr 200px; | |
min-height: 100vh; | |
margin: 0 |
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1, width=device-width"> | |
<title>Defer non-essential stylesheets</title> | |
<style> | |
/* Critical above-the-fold styles */ | |
* { margin: 0; padding: 0 } | |
:root { background: red } |
This file contains 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 getPathBoundingBox = (() => { | |
const toPolygon = (path, points = 50) => { | |
const polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon"); | |
const total = path.getTotalLength(); | |
const step = total / points; | |
const getPoints = (dist = 0, arr = []) => { | |
const {x, y} = path.getPointAtLength(dist); | |
arr.push(`${x},${y}`); | |
const next = step + dist; |
This file contains 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 duplicate = obj => JSON.parse(JSON.stringify(obj)); |
This file contains 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
<!doctype html> | |
<meta charset="utf-8"> | |
<title>Example</title> | |
<style> | |
div { | |
width: 100px; | |
height: 100px; | |
background: black; | |
animation-duration: .5s; |