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 / README.md
Last active June 4, 2025 23:57
Typesafe search & path params hooks for TanStack Router

Typesafe search & path params hooks for TanStack Router

With the following route setup:

import {type} from 'arktype'

const flightDetailSchema = type({
  step: 'number',
 option: 'number.integer',
@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;