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
| var test = () => { | |
| console.log('fired on DOMContentLoaded or after'); | |
| } | |
| window.onwheneva = test; | |
| document.readyState !== 'loading' ? onwheneva() : | |
| document.addEventListener('DOMContentLoaded', onwheneva); |
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
| // Thanks to https://vincent.billey.me/pure-javascript-immutable-array | |
| import React, { Component } from 'react'; | |
| const setStateArraySplice = ( | |
| stateKey, | |
| arrayStart, | |
| arrayDeleteCount, | |
| ...items | |
| ) => ({ |
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 getProxy = (target = {}, key) => | |
| target[key] || (target[key] = new Proxy({}, { get: getProxy })); | |
| const fillPick = (proxy, fn, fromObject = fn(proxy)) => | |
| Object.assign( | |
| {}, | |
| ...Object.entries(proxy).map(([key, value]) => ({ | |
| [key]: Object.keys(value).length | |
| ? fillPick(value, fn, fromObject[key]) | |
| : fromObject[key], |
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
| new URLSearchParams([...new FormData(ev.target)]) |
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
| open -a Preview ~/Library/Messages/Attachments |
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 getCircularArrayIndex = (i, { length }) => | |
| (i % length + length) % length; | |
| const testArray = new Array(5); | |
| for (let i = -30; i < 31; i++) { | |
| console.log(i, getCircularArrayIndex(i, testArray)) | |
| } |
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
| Exclude file types | |
| !*.snap, !*.test.jsx, !*.test.js |
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 areUnsortedArraysEqual = (...arrs) => { | |
| const everyEqual = ([first, ...arr], isEqual) => | |
| arr.every(item => isEqual(first, item)); | |
| return ( | |
| everyEqual(arrs, (first, arr) => arr.length === first.length) && | |
| everyEqual( | |
| arrs.map(arr => | |
| arr.reduce( | |
| (map, item) => map.set(item, (map.get(item) || 0) + 1), |
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
| // React hook that returns a new key | |
| // when its passed in value goes from false to true. | |
| // Use this for resetting a child component, firing events, etc! | |
| const useNewKey = bool => { | |
| const [key, setKey] = useState(bool ? 0 : 1); | |
| const newKey = Boolean(bool) === Boolean(key % 2) ? key + 1 : key; | |
| useEffect(() => { | |
| setKey(newKey); |
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
| // Thanks to eddmann.com/posts/cartesian-product-in-javascript | |
| const cartesianProduct = (...sets) => | |
| sets.reduce((sets, set) => sets.flatMap(x => set.map(y => [...x, y])), [[]]); | |
| cartesianProduct( | |
| ['a', 'b', 'c'], | |
| ['x', 'y', 'z'], | |
| ); |
OlderNewer