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
export function useCallbackInNextRender() { | |
const [value, set] = useState(null); | |
useSafeEffect( | |
(safetyGuard) => { | |
if (!value) return; | |
const [callback, args] = value; | |
callback(safetyGuard, ...args); | |
}, | |
[value] |
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 when = (pred, f) => (data) => pred(data) ? f(data) : data | |
// example | |
pipe( | |
when(isOdd, increment), | |
) |
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
import { useEffect } from 'react' | |
export default function useReference(lazyRefCreator, deps) { | |
const ref = useRef() | |
useEffect(() => { | |
ref.current = lazyRefCreator() | |
}, deps) | |
return ref.current |
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
// require without cache | |
const __r = (m) => { delete require.cache[require.resolve(m)]; return require(m) } | |
const reload = () = { | |
Object.keys(require.cache).forEach((module) => { | |
delete require.cache[module] | |
require(module) | |
}) | |
} |
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 withLogger = (reducer) => (state, action) => { | |
const boldStyle = 'font-weight:bold'; | |
console.groupCollapsed(`%caction %c${action.type}`, 'color:#CCC', boldStyle); | |
console.log('%cprev state', `${boldStyle};color:#9E9E9E`, state); | |
console.log('%caction ', `${boldStyle};color:#03A9F4`, action); | |
const after = reducer(state, action); | |
console.log('%cnext state', `${boldStyle};color:#4CAF50`, after); | |
console.groupEnd(); | |
return after; | |
}; |
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
// @flow | |
import * as React from 'react'; | |
import classNames from 'classnames'; | |
// import type { ClassNames } from 'classnames'; | |
type ClassNames = any; | |
export type ClassNamesOrFunction = ClassNames | ((props: any) => ClassNames); |
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
beforeEach(() => { | |
cy.window().then((win) => { | |
cy.spy(win.console, "error"); | |
cy.spy(win.console, "warn"); | |
}); | |
}); | |
afterEach( () => { | |
cy.window().then((win) => { | |
expect(win.console.error).to.have.callCount(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
import hashlib | |
import os | |
from os.path import exists, isfile, join, basename | |
import shutil | |
def md5(file): | |
hash_md5 = hashlib.md5() | |
with open(file, "rb") as f: | |
for chunk in iter(lambda: f.read(4096), b""): | |
hash_md5.update(chunk) |
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
(defn get-final-freq | |
"Day one: calculate resulting frequency" | |
[freq_list] | |
; 1. clojurist prefer to use `-` instead of `_` in names | |
; 2. I'm not sure how you got and what's inside `freq_list` (I suppose integers, then it's fine) | |
(reduce + freq_list)) | |
(defn repeated-freq | |
"Day one: first occur of repeated frequency" | |
[freq_list] |