Skip to content

Instantly share code, notes, and snippets.

View kaungmyatlwin's full-sized avatar
🍴
Forking

Kaung Myat Lwin kaungmyatlwin

🍴
Forking
View GitHub Profile
@kaungmyatlwin
kaungmyatlwin / NavigationBlocker.js
Last active August 18, 2021 16:38
React Navigation Blocker with React Router Prompt. Usage included.
import React, { useEffect } from 'react';
import { Prompt } from 'react-router-dom';
export default ({ shouldBlockNavigation = false, message = '' }) => {
useEffect(() => {
if (shouldBlockNavigation) {
window.onbeforeunload = () => true;
} else {
window.onbeforeunload = null;
}
{"version":1,"resource":"vscode-userdata:/Users/kaungmyatlwin/Library/Application%20Support/Code/User/settings.json","entries":[{"id":"jslQ.json","timestamp":1650265248517}]}
const router = require('express').Router();
const upload = require('./upload')('./cats');
router.post('/', upload.array('photos', 10), (req, res) => {
// handle logic
res.send('ok');
});
module.exports = router;
@kaungmyatlwin
kaungmyatlwin / cats.js
Last active June 12, 2020 17:15
Refactoring Multer diskStorage instance using Javascript Closures (before refactor)
const router = require('express').Router();
const multer = require('multer');
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, './cats');
},
filename: (req, file, cb) => {
const fname = `${Date.now()}-${encodeURIComponent(file.originalname)}`;
cb(null, fname);
@kaungmyatlwin
kaungmyatlwin / myanmar_regions.js
Last active June 25, 2020 05:15
Myanmar Regions and Townships compatible with MIMU standards
module.exports = [{
region_pcode_idx: 1,
name_en: 'Kachin',
name_mm: 'ကချင်ပြည်နယ်',
region_pcode: 'MMR001',
type: 'state',
}, {
region_pcode_idx: 2,
name_en: 'Kayah',
name_mm: 'ကယားပြည်နယ်',
@kaungmyatlwin
kaungmyatlwin / multiple_db_connection.js
Created December 6, 2019 11:09
Connect to multiple database connects with MongoDB client.
const config = require('config');
const MongoClient = require('mongodb').MongoClient;
const { host } = config.get('dbConfig');
const mongoIp = process.env.NODE_ENV === 'production' ? host : 'localhost';
class Connection {
static databases = {};
static connectToMongo(dbName: string, options: object) {
import React from "react";
import ReactDOM from "react-dom";
import EditableText from "./EditableText";
import "./styles.css";
function App() {
return (
<div className="App">
<h1>Editable Text Demo</h1>
import React from "react";
import ReactDOM from "react-dom";
import EditableText from "./EditableText";
import "./styles.css";
function App() {
return (
<div className="App">
<h1>Editable Text Demo</h1>
import React, { useState, useRef, useEffect } from "react";
const EditableInput = props => {
return (
<React.Fragment>
<input />
<span></span>
</React.Fragment>
);
};
import React, { useState, useRef,useEffect } from 'react';
const EditableInput = ({
onChange,
text,
placeholder,
}) => {
const inputRef = useRef(null);
const [inputVisible, setInputVisible] = useState(false);