Skip to content

Instantly share code, notes, and snippets.

:octocat:
Working from home

Sung M. Kim dance2die

:octocat:
Working from home
Block or report user

Report or block dance2die

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View add numbers by currying.js
// refer to https://dev.to/minimumviableperson/comment/c0b9
// by @minimumviableperson
const double = x => x*2;
const addOne = x => x+1;
const addFn = (...args) => {
let count = 0;
const map = {
View Comparison Table.md
Short-circuit? Short-circuits on? Fulfilled on? Rejected on?
Promise.all First rejected promise All promise fulfilled First rejected promise
Promise.allSettled N/A Always N/A
Promise.race First settled First promise fulfilled First rejected promise
Promise.any First fulfilled First promise fulfilled All rejected promises
View 1. Promise.any.js
// Example #1
Promise.any([
Promise.reject(''),
Promise.reject(''),
Promise.resolve(''),
Promise.reject(''),
]).then(function(value) {
console.log(`You win at life`, value)
});
View 1. Promise.race.js
const promiseWillFulfill = [
new Promise((resolve, reject) => setTimeout(reject, 250, '😈')),
new Promise((resolve, reject) => setTimeout(resolve, 150, '😇')),
new Promise((resolve, reject) => setTimeout(resolve, 1, '😇')),
]
Promise.race(promiseWillFulfill)
.then(value => console.log(`The humanity survives "${value}"`))
.catch(error => console.log(`Won't be called as 😇 will win the race`))
View 1. Promise.allSettled.js
const allRejectedPromises = [
Promise.reject('🍏 #1'),
Promise.reject('🍏 #2'),
Promise.reject('🍏 #3'),
]
Promise.allSettled(allRejectedPromises)
.then(badApples =>
console.log(`We can't sell any of these apples...`, badApples))
.catch(error => console.error('This should never occur'))
View 1. Promise.all.js
const promisesWithoutReject = [
Promise.resolve('🍎 #1'),
'🍎 #2',
new Promise((resolve, reject) => setTimeout(resolve, 100, '🍎 #3'))
]
Promise.all(promisesWithoutReject)
.then(apples => console.log(`We can sell all these good apples`, apples))
View Promise.all.js
const promisesWithoutReject = [
Promise.resolve('🍎 #1'),
'🍎 #2',
new Promise((resolve, reject) => setTimeout(resolve, 100, '🍎 #3'))
]
Promise.all(promisesWithoutReject)
.then(apples => console.log(`We can sell all these good apples`, apples))
View Example.useLayoutEffect.md
const Example = () => {
  // code above removed for brevity...
  
  const handleKeyDown = ({ keyCode }) => {
    keys[keyCode] && setScrollOffset(keys[keyCode])
  }

+  useLayoutEffect(() => {
+    outerListRef.current &&
View Example.handleKeyDown.md
const Example = () => {
  const outerListRef = useRef(undefined)
  const innerListRef = useRef(undefined)
+  const [scrollOffset, setScrollOffset] = useState(0)
+  const listHeight = 150

+  const [pageUp, pageDown, home, end] = [33, 34, 36, 35]
   // The magic number "5" is an arbitrary value from trial & error...
+  const pageOffset = listHeight * 5
View Example.div.md
const Example = () => {
  //.. rest hidden for brevity

  return (
+    <div onKeyDown={handleKeyDown} tabIndex="0" style={{ width: '151px' }}>
      <List
        className="List"
        height={listHeight}
        itemCount={1000}
You can’t perform that action at this time.