Find the code you need
Search through tutorials, code snippets, and development resources
ما هو حقن التبعيات (Dependency Injection)؟
- هيكلة واضحة وسهلة الفهم.
- تقليل التكرار وزيادة إعادة الاستخدام.
- مرونة عالية في تبديل المكونات.
- دعم أفضل لاختبارات الوحدة (Unit Testing).
- فصل مسؤوليات إنشاء التبعيات عن مسؤوليات العمل الفعلي.
حقن التبعيات ليس مجرد تقنية، بل هو نمط يُسهم في بناء أنظمة نظيفة، قابلة للتوسّع، وسهلة الصيانة. اعتماد هذا الأسلوب يرفع من جودة العمل، ويمنح المطور قدرة أكبر على التحكم في هيكلة التطبيق، خاصةً في الأنظمة الكبيرة أو المعتمدة على خدمات متعددة.
How to Stop SSH From Timing Out
Add these lines:
ClientAliveInterval 60
ClientAliveCountMax 3How to Translate URLs in React (2025 Guide)
When building a multilingual React application, translating the visible content is just part of the job. To make your app SEO-friendly and user-centric, you also need to:
- Translate URLs/slugs (e.g.,
/about-us→/fr/a-propos) - Maintain SEO with hreflang for each language
- Improve UX by aligning URLs with user language
- Ensure route accessibility via browser language or manual switching
Globalization in React (2025 Trends & Best Practices)
Make this dynamic in React:
const formatCurrency = (value, lng) => {
const currency = lng === 'ar' ? 'EGP' : 'USD';
return new Intl.NumberFormat(lng, {
style: 'currency',
currency
}).format(value);
};Implementing Internationalization (i18n) in a Large React Application (2025 Guide)
Update i18n.js:
import ICU from 'i18next-icu';
i18n
.use(ICU) // Enables datetime and currency formatting
.use(LanguageDetector)
.use(initReactI18next)
.init({
...
interpolation: {
format: (value, format, lng) => {
if (format === 'datetime') {
return new Intl.DateTimeFormat(lng).format(value);
}
if (format === 'currency') {
return new Intl.NumberFormat(lng, {
style: 'currency',
currency: lng === 'fr' ? 'EUR' : 'USD',
}).format(value);
}
return value;
},
}
});Building Micro-Frontends with Webpack Module Federation (2025 Guide)
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModuleFederationPlugin = require('webpack').container.ModuleFederationPlugin;
const path = require('path');
module.exports = {
mode: 'development',
devServer: {
port: 8080,
},
entry: './src/bootstrap.js',
output: {
publicPath: 'http://localhost:8080/',
},
plugins: [
new ModuleFederationPlugin({
name: 'app_shell',
remotes: {
analytics_app: 'analytics_app@http://localhost:8081/remoteEntry.js',
},
shared: require('./package.json').dependencies,
}),
new HtmlWebpackPlugin({ template: './public/index.html' }),
],
};Update src/bootstrap.js:
State Management Beyond Redux: Using Zustand for Scalable React Apps
Zustand's simplicity and performance make it a compelling choice for projects where Redux might be overkill.
Zustand isn't just for simple state management; it also offers advanced features that cater to more complex scenarios:
Mastering React Rendering Performance with Memoization and Context
import React, { useState, useCallback } from 'react';
function Counter() {
const [count, setCount] = useState(0);
const increment = useCallback(() => setCount(c => c + 1), []);
const decrement = useCallback(() => setCount(c => c - 1), []);
return (
<div>
<button onClick={increment}>+</button>
<span>{count}</span>
<button onClick={decrement}>-</button>
</div>
);
}By wrapping increment and decrement with useCallback, their references remain stable across renders, preventing unnecessary re-renders in child components that receive these functions as props.([GeeksforGeeks][2])
How to Disable MySQL Password Validation on Ubuntu 25.04
CREATE USER 'devuser'@'localhost' IDENTIFIED BY '123';
GRANT ALL PRIVILEGES ON *.* TO 'devuser'@'localhost';
FLUSH PRIVILEGES;This should now work without any errors.
How to Move the MySQL Data Directory to a New Location on Ubuntu 25.04
Edit AppArmor profile for MySQL:
sudo nano /etc/apparmor.d/usr.sbin.mysqldHow to Install PHP, MySQL, and phpMyAdmin on Ubuntu 25.04 (LAMP Stack Setup Guide)
sudo apt updateUbuntu 25.04 includes PHP 8.3 in its official repositories. Install PHP along with commonly used extensions for Laravel:
How to Fix NVIDIA Driver Issues on Ubuntu (Dell Vostro 3521)
Install the recommended version:
sudo apt install nvidia-driver-550 nvidia-primeAvoiding Memory Leaks in C++ Without Smart Pointers
- Prevents memory leaks.
- Simplifies exception handling.
- Keeps your code clean and maintainable.
In newer projects, always prefer std::unique_ptr and std::shared_ptr. But in legacy systems, RAII with simple wrappers like ScopedPointer can save you.
Deep Copy in C++: How to Avoid Shallow Copy Pitfalls
This causes both a.data and b.data to point to the same memory. When both destructors run, delete is called twice on the same pointer — undefined behavior!
A deep copy duplicates the actual data pointed to, not just the pointer.
Protect Your Forms Like a Pro: Anti-Spam Techniques That Actually Work
const duration = Date.now() - formStartTime;
if (duration < 3000) {
return res.status(403).send("Too fast, bot?");
}Yes, reCAPTCHA is still useful—especially v3, which assigns a score based on user behavior.
Build a Custom Rate Limiter in Node.js with Redis
- Atomic operations with Redis
- Manual request tracking logic
- Flexibility to customize based on business rules
You’re no longer blindly relying on a package—you understand and control the system.
Arduino Basics: A Step-by-Step Tutorial
Choose your board based on the complexity and size of your project.
- Definition: Represent two states: HIGH (ON) and LOW (OFF).
- Usage: Turning LEDs on/off, reading button states.
Building a Real-Time Object Detection Web App with TensorFlow.js and p5.js
Before you begin, make sure you have the following installed and set up:
- A modern web browser that supports webcam access (Chrome, Firefox, or Edge).
- Basic knowledge of HTML, CSS, and JavaScript.
- Familiarity with p5.js (optional, but helpful).
- A code editor (Visual Studio Code, Sublime Text, etc.).
Building a Cross-Platform Desktop App with Tauri and Svelte: A Step-by-Step Tutorial
Desktop applications have traditionally been built with heavyweight frameworks like Electron. However, Tauri—a modern, lightweight alternative built on Rust—offers improved performance, smaller bundle sizes, and enhanced security. In this tutorial, we’ll guide you through creating a simple cross-platform desktop application using Tauri for the backend and Svelte for the user interface.
Tauri leverages web technologies to build native desktop applications while offloading critical operations to Rust. Paired with Svelte—a fast, compile-time JavaScript framework—you can create modern apps that are both visually appealing and highly performant. This tutorial will walk you through setting up your development environment, creating a Svelte project, integrating Tauri, and building your first desktop app.
Implementing a Domain-Specific Language (DSL) with LLVM and C++
#include "DSL/Lexer.h"
#include "DSL/Parser.h"
#include "DSL/AST.h"
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/TargetSelect.h>
#include <iostream>
#include <memory>
extern llvm::Function* generateFunction(llvm::LLVMContext& context, llvm::Module& module, ASTNode* root);
extern void optimizeModule(llvm::Module& module);
int main() {
// Initialize LLVM.
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
llvm::LLVMContext context;
llvm::Module module("MyDSLModule", context);
std::string input;
std::cout << "Enter an expression: ";
std::getline(std::cin, input);
Lexer lexer(input);
Parser parser(lexer);
std::unique_ptr<ASTNode> astRoot;
try {
astRoot = parser.parseExpression();
} catch (const std::exception& ex) {
std::cerr << "Parsing error: " << ex.what() << std::endl;
return 1;
}
llvm::Function* func = generateFunction(context, module, astRoot.get());
if (!func) {
std::cerr << "Failed to generate LLVM function." << std::endl;
return 1;
}
optimizeModule(module);
// For demonstration, print the LLVM IR.
module.print(llvm::outs(), nullptr);
// In a full implementation, you could now JIT compile and execute the function.
return 0;
}This basic runtime lets you enter a mathematical expression, compiles it into LLVM IR, optimizes the code, and prints the IR. Expanding this further, you can use LLVM’s JIT compilation APIs to execute the code on the fly, integrate debugging information, or even embed the DSL into larger systems.