Skip to content

Instantly share code, notes, and snippets.

View hunghg255's full-sized avatar
:octocat:
At least i'm still alive

Hung Hoang hunghg255

:octocat:
At least i'm still alive
View GitHub Profile
@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: {
@hunghg255
hunghg255 / useSpeechToText.ts
Created February 7, 2024 02:16 — forked from KristofferEriksson/useSpeechToText.ts
An experimental React hook for real-time speech-to-text using the Web Speech API
import { useCallback, useEffect, useState } from "react";
// Define custom types for SpeechRecognition and SpeechRecognitionEvent
interface ISpeechRecognitionEvent extends Event {
results: SpeechRecognitionResultList;
resultIndex: number;
}
interface ISpeechRecognition extends EventTarget {
lang: string;
@hunghg255
hunghg255 / index.ts
Created February 3, 2024 11:49
SIEVE
# https://cachemon.github.io/SIEVE-website/blog/2023/12/17/sieve-is-simpler-than-lru/#appendix
class Node {
constructor(value) {
this.value = value;
this.visited = false;
this.prev = null;
this.next = null;
}
}
type GetComponentProps<T> = T extends React.ComponentType<infer P>
? P
: T extends (props: any) => any
? Parameters<T>
: never;
class ClassComponent extends React.Component<{ a: number }> {
render() {
return <div />;
@hunghg255
hunghg255 / esm-package.md
Created January 21, 2024 13:44 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@hunghg255
hunghg255 / Dockerfile
Last active January 16, 2024 07:06
React Static Docker Nginx
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat