Welcome to the future of code sharing
Share Your Genius
The fastest way for developers to store, share, and discover beautiful code snippets in a modern, dark-themed environment.
AuthService.ts
1export const useAuth = () => {
2 const [user, setUser] = useState(null);
3
4 // Initialize authentication logic
5 useEffect(() => {
6 const unsubscribe = auth.onStateChange(u => {
7 setUser(u);
8 });
9 return unsubscribe;
10 }, []);
11}Syntax Highlighting
Support for 22 languages with vibrant themes that make code pop.
Cloud Sync
Your snippets available on every device, instantly with secure cloud storage.
Instant Copy
One-click copy to clipboard with beautiful visual feedback built-in.
html
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<title>Merhaba</title>
<style>
body {
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background: #0f172a;
color: white;
}
h1 { color: #6366f1; }
</style>
</head>
<body>
<h1>Merhaba Dünya 👋</h1>
</body>
</html>Ömer Şengül
javascript
const createEventEmitter = () => {
let listeners = {};
const on = (event, callback) => {
if (!listeners[event]) listeners[event] = [];
listeners[event] = [...listeners[event], callback];
};
const off = (event, callback) => {
if (!listeners[event]) return;
listeners[event] = listeners[event].filter((cb) => cb !== callback);
};
const once = (event, callback) => {
const wrapper = (...args) => {
callback(...args);
off(event, wrapper);
};
on(event, wrapper);
};
const emit = (event, ...args) => {
if (!listeners[event]) return;
listeners[event].forEach((cb) => cb(...args));
};
const clear = (event) => {
if (event) delete listeners[event];
else listeners = {};
};
return { on, off, once, emit, clear };
};
// Kullanım
const emitter = createEventEmitter();
const onLogin = (user) => console.log(`User logged in: ${user}`);
emitter.on("login", onLogin);
emitter.once("login", (user) => console.log(`Welcome message sent to ${user}`));
emitter.emit("login", "ahmet"); // ikisi de çalışır
emitter.emit("login", "mehmet"); // once artık çalışmaz
emitter.off("login", onLogin);
emitter.emit("login", "ali"); // hiçbir şey olmazÖmer Şengül
javascript
const createShoppingCart = () => {
let items = [];
const addItem = (name, price, quantity = 1) => {
const existing = items.find((i) => i.name === name);
if (existing) {
items = items.map((i) =>
i.name === name ? { ...i, quantity: i.quantity + quantity } : i
);
} else {
items = [...items, { name, price, quantity }];
}
};
const removeItem = (name) => {
items = items.filter((i) => i.name !== name);
};
const updateQuantity = (name, quantity) => {
if (quantity <= 0) return removeItem(name);
items = items.map((i) => (i.name === name ? { ...i, quantity } : i));
};
const getTotal = () =>
items.reduce((acc, i) => acc + i.price * i.quantity, 0);
const applyDiscount = (percent) => {
const total = getTotal();
const discount = total * (percent / 100);
return +(total - discount).toFixed(2);
};
const getItems = () => items;
const clear = () => {
items = [];
};
return { addItem, removeItem, updateQuantity, getTotal, applyDiscount, getItems, clear };
};
// Kullanım
const cart = createShoppingCart();
cart.addItem("Keyboard", 49.99, 1);
cart.addItem("Mouse", 29.99, 2);
cart.addItem("Keyboard", 49.99, 1); // quantity 2 olur
cart.updateQuantity("Mouse", 1);
console.log(cart.getItems());
console.log("Total:", cart.getTotal());
console.log("After 10% discount:", cart.applyDiscount(10));
cart.removeItem("Keyboard");
console.log("After remove:", cart.getItems());Ömer Şengül
javascript
const createTaskManager = () => {
let tasks = [];
let idCounter = 1;
const addTask = (title, priority = "medium", dueDate = null) => {
const task = {
id: idCounter++,
title,
priority,
dueDate: dueDate ? new Date(dueDate) : null,
completed: false,
createdAt: new Date(),
};
tasks = [...tasks, task];
return task;
};
const completeTask = (id) => {
tasks = tasks.map((t) => (t.id === id ? { ...t, completed: true } : t));
};
const deleteTask = (id) => {
tasks = tasks.filter((t) => t.id !== id);
};
const getByPriority = (priority) =>
tasks.filter((t) => t.priority === priority && !t.completed);
const getOverdue = () => {
const now = new Date();
return tasks.filter((t) => t.dueDate && t.dueDate < now && !t.completed);
};
const getSummary = () => ({
total: tasks.length,
completed: tasks.filter((t) => t.completed).length,
pending: tasks.filter((t) => !t.completed).length,
highPriority: getByPriority("high").length,
});
const sortByPriority = () => {
const order = { high: 0, medium: 1, low: 2 };
return [...tasks].sort((a, b) => order[a.priority] - order[b.priority]);
};
return { addTask, completeTask, deleteTask, getSummary, getOverdue, sortByPriority };
};
// Kullanım
const manager = createTaskManager();
manager.addTask("Fix login bug", "high", "2024-01-10");
manager.addTask("Write docs", "low", "2024-02-01");
manager.addTask("Deploy to prod", "high", "2024-01-08");
manager.completeTask(1);
console.log(manager.getSummary());
console.log(manager.sortByPriority());
console.log(manager.getOverdue());Ömer Şengül