Skip to content

Instantly share code, notes, and snippets.

View hunghg255's full-sized avatar
:octocat:
Make Frontend Better 👨‍💻

Hung Hoang hunghg255

:octocat:
Make Frontend Better 👨‍💻
View GitHub Profile
@hunghg255
hunghg255 / readme.md
Created October 15, 2024 10:51
Next ENV

Next page

client: publicRuntimeConfig server: process.env

  • publicRuntimeConfig ở client check NEXT_DATA sẽ lộ hết config

  • Muốn dấu ở client thì thêm NEXT_PUBLIC_ vào trước tên biến truy cập bằng process.env

@hunghg255
hunghg255 / main.js
Created October 10, 2024 07:51
nextTick nodejs
const getDataService = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('data');
}, 1000);
});
};
const getA = async () => {
process.nextTick(async () => {
export default async function getSeoDataFromLink(url: string) {
try {
if (!url) {
throw new Error('URL is required');
}
if (url.includes('tiktok')) {
const rest: any = await fetch(`https://www.tiktok.com/oembed?url=${new URL(url)}`).then(
(res: any) => res.json(),
);
/*
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
*/
*,
::before,
::after {
box-sizing: border-box; /* 1 */
border-width: 0; /* 2 */
@hunghg255
hunghg255 / dom_performance_reflow_repaint.md
Created August 17, 2024 10:14 — forked from faressoft/dom_performance_reflow_repaint.md
DOM Performance (Reflow & Repaint) (Summary)

DOM Performance

Rendering

  • How the browser renders the document
    • Receives the data (bytes) from the server.
    • Parses and converts into tokens (<, TagName, Attribute, AttributeValue, >).
    • Turns tokens into nodes.
    • Turns nodes into the DOM tree.
  • Builds CSSOM tree from the css rules.
@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 (