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 elementIsVisibleInViewport = (el, partiallyVisible = false) => { | |
const { top, left, bottom, right } = el.getBoundingClientRect(); | |
const { innerHeight, innerWidth } = window; | |
return partiallyVisible | |
? ((top > 0 && top < innerHeight) || (bottom > 0 && bottom < innerHeight)) && | |
((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth)) | |
: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth; | |
}; |
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 detectDeviceType = () => | |
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) | |
? 'Mobile' | |
: 'Desktop'; |
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 fs = require('fs'); | |
const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined); |
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 arrayToCSV = (arr, delimiter = ',') => | |
arr.map(v => v.map(x => `"${x}"`).join(delimiter)).join('\n'); |
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 words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolean); |
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 httpsRedirect = () => { | |
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]); | |
}; |
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 flattenObject = (obj, prefix = '') => | |
Object.keys(obj).reduce((acc, k) => { | |
const pre = prefix.length ? prefix + '.' : ''; | |
if (typeof obj[k] === 'object') Object.assign(acc, flattenObject(obj[k], pre + k)); | |
else acc[pre + k] = obj[k]; | |
return acc; | |
}, {}); |
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 JSONtoCSV = (arr, columns, delimiter = ',') => | |
[ | |
columns.join(delimiter), | |
...arr.map(obj => | |
columns.reduce( | |
(acc, key) => `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`, | |
'' | |
) | |
) | |
].join('\n'); |
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 fs = require('fs'); | |
const JSONToFile = (obj, filename) => | |
fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2)); |
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
def shortest_path(v,w) | |
raise ArgumentError unless path?(v,w) to_edge = [] | |
bfs(w) { |v1,v2| to_edge[v2] = v1 } result = [] | |
x= v | |
while x != w | |
result << x | |
x = to_edge[x] | |
end | |
result << x | |
end |
NewerOlder