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 default function isolate<T extends (...args: unknown[]) => unknown>(fn: T): T { | |
// eslint-disable-next-line @typescript-eslint/no-implied-eval -- workaround | |
return new Function(` | |
with (new Proxy({}, { | |
has () { return true; }, | |
get (target, property) { | |
if (typeof property !== 'string') return target[property]; | |
throw new ReferenceError(property + ' accessed from isolated scope'); | |
}, | |
set (target, property) { |
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 detangle() { | |
let blocked = false | |
return callback => (...args) => { | |
if (blocked) return | |
blocked = true | |
callback(...args) |
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
#!/bin/sh | |
TARGET_DIR=node_modules | |
if [ ! -d $TARGET_DIR ]; then | |
echo "$TARGET_DIR" does not exist | |
exit 1 | |
fi | |
PATTERNS=" |
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
function bigIntToFloatString(value: bigint, decimalPlaces: number) { | |
if (typeof decimalPlaces !== 'number' || decimalPlaces < 0 || !Number.isInteger(decimalPlaces)) { | |
throw new TypeError('The second argument must be a non-negative integer'); | |
} | |
const divisor = BigInt(10 ** decimalPlaces); // 1e{decimalPlaces} | |
const integerPart = value / divisor; | |
const fractionalPart = value % divisor; |
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
Đầu tiên là phải hiểu đúng web3 là gì. Web3 có phải là blockchain không, hay là crypto? Web3.0 là Internet 3.0. Định nghĩa thì dài lắm nhưng cách hiểu nhanh nhất có thể được thể hiện qua sự so sánh của internet ở các thời kỳ như sau: | |
Web1.0 = 1 bên đăng, 1 bên đọc | |
Web2.0 = 2 bên đều có thể đọc và đăng nhưng 1 bên sở hữu, quản lý, hưởng lợi | |
(google, fb hạn chế 1 số chủ đề, bài viết chẳng hạn; thanh toán qua trung gian như sàn thương mại điện tử hoặc tài khoản ngân hàng) | |
Web3.0 = tất cả các bên đều có thể đọc, đăng, sở hữu, quản lý và hưởng lợi | |
(tự do tạo nội dung, tạo ra các loại app, thanh toán trực tiếp vào ví crypto và/hoặc thông qua smart contract). | |
Để hiểu đầy đủ, tường tận, bạn nên đọc kĩ bài viết này nhé: https://ethereum.org/en/web3/ | |
Có 1 số người tin rằng web3.0 là tương lai của internet, 1 số người thì nghĩ web3.0 là scam. 1 số còn lại nghĩ rằng web2.0 và web3.0 sẽ tồn tại song song. | |
Chúng ta đều có những nhận định của riêng mình. Vì vậy, sau khi hiểu rõ web3.0 là gì thì mình sẽ chuyển qua bước tiếp |
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 cache = {} | |
export default function useGlobalMemo (key, fn, deps) { | |
if (!cache[key]) { | |
cache[key] = { | |
subs: 0, | |
deps, | |
value: fn(), | |
} |
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 default function blockSync(ms: number) { | |
const start = Date.now() | |
let now = start | |
while (now - start < ms) { | |
now = Date.now() | |
} | |
} |
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 {useReducer, useRef} from 'react' | |
import {useCallback} from '@/utils/hooks/useCallback' | |
/* | |
* This hook create a ref that mirror every change to the state | |
* This is useful when we have an effect or memo that read value from state, but dont want to react to state change => use the ref for reading | |
* Future react version will add a support for `useEffectEvent` https://react.dev/reference/react/experimental_useEffectEvent which can solve the case | |
* This hook have 2 modes: | |
* 1. sync: (default mode) ref value and react state value will be update by react scheduler at the sametime that determined by the scheduler (usually lag behind the method call) |
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 {useCallback as useCallbackBase} from 'react' | |
/* | |
* Use this type to make sure that the callback passed will always be a memoized callback | |
*/ | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
export interface MemoizedCallback<T extends (...args: any[]) => any> { | |
(...args: Parameters<T>): ReturnType<T> | |
memoized: true | |
} |
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 * as React from "react"; | |
import { useMousePosition } from "~/hooks/useMousePosition"; | |
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */ | |
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) { | |
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {}; | |
const [mouseX, mouseY] = useMousePosition(); | |
const positions = { x, y, h, w, mouseX, mouseY }; | |
return ( | |
<div |
NewerOlder