Skip to content

Instantly share code, notes, and snippets.

View huynhducduy's full-sized avatar
😍
I'm in love with js <3

Huynh Duc Duy huynhducduy

😍
I'm in love with js <3
View GitHub Profile
@huynhducduy
huynhducduy / tryCatch.ts
Last active February 28, 2025 10:42
tryCatch.ts
interface Success<T> {
result: T
exception?: never
}
interface Failure {
result?: never
exception: {getError: () => unknown}
}
You are an expert AI programming assistant that primarily focuses on producing clear, readable React and TypeScript code.
You always use the latest stable, modern version of TypeScript, JavaScript, React, Node.js, Tanstack React Router, Tanstack React Query, HeroUI (formerly NextUI), Tailwind CSS, Vitest and you are familiar with the latest features, best practices and standards. Remember to check `package.json` to see our libraries/packages and make the full use of them.
You keep your code clean, readable, and maintainable, fix all linting and formatting errors/warnings, and make sure the code is up to date with the latest standards.
You carefully, slowly and methodically, step by step, and outline your reasoning to provide accurate, factual, thoughtful answers, and are a genius at reasoning ai to chat, to generate Code Style, Structure, Naming Conventions, TypeScript Usage, UI and Styling, Performance Optimization.
You always check if a similar work has been done before, and if so, you would reference it to
@huynhducduy
huynhducduy / memoizedCallback.d.ts
Created January 18, 2025 02:27
memoizedCallback.d.ts
import 'react'
declare module 'react' {
/* eslint-disable @typescript-eslint/no-explicit-any -- its intentional */
/*
* Use this type to make sure that the callback passed will always be a memoized callback
* For any function type, wrap it with MemoizedCallback<T>
* Example: MemoizedCallback<(param: number) => boolean>
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type -- its intentional
@huynhducduy
huynhducduy / eslint-plugin-react-perf.patch
Created January 6, 2025 09:14
Eslint-plugin-react-perf v3.3.3 - huynhducduy's PRs Patch
diff --git a/lib/utils/common.js b/lib/utils/common.js
index 90415975e33ea77d161df0329d3ed2426977c404..aa02006b46bb6a5d9143d8b86679e782a9fc06f7 100644
--- a/lib/utils/common.js
+++ b/lib/utils/common.js
@@ -1,11 +1,14 @@
-"use strict";
+'use strict'
+
+const {get} = require('http')
+const {type} = require('os')
@huynhducduy
huynhducduy / test.ts
Created September 7, 2024 05:18
Structural Typing vs Excess Property Check https://talohana.com/blog/typescript-excess-property-checks
type Data = {
id: string;
};
const data: Data = {
id: "123",
name: "Hello!",
}
const data2 = {
@huynhducduy
huynhducduy / isolate.ts
Created July 12, 2024 06:20
Wrap a function in `isolate` to prevent it from create closure.
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) {
@huynhducduy
huynhducduy / detangle.js
Created July 2, 2024 18:55
detangle.js
export function detangle() {
let blocked = false
return callback => (...args) => {
if (blocked) return
blocked = true
callback(...args)
#!/bin/sh
TARGET_DIR=node_modules
if [ ! -d $TARGET_DIR ]; then
echo "$TARGET_DIR" does not exist
exit 1
fi
PATTERNS="
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;
Đầ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