Skip to content

Instantly share code, notes, and snippets.

View nguyenit67's full-sized avatar
🚀
Aim for the best 💪💪💪

Nguyen Hoang Nguyen nguyenit67

🚀
Aim for the best 💪💪💪
View GitHub Profile
@nguyenit67
nguyenit67 / functions.php
Last active June 1, 2021 07:46
Custom Menu In WordPress
<?php register_nav_menus( [ 'primary' => __( 'Primary Menu' ) ] ); ?>
@nguyenit67
nguyenit67 / script.js
Created June 29, 2021 05:47
Array.prototype.flatMap()
let arr1 = ["it's Sunny in", "", "California"];
arr1.map(x => x.split(" "));
// [["it's","Sunny","in"],[""],["California"]]
arr1.flatMap(x => x.split(" "));
// ["it's","Sunny","in", "", "California"]
# use $(pwd) instead of $PWD because $PWD is just a variable for display purpose
# not actually change (cd) current working directory
~/dev/MyRepo$ PWD=~/dev/
~/dev$
~/dev$ $PWD
bash: /home/Nashu/dev/: Is a directory
~/dev$ pwd
@nguyenit67
nguyenit67 / git-bash.sh
Last active July 19, 2021 16:33
Git show what changes has made of a commit use git-log
Show the last N commits from a certain author:
$ git log -n number --author=author
For example:
# (changes in latest commit)
$ git log --stat -n 1
# git-whatchanged show little more detail of all changes happened
$ git whatchanged
@nguyenit67
nguyenit67 / git-bash.sh
Created July 21, 2021 09:30
git: apply stash when conflict
$ git reset --merge
https://stackoverflow.com/a/60444590
@nguyenit67
nguyenit67 / useEffect.js
Last active July 27, 2021 09:02
react Hooks
componentDidMount() {
}
componentDidUpdate() {
}
componentWillUnmount() {
@nguyenit67
nguyenit67 / async-await-without-trycatch-hell.js
Created August 14, 2021 04:08
Async Await try-catch hell
// #1 catch in promise-based
await step1().catch(fun);
async function gettingBetter() {
const a = await step1().catch(err => handle(err));
const b = await step2().catch(err => handle(err));
const c = await step3().catch(err => handle(err));
}
// #2 create a function handle try catch => [data, error]
async function awesome() {
@nguyenit67
nguyenit67 / folder-structure.md
Last active September 2, 2021 02:06
Duck Pattern
src
|__ assets
|  |__ images
|  |__ styles (global styles) 
|
|__ components (shared components)
|
|__ features
 |__ Photo
@nguyenit67
nguyenit67 / jsconfig.json
Created September 6, 2021 02:55
Fix issue weird path when import package from node_modules for jsconfig.json in React App
{
"compilerOptions": {
"module": "es6",
"target": "es6",
"baseUrl": "src",
"moduleResolution": "node"
},
"include": ["src/**/*"]
}
@nguyenit67
nguyenit67 / array.js
Last active October 8, 2021 02:00
Array init non-empty array with N-size
const LEN = 1000;
// First choice
[...Array(12).keys()]
// Another choice
Array.from({length: LEN})
Array.from(Array(LEN))