Skip to content

Instantly share code, notes, and snippets.

View lahin31's full-sized avatar
🎯
Focusing

Lahin lahin31

🎯
Focusing
View GitHub Profile
/*
Simple Memoization example used Closure
Made by: Muhammad Lahin
*/
const myObj = {memo: {}}
const memo = fn => {
return (first_name, last_name) => {
let slice = Array.prototype.slice;
let key = JSON.stringify(slice.call(arguments));
/**
* Custom Iterator
* Making an Object iterable by using for...of loop
* By Muhammad Lahin
*/
let obj = {
id: 1,
name: "John Cena",
profession: "Wrestling"
@lahin31
lahin31 / eslintrc.json
Last active July 25, 2021 18:54
Node.js eslint configuration.
{
"env": {
"commonjs": true,
"es6": true,
"node": true,
"mocha": true
},
"plugins": [
"security"
],
// accordion component using Compound Component (with context)
// app.js
function App() {
return (
<div className="App">
<Accordion defaultSelect="1" collapsible>
<AccordionItem id="1">
<AccordionToggle>Section 1</AccordionToggle>
<AccordionPanel>Section 1 content</AccordionPanel>
// useClickOutside.js
import { useEffect, useRef } from "react";
function useClickOutside(elRef, callback) {
const callbackRef = useRef();
callbackRef.current = callback;
useEffect(() => {
const handleClickOutside = (e) => {
if (!elRef?.current?.contains(e.target) && callbackRef.current) {
@lahin31
lahin31 / .dockerignore
Last active September 24, 2022 16:35
Node.js with Docker
.dockerignore
.env
.git
.gitignore
.vs
.vscode
*.dbmdl
*.jfm
azds.yaml
charts
@lahin31
lahin31 / .dockerignore
Created September 24, 2022 17:59
Node.js with Docker Compose
.dockerignore
.env
.git
.gitignore
.vs
.vscode
*.dbmdl
*.jfm
azds.yaml
charts
@lahin31
lahin31 / .env
Created September 25, 2022 08:20
MongoDB inside Docker (docker-compose)
MONGO_ROOT_USER=root
MONGO_ROOT_PASSWORD=123456
@lahin31
lahin31 / README.md
Last active September 25, 2022 16:00
JavaScript Utility Function to get time ago etc

For example

timeAgo('Sun Sep 25 2022 12:57:46 GMT+0600 (Bangladesh Standard Time)'); // 16 seconds ago
@lahin31
lahin31 / add-more-image.js
Created October 16, 2023 17:39
upload add more image
const [images, setImages] = useState([]);
const [base64Images, setBase64Images] = useState([]);
const handleFileChange = (event, index) => {
const files = event.target.files;
const _images = [...images];
_images[index] = files[0];
setImages(_images);