Skip to content

Instantly share code, notes, and snippets.

View lahin31's full-sized avatar
🎯
Focusing

Lahin lahin31

🎯
Focusing
View GitHub Profile
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://localhost:3000;
@lahin31
lahin31 / rate_limit_next.js
Created November 14, 2023 05:38
Rate Limit for a Nextjs Serverless API
import { LRUCache } from 'lru-cache';
const rateLimit = (options) => {
const tokenCache = new LRUCache({
max: options?.uniqueTokenPerInterval || 500,
ttl: options?.interval || 60000,
})
return {
check: (res, limit, token) =>
@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);
@lahin31
lahin31 / .env
Created September 25, 2022 08:20
MongoDB inside Docker (docker-compose)
MONGO_ROOT_USER=root
MONGO_ROOT_PASSWORD=123456
@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 / .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 / 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
// 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) {
// 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>
/**
* Custom Iterator
* Making an Object iterable by using for...of loop
* By Muhammad Lahin
*/
let obj = {
id: 1,
name: "John Cena",
profession: "Wrestling"