<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mansouriyoussef on Medium]]></title>
        <description><![CDATA[Stories by Mansouriyoussef on Medium]]></description>
        <link>https://medium.com/@mansouriyoussef1991?source=rss-7880d244c3bd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2hDM1Qie2vWvkUCxg2k0aA.png</url>
            <title>Stories by Mansouriyoussef on Medium</title>
            <link>https://medium.com/@mansouriyoussef1991?source=rss-7880d244c3bd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 05:43:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mansouriyoussef1991/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Comprehensive Guide to Indexing in Mongoose ❤️‍]]></title>
            <link>https://medium.com/@mansouriyoussef1991/a-comprehensive-guide-to-indexing-in-mongoose-%EF%B8%8F-dcdbd394a320?source=rss-7880d244c3bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcdbd394a320</guid>
            <dc:creator><![CDATA[Mansouriyoussef]]></dc:creator>
            <pubDate>Sun, 21 Jul 2024 11:49:01 GMT</pubDate>
            <atom:updated>2024-07-21T11:56:07.663Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="cover" src="https://cdn-images-1.medium.com/max/698/1*GZAWgXdlQqzPZZBrwDN2HQ.jpeg" /></figure><p>Indexing is a powerful feature in MongoDB that helps optimize query performance. Mongoose, a popular ODM (Object Data Modeling) library for MongoDB and Node.js, provides robust support for defining and managing indexes. In this article, we’ll explore why indexing is crucial, how to create indexes in Mongoose, and some best practices to follow.</p><h4><strong>Why Indexing Matters</strong></h4><p>Indexes improve the speed of query operations on a database. Without indexes, MongoDB must scan every document in a collection to select those that match the query. This can be slow and resource-intensive, especially for large datasets. Indexes store a portion of the collection’s data in a structure that allows MongoDB to quickly locate documents.</p><h4><strong>Getting Started with Mongoose Indexes</strong></h4><p><strong><em>Step 1: Install Mongoose</em></strong></p><pre>npm install mongoose</pre><p><strong><em>Step 2: Connect to MongoDB</em></strong></p><pre>const mongoose = require(&#39;mongoose&#39;);<br><br>mongoose.connect(&#39;mongodb://localhost:27017/mydatabase&#39;, {<br>  useNewUrlParser: true,<br>  useUnifiedTopology: true,<br>  useCreateIndex: true,<br>})<br>.then(() =&gt; console.log(&#39;MongoDB connected...&#39;))<br>.catch(err =&gt; console.error(&#39;Connection error&#39;, err));</pre><p><strong><em>Step 3: Define a Schema with Indexes</em></strong></p><p>Let’s create a User schema and add indexes to it. We’ll index the email field to ensure it’s unique and quickly searchable.</p><pre>const userSchema = new mongoose.Schema({<br>  name: {<br>    type: String,<br>    required: true,<br>    trim: true,<br>    index: true, // Index the name field<br>  },<br>  email: {<br>    type: String,<br>    required: true,<br>    unique: true, // Unique index<br>    match: [/.+@.+\..+/, &#39;Please fill a valid email address&#39;],<br>    trim: true,<br>    index: true, // Index the email field<br>  },<br>  password: {<br>    type: String,<br>    required: true,<br>    minlength: 6,<br>  },<br>  createdAt: {<br>    type: Date,<br>    default: Date.now,<br>    index: true, // Index the createdAt field<br>  },<br>});<br><br>// Create a compound index for name and email<br>userSchema.index({ name: 1, email: 1 });<br><br>// Create the User model<br>const User = mongoose.model(&#39;User&#39;, userSchema);</pre><h4>Best Practices for Indexing</h4><blockquote><strong>1. Index Frequently Queried Fields: </strong>Only index fields that are frequently queried or need unique constraints.<br> <strong>2. Use Compound Indexes: </strong>For queries involving multiple fields, use compound indexes to improve performance.<br> <strong>3. Monitor Performance: </strong>Regularly monitor your database performance to ensure indexes are beneficial and not causing overhead.<br><strong> 4. Balance Read and Write Performance:</strong> Indexes speed up read operations but can slow down write operations. Find a balance based on your application’s needs.</blockquote><h4><strong>Conclusion</strong></h4><p>Indexes are essential for optimizing the performance of your MongoDB queries. By leveraging Mongoose’s indexing capabilities, you can ensure that your applications run efficiently, even with large datasets. Follow best practices and continuously monitor your performance to make the most out of your database indexes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcdbd394a320" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostFix configuration in Debian 11]]></title>
            <link>https://medium.com/@mansouriyoussef1991/postfix-configuration-in-debian-11-0ed7328cbfd7?source=rss-7880d244c3bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ed7328cbfd7</guid>
            <dc:creator><![CDATA[Mansouriyoussef]]></dc:creator>
            <pubDate>Tue, 24 Oct 2023 12:38:19 GMT</pubDate>
            <atom:updated>2023-10-24T12:38:19.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*LKdrcedk7UIAy_O6rEYUvw.jpeg" /></figure><p>In this guide, we’ll walk you through configuring the Postfix SMTP server on Debian 11, a reliable and widely-used mail transfer agent. Whether you’re running a business, managing a website, or simply looking to streamline your email communications, this article will provide step-by-step instructions and insights to help you set up a robust email infrastructure on your Debian 11 server. By the end of this tutorial, you’ll have the knowledge and confidence to establish your SMTP server, sending emails with ease and control. Let’s dive in and empower your email communication.</p><p>Here’s a step-by-step guide for setting up Postfix on Debian 11</p><blockquote>Install Postfix and telnet</blockquote><pre>sudo apt update<br>sudo apt install postfix<br>sudo apt install mailutils<br>sudo apt install telnet</pre><p>During the installation, you’ll be prompted to configure Postfix. Choose “Internet Site” and enter example.com for example if your domain example.com.</p><blockquote>Backup main.cf:</blockquote><pre>sudo cp /etc/postfix/main.cf /etc/postfix/main.cd.backup</pre><blockquote>Edit <em>main.cf</em></blockquote><p>Open the Postfix configuration file for editing:</p><pre>sudo nano /etc/postfix/main.cf</pre><p>Set the value of the inet_interfaces setting to loopback-only:</p><pre>inet_interfaces = loopback-only</pre><p>Add or modify the following settings:</p><pre>myhostname = mail.example.com<br>mydomain = example.com<br>mydestination = $myhostname, localhost.$mydomain, subdomain.$mydomain, localhost</pre><p>If you dont have a subdomain, so that you dont need to add the bloc =&gt; subdomain.$mydomain</p><p>Check and Restart Postfix by running the following commands:</p><pre>sudo postfix check<br>sudo systemctl restart postfix</pre><blockquote>Configure Firewall</blockquote><pre>ufw allow Postfix<br><br>ufw allow &quot;Postfix SMTPS&quot;<br><br>ufw allow &quot;Postfix Submission&quot;</pre><blockquote>Testing Your SMTP server</blockquote><pre>telnet Ip_Server_POSTFIX 25</pre><pre>echo &quot;This is the email body&quot; | mail -a &quot;From: Custom Name &lt;no-reply@example.com&gt;&quot; -s &quot;Subject&quot; receiver-email</pre><p>Please remember to adapt this configuration to your specific needs, and consider implementing additional security measures, such as SSL/TLS encryption and firewall rules, to secure your email server. Additionally, configure mailbox delivery agents (MDAs) like Dovecot for email storage and user access.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ed7328cbfd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide to Working with @tanstack/react-query in React.js]]></title>
            <link>https://medium.com/@mansouriyoussef1991/a-guide-to-working-with-tanstack-react-query-in-react-js-2e4d77a832a0?source=rss-7880d244c3bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e4d77a832a0</guid>
            <dc:creator><![CDATA[Mansouriyoussef]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 09:16:13 GMT</pubDate>
            <atom:updated>2023-06-12T09:16:13.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wTCpU-Xd9pRo9KJxrqcFnQ.png" /></figure><h3>Introduction</h3><p>React.js has gained popularity due to its efficiency and flexibility in building user interfaces. To enhance the development process, various libraries and tools have been introduced, and one such powerful tool is @tanstack/react-query. In this article, we will explore the basics of @tanstack/react-query and demonstrate how it can streamline data fetching, caching, and state management in your React.js applications.</p><p>1- <strong>Installing and Setting up @tanstack/react-query:</strong></p><p>To get started, you need to install @tanstack/react-query and its dependencies. Using npm or yarn, run the following command in your project directory:</p><pre><br>npm install @tanstack/react-query</pre><p>After successful installation, import the necessary components and providers in your application.</p><p><strong>2- Fetching Data with @tanstack/react-query:</strong></p><p>One of the primary features of @tanstack/react-query is its ability to simplify data fetching. It provides a Query component that allows you to make API requests effortlessly. Here’s an example of how to fetch data using the Query component:</p><pre>import { useQuery } from &#39;@tanstack/react-query&#39;;<br><br>function ExampleComponent() {<br>  const { isLoading, error, data } = useQuery(&#39;todos&#39;, fetchTodos);<br><br>  if (isLoading) {<br>    return &lt;div&gt;Loading...&lt;/div&gt;;<br>  }<br><br>  if (error) {<br>    return &lt;div&gt;Error fetching data.&lt;/div&gt;;<br>  }<br><br>  return (<br>    &lt;div&gt;<br>      {data.map((todo) =&gt; (<br>        &lt;div key={todo.id}&gt;{todo.title}&lt;/div&gt;<br>      ))}<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>3- Mutating Data:</strong></p><p>Apart from fetching data, @tanstack/react-query provides mutation functionality to handle data updates on the server. You can easily perform mutations using the useMutation hook. Here’s an example of updating a todo item:</p><pre>import { useMutation } from &#39;@tanstack/react-query&#39;;<br><br>function ExampleComponent() {<br>  const { mutate } = useMutation(updateTodo);<br><br>  const handleUpdate = async (id, updatedData) =&gt; {<br>    await mutate({ id, updatedData });<br>    // Additional logic after the mutation<br>  };<br><br>  return (<br>    &lt;button onClick={() =&gt; handleUpdate(todo.id, { completed: true })}&gt;<br>      Update Todo<br>    &lt;/button&gt;<br>  );<br>}</pre><p><strong>4- Caching and State Management:</strong></p><p>@tanstack/react-query comes with a built-in caching mechanism, which eliminates the need to manually manage the data cache. By default, it caches data in memory and automatically updates the cache when mutations occur. This feature significantly optimizes subsequent API calls, reducing network requests and improving performance.</p><p><strong>5- Optimistic Updates:</strong></p><p>Optimistic updates are another powerful feature of @tanstack/react-query. They allow you to update the UI optimistically before the actual server response comes back, providing a seamless user experience. The useMutation hook supports optimistic updates out of the box.</p><p><strong>Conclusion:</strong></p><p>@tanstack/react-query is an excellent addition to your React.js toolkit when it comes to data fetching, caching, and state management. It simplifies the process of working with remote data and offers powerful features like caching, mutation handling, and optimistic updates. By leveraging @tanstack/react-query, you can enhance the performance and responsiveness of your React.js applications while reducing boilerplate code and development effort. So, give it a try and unlock the full potential of @tanstack/react-query in your projects!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e4d77a832a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Of The Most Populars React Animation Libraries in 2023]]></title>
            <link>https://medium.com/@mansouriyoussef1991/5-of-the-most-populars-react-animation-libraries-in-2023-50bcfdc53cc0?source=rss-7880d244c3bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/50bcfdc53cc0</guid>
            <dc:creator><![CDATA[Mansouriyoussef]]></dc:creator>
            <pubDate>Tue, 06 Jun 2023 09:28:51 GMT</pubDate>
            <atom:updated>2023-06-06T09:28:51.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*nUHUYdYfZriVKWWQ" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sKkLutg9kEZ_VW8Mkf5dFA.png" /></figure><p>1- <a href="https://www.framer.com/motion/">Framer Motion</a> is a popular React animation toolkit designed to make simple animations. It has two APIs named Framer API and Motion API. Framer API is responsible for providing rapid interactions, while Motion API provides gestures and animations.</p><p>Framer Motion has more than 15,000 <a href="https://github.com/framer/motion">GitHub</a> stars and 1.2 million weekly <a href="https://www.npmjs.com/package/framer-motion">NPM</a> downloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*iBo_Y68F6sXUPWjn" /></figure><p>2- <a href="https://react-spring.io/">react-spring</a> is a modern animation library based on the physics of springs. It’s pretty flexible and has some amazing features, including hooks, to help developers.</p><p>react-spring has more than 23,700 <a href="https://github.com/pmndrs/react-spring">GitHub</a> stars and 700,00+ weekly <a href="https://www.npmjs.com/package/react-spring">NPM</a> downloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FJpDiHS_brQktCb7" /></figure><p>3- <a href="https://www.remotion.dev/">Remotion</a> allows developers to create videos and animation using familiar languages like CSS, HTML, JavaScript, and TypeScript. So, developers do not need any knowledge about video creation. Instead, they can use their programming knowledge to create animation and videos using Remotion.</p><p>Remotion has more than 13,000 <a href="https://github.com/remotion-dev/remotion#readme">GitHub</a> stars and 5,000+ weekly <a href="https://www.npmjs.com/package/remotion">NPM</a> downloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/0*rYy2AHKrx-WP2QTX" /></figure><p>4- <a href="https://react-move-docs.netlify.app/#/">React Move</a> is a React library that allows you to make attractive, data-driven animations. It is a lightweight library that has lifecycle events on transitions.</p><p>React Move has more than 6,500 <a href="https://github.com/sghall/react-move#readme">GitHub</a> stars and 90,00 weekly <a href="https://www.npmjs.com/package/react-move">NPM</a> downloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*-r-JFGr4RoZDNNFsk39Lhw.png" /></figure><p>5- <a href="https://react-awesome-reveal.morello.dev/">React Awesome Reveal</a> is a TypeScript package that provides reveal animations using the Intersection Observer API to detect when elements appear in the viewport. Its animations are provided by <a href="https://emotion.sh/docs/introduction">Emotion</a> and implemented as CSS animations to benefit from hardware acceleration.</p><p>React Awesome Reveal has more than 10,000 weekly <a href="https://www.npmjs.com/package/react-awesome-reveal">NPM</a> downloads.</p><p>Enjoy ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50bcfdc53cc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install Mail Server on Linux, Mac OS]]></title>
            <link>https://medium.com/@mansouriyoussef1991/how-to-install-mail-server-on-linux-mac-os-aa1a5e2685fe?source=rss-7880d244c3bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa1a5e2685fe</guid>
            <dc:creator><![CDATA[Mansouriyoussef]]></dc:creator>
            <pubDate>Tue, 09 May 2023 10:57:41 GMT</pubDate>
            <atom:updated>2023-05-09T11:02:21.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*FJ0lqIxo0oizbI6AYLHEHw.png" /></figure><p>In this post, I would like to share with you how to install mail server on Linux (Ubuntu, Debian, … ) or Mac OS (Unix). Is very important if you need to send email from your web application in local environment.</p><p>There are many tools and software applications available that can be used to send email, in this article we’ll use <strong>PostFix.</strong></p><p><strong>1- Install Postfix:</strong></p><p>If you’re using a Linux distribution such as Ubuntu, you can use the following command to install Postfix:</p><pre>sudo apt-get install postfix</pre><p>If you’re using MacOS (Unix): <strong>Pre-installed</strong></p><p><strong>2- Configure Postfix:</strong></p><p>After installing Postfix, you need to configure it. The main configuration file for Postfix is located at /etc/postfix/main.cf. You can edit this file using your preferred text editor. Some of the configuration options you might want to set include:</p><p>myhostname: This should be set to the hostname of your server. try the following command to verify the hostname of the server</p><pre>hostname</pre><ul><li>mydomain: This should be set to your domain name.</li><li>mydestination: This should be set to the list of domains for which your server will accept mail.</li><li>mynetworks: This should be set to the IP addresses of the networks that are allowed to use your server as a mail relay.</li></ul><pre>mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128</pre><ul><li>relayhost: If you want to use an external SMTP server to relay your mail, you can set this to the hostname or IP address of the server.</li></ul><p>For example if you want to use gmail smtp:</p><pre>relayhost = smtp.gmail.com:587</pre><ul><li>inet_interfaces: This should be set to all to listen on all network interfaces.</li></ul><p><strong>2- Restart Postfix:</strong></p><pre>linux: sudo systemctl restart postfix<br>macos: sudo postfix reload (if not started try sudo postfix start)</pre><p>3- <strong>Testing:</strong></p><p>Postfix allow you to send email to external emails or username (locally)</p><p>. Locally:</p><pre>echo &quot;This is the body of the email.&quot; | mail -s &quot;This is the subject&quot; &lt;username-computer&gt;</pre><p>. Emails:</p><pre>echo &quot;This is the body of the email.&quot; | mail -s &quot;This is the subject&quot; your-mail</pre><p>4-<strong> Add passwords to your smtp configuration</strong></p><p>Install and Configure SASL: After installing SASL, you need to configure it to use a password file for authentication. Create a new password file using the following command:</p><pre>sudo apt-get install libsasl2-modules</pre><pre># Use Gmail SMTP (Or others just change the relayhost)<br>relayhost = smtp.gmail.com:587<br>smtp_sasl_mechanism_filter = plain<br>smtp_sasl_auth_enable = yes<br>smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd<br>smtp_use_tls = yes<br>smtp_tls_security_level = encrypt<br>smtpd_sasl_security_options = noanonymous</pre><p>Then, add the following line to the file, replacing smtp.example.com with your own mail server hostname:</p><pre>smtp.example.com username:password<br>&lt;!--smtp.gmail.com:587 your_username@gmail.com:your_password--&gt;</pre><p>Replace username and password with the credentials of the authorized user who will be sending mail.</p><p>After creating the password file, you need to generate a hash of the password file using the following command:</p><pre>sudo postmap /etc/postfix/sasl_passwd</pre><p>After that restart postfix</p><p><strong>5- Logging:</strong></p><p>After sending email you can check tail -f /var/log/mail.log or tail -f /var/log/{username} (if locally)</p><p>Conclusion:</p><p>Sending email from your server is very important, Postfix is a popular and reliable Mail Transfer Agent (MTA) that is widely used by organizations of all sizes to send and receive email. It is highly configurable, easy to manage, and provides advanced features and security measures that make it a preferred choice for many users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa1a5e2685fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>