Skip to content

Instantly share code, notes, and snippets.

View luannguyenQV's full-sized avatar
🎯
Focusing

luannguyen luannguyenQV

🎯
Focusing
View GitHub Profile
@luannguyenQV
luannguyenQV / refreshPage.ts
Created February 22, 2024 11:13
Refresh nextjs page after data is changed
// https://www.joshwcomeau.com/nextjs/refreshing-server-side-props/
router.refresh()
@luannguyenQV
luannguyenQV / axiosInstance.ts
Last active February 22, 2024 07:37
Axios: paramsSerializer
const axiosInstance: AxiosInstance = axios.create({
baseURL: API_URI,
paramsSerializer: (params) => {
return qs.stringify(params, { arrayFormat: 'brackets' })
},
})
@luannguyenQV
luannguyenQV / LongText.tsx
Last active January 30, 2024 07:54
If the text is truncated, wrap it in the tooltip with ReactJs
import React, { useMemo, useRef, useState } from 'react';
import { Text, TextProps, Tooltip } from '@chakra-ui/react';
const LongText = (props: TextProps) => {
const ref = useRef<HTMLParagraphElement>(null);
const [showShowTooltip, setShowShowTooltip] = useState(false);
const shouldShowTooltip = useMemo(() => {
if (ref.current) {
return ref.current.scrollWidth > ref.current.clientWidth;
@luannguyenQV
luannguyenQV / gist:b7db3493b8ca42752cf1ac5afbf3ac42
Created January 22, 2024 03:33
Japan KATAKANA and number regex
export const TEXT_KATAKANA_REGEX = /^([ァ-ン]|ー|ヴ)*$/
export const HALF_WIDTH_NUMBER_REGEX = /^[0-9]+$/
export const FULL_WIDTH = '0123456789-';
@luannguyenQV
luannguyenQV / cloudSettings
Last active September 7, 2017 05:03
Visual Studio Code Settings Sync Gist
{"lastUpload":"2017-09-07T05:02:40.607Z","extensionVersion":"v2.8.3"}
@luannguyenQV
luannguyenQV / connect.js
Created July 6, 2017 06:21 — forked from gaearon/connect.js
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@luannguyenQV
luannguyenQV / JavascriptCoroutines.js
Created June 27, 2017 04:44
Javascript Coroutines
// Javascript Coroutines
var toggle = (function*(){
while(true) {
yield true
yield false
}
})();
for (var x = 0; x < 10; x++) {
console.log(toggle.next().value)
@luannguyenQV
luannguyenQV / Generator.js
Created June 27, 2017 04:16
Javascript generator example.
// Javascript generator example.
var sequence, sq;
sq = function * (initialValue) {
var current, num, step;
num = initialValue || 2;
step = 1;
while (true) {
current = num * step++;
yield current;
@luannguyenQV
luannguyenQV / Singleton.js
Last active June 27, 2017 04:43
Javascript Singleton Pattern
// Javascript Singleton Pattern
var mySingleton = (function() {
var instance;
function init() {
function privateMethod() {
console.log("I am private")
}
var privateVariable = "I am also private"
var privateRandomNumber = Math.random()
// Coercion type in javascript:
var ToPrimitive;
ToPrimitive = function (obj) {
var funct, functions, val, _i, _len;
functions = ["valueOf", "toString"];
if (typeof obj === "object") {
if (obj instanceof Date) {
functions = ["toString", "valueOf"];