Skip to content

Instantly share code, notes, and snippets.

View duongdam's full-sized avatar
🙌

pa.duongdam duongdam

🙌
View GitHub Profile
@duongdam
duongdam / bun-js-dockerfile
Last active April 15, 2024 09:22
Dockerfile for Bun API with size reduced to 298Mb
#Simple size about 298Mb. Bun v1.0.21
FROM oven/bun:latest as build-stage
WORKDIR /dist
COPY . .
COPY .env.production .env
COPY package.json package.json
COPY bun.lockb bun.lockb
@duongdam
duongdam / next-use-devices-detect
Created April 26, 2023 03:41
Next js detect devices (mobile, pc, android, ios, ssr, windown)
import {useEffect} from 'react'
const getDevices = (userAgent: NavigatorID['userAgent']) => {
const isAndroid = () => Boolean(userAgent.match(/Android/i))
const isIos = () => Boolean(userAgent.match(/iPhone|iPad|iPod/i))
const isOpera = () => Boolean(userAgent.match(/Opera Mini/i))
const isWindows = () => Boolean(userAgent.match(/IEMobile/i))
const isSSR = () => Boolean(userAgent.match(/SSR/i))
const isMobile = () => Boolean(isAndroid() || isIos() || isOpera() || isWindows())
const isDesktop = () => Boolean(!isMobile() && !isSSR())
import React from "react";
// use usePanter2D.js to drawing
interface Props {
canvasRef?: React.MutableRefObject<HTMLCanvasElement | undefined>;
width?: number;
}
export const Canvas: React.FC<Props> = ({ canvasRef, width }) => {
const widthHalf = width ? width / 2 : 0;
import { useCallback, useRef, useState } from "react";
export const usePainter = () => {
const canvas = useRef<HTMLCanvasElement>();
const [isReady, setIsReady] = useState(false);
const [isRegularMode, setIsRegularMode] = useState(true);
const [isAutoWidth, setIsAutoWidth] = useState(false);
const [isEraser, setIsEraser] = useState(false);
const [currentColor, setCurrentColor] = useState("#000000");
@duongdam
duongdam / firebase-hosting-gcp-cloud-build.md
Last active December 10, 2021 10:39
Reactjs - CF Learning - Part 1 - Làm quen với GCP Part 1

Firebase hosting

  1. Kiểm tra, init firebase vào project của bạn
//install firebase cli
npm install -g firebase-tools

firebase login

firebase init hosting
@duongdam
duongdam / element.js
Created November 18, 2021 01:50
Get position element
export function getPosition(el) {
let xPos = el.offsetWidth || 0
let yPos = 0
while (el) {
if (el.tagName === "BODY") {
let xScroll = el.scrollLeft || document.documentElement.scrollLeft
let yScroll = el.scrollTop || document.documentElement.scrollTop
xPos += (el.offsetLeft - xScroll + el.clientLeft)
yPos += (el.offsetTop - yScroll + el.clientTop)
@duongdam
duongdam / svgFillCustom.js
Last active November 18, 2021 01:52
Fill color and more to SVG Image
import React from 'react'
import styled from "styled-components";
function SVGFillCustom({
children,
color = '#F2685B',
stroke = null,
padding = null,
maxWidth = "28px",