Skip to content

Instantly share code, notes, and snippets.

View htdangkhoa's full-sized avatar
💪
Every problem has more than one way to solve it.

Huỳnh Trần Đăng Khoa htdangkhoa

💪
Every problem has more than one way to solve it.
View GitHub Profile
@htdangkhoa
htdangkhoa / AbstractFactory.ts
Last active April 21, 2022 06:54
Abstract Factory Pattern in Typescript
export interface AbstractFactory {
createProductA(): AbstractProductA;
createProductB(): AbstractProductB;
}
@htdangkhoa
htdangkhoa / docker-compose.yml
Created March 7, 2022 14:11 — forked from pantsel/docker-compose.yml
example docker-compose.yml for kong, postgres and konga
version: "3"
networks:
kong-net:
driver: bridge
services:
#######################################
# Postgres: The database used by Kong
@htdangkhoa
htdangkhoa / redirects-in-react-router-v6.md
Created November 6, 2021 17:25 — forked from mjackson/redirects-in-react-router-v6.md
Notes on handling redirects in React Router v6, including a detailed explanation of how this improves on what we used to do in v4 and v5

Redirects in React Router v6

An important part of "routing" is handling redirects. Redirects usually happen when you want to preserve an old link and send all the traffic bound for that destination to some new URL so you don't end up with broken links.

The way we recommend handling redirects has changed in React Router v6. This document explains why.

Background

In React Router v4/5 (they have the same API, you can read about why we had to bump the major version here) we had a <Redirect> component that you could use to tell the router when to automatically redirect to another URL. You might have used it like this:

@htdangkhoa
htdangkhoa / en.json
Last active January 6, 2021 05:28
Alternative moment.js
{
"months": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"monthsShort": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
"weekdays": [
{ "index": 0, "label": "Sunday" },
{ "index": 1, "label": "Monday" },
{ "index": 2, "label": "Tuesday" },
{ "index": 3, "label": "Wednesday" },
{ "index": 4, "label": "Thursday" },
{ "index": 5, "label": "Friday" },
@htdangkhoa
htdangkhoa / node-logger.js
Created November 18, 2020 05:11
Override node js console.
import { readFileSync } from 'fs';
import { resolve } from 'path';
const pkg = JSON.parse(
readFileSync(resolve(process.cwd(), 'package.json'), 'utf-8').toString(),
);
const DATE_FORMAT = 'DD-MM-YYYY-hh:mm:ss.SSS';
const colors = {
https://www.facebook.com/sharer.php?u={url}
https://www.facebook.com/dialog/share?app_id={app_id}&display={page_type}&href={url}&redirect_uri={redirect_url}
https://reddit.com/submit?url={url}&title={title}
https://twitter.com/intent/tweet?url={url}&text={title}&via={user_id}&hashtags={hash_tags}
https://www.linkedin.com/sharing/share-offsite/?url={url}
https://api.whatsapp.com/send?phone={phone_number}&text={title}%20{url}
https://www.tumblr.com/widgets/share/tool?canonicalUrl={url}&title={title}&caption={text}&tags={hash_tags}
http://pinterest.com/pin/create/button/?url={url}
https://www.blogger.com/blog-this.g?u={url}&n={title}&t={text}
https://www.evernote.com/clip.action?url={url}&title={title}
@htdangkhoa
htdangkhoa / chunk.js
Last active May 30, 2021 19:13
Alternative lodash.js
const chunk = (input, size) => {
return input.reduce((arr, item, idx) => {
return idx % size === 0 ? [...arr, [item]] : [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
}, []);
};
export default chunk;
@htdangkhoa
htdangkhoa / js-expired-token.js
Created August 19, 2020 06:51 — forked from paulnguyen-mn/js-expired-token.js
Xử lý expired token trong javascript (js nâng cao)
// Easy Frontend
// Học FE đơn giản, dễ hiểu và đặc biệt phải vui ❤️
// JS NÂNG CAO - Xử lý expired token trong Javascript như thế nào?
// ❓ Chuyện gì xảy ra nếu giữa chừng token bị expired?
// Ví dụ: 3 api requests đồng thời với nhau
// TRƯỜNG HỢP 1: Token chưa expired, vẫn còn tốt chán 🤣
// --request 1-->
[
{
"en_name": "Visa",
"vn_name": "Visa",
"bankId": "4",
"atmBin": "4",
"cardLength": 13,
"shortName": "Visa",
"bankCode": "",
"type": "",
{"lastUpload":"2020-06-21T09:23:26.399Z","extensionVersion":"v3.4.3"}