<?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 Hafez Heybati Goujani on Medium]]></title>
        <description><![CDATA[Stories by Hafez Heybati Goujani on Medium]]></description>
        <link>https://medium.com/@hafez-heybati?source=rss-bd8725ae87c8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*si_ZXHuTt1b15_pVr2d9Uw.jpeg</url>
            <title>Stories by Hafez Heybati Goujani on Medium</title>
            <link>https://medium.com/@hafez-heybati?source=rss-bd8725ae87c8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 13:21:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hafez-heybati/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[Install NodeJs in Linux (NodeSource Node.js Binary Distributions)]]></title>
            <link>https://hafez-heybati.medium.com/install-nodejs-in-linux-nodesource-node-js-binary-distributions-5a12fed48773?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a12fed48773</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[downgrade]]></category>
            <category><![CDATA[nodesource]]></category>
            <category><![CDATA[upgrade]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Tue, 09 Jan 2024 06:16:57 GMT</pubDate>
            <atom:updated>2024-01-09T06:16:57.468Z</atom:updated>
            <content:encoded><![CDATA[<h3>Debian and Ubuntu based distributions</h3><h3>DEB Available architectures</h3><p>NodeSource will continue to maintain the following architectures and may add additional ones in the future.</p><ul><li><strong>amd64</strong> (64-bit)</li><li><strong>armhf</strong> (ARM 32-bit hard-float, ARMv7 and up: <em>arm-linux-gnueabihf</em>)</li><li><strong>arm64</strong> (ARM 64-bit, ARMv8 and up: <em>aarch64-linux-gnu</em>)</li></ul><h3>DEB Supported Versions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*h1J0ERAKSmTxRVGbyfWm5Q.png" /></figure><h3>Installation Instructions</h3><h4>Node.js</h4><p><strong>Node.js v21.x</strong>:</p><p>Using Ubuntu</p><pre>curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &amp;&amp;\<br>sudo apt-get install -y nodejs</pre><p>Using Debian, as root</p><pre>curl -fsSL https://deb.nodesource.com/setup_21.x | bash - &amp;&amp;\<br>apt-get install -y nodejs</pre><p><strong>Node.js v20.x</strong>:</p><p>Using Ubuntu</p><pre>curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - &amp;&amp;\<br>sudo apt-get install -y nodejs</pre><p>Using Debian, as root</p><pre>curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &amp;&amp;\<br>apt-get install -y nodejs</pre><p><strong>Node.js v18.x</strong>:</p><p>Using Ubuntu</p><pre>curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &amp;&amp;\<br>sudo apt-get install -y nodejs</pre><p>Using Debian, as root</p><pre>curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &amp;&amp;\<br>apt-get install -y nodejs</pre><p><strong>Node.js LTS (v20.x)</strong>:</p><p>Using Ubuntu</p><pre>curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &amp;&amp;\<br>sudo apt-get install -y nodejs</pre><p>Using Debian, as root</p><pre>curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - &amp;&amp;\<br>apt-get install -y nodejs</pre><p><strong>Node.js Current (v21.x)</strong>:</p><p>Using Ubuntu</p><pre>curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash - &amp;&amp;\<br>sudo apt-get install -y nodejs</pre><p>Using Debian, as root</p><pre>curl -fsSL https://deb.nodesource.com/setup_current.x | bash - &amp;&amp;\<br>apt-get install -y nodejs</pre><h3>Uninstall nodejs Ubuntu &amp; Debian packages</h3><p>To completely remove Node.js installed from the deb.nodesource.com package methods above:</p><h4>use sudo on Ubuntu or run this as root on debian</h4><pre>apt-get purge nodejs &amp;&amp;\<br>rm -r /etc/apt/sources.list.d/nodesource.list &amp;&amp;\<br>rm -r /etc/apt/keyrings/nodesource.gpg</pre><h3>Enterprise Linux Based Distributions</h3><h3>RPM Available architectures</h3><p>NodeSource will continue to maintain the following architectures and may add additional ones in the future.</p><ul><li><strong>x86_64</strong> (64-bit)</li><li><strong>arm64</strong> (ARM 64-bit, ARMv8 and up: <em>aarch64-linux-gnu</em>)</li></ul><h3>RPM Supported Versions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*xPqAytYNhfeLqHgUq6qvvA.png" /></figure><h3>RPM Installation Instructions</h3><p>The Nodesource RPM package signing key is available here: <a href="https://rpm.nodesource.com/gpgkey/nodesource.gpg.key">https://rpm.nodesource.com/gpgkey/nodesource.gpg.key</a></p><p><strong>Node.js v21.x</strong></p><p>As root</p><pre>curl -fsSL https://rpm.nodesource.com/setup_21.x | bash -<br>yum install -y nodejs</pre><p>No root privileges</p><pre>curl -fsSL https://rpm.nodesource.com/setup_21.x | sudo bash -<br>yum install -y nodejs</pre><p><strong>Node.js v20.x</strong></p><p>As root</p><pre>curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -<br>yum install -y nodejs</pre><p>No root privileges</p><pre>curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -<br>yum install -y nodejs</pre><p><strong>Node.js v18.x</strong></p><p>As root</p><pre>curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -<br>yum install -y nodejs</pre><p>No root privileges</p><pre>curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -<br>yum install -y nodejs</pre><p><strong>Node.js LTS (20.x)</strong></p><p>As root</p><pre>curl -fsSL https://rpm.nodesource.com/setup_lts.x | bash -<br>yum install -y nodejs</pre><p>No root privileges</p><pre>curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -<br>yum install -y nodejs</pre><p><strong>Node.js Current (21.x)</strong></p><p>As root</p><pre>curl -fsSL https://rpm.nodesource.com/setup_current.x | bash -<br>yum install -y nodejs</pre><p>No root privileges</p><pre>curl -fsSL https://rpm.nodesource.com/setup_current.x | sudo bash -<br>yum install -y nodejs</pre><p><strong><em>Optional</em></strong>: install build tools</p><p>To compile and install native addons from npm you may also need to install build tools:</p><pre>yum install gcc-c++ make<br># or: yum groupinstall &#39;Development Tools&#39;</pre><h3>Uninstall nodejs Enterprise Linux packages</h3><p>To completely remove Node.js installed from the rpm.nodesource.com package methods above:</p><h4>use sudo or run this as root</h4><pre>yum remove nodejs &amp;&amp;\<br>rm -r /etc/yum.repos.d/nodesource*.repo &amp;&amp;\<br>yum clean all</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a12fed48773" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install swagger in NestJs]]></title>
            <link>https://hafez-heybati.medium.com/install-swagger-in-nestjs-618732123fa1?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/618732123fa1</guid>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[rest-api-documentation]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[swagger-ui]]></category>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Wed, 03 Jan 2024 05:42:20 GMT</pubDate>
            <atom:updated>2024-01-03T05:55:49.798Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Is OpenAPI?</h3><p><strong>OpenAPI Specification</strong> (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API, including:</p><ul><li>Available endpoints (/users) and operations on each endpoint (GET /users, POST /users)</li><li>Operation parameters Input and output for each operation</li><li>Authentication methods</li><li>Contact information, license, terms of use and other information.</li></ul><p>API specifications can be written in YAML or JSON. The format is easy to learn and readable to both humans and machines. The complete OpenAPI Specification can be found on GitHub: <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md">OpenAPI 3.0 Specification</a></p><h3>What Is Swagger?</h3><p><strong>Swagger</strong> is a set of open-source tools built around the OpenAPI Specification that can help you design, build, document and consume REST APIs. The major Swagger tools include:</p><ul><li><a href="https://editor.swagger.io/">Swagger Editor</a> — browser-based editor where you can write OpenAPI definitions.</li><li><a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a> — renders OpenAPI definitions as interactive documentation.</li><li><a href="https://github.com/swagger-api/swagger-codegen">Swagger Codegen</a> — generates server stubs and client libraries from an OpenAPI definition.</li><li><a href="https://editor-next.swagger.io/">Swagger Editor Next (beta)</a> — browser-based editor where you can write and review OpenAPI and AsyncAPI definitions.</li><li><a href="https://github.com/swagger-api/swagger-core">Swagger Core </a>— Java-related libraries for creating, consuming, and working with OpenAPI definitions.</li><li><a href="https://github.com/swagger-api/swagger-parser">Swagger Parser</a> — standalone library for parsing OpenAPI definitions</li><li><a href="https://github.com/swagger-api/apidom">Swagger APIDom</a> — provides a single, unifying structure for describing APIs across various description languages and serialization formats.</li></ul><p>Refer to the <a href="https://swagger.io/">https://swagger.io</a> website for more information. Now lets go to install swagger in nestJs.</p><h3>Install Swagger in NestJs:</h3><h3>1. Installing Required Packages:</h3><p>Start by installing the necessary libraries:</p><pre>npm install @nestjs/swagger swagger-ui-express</pre><h3>2. Setting Up Swagger:</h3><p>Navigate to your main file (typically main.ts) and set up Swagger:</p><pre>import { NestFactory } from &#39;@nestjs/core&#39;;<br>import { SwaggerModule, DocumentBuilder } from &#39;@nestjs/swagger&#39;;<br>import { AppModule } from &#39;./app.module&#39;;</pre><pre>async function bootstrap() {<br>  const app = await NestFactory.create(AppModule);<br>  const options = new DocumentBuilder()<br>    .setTitle(&#39;API Title&#39;)<br>    .setDescription(&#39;API description&#39;)<br>    .setVersion(&#39;1.0&#39;)<br>    .addServer(&#39;http://localhost:3000/&#39;, &#39;Local environment&#39;)<br>    .addServer(&#39;http://staging URL/&#39;, &#39;Staging&#39;)<br>    .addServer(&#39;http://production URL/&#39;, &#39;Production&#39;)<br>    .addTag(&#39;API Tag&#39;)<br>    .build();<br>const document = SwaggerModule.createDocument(app, options);<br>  SwaggerModule.setup(&#39;api-docs&#39;, app, document);<br>await app.listen(3000);<br>}<br>bootstrap();</pre><p>With this setup, your Swagger UI will be available at <a href="http://localhost:3000/api-docs.">http://localhost:3000/api-docs.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4u0nZfBSt-wRw_BMexIgA.png" /><figcaption>UI Swagger Documentation : http://localhost:3000/api-docs</figcaption></figure><p>It feels almost otherworldly, doesn’t it? The tedious task of manually drafting .yml or .json files has been whisked away. Everything is generated on the fly. And the best part? Instead of just hosting, you have the option to download and utilize it in diverse manners. Also, you can check we have a dropdown where we select the Server base URL.</p><h3>3. Annotating APIs with Swagger Decorators:</h3><p>NestJS provides decorators that integrate seamlessly with Swagger to auto-generate documentation.</p><h3>a) Controllers and Routes:</h3><p>Decorate your controllers and routes with appropriate Swagger decorators:</p><pre>import { Controller, Get } from &#39;@nestjs/common&#39;;<br>import { ApiTags } from &#39;@nestjs/swagger&#39;;<br><br><br>@ApiTags(&#39;User&#39;)<br>@Controller(&#39;user&#39;)<br>export class UserController {<br>  @Get()<br>  findAllUsers(): string {<br>    return this.userService.findAll();<br>  }<br>}</pre><h3>b) Defining Data Models:</h3><p>Use class decorators to define data models and DTOs:</p><pre>import { ApiProperty } from &#39;@nestjs/swagger&#39;;<br>import { IsEmail, IsNotEmpty, MinLength } from &#39;class-validator&#39;;<br><br><br>export enum UserRole {<br>   Admin = &#39;Admin&#39;,<br>   Moderator = &#39;Moderator&#39;,<br>   User = &#39;User&#39;<br>}<br>export class CreateUserDto {<br>id: number;<br>@ApiProperty({<br>   example: &#39;rehmat.sayani@gmail.com&#39;,<br>   required: true<br>})<br>@IsEmail()<br>email: string;<br>@ApiProperty({<br>   example: &#39;1234578910&#39;,<br>   required: true<br>})<br>@IsNotEmpty()<br>@MinLength(10)<br>password: string;<br>@ApiProperty({ example: &quot;Admin|Moderator|User&quot;})<br>role: UserRole;<br>}</pre><p>populated UI Schema for swagger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*zjlhB0ADuAtMr2um.png" /></figure><h3>c) Further Descriptions:</h3><p>Enhance endpoint documentation using @ApiResponse(), @ApiBody(), and more.</p><pre>export class UserController {<br>    @Post()<br>    @ApiResponse({ status: 201, description: &#39;The record has been successfully created.&#39;})<br>    @ApiResponse({ status: 403, description: &#39;Forbidden.&#39;})<br>    @ApiBody({<br>       type: CreateUserDto,<br>       description: &#39;Json structure for user object&#39;,<br>    })<br>    async create(@Body() createUserDto: CreateUserDto) {<br>      this.userService.create(createUserDto);<br>     }<br>}</pre><p>Poulates request body for swagger in the below image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ngsZaNsLMaWWfoIH.png" /></figure><p>JSON object structure for post new user</p><h3>4. Adding Global Parameters:</h3><p>In some scenarios, you may have parameters that are consistent across all routes, such as headers for authentication. In my case, we have a country parameter which is a query parameter and is required in all routes of the application. NestJS Swagger has a direct way to globally set these.</p><p>Here’s how:</p><p>Navigate to your main file again (typically main.ts) and update your code.</p><pre>async function bootstrap() {<br>  const app = await NestFactory.create(AppModule);<br>  const options = new DocumentBuilder()<br>    .setTitle(&#39;Your API Title&#39;)<br>    .setDescription(&#39;Your API description&#39;)<br>    .setVersion(&#39;1.0&#39;)<br>    .addServer(&#39;http://localhost:3000/&#39;, &#39;Local environment&#39;)<br>    .addServer(&#39;https://staging.yourapi.com/&#39;, &#39;Staging&#39;)<br>    .addServer(&#39;https://production.yourapi.com/&#39;, &#39;Production&#39;)<br>    .addTag(&#39;Your API Tag&#39;)<br>    .addGlobalParameters({<br>      name: &#39;country&#39;,<br>      in: &#39;query&#39;<br>    })<br>    .build();</pre><pre>const document = SwaggerModule.createDocument(app, options);<br>  SwaggerModule.setup(&#39;api-docs&#39;, app, document);<br>await app.listen(process.env.PORT || 3000);<br>}<br>bootstrap();</pre><h3>Password protection</h3><p>So first let’s protect the Swagger UI with <a href="https://en.wikipedia.org/wiki/Basic_access_authentication">HTTP basic auth</a> requiring visitors to enter a username and password to access /docs or /docs-json. This can easily be done by implementing <a href="https://www.npmjs.com/package/express-basic-auth">express-basic-auth</a>, a simple plug &amp; play HTTP basic auth middleware for Express.</p><p>npm i express-basic-auth</p><p>After installing express-basic-auth you would want to enable this middleware for your /docs and /docs-json endpoints. To do so modify main.ts like the following:</p><pre>// main.ts<br>import { NestFactory } from &#39;@nestjs/core&#39;;<br>import { SwaggerModule, DocumentBuilder } from &#39;@nestjs/swagger&#39;;<br>import * as basicAuth from &#39;express-basic-auth&#39;;<br>import { AppModule } from &#39;./app.module&#39;;<br>async function bootstrap() {<br>  const app = await NestFactory.create(AppModule);<br>  app.use([&#39;/docs&#39;, &#39;/docs-json&#39;], basicAuth({<br>    challenge: true,<br>    users: {<br>      [process.env.SWAGGER_USER]: process.env.SWAGGER_PASSWORD,<br>    },<br>  }));<br>  const config = new DocumentBuilder()<br>    .setTitle(&#39;API Docs&#39;)<br>    .setDescription(&#39;The API documentation&#39;)<br>    .setVersion(&#39;1.0&#39;)<br>    .build();<br>  const document = SwaggerModule.createDocument(app, config);<br>  SwaggerModule.setup(&#39;docs&#39;, app, document);<br>  await app.listen(3000);<br>}<br>bootstrap();</pre><p>The key to getting this to work is the right order, it is important to apply the middleware app.use([&#39;/docs&#39;, &#39;/docs-json&#39;], basicAuth({…}) <strong>before</strong> you initialize Swagger.</p><p>basicAuth() in this scenario expects an object of users, I am using just one here. Keep in mind that it is always a good idea to not hardcode credentials, so relying on environment variables is a good option here. There are quite a few config options to express-basic-auth available, just check out the <a href="https://www.npmjs.com/package/express-basic-auth">docs</a>.</p><h3>Hide Swagger UI on production</h3><p>As mentioned the second thing I tend to do is hiding Swagger UI entirely on production. The most simple way to do so might be by wrapping a conditional statement around the parts initializing Swagger. Check this out:</p><pre>// main.ts<br><br>import { NestFactory } from &#39;@nestjs/core&#39;;<br>import { SwaggerModule, DocumentBuilder } from &#39;@nestjs/swagger&#39;;<br>import * as basicAuth from &#39;express-basic-auth&#39;;<br>import { AppModule } from &#39;./app.module&#39;;<br>const SWAGGER_ENVS = [&#39;local&#39;, &#39;dev&#39;, &#39;staging&#39;];<br>async function bootstrap() {<br>  const app = await NestFactory.create(AppModule);<br>  if (SWAGGER_ENVS.includes(process.env.NODE_ENV)) {<br>    app.use([&#39;/docs&#39;, &#39;/docs-json&#39;], basicAuth({<br>      challenge: true,<br>      users: {<br>        [process.env.SWAGGER_USER]: process.env.SWAGGER_PASSWORD,<br>      },<br>    }));<br>    const config = new DocumentBuilder()<br>      .setTitle(&#39;API Docs&#39;)<br>      .setDescription(&#39;The API documentation&#39;)<br>      .setVersion(&#39;1.0&#39;)<br>      .build();<br>    const document = SwaggerModule.createDocument(app, config);<br>    SwaggerModule.setup(&#39;docs&#39;, app, document);<br>  }<br>  await app.listen(3000);<br>}<br>bootstrap();</pre><p>This basically only applys the basic auth middleware and initializes Swagger when NODE_ENV is local, dev or staging. Depending on how you handle your environment names or have any other mechanism to check for a prodcution deployment, this may look slightly different in your project, but I think you get the gist.</p><p>Thanks to <a href="https://rehmat-sayany.medium.com/">https://rehmat-sayany.medium.com</a> And <a href="https://manuel-heidrich.dev/">https://manuel-heidrich.dev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=618732123fa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Duplicate Documents in MongoDB]]></title>
            <link>https://hafez-heybati.medium.com/finding-duplicate-documents-in-mongodb-0523e5e9203c?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/0523e5e9203c</guid>
            <category><![CDATA[duplicate]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[unique]]></category>
            <category><![CDATA[duplicate-content]]></category>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Wed, 27 Dec 2023 07:19:35 GMT</pubDate>
            <atom:updated>2023-12-27T07:19:35.616Z</atom:updated>
            <content:encoded><![CDATA[<p>You can connect to the database using the command line utility or whatever tool you prefer and use the following aggregation pipeline:</p><pre>db.collectionName.aggregate([<br>    // Group by the key and compute the number of documents that match the key<br>    {<br>        $group: {<br>            _id: &quot;$Fieldname&quot;,  // or if you want to use multiple fields _id: { a: &quot;$FirstName&quot;, b: &quot;$LastName&quot; }<br>            count: { $sum: 1 }<br>        }<br>    },<br>    // Filter group having more than 1 item, which means that at least 2 documents have the same key<br>    {<br>        $match: {<br>            count: { $gt: 1 }<br>        }<br>    }<br>])</pre><p>Below are other examples:</p><p>Example1: Use aggregation on fieldName and get fieldName with count &gt; 1:</p><pre>db.collectionName.aggregate([<br>    {&quot;$group&quot; : { &quot;_id&quot;: &quot;$fieldName&quot;, &quot;count&quot;: { &quot;$sum&quot;: 1 } } },<br>    {&quot;$match&quot;: {&quot;_id&quot; :{ &quot;$ne&quot; : null } , &quot;count&quot; : {&quot;$gt&quot;: 1} } }, <br>    {&quot;$project&quot;: {&quot;fieldName&quot;,&quot; : &quot;$_id&quot;, &quot;_id&quot; : 0} }<br>]);</pre><p>Example2: To sort the results by most to least duplicates:</p><pre>db.collectionName.aggregate([<br>    {&quot;$group&quot; : { &quot;_id&quot;: &quot;$fieldName&quot;, &quot;count&quot;: { &quot;$sum&quot;: 1 } } },<br>    {&quot;$match&quot;: {&quot;_id&quot; :{ &quot;$ne&quot; : null } , &quot;count&quot; : {&quot;$gt&quot;: 1} } }, <br>    {&quot;$sort&quot;: {&quot;count&quot; : -1} },<br>    {&quot;$project&quot;: {&quot;fieldName&quot; : &quot;$_id&quot;, &quot;_id&quot; : 0} }     <br>]);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0523e5e9203c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Change Swap Space on Ubuntu 18.04]]></title>
            <link>https://hafez-heybati.medium.com/how-to-change-swap-space-on-ubuntu-18-04-539ce022c417?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/539ce022c417</guid>
            <category><![CDATA[swap]]></category>
            <category><![CDATA[ram-shortage]]></category>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 13:48:51 GMT</pubDate>
            <atom:updated>2023-08-02T13:48:51.303Z</atom:updated>
            <content:encoded><![CDATA[<h3>here are the steps to change the swap settings in Ubuntu 18.04:</h3><ol><li>First, make sure that your current swap is inactive. To do this, run the following command in the terminal:</li></ol><pre>sudo swapoff -a</pre><ol><li>Then, delete the existing swap file:</li></ol><pre>sudo rm /swapfile</pre><p>(If you have used a separate partition for swap, disregard the following steps.)</p><ol><li>Create a new swap file with the desired size. For example, if you want to create a 4GB swap file:</li></ol><pre>sudo fallocate -l 4G /swapfile</pre><ol><li>Set the swap file’s permissions to read and write only:</li></ol><pre>sudo chmod 600 /swapfile</pre><ol><li>Format the swap file:</li></ol><pre>sudo mkswap /swapfile</pre><ol><li>Activate the new swap file:</li></ol><pre>sudo swapon /swapfile</pre><ol><li>Set up the new swap file in the /etc/fstab file to be used during system boot:</li></ol><p>Open the /etc/fstab file using a text editor like nano or vi:</p><pre>sudo nano /etc/fstab</pre><p>Add the following line at the end of the file:</p><pre>/swapfile none swap sw 0 0</pre><ol><li>Test the swap settings with the following command:</li></ol><pre>sudo swapon --show</pre><p>The output should display your new swap settings.</p><p>Now your current swap has been replaced with the new settings. You can adjust the size or location of the swap accordingly. Please note that changing the swap size may be limited by partitioning and disk space constraints on your system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=539ce022c417" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ddosify]]></title>
            <link>https://hafez-heybati.medium.com/ddosify-e004c1b790aa?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e004c1b790aa</guid>
            <category><![CDATA[performance-testing]]></category>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 16:08:29 GMT</pubDate>
            <atom:updated>2023-06-07T16:12:18.343Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Distributed Performance Testing Platform</strong></h4><h3>What is Ddosify?</h3><p>Ddosify is a comprehensive performance testing platform, designed specifically to evaluate backend load and latency. It offers three distinct deployment options to cater to various needs: Ddosify Engine, Ddosify Self-Hosted, and Ddosify Cloud.</p><h3>Installation</h3><p>ddosify is available via <a href="https://hub.docker.com/r/ddosify/ddosify">Docker</a>, <a href="https://hub.docker.com/extensions/ddosify/ddosify-docker-extension">Docker Extension</a>, <a href="https://github.com/ddosify/ddosify/tree/master/engine_docs#homebrew-tap-macos-and-linux">Homebrew Tap</a>, and downloadable pre-compiled binaries from the <a href="https://github.com/ddosify/ddosify/releases/latest">releases page</a> for macOS, Linux and Windows. For auto-completion, see: <a href="https://github.com/ddosify/ddosify/blob/master/completions/README.md">Ddosify Completions</a>.</p><p>Here I explain the setup with Docker, If Docker is not installed on your OS you should install it.</p><pre>docker run -it --rm ddosify/ddosify</pre><h4>Simple load test:</h4><blockquote>ddosify -t <a href="http://target_site.com/">http://target_site.com</a></blockquote><p>The above command runs a load test with the default value that is 100 requests in 10 seconds.</p><h4>Using some of the features:</h4><blockquote>ddosify -t <a href="http://target_site.com/">http://target_site.com</a> -n 1000 -d 20 -m PUT -T 7 -P <a href="http://proxy_server.com/">http://proxy_server.com:80</a></blockquote><blockquote>OR<br>ddosify -t <a href="http://target_site.com/">https://test.mom.ir</a> -n 100 -d 10</blockquote><p>Ddosify sends a total of <em>1000</em> <em>PUT</em> requests to <a href="https://target_site.com/"><em>https://target_site.com</em></a> over proxy <a href="http://proxy_server.com/"><em>http://proxy_server.com:80</em></a> in <em>20</em> seconds with a timeout of <em>7</em> seconds per request.</p><h3>Easy Start</h3><p>This section aims to show you how to use Ddosify without deep dive into its details easily.</p><h4>1.Simple load test</h4><blockquote>ddosify -t <a href="http://target_site.com/">http://target_site.com</a></blockquote><p>The above command runs a load test with the default value that is 100 requests in 10 seconds.</p><h4>2.Using some of the features:</h4><blockquote>ddosify -t <a href="http://target_site.com/">http://target_site.com</a> -n 1000 -d 20 -m PUT -T 7 -P <a href="http://proxy_server.com/">http://proxy_server.com:80</a></blockquote><p>Ddosify sends a total of <em>1000</em> <em>PUT</em> requests to <a href="https://target_site.com/"><em>https://target_site.com</em></a> over proxy <a href="http://proxy_server.com/"><em>http://proxy_server.com:80</em></a> in <em>20</em> seconds with a timeout of <em>7</em> seconds per request.</p><h4>3.Usage for CI/CD pipelines (JSON output):</h4><blockquote><em>ddosify -t http://target_site.com -o stdout-json | jq .avg_duration</em></blockquote><p>Ddosify outputs the result in JSON format. Then jq (or any other command-line JSON processor) fetches the avg_duration. The rest depends on your CI/CD flow logic.</p><h4>4.Scenario based load test:</h4><p>ddosify -config config_examples/config.json Ddosify first sends <em>HTTP/2 POST</em> request to <a href="https://test_site1.com/endpoint_1"><em>https://test_site1.com/endpoint_1</em></a> using basic auth credentials <em>test_user:12345</em> over proxy <a href="http://proxy_host.com:proxy_port"><em>http://proxy_host.com:proxy_port</em></a> and with a timeout of <em>3</em> seconds. Once the response is received, HTTPS GET request will be sent to <a href="https://test_site1.com/endpoint_2"><em>https://test_site1.com/endpoint_2</em></a> along with the payload included in <em>config_examples/payload.txt</em> file with a timeout of 2 seconds. This flow will be repeated <em>20</em> times in <em>5</em> seconds and response will be written to <em>stdout</em>.</p><h4>5.Load test with Dynamic Variables (Parameterization):</h4><blockquote><em>ddosify -t http://target_site.com/{{_randomInt}} -d 10 -n 100 -h &#39;User-Agent: {{_randomUserAgent}}&#39; -b &#39;{&quot;city&quot;: &quot;{{_randomCity}}&quot;}&#39;</em></blockquote><p>Ddosify sends a total of <em>100</em> <em>GET</em> requests to <a href="https://target_site.com/%7B%7B_randomInt%7D%7D"><em>https://target_site.com/{{_randomInt}}</em></a> in <em>10</em> seconds. {{_randomInt}} path generates random integers between 1 and 1000 in every request. Dynamic variables can be used in <em>URL</em>, <em>headers</em>, <em>payload (body)</em> and <em>basic authentication</em>. In this example, Ddosify generates a random user agent in the header and a random city in the body. The full list of the dynamic variables can be found in the <a href="https://docs.ddosify.com/extra/dynamic-variables-parameterization">docs</a>.</p><h4>6.Correlation (Captured Variables):</h4><blockquote><em>ddosify -config ddosify_config_correlation.json</em></blockquote><p>Ddosify allows you to specify variables at the global level and use them throughout the scenario, as well as extract variables from previous steps and inject them to the next steps in each iteration individually. You can inject those variables in requests <em>url</em>, <em>headers</em> and <em>payload(body)</em>. The example config can be found in <a href="https://github.com/ddosify/ddosify/tree/master/engine_docs#Correlation">correlation-config-example</a>.</p><h4>7.Test Data:</h4><blockquote><em>ddosify -config ddosify_data_csv.json</em></blockquote><p>Ddosify allows you to load test data from a file, tag specific columns for later use. You can inject those variables in requests <em>url</em>, <em>headers</em> and <em>payload(body)</em>. The example config can be found in <a href="https://github.com/ddosify/ddosify/tree/master/engine_docs#test-data-set">test-data-example</a>.</p><h3>Details</h3><p>You can configure your load test by the CLI options or a config file. Config file supports more features than the CLI. For example, you can’t create a scenario-based load test with CLI options.</p><p>CLI Flags</p><pre>ddosify [FLAG]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*qejdwnLh0Kpjlhy63dvg9w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e004c1b790aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use Sentry in Nuxt.JS]]></title>
            <link>https://hafez-heybati.medium.com/how-to-use-sentry-in-nuxt-js-389393e83e4d?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/389393e83e4d</guid>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[sentry]]></category>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 14:16:21 GMT</pubDate>
            <atom:updated>2023-06-07T14:16:21.084Z</atom:updated>
            <content:encoded><![CDATA[<p>You can start by running bellow command to install the required dependency.</p><blockquote>npm install <a href="http://twitter.com/sentry/vue">@sentry/vue</a><br>npm install <a href="http://twitter.com/nuxtjs/sentry">@nuxtjs/sentry</a><br>npm install <a href="http://twitter.com/sentry/profiling-node">@sentry/profiling-node</a></blockquote><p>In the next step you have to add the module in your nuxt.config.js like this:</p><blockquote>export default {<br> loading: { … , [‘<a href="http://twitter.com/nuxtjs/sentry">@nuxtjs/sentry</a>’ ],<br> sentry: {<br> dsn: ‘dsn’,<br> tracing: {<br> tracesSampleRate: 1.0,<br> },<br> serverIntegrations: {<br> ProfilingIntegration: {},<br> },<br> serverConfig: {<br> // Set sampling rate for profiling — this is relative to tracesSampleRate<br> profilesSampleRate: 1.0,<br> },</blockquote><blockquote>},</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=389393e83e4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Configure CentOS to Sync Time with NTP Time Servers]]></title>
            <link>https://hafez-heybati.medium.com/how-configure-centos-to-sync-time-with-ntp-time-servers-49d91dc7f65d?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/49d91dc7f65d</guid>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Wed, 22 Sep 2021 10:04:42 GMT</pubDate>
            <atom:updated>2021-09-22T10:04:42.967Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Scenario</h3><p>The system is not configured to use the ntpd service to synchronize time and date.</p><p>CentOS/RHEL 7 uses systemd to manage services. The timedatectl utility is distributed as part of the systemd, and allows you to review and change the configuration of the system clock: change the current date and time, set the time zone, or enable automatic synchronization of the system clock with a remote server.</p><p>The NTP service is enabled, but as this system is running CentOS/RHEL 7, timedatectl also needs to be configured to enable NTP, as it is used to manage the date and time on the system.</p><pre># timedatectl<br>...<br>NTP enabled: no<br>...</pre><p>This shows system is not using NTP.</p><h3>The Solution</h3><p>you can install it using <a href="http://woshub.com/yum-dnf-package-manager/">yum</a> in CentOS 7:</p><pre># yum install ntp -y</pre><p>Force NTP usage for time synchronisation:</p><pre># timedatectl set-ntp 1</pre><p>Then do the following:</p><p>1. Restart systemd time date control.</p><pre># systemctl restart systemd-timedated.service</pre><p>2. Start the ntp service</p><pre># systemctl start ntpd</pre><p>3. Sync the time with the remote server</p><pre># ntpq -p</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49d91dc7f65d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Query of changing data type in MongoDb]]></title>
            <link>https://hafez-heybati.medium.com/query-of-changing-data-type-in-mongodb-b54fc0c5fd2a?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b54fc0c5fd2a</guid>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Sat, 18 Sep 2021 06:36:26 GMT</pubDate>
            <atom:updated>2021-09-18T06:36:26.819Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>db.collection.find().forEach(function (doc1) {<br>db.collection.update({‘_id’ : doc1._id}, [ { $set: { “field” :String(doc1.field)} } ]);<br> });</strong></p><p><strong>db.collection.find().forEach(function (doc1) {<br>db.collection.update({‘_id’ : doc1._id}, [ { $set: { “field”:ObjectId(doc1.field)} } ]);<br> });</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b54fc0c5fd2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How use free vpn with vpnbook in ubuntu]]></title>
            <link>https://hafez-heybati.medium.com/how-use-free-vpn-with-vpnbook-in-ubuntu-3579097b6138?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3579097b6138</guid>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Sat, 27 Mar 2021 11:58:56 GMT</pubDate>
            <atom:updated>2021-03-27T11:58:56.365Z</atom:updated>
            <content:encoded><![CDATA[<p>you should use guide in <a href="https://www.vpnbook.com/">https://www.vpnbook.com</a></p><p>Also, do not forget to run the following command</p><pre>sudo apt-get install network-manager-openvpn-gnome</pre><p>And then use Settings &gt; Network &gt; Add VPN &gt; Import from file…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3579097b6138" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Upgrade (or Downgrade) Node.js Using npm]]></title>
            <link>https://hafez-heybati.medium.com/how-to-upgrade-or-downgrade-node-js-using-npm-630554b3ee14?source=rss-bd8725ae87c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/630554b3ee14</guid>
            <dc:creator><![CDATA[Hafez Heybati Goujani]]></dc:creator>
            <pubDate>Sat, 27 Mar 2021 07:38:04 GMT</pubDate>
            <atom:updated>2024-01-08T13:35:09.641Z</atom:updated>
            <content:encoded><![CDATA[<p>By Cory LaViska on May 29, 2019</p><p>Need to update your version of Node.js? Here’s how you can upgrade or downgrade from the command line using npm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eyLCUCLPZmkLPRde.png" /></figure><p>As you may know, Surreal CMS used to be a PHP app but last year <a href="https://www.surrealcms.com/blog/announcing-surreal-cms-7.html">I rebuilt it in Vue.js + Node.js</a>. Being able to switch between Node versions quickly was really helpful while developing, so here are my notes for managing which version is currently installed.</p><h4>Big news! 🎉</h4><p>I just made Surreal CMS <a href="https://www.surrealcms.com/blog/free-for-personal-educational-and-non-profit-use.html">free for personal, educational, and non-profit websites</a>. If you’re looking for a new way to manage your static website, check it out and <a href="https://twitter.com/claviska">let me know what you think</a>!</p><h3>Determining your Node version</h3><p>First off, let’s figure out which version of Node is currently installed.</p><pre>node -v</pre><p>The version number displayed is the one that’s currently active on your machine. Now, let’s install a program called <a href="https://www.npmjs.com/package/n">n</a> that will let us easily switch between Node versions.</p><pre>sudo npm install -g n</pre><h3>Upgrading to the latest stable version</h3><p>Once n is installed, this simple command will update you to the latest stable version of Node.</p><pre>sudo n stable</pre><h3>Changing to a specific version</h3><p>If you need a specific version, simply specify the version number you want like this.</p><pre>sudo n 10.16.0</pre><p><a href="https://nodejs.org/en/download/releases/">You can find a full list of releases here.</a></p><p>As you can see, n is a really handy program that makes switching between Node versions effortless. It’s worth keeping around if you do any serious development with Node.js.</p><p>Other way for upgrade or downgrade nodeJs is NVM:</p><h3>How to Install NVM on Linux and Mac</h3><p>Since Linux and Mac have some similarities (they are both UNIX-based OSes), you can install nvm on them in similar ways.</p><h3>1. Run the nvm installer</h3><p>In your terminal, run the nvm installer like this:</p><pre>curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash</pre><pre># or</pre><pre>wget -qO- <a href="https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh">https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh</a> | bash</pre><p>You can use curl or bash depending on the command available on your device.</p><p>These commands will clone the nvm repository to a ~/.nvm directory on your device.</p><h3>2. Update your profile configuration</h3><p>The installation process from step 1 should also automatically add the nvm configuration to your profile. If you’re using zsh, that would be ~/.zshrc. If you&#39;re using bash, that would be ~/.bash_profile...or some other profile.</p><p>If it doesn’t automatically add nvm configuration, you can add it yourself to your profile file:</p><pre>export NVM_DIR=&quot;$([ -z &quot;${XDG_CONFIG_HOME-}&quot; ] &amp;&amp; printf %s &quot;${HOME}/.nvm&quot; || printf %s &quot;${XDG_CONFIG_HOME}/nvm&quot;)&quot;<br>[ -s &quot;$NVM_DIR/nvm.sh&quot; ] &amp;&amp; \. &quot;$NVM_DIR/nvm.sh&quot;</pre><p>This command above loads nvm for use.</p><h3>3. Reload the shell configuration</h3><p>With your profile configuration updated, now you will reload the configuration for your terminal to use:</p><pre>source ~/.bashrc</pre><p>With this command executed, nvm is ready for you to use. You can confirm that nvm is installed correctly by running:</p><pre>nvm -v</pre><p>This should show the version of nvm installed.</p><h3>Wrapping up</h3><p>With nvm installed, you can now install, uninstall, and switch between different Node versions in your Windows, Linux, or Mac device.</p><p>You can install Node versions like this:</p><pre>nvm install latest</pre><p>This command will install the last version of Node:</p><pre>nvm install vX.Y.Z</pre><p>This will install the X.Y.Z Node version.</p><p>You can also make a version your default by running:</p><pre>nvm alias default vX.Y.Z</pre><p>And if you want to use a specific version at any point, you can run the following in your terminal:</p><pre>nvm use vA.B.C</pre><p>NVM makes it easier to manage multiple versions of Node.js across different projects that require different versions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=630554b3ee14" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>