Skip to content

Instantly share code, notes, and snippets.

View michchan's full-sized avatar

Michael Chan L. S. michchan

View GitHub Profile
@michchan
michchan / RouteLeavingGuard-function-ts-ca839f5faf39.tsx
Created July 15, 2022 03:10
RouteLeavingGuard full implementation in TypeScript & React 16+ for Medium article ca839f5faf39
import { Location } from 'history';
import React, { useEffect, useState } from 'react';
import { Prompt } from 'react-router-dom';
import WarningDialog from './WarningDialog';
interface Props {
when?: boolean | undefined;
navigate: (path: string) => void;
shouldBlockNavigation: (location: Location) => boolean;
@michchan
michchan / RouteLeavingGuard-class-usage-ca839f5faf39.jsx
Created July 15, 2022 03:07
RouteLeavingGuard Usage for Medium article ca839f5faf39
import React from ‘react’
import RouteLeavingGuard from 'components/RouteLeavingGuard'
export class LoginScene extends React.Component {
state = {
username: '',
password: '',
isDirty: false,
}
@michchan
michchan / RouteLeavingGuard-class-ca839f5faf39.jsx
Created July 15, 2022 03:02
RouteLeavingGuard full implementation for Medium article ca839f5faf39
import React from 'react'
import {Prompt} from 'react-router-dom'
import {CustomModal} from './CustomModal'
export class RouteLeavingGuard extends React.Component {
state = {
modalVisible: false,
lastLocation: null,
confirmedNavigation: false,
}
@michchan
michchan / .vscode_workspace_settings.json
Created April 1, 2022 05:17
VSCode Workspace Settings for TypeScript project
{
"eslint.workingDirectories": ["./src"],
"typescript.tsdk": "src/node_modules/typescript/lib"
}
@michchan
michchan / vscode-keybindings.json
Created March 29, 2022 15:44
My VSCode Custom Key bindings
// Place your key bindings in this file to override the defaults
[
{
"key": "shift+cmd+n",
"command": "explorer.newFolder"
},
{
"key": "cmd+n",
"command": "explorer.newFile"
}
@michchan
michchan / .gitconfig
Last active June 7, 2023 10:06
Git Config (Aliases)
[alias]
aliases = "!f() { git config --global -l | grep alias | sort; }; f"
br = branch
cl = clone
st = status
a = add
cm = commit -m
cmn = commit -m --no-verify
cam = commit -am
co = checkout
@michchan
michchan / useful-commands-fullstack-dev.sh
Last active March 10, 2022 05:38
Useful Shell command for Fullstack Dev
# Open Chrome chrome with CORS disabled
# (!!CAUTION: This will remove all history/plugins/preferences)
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security
@michchan
michchan / .zshrc
Last active July 5, 2022 11:58
.zshrc for Frontend/Fullstack Dev
#### Git branch on terminal
# Reference: https://stackoverflow.com/questions/17333531/how-can-i-display-the-current-branch-and-folder-path-in-terminal
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF=$'\e[0m'
COLOR_USR=$'\e[38;5;243m'
COLOR_DIR=$'\e[38;5;197m'
COLOR_GIT=$'\e[38;5;39m'
@michchan
michchan / cdk.webpack.config.js
Last active November 3, 2020 14:24
webpack.config.js for CDK usage (small-scale projects)
const fs = require('fs')
const path = require('path')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const DEFAULT_ANALYZER_PORT = 8888
const createBundleAnalyzerPlugin = (reportTitle, portOffset = 0) => new BundleAnalyzerPlugin({
// Avoid CI crash issue
analyzerMode: 'static',
openAnalyzer: false,
reportTitle,
@michchan
michchan / .eslintignore-aws-cdk
Last active October 27, 2020 10:42
.eslintignore file for AWS-CDK stack
# Package manager files
**/node_modules/*
**/package-lock.json
**/yarn.lock
# Build/executable files
**/build/*
**/bundles/*
**/dist/*