Code Snippets Library
50+ professional snippets. Use tabs to switch between categories 🚀
JavaScript
Python
CSS
HTML
Tools
Toggle Dark Mode
Switch themes with one click.
const toggle = document.querySelector('#themeToggle');
toggle.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
});
Pro Tip: Use
transition:0.3s
for smooth effect.Copy to Clipboard
Quickly copy text programmatically.
navigator.clipboard.writeText("Hello World");
Pro Tip: Wrap inside
try...catch
for browser support.Debounce Function
Delay execution for performance.
function debounce(fn, delay){
let timer;
return function(...args){
clearTimeout(timer);
timer = setTimeout(()=>fn.apply(this,args),delay);
}
}
Pro Tip: Great for search inputs.
Random Hex Color
const color = "#" + Math.floor(Math.random()*16777215).toString(16);
Pro Tip: Use to theme buttons dynamically.
Fetch API
fetch('https://api.example.com/data')
.then(res => res.json())
.then(data => console.log(data));
Pro Tip: Use
async/await
for cleaner syntax.Check Even/Odd
function isEven(n){return n%2===0;}
Pro Tip: Use bitwise
(n & 1)
for speed.LocalStorage Save
localStorage.setItem("theme","dark");
Pro Tip: Use
JSON.stringify
for objects.Scroll to Top
window.scrollTo({top:0,behavior:'smooth'});
Pro Tip: Add button click event for UX.
Unique Array
const uniq = [...new Set([1,1,2,3,3])];
Pro Tip: Works for strings too.
Generate UUID
const id = crypto.randomUUID();
Pro Tip: Polyfill needed for older browsers.
Hello World
print("Hello, World!")
Pro Tip: Always start with simple print test.
List Comprehension
squares = [x*x for x in range(10)]
Pro Tip: Faster than loops.
Dictionary Merge
dict1|dict2
Pro Tip: Requires Python 3.9+.
File Read
with open("file.txt") as f:
data=f.read()
Pro Tip: Use
with
to auto-close files.F-Strings
name="Maxon"
print(f"Hello {name}")
Pro Tip: Cleaner than
format()
.Center Div
.container{
display:flex;
justify-content:center;
align-items:center;
}
Pro Tip: Use
vh
for full-page center.Gradient Background
background:linear-gradient(45deg,#e67e22,#1abc9c);
Pro Tip: Add
animation
for moving gradient.Box Shadow Glow
box-shadow:0 0 15px rgba(0,255,0,0.6);
Pro Tip: Perfect for neon buttons.
Basic Template
<!DOCTYPE html>
<html>
<head>
<title>Page</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
Pro Tip: Always declare
<!DOCTYPE html>
.Input Field
<input type="text" placeholder="Enter name">
Pro Tip: Add
required
for validation.cURL Request
curl -X GET https://api.example.com
Pro Tip: Add
-H
for headers.Git Init Repo
git init
git add .
git commit -m "first"
Pro Tip: Set remote with
git remote add origin
.