Skip to content

Instantly share code, notes, and snippets.

View kashyapkaki's full-sized avatar

Kashyap Kaki kashyapkaki

View GitHub Profile
@kashyapkaki
kashyapkaki / Copy to Clipboard (Plain JavaScript)
Created June 1, 2025 12:05
A simple utility that copies a string to the clipboard using the native navigator.clipboard API. Works great for "Copy" buttons in UI components, like sharing links or copying codes/passwords.
function copyToClipboard(text) {
navigator.clipboard.writeText(text)
.then(() => console.log('Copied!'))
.catch(err => console.error('Failed to copy:', err));
}
@kashyapkaki
kashyapkaki / Debounce.js
Created May 23, 2025 15:10
A lightweight debounce function to delay execution of a given callback until after a specified delay in milliseconds. Commonly used in scroll, resize, search input, or canvas-related event handling to avoid performance issues from rapid firing.
// Debounce function to limit how often a function is executed
function debounce(fn, delay) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn(...args), delay);
};
}
// Usage
## commands from terminal
mkdir my-app
cd my-app
npm init -y -- creates package.json file with default configurations
npm install react react-dom -- install react and react-dom dependencies
vim .gitignore -- creates gitigonre file
mkdir app --create app folder in your project folder
cd app
touch index.js index.css -- creates two files in app directory
npm install --save-dev @babel/core @babel/preset-env @babel/preset-react webpack webpack-cli webpack-dev-server babel-loader css-loader style-loader html-webpack-plugin -- adding all require depnendincies to the project