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 useAsync = <T, E = string>( | |
| asyncFunction: () => Promise<T>, | |
| immediate = true | |
| ) => { | |
| const [status, setStatus] = useState< | |
| "idle" | "pending" | "success" | "error" | |
| >("idle"); | |
| const [value, setValue] = useState<T | null>(null); | |
| const [error, setError] = useState<E | null>(null); | |
| // The execute function wraps asyncFunction and |
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
| function useTimeout(callback: () => void, delay = 1000 * 5) { | |
| const callbackRef = useRef<typeof callback | null>(null); | |
| useEffect(() => { | |
| callbackRef.current = callback; | |
| }, [callback]); | |
| useEffect(() => { | |
| function execute() { | |
| callbackRef.current?.(); |
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
| // Define which elements this form is going to have | |
| interface FormElements extends HTMLFormControlsCollection { | |
| fieldName: HTMLInputElement; | |
| } | |
| // Set a "HTMLFormElement" interface with those elements | |
| interface MyForm extends HTMLFormElement { | |
| readonly elements: FormElements; | |
| } |
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 RegExp(".*" + "string".split("").join(".*") + ".*") |
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
| <div id="app"></div> |
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
| Compile the latest Vim 7.4 on CentOS 7 | |
| # yum install gcc make ncurses ncurses-devel | |
| # yum install ruby ruby-devel lua lua-devel luajit \ | |
| luajit-devel ctags git python python-devel \ | |
| python3 python3-devel tcl-devel \ | |
| perl perl-devel perl-ExtUtils-ParseXS \ | |
| perl-ExtUtils-XSpp perl-ExtUtils-CBuilder \ | |
| perl-ExtUtils-Embed |
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
| import sleep from 'utils/sleep'; | |
| const SONG_DELAY_TIME = 400; | |
| export const sing = payload => async (dispatch, getState) => { | |
| dispatch(startSong()); | |
| const { match } = getState(); | |
| for (let i = 0; i <= match.all.length - 1; i++) { | |
| const id = match.all[i]; | |
| dispatch(lightenPad({ id })); | |
| await sleep(SONG_DELAY_TIME); // sleep time during note play |
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
| export default function sleep(ms = 0) { | |
| return new Promise(r => setTimeout(r, ms)); | |
| } |
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 start = createAction(START_GAME); | |
| const next = createAction(NEXT_LEVEL); | |
| const startGame = payload => start({ next: getRandomId() }); | |
| const nextLevel = payload => next({ next: getRandomId() }); | |
| startGame(); // { type: ‘START_GAME’, payload: { next: ‘red’ } } | |
| startGame(); // { type: ‘START_GAME’, payload: { next: ‘blue’ } } | |
| startGame(); // { type: ‘START_GAME’, payload: { next: ‘yellow’ } } |
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 { guessed, all } = getState().match; | |
| console.log(all, guessed) // ['red'] ['red'] | |
| if (guessed[0] === all[0]) { | |
| // keep going from here, guesses are correct | |
| return; | |
| } | |
| // player didnt guessed properly, do something about it |
NewerOlder