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 { interval, merge } from 'rxjs'; | |
import { map, takeWhile } from 'rxjs/operators'; | |
//visual renders | |
const drawCell = (text: string) => { | |
const finalText = text || '' | |
const padText = ' ' | |
return `${padText.substring(0, padText.length - finalText.length)}${finalText}` | |
} |
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
<style> | |
body{ | |
margin:0; | |
height: 500px; | |
background-color: black; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
align-content: center; | |
} |
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 setResizeDebounced = useDebouncedCallback(() => { | |
setResizeCount(curr => curr + 1) | |
}, 400) | |
useEffect(() => { | |
const rObs = new ResizeObserver(() => { | |
setResizeDebounced() | |
}) | |
if (boardDrawRef.current) { | |
rObs.observe(boardDrawRef.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
import { fromEvent, scan, Subject } from "https://cdn.skypack.dev/[email protected]"; | |
import { | |
switchMap, | |
map, | |
combineLatestWith | |
} from "https://cdn.skypack.dev/[email protected]/operators"; | |
let items = []; | |
const subjectList = new Subject(); |
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 sumCPF = (cpf, digitos) => { | |
const sum = cpf | |
.split('') | |
.filter((...[,index]) => index < digitos) | |
.reduce((sum, curr, index) => sum + (curr * (1+digitos - index)), 0); | |
const total = (sum * 10) % 11; | |
return [10,11].includes(total) ? 0 : total; | |
} |
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 MD5 from "crypto-js/md5"; | |
const appendToString = (text: string, appendText: string, positionIndex: number) => { | |
return [text.slice(0, positionIndex), appendText, text.slice(positionIndex)].join(''); | |
}; | |
const genUUID = () => { | |
if (globalThis?.crypto && 'randomUUID' in globalThis.crypto) { | |
return `${globalThis.crypto.randomUUID()}`.replaceAll("-", "_"); | |
} |
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
(async () => { | |
const fakeRefreshComp = (compName: string) => console.log('refresh-comp1:', compName); | |
const fakeRequest = (durationInSecs: number) => { | |
return new Promise<number>(success => { | |
const timeOutId = setTimeout(() => success(timeOutId), durationInSecs * 1000); | |
}) | |
} | |
const elementList = [ |
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 [, firstChar, lastChar] = /^(\w).*?(\w)\w+$/gm.exec('Izabella da Silva Xauro'); | |
return { | |
firstChar, | |
lastChar, | |
} | |
})() |
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
async function* nextFrame(fps: number) { | |
let then = performance.now(); | |
const interval = 1000 / fps; | |
let delta = 0; | |
while (true) { | |
let now = await new Promise(requestAnimationFrame); | |
if (now - then < interval - delta) { | |
continue; | |
}; |
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, useRef } from "react"; | |
const useMount = (fun: () => Promise<void>, condition = true) => { | |
const firstFlow = useRef(true); | |
useEffect(() => { | |
if (condition && firstFlow.current) { | |
firstFlow.current = false; | |
fun(); | |
} | |
}, [fun, condition]); |
NewerOlder