Skip to content

Instantly share code, notes, and snippets.

@hunghg255
hunghg255 / detect-recursion-functions.js
Last active July 19, 2024 07:45
detect-recursion-functions.js
// npm i @babel/parser @babel/traverse -D
const fs = require('node:fs');
const path = require('node:path');
const traverse = require('@babel/traverse').default;
const parser = require('@babel/parser');
// Change dir folder
@hunghg255
hunghg255 / index.html
Created June 12, 2024 00:51
Dark Mode Favicon
<link href="favicon.png" rel="icon" media="(prefers-color-scheme: light)">
<link href="favicon-dark.png" rel="icon" media="(prefers-color-scheme: dark)">
import { Dispatch, SetStateAction, useCallback, useState } from "react";
/**
* Returns a stateful value, its previous value, and a function to update it.
*/
export function useStateWithPrev<S>(
initialState: S | (() => S),
initialPrevState: S | (() => S)
): [prevState: S, state: S, setState: Dispatch<SetStateAction<S>>];
// convenience overload when second argument is omitted
/**
@hunghg255
hunghg255 / readme.md
Last active June 8, 2024 06:47
background github
$$\ce{$&#x5C;unicode[goombafont; color:red; pointer-events: none; z-index: -10; position: fixed; top: 0; left: 0; height: 100vh; background-size: cover !important; background-position: center; width: 100vw; opacity: 1; background: url('https://raw.githubusercontent.com/hunghg255/hunghg255/master/img/bg-white.webp') no-repeat;]{x0000}$}$$
@hunghg255
hunghg255 / createComponent.ts
Created May 22, 2024 07:47
Script Create Component
//@ts-nocheck
import { exec } from 'node:child_process';
import fs from 'node:fs';
import inquirer from 'inquirer';
/**
* @returns { Promise<string> }
*/
const chooseComponentDirectory = async (
@hunghg255
hunghg255 / PressableText.tsx
Created April 21, 2024 04:36 — forked from ladifire/PressableText.tsx
PressableText.tsx - Rewritten by Cong Nguyen
// Rewritten by Cong Nguyen
// original code from Facebook Frontend website: https://gist.github.com/ladifire/21fb3e774cf62ac50d0700fd50d1ccb2
import React, { useCallback, useContext, useRef, useState } from "react";
import { PressableGroupContext } from "@facebook-frontend/context";
import { joinClasses, useMergeRefs } from "@facebook-frontend/utils";
import stylex from "@stylexjs/stylex";
import { Pressability } from "./Pressability";
import { useWebPressableTouchStartHandler } from "./useWebPressableTouchStartHandler";
@hunghg255
hunghg255 / buildProvidersTree.tsx
Created February 21, 2024 04:35
buildProvidersTree
import React from "react";
type ProvidersType = [React.ElementType, Record<string, unknown>];
type ChildrenType = {
children: Array<React.ElementType>;
};
export const buildProvidersTree = (
componentsWithProps: Array<ProvidersType>
) => {
const initialComponent = ({ children }: ChildrenType) => <>{children}</>;
@hunghg255
hunghg255 / reset.css
Created February 15, 2024 06:48
Reset CSS
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:where([hidden]:not([hidden='until-found'])) {
display: none !important;
@hunghg255
hunghg255 / md.ts
Created February 14, 2024 04:13
Shiki Transformer Bracket Pair Color
md.use(
await markdownItShikiji({
highlightLines: false,
themes: {
light: 'dark-plus',
dark: 'dark-plus',
},
transformers: [
transformerBracketPairColor({
colors: ['#ffd700', '#da70d6', '#179fff'],
@hunghg255
hunghg255 / useLocation.ts
Created February 13, 2024 13:27 — forked from KristofferEriksson/useLocation.ts
A React Typescript hook that provides real-time geolocation data, complete with heading and speed metrics
import { useEffect, useState } from "react";
interface LocationOptions {
enableHighAccuracy?: boolean;
timeout?: number;
maximumAge?: number;
}
interface LocationState {
coords: {