Skip to content

Instantly share code, notes, and snippets.

View HaiBV's full-sized avatar
🔥
Journeyman in craftsmanship

Harvey Bui HaiBV

🔥
Journeyman in craftsmanship
View GitHub Profile
@HaiBV
HaiBV / service.js
Created November 14, 2023 15:41 — forked from santospatrick/service.js
An example Service class wrapper for Axios
import axios from "axios";
class HttpService {
constructor() {
const token = window.localStorage.getItem("token");
const service = axios.create({
baseURL: process.env.REACT_APP_API_URL,
headers: token
? {
Authorization: `Bearer ${token}`,
@HaiBV
HaiBV / tree-view.html
Created November 24, 2022 13:08
Tree view with pure CSS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.tree {
@HaiBV
HaiBV / convertVietnameseToLatin.js
Created September 26, 2021 13:59
convert string in Vietnamese to Latin
const convertTextToLatin = (str) => {
if (!str) return '';
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/gi, 'a');
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/gi, 'e');
str = str.replace(/ì|í|ị|ỉ|ĩ/gi, 'i');
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/gi, 'o');
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/gi, 'u');
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/gi, 'y');
str = str.replace(/đ/gi, 'd');
// Some system encode vietnamese combining accent as individual utf-8 characters
@HaiBV
HaiBV / host-react-app-on-apache-server.md
Last active September 7, 2020 00:51 — forked from ywwwtseng/host-react-app-on-apache-server.md
Host react application on Apache server

Host react application on Apache server

Step 1 : Create your app

$ npm install -g create-react-app 
$ create-react-app my-app

Step 2 : Build it for production

@HaiBV
HaiBV / cloudSettings
Last active July 22, 2020 09:38
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-07-22T09:37:59.331Z","extensionVersion":"v3.4.3"}
@HaiBV
HaiBV / jsconfig.json
Created February 20, 2020 09:12
Config VSCode with NODE_PATH=.
{
"compilerOptions": {
"target": "ES6",
"baseUrl": "."
},
"exclude": ["node_modules", "**/node_modules/*"]
}
@HaiBV
HaiBV / server.js
Created February 4, 2020 04:50
Custom Reverse Proxy
/* eslint-disable no-console */
const express = require('express')
const next = require('next')
const devProxy = {
'/api': {
target: 'https://swapi.co/api/',
pathRewrite: { '^/api': '/' },
changeOrigin: true,
},
@HaiBV
HaiBV / ResolvedCORSDevEnv3Ways.js
Last active January 21, 2020 02:20
Resolved CORS issue
// 1. Install extend enable CORS in web browser (simple, fast but situation)
// 2. Using middleware plug-in in server
// https://expressjs.com/en/resources/middleware/cors.html
var express = require('express')
var cors = require('cors')
var app = express()
app.use(cors())
@HaiBV
HaiBV / OptionalChaining.js
Last active February 4, 2020 04:48
Optional Chaining
// without Optional Chaining
function sayHi(user) {
let name = (user && user.name && user.name.toUpperCase()) || "Unknown";
console.log(`Hi Mr. ${name}`);
}
sayHi({}); // Hi Mr. Unknown
sayHi(); // Hi Mr. Unknown
// with Optional Chaining
function sayHi(user) {
@HaiBV
HaiBV / splitToNCharLong.js
Last active December 12, 2019 15:02
split string in to n-char long tokens
function split(input, len) {
return input.match(new RegExp('.{1,' + len + '}(?=(.{' + len + '})+(?!.))|.{1,' + len + '}$', 'g'))
}
console.log(split('11010101101', 4)) // ['110', '1010', '1101']
console.log(split('ab22883b0ada0', 2)) // ['a', 'b2', '28', '83', 'b0', 'ad', 'a0']