Find the code you need
Search through tutorials, code snippets, and development resources
ما هو حقن التبعيات (Dependency Injection)؟
حقن التبعيات ليس مجرد تقنية، بل هو نمط يُسهم في بناء أنظمة نظيفة، قابلة للتوسّع، وسهلة الصيانة. اعتماد هذا الأسلوب يرفع من جودة العمل، ويمنح المطور قدرة أكبر على التحكم في هيكلة التطبيق، خاصةً في الأنظمة الكبيرة أو المعتمدة على خدمات متعددة.
إذا كنت تعمل على تطبيق معقّد أو تستخدم إطاراً حديثاً، فإن تطبيق حقن التبعيات يعد خطوة أساسية لبناء بنية متينة ومرنة.
How to Stop SSH From Timing Out
On your local machine, edit or create:
nano ~/.ssh/configHow to Translate URLs in React (2025 Guide)
npm install react-router-dom i18next react-i18next i18next-browser-languagedetector/src
/locales
en.json
fr.json
/pages
Home.js
About.js
i18n.js
App.js
routes.jsGlobalization 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)
Edit src/index.js:
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import './i18n'; // import i18n config
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);Building Micro-Frontends with Webpack Module Federation (2025 Guide)
import React from 'react';
// Lazy load the remote Vue component
const Analytics = React.lazy(() => import('analytics_app/Analytics'));
function App() {
return (
<div className="App">
<h1>Host Dashboard</h1>
<React.Suspense fallback={<div>Loading Analytics...</div>}>
<Analytics />
</React.Suspense>
</div>
);
}
export default App;Start the remote app (Vue):
State Management Beyond Redux: Using Zustand for Scalable React Apps
- Project Size: For small to medium-sized projects, Zustand's simplicity can accelerate development.
- Team Experience: Teams new to state management may find Zustand's learning curve more approachable.
- Boilerplate Reduction: If minimizing boilerplate is a priority, Zustand offers a cleaner setup.
- Performance Needs: Zustand's selective rendering can enhance performance in applications with frequent state updates.
However, for large-scale applications requiring complex state interactions, middleware, and extensive tooling, Redux might still be the preferred choice.
Mastering React Rendering Performance with Memoization and Context
const increment = useCallback(() => setCount(c => c + 1), []);Implementing these practices ensures that only components dependent on specific context values re-render when those values change.([Medium][7])
How to Disable MySQL Password Validation on Ubuntu 25.04
UNINSTALL COMPONENT 'file://component_validate_password';If successful, you'll see:
How to Move the MySQL Data Directory to a New Location on Ubuntu 25.04
mysql -u root -p -e "SHOW VARIABLES LIKE 'datadir';"You should see:
How to Install PHP, MySQL, and phpMyAdmin on Ubuntu 25.04 (LAMP Stack Setup Guide)
If you're installing global Composer packages:
Add this line to your ~/.bashrc or ~/.zshrc file:
How to Fix NVIDIA Driver Issues on Ubuntu (Dell Vostro 3521)
driver : nvidia-driver-550 - distro non-free recommended
...
driver : xserver-xorg-video-nouveau - distro free builtin Make note of the recommended driver (e.g. nvidia-driver-550).
Avoiding Memory Leaks in C++ Without Smart Pointers
void loadData() {
char* buffer = new char[1024];
try {
if (someCondition()) {
throw std::runtime_error("Something went wrong");
}
// more code...
} catch (...) {
delete[] buffer;
throw;
}
delete[] buffer;
}Not elegant. Easy to forget or misplace deletes. Let's go better.
Deep Copy in C++: How to Avoid Shallow Copy Pitfalls
class String {
private:
char* buffer;
public:
String(const char* str) {
buffer = new char[strlen(str) + 1];
strcpy(buffer, str);
}
// Copy constructor
String(const String& other) {
buffer = new char[strlen(other.buffer) + 1];
strcpy(buffer, other.buffer);
}
// Assignment operator
String& operator=(const String& other) {
if (this != &other) {
delete[] buffer;
buffer = new char[strlen(other.buffer) + 1];
strcpy(buffer, other.buffer);
}
return *this;
}
~String() {
delete[] buffer;
}
void print() const {
std::cout << buffer << std::endl;
}
};String a("Hello");
String b = a; // deep copy
String c("World");
c = a; // deep assignmentProtect Your Forms Like a Pro: Anti-Spam Techniques That Actually Work
<input type="text" name="phone_number" style="display:none" autocomplete="off">if (!empty($_POST['phone_number'])) {
die("Bot detected");
}Build a Custom Rate Limiter in Node.js with Redis
Instead of IP address, use API keys for user-specific limits:
const userKey = req.headers['x-api-key'] || req.ip;
const key = `rate_limit:${userKey}`;Arduino Basics: A Step-by-Step Tutorial
Here’s a simplified table of the Arduino Uno’s pin configuration:
Table 3: Key pin configurations on the Arduino Uno.
Building a Real-Time Object Detection Web App with TensorFlow.js and p5.js
Create a new file called sketch.js in your project folder. We’ll use p5.js to access the webcam and display the video on a canvas:
let video;
let detector;
let detections = [];
function setup() {
// Create the canvas to match the video dimensions
createCanvas(640, 480);
// Capture video from the webcam
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();
// Load the pre-trained COCO-SSD model
cocoSsd.load().then(model => {
detector = model;
console.log("Model Loaded!");
// Begin detecting objects every frame
detectObjects();
});
}
function detectObjects() {
detector.detect(video.elt).then(results => {
detections = results;
// Continue detection in a loop
detectObjects();
});
}
function draw() {
// Draw the video
image(video, 0, 0);
// Draw detection boxes and labels if available
if (detections) {
for (let i = 0; i < detections.length; i++) {
let object = detections[i];
stroke(0, 255, 0);
strokeWeight(2);
noFill();
rect(object.bbox[0], object.bbox[1], object.bbox[2], object.bbox[3]);
noStroke();
fill(0, 255, 0);
textSize(16);
text(object.class, object.bbox[0] + 4, object.bbox[1] + 16);
}
}
}Building a Cross-Platform Desktop App with Tauri and Svelte: A Step-by-Step Tutorial
We’ll start by creating a new Svelte project. You can use a template via degit:
npx degit sveltejs/template tauri-svelte-app
cd tauri-svelte-app
npm installImplementing 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.