<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ilya R</title>
    <description>The latest articles on Forem by Ilya R (@ilyary).</description>
    <link>https://forem.com/ilyary</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F866249%2Fc7b4db90-c60c-4033-acf9-e0bacd428e51.png</url>
      <title>Forem: Ilya R</title>
      <link>https://forem.com/ilyary</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ilyary"/>
    <language>en</language>
    <item>
      <title>When you need a message broker</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Mon, 19 Feb 2024 11:24:56 +0000</pubDate>
      <link>https://forem.com/ilyary/when-you-need-a-message-broker-51di</link>
      <guid>https://forem.com/ilyary/when-you-need-a-message-broker-51di</guid>
      <description>&lt;h2&gt;
  
  
  What is a message broker
&lt;/h2&gt;

&lt;p&gt;A message broker is a software that enables communication and message passing between different components or applications in a distributed system. It plays the role of an intermediary, handling the sending, routing, and delivery of messages from the sender to the recipient. A message broker is typically used in asynchronous communication models where the sender and receiver do not need to interact directly in real time.&lt;/p&gt;

&lt;p&gt;Some of the popular message brokers are Apache Kafka and RabbitMQ. They are widely used to process data streams and create streaming platforms. Message brokers play an important role in modern distributed systems by enabling reliable and scalable communication between components. &lt;/p&gt;

&lt;h2&gt;
  
  
  How do brokers work
&lt;/h2&gt;

&lt;p&gt;Message brokers are based on a publisher-subscriber model. In this model, the sender of a message, called the publisher, does not directly contact the recipient, called the subscriber. Instead, the publisher sends the message to the broker, which then routes the message to the appropriate subscribers. The message broker ensures reliable delivery of messages, manages queues, and handles delivery errors.&lt;/p&gt;

&lt;p&gt;When sending a message, the publisher specifies the topic or channel to which the message belongs. Subscribers who are interested in this topic are registered with the broker and expect to receive messages. The broker routes the message to appropriate subscribers based on their preferences and subscription filters.&lt;/p&gt;

&lt;p&gt;The message broker can also handle situations where subscribers are temporarily unavailable or unable to process a message. It can store messages in a queue and deliver them to subscribers when they are available again.&lt;/p&gt;

&lt;h2&gt;
  
  
  When is a broker needed in architecture
&lt;/h2&gt;

&lt;p&gt;A message broker is useful in the following cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When it is necessary to provide asynchronous communication between components or applications in a distributed system. It may be that a message from a queue can be processed by several services. And instead of sending a message or data to each service in turn, you can load the message into the broker’s queue, and the recipients who listen to this queue will themselves pick up the messages sent to them and process them.&lt;/li&gt;
&lt;li&gt;When you need to process large volumes of messages and ensure their delivery with high reliability. This reduces the load on services and allows you to be sure that the message or data will definitely reach the desired service. The sender service places messages in a queue, and the receiver service takes each such message from the queue, processes it, and then takes the next one.&lt;/li&gt;
&lt;li&gt;When the ability to scale and process data streams is needed.&lt;/li&gt;
&lt;li&gt;When the sender and recipient do not have to interact in real time, but can work independently of each other. Also, brokers allow you to ignore how a particular service works. The sender service only needs to know which queue to send messages to.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of Message Brokers
&lt;/h2&gt;

&lt;p&gt;Although message brokers provide many benefits, they also have some limitations and disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single point of failure: When a centralized message broker is used, there is a risk that if it fails, all communication between components will be disrupted. This can lead to data integrity problems and unavailability of services. In some cases, clustering or replication can be used to increase fault tolerance, but this adds complexity and cost.&lt;/li&gt;
&lt;li&gt;Message Latency: Using a message broker may result in increased message delivery latency. Since messages are routed through a broker, this may add some delay to the overall delivery time. For some applications that require instant data transfer, this may not be acceptable.&lt;/li&gt;
&lt;li&gt;Management Complexity: Managing and configuring a message broker can be challenging. This includes queue management, message routing, error handling, and scaling. A sufficient understanding of the broker's architecture and configuration is required to use it effectively.&lt;/li&gt;
&lt;li&gt;Difficulty in Debugging: When messaging problems occur, debugging can be difficult. Due to the intermediary role of the broker and the interaction between various components, identifying and resolving errors may require additional effort and resources.&lt;/li&gt;
&lt;li&gt;Added Security Complexity: Using a message broker adds complexity in securing data transfers. It is necessary to ensure secure connections, access control and encryption of messages to protect against unauthorized access and information leakage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, I would like to note that message brokers provide a reliable and flexible mechanism for exchanging messages between components in distributed systems. However, brokers also have disadvantages and these disadvantages must be taken into account when developing and implementing a system using message brokers.&lt;/p&gt;

</description>
      <category>api</category>
      <category>architecture</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Lifecycle of Webpage (HTML)</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Tue, 09 Jan 2024 11:49:58 +0000</pubDate>
      <link>https://forem.com/ilyary/life-cycle-of-webpage-html-g09</link>
      <guid>https://forem.com/ilyary/life-cycle-of-webpage-html-g09</guid>
      <description>&lt;p&gt;Loading and rendering of HTML document in a browser has several stages. In this article we will only look a process of rendering and loading HTML document in a browser and how we can work with it in JS. But here we will not describe the process of receiving an HTML document and additional files from the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stages&lt;/strong&gt; of rendering and loading HTML document:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A DOM tree is formed from the loaded HTML document.&lt;/li&gt;
&lt;li&gt;Styles are loaded and recognized, CSS Object Model is generated&lt;/li&gt;
&lt;li&gt;Forming of The Rendering Tree. &lt;strong&gt;Render Tree&lt;/strong&gt; - duplicates the DOM, but without invisible elements. Describes the visual representation of the DOM.&lt;/li&gt;
&lt;li&gt;Calculation of positions on pages for elements (&lt;strong&gt;Layout&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Rendering colors of elements (&lt;strong&gt;Paint&lt;/strong&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Render Tree&lt;/strong&gt; created from DOM and CSS Object Model. The Render Tree is necessary to determine exactly what needs to draw and in what order. The construction of a Render Tree goes something like this: the parser start from the root element and goes through all visible elements. For each visible element the parser finds the corresponding CSS rule from the CSS Object Model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layout&lt;/strong&gt; is a recursive process of determining the position and size of elements from the Render Tree. It starts from the root Render Object and goes recursively down the entire tree hierarchy, calculating the geometric dimensions of the child render objects.&lt;/p&gt;

&lt;p&gt;The root element has position (0,0) and its dimensions are equal to the size of the viewport.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Paint&lt;/strong&gt; is the stage where the monitor pixels are filled with the color specified in the properties of the render object.&lt;/p&gt;

&lt;p&gt;And now let look how we can work with this process in JS.&lt;/p&gt;

&lt;p&gt;In JS the life cycle of an HTML page has three important &lt;strong&gt;events&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DOMContentLoaded&lt;/li&gt;
&lt;li&gt;load&lt;/li&gt;
&lt;li&gt;beforeunload/unload&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;DOMContentLoaded&lt;/strong&gt; - The HTML has been fully loaded by the browser and the DOM tree has been built. But resources such as images and styles may not be loaded yet. At this stage, you can work with the DOM tree, but there is no way to work with images yet. You can trigger a specific event at this stage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.addEventListener('DOMContentLoaded', myCallback);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;load&lt;/strong&gt; - the browser has completely loaded the page with all its resources. At this stage, you can freely work with all elements of the DOM tree and page resources, such as images, styles, and so on.&lt;/p&gt;

&lt;p&gt;To be sure that the page is completely ready, you can use the following handler.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.onload = function() {...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;beforeunload/unload&lt;/strong&gt; - the user leaves the page. When a visitor leaves the page, an unload event is fired on the window object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.addEventListener('unload', myCallback);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is another way to check the loading status of a document. The &lt;code&gt;document.readyState&lt;/code&gt; property shows us the current loading state.&lt;/p&gt;

&lt;p&gt;There are three possible values:&lt;br&gt;
&lt;code&gt;"loading"&lt;/code&gt; – the document is being loaded.&lt;br&gt;
&lt;code&gt;"interactive"&lt;/code&gt; – the document has been completely read.&lt;br&gt;
&lt;code&gt;"complete"&lt;/code&gt; – The document has been completely read and all resources (such as images) have also been downloaded.&lt;/p&gt;

&lt;p&gt;You can also set a handler to change the document loading state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.addEventListener('readystatechange', myCallback);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, it is possible to check the status of the connection to the network.&lt;/p&gt;

&lt;p&gt;An event is generated when page disconnect from the network. When page connect to the network, an event is also generated. We can subscribe to this events:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.addEventListener('offline', myCallback);
window.addEventListener('online', myCallback);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python3 Abbreviations</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Thu, 19 Oct 2023 11:52:20 +0000</pubDate>
      <link>https://forem.com/ilyary/python3-abbreviations-5c7g</link>
      <guid>https://forem.com/ilyary/python3-abbreviations-5c7g</guid>
      <description>&lt;p&gt;Python3 is a very flexible language. It has a lot of different features that make it easier to work with lists and dictionaries. Today I propose to consider a couple of techniques on how to reduce the amount of code when working with lists and dictionaries&lt;/p&gt;

&lt;p&gt;It often happens that we need to iterate through a list and, at the same time, changing and processing each element, get a new list with processed elements.&lt;/p&gt;

&lt;p&gt;Let's assume we have a list of integers. And we need to go through it and square each element.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nums = [1, 2, 3]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The simplest way to do this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for num in nums:
    squares.`append`(num**2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we can reduce this code to one line:&lt;br&gt;
&lt;code&gt;squares= [ num ** 2 for num in nums]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In such abbreviations we can use conditional statements.&lt;/p&gt;

&lt;p&gt;For example, let's take a list of cars. We are interested in all cars starting with the letter M.&lt;br&gt;
&lt;code&gt;cars = [”Toyota”, “Mitsubishi”, “Honda”, “Mazda”]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We could also write a loop as in the previous example and in the body of the loop check through ‘if’ statment the capital letter in the name of the car. But we can fit everything into one line.&lt;br&gt;
&lt;code&gt;starts = [car for car in cars if car.startsWith(”M”)]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's see how we can work with a dictionary using the same method.&lt;/p&gt;

&lt;p&gt;Let's assume we have a dictionary of integers.&lt;br&gt;
&lt;code&gt;nums = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And here we also need to square each number. Again, we could write a loop and do certain things inside the body of the loop, but we can fit everything into one line.&lt;br&gt;
&lt;code&gt;squares= {k:v**2 for (k,v) in nums.items()}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Thus, we can significantly reduce the amount of code and make it more readable. And the less code we have, the less likely it is that we will make a mistake somewhere.&lt;/p&gt;

</description>
      <category>python</category>
      <category>list</category>
      <category>development</category>
    </item>
    <item>
      <title>Stack and queue. Difference</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Fri, 18 Aug 2023 08:00:35 +0000</pubDate>
      <link>https://forem.com/ilyary/stack-and-queue-difference-5f1o</link>
      <guid>https://forem.com/ilyary/stack-and-queue-difference-5f1o</guid>
      <description>&lt;p&gt;Ideas of stack and queue you can find in different program languages. Let's find out what differences between stack and queue and how they can be help us.&lt;/p&gt;

&lt;p&gt;We have deal with queus everywhere. In shops - it is a group of people which stay one after another to the cashier in the store. The one who stand closer to cashier will pay for products first.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88mezjkofyhq3lxj0v2s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F88mezjkofyhq3lxj0v2s.png" alt="Image description" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In programming, a queue works similarly. A queue in programming is a collection of elements that are processed on “a first in, first out” (FIFO) basis. It is better to use queu for tasks which should be done in stages. For example, when user loads several images to site, after server needs to process all images. All that images put to queue for processing. And the first file that the user has uploaded will be the first one processed on the server.&lt;/p&gt;

&lt;p&gt;The stack works differently. A stack is also a collection of elements, but it works on a "last in, first out" (LIFO) basis. In everyday life, we can come across an analogy when we put documents on top of each other, and then iterate over them, starting from the top one. It's like working with a stack: you can work only with the last element that got into the collection.&lt;/p&gt;

&lt;p&gt;Frequent use of the stack in programming it is organising logs of changes in file or document. Text editors often record user’s changes in file to the stack. And after it is easily in reverse mode undo changes which user did in file.&lt;/p&gt;

&lt;p&gt;When you work with stack or queue you cant access an arbitrary element in collection. Becouse it would violate the principles LIFO and FIFO. If you need to get neccessery element, you need itarate all element before it.&lt;/p&gt;

&lt;p&gt;In programming, the stack and queue are often used for various complex mathematical calculations, data manipulation and operations. The principles of FIFO and LIFO allow us to structure and organize our work with data. This allows you to be sure that data and operations will be processed in the right order.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>computerscience</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>JSON in Python3</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Tue, 01 Aug 2023 07:26:28 +0000</pubDate>
      <link>https://forem.com/ilyary/json-in-python3-1hci</link>
      <guid>https://forem.com/ilyary/json-in-python3-1hci</guid>
      <description>&lt;p&gt;JSON (JavaScript Object Notation) is a text-based data exchange between different services.&lt;/p&gt;

&lt;p&gt;In Python 3, as in many other programming languages, the JSON format is widely used in web development for messaging between a client and a server or various microservices. Also, it is not rare that system settings are stored in JSON format, which are placed in special files with the .json extension. In Python 3, a JSON object is obtained from a dictionary. Typically, a dictionary is serialized, i.e. cast to a JSON string. And such a string is sent, for example, in an HTTP request to a remote server, to a client, or to another microservice. Python 3 has built-in tools for working with the JSON format, which will be described later in the text. When you need to send several dictionaries (JSON objects) to the same remote server or microservice, the dictionaries are placed in a list and this list is also converted using Python 3 to a JSON string.&lt;/p&gt;

&lt;p&gt;Let's take a little look at the history of the creation of the JSON format and what it was created for. The development of the JSON format began in 2001 by Chip Moningstar and Douglas Crockford. Douglas and Chip were looking for a way to transfer information between a browser and a server more efficiently than XML. It needed a way to exchange data between programs written in two different languages. The model for working with XML is that a request is first sent to the server, which responds with an XML document. And then, in order to get the data, additional requests were made to the previously received XML document. It's been long enough. A more easy-to-use messaging (data) exchange format was needed.&lt;/p&gt;

&lt;p&gt;As a result, the JSON data transfer format was created, which makes it easier to “communicate” between different programs. The format was developed based on the JavaScript language, but in the future this format received complete independence from JavaScript and can be used by almost any programming language.&lt;/p&gt;

&lt;p&gt;Initially, the JSON format was intended solely for exchanging data over the network between programs written in different languages. There were a number of difficulties in developing the format. For example, the creators of the format have been trying for a long time to develop a standard for comments in JSON. As a result, they decided to drop it. Comments in JSON are always ignored. But, the creators of the format managed to make JSON able to provide data exchange between languages with different representations of numbers. Different programming languages may have different representations of numbers. For example, in JavaScript there is no difference between floating point numbers or integers. At the same time, in Python 3, floats and integers are different data types. But with the JSON format you don't have to worry about that. You do not need to think in what language this or that microservice with which you want to work is written. All you need to do is create a dictionary, convert it to a JSON string using the built-in tools, and send this string as a request to the microservice you need.&lt;/p&gt;

&lt;p&gt;Today, the JSON format does not have a trademark, logo, or copyright. This format is absolutely free and you can freely use it in any projects.&lt;/p&gt;

&lt;p&gt;Also, the JSON format does not have any version. This was done so that there would be a single data transfer format.&lt;/p&gt;

&lt;p&gt;The structure of JSON objects is quite simple. Such an object is an unordered set of type "key: value". The object itself is enclosed in curly braces. Keys are specified in double quotes. In a JSON object, all strings must be enclosed in double quotes, but not numbers. The key must always be a string. The key:value pairs are separated by commas.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value may be not only a string or a number, but it can also be another JSON object or an array of such objects. Nesting is not limited to any limit. Inside the array can be all valid values in JSON format. JSON has its own MIME type, application/json.&lt;/p&gt;

&lt;p&gt;Types of values in JSON:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;number&lt;/li&gt;
&lt;li&gt;JSON object (not to be confused with objects in Python 3)&lt;/li&gt;
&lt;li&gt;array&lt;/li&gt;
&lt;li&gt;boolean value&lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is not uncommon when more then one JSON object need to be passed at once in a list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    {
      "userId": 1,
      "id": 1,
      "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
      "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
    },
    {
      "userId": 2,
      "id": 3,
      "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
      "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
    }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see how we can work with JSON format in Python 3.&lt;/p&gt;

&lt;p&gt;A JSON object in Python 3 is a dictionary (dict). To send such a dictionary or list of dictionaries from one service to another service or to a remote server, you must first convert the dictionary or list to a valid JSON string. In Python 3, this can be done through the built-in json library. The “dumps” method creates a string from a dictionary or list. And with the help of the “loads” method, the reverse transformation occurs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# First we include the json library in our file
import json

# Next, we convert the dictionary to a JSON string using the "dumps" method
# A dictionary is passed to the "dumps" method, which will be converted to a JSON string
data = json.dumps({"c": 0, "b": 0, "a": 0})

# And here it is shown how to translate JSON string back into a dictionary
# A JSON string is passed to the "loads" method, which will be converted to a dictionary
dict_from_json = json.loads(data) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And after transformation list or dict to JSON string you can send that string to remote server, another service or module through HTTP query.&lt;/p&gt;

&lt;p&gt;Also JSON data can be in special files with .json extension. Commonly in that are stored system configuration of application.  It's comfortable to use because JSON has standard structure and it is easy to transform or read by Python’s methods.&lt;/p&gt;

&lt;p&gt;In such files can not only JSON objects, but also there can be a list of JSON objects. Python3 allow as work with such files - read and write. Note that for read data from file you need to use “load” method, but to transform JSON string to dict or list you need to use methods “loads”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Connecting json library
import json

# With "open" function we can open file and put it to descriptor f
f = open('data.json')

# Using the "load" method of the "json" library, we will convert the data from the file into a dictionary
data = json.load(f)
print(data)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see from the code example, the “load” method from the json library is used to convert a JSON object into a dictionary. First, the json file is opened, and then the data is converted.&lt;/p&gt;

&lt;p&gt;And thus, we can work with the data from the JSON file as with a normal dictionary.&lt;/p&gt;

&lt;p&gt;Let's take a look at how this works in practice. For practice we need to get data from a remote server. For this we will use the free JSONPlaceholder API. This API allows us to get fake data in JSON format for learning how to work with the format or for some other non-commercial purposes. You can find documentation on working with this API on their website &lt;a href="https://jsonplaceholder.typicode.com" rel="noopener noreferrer"&gt;https://jsonplaceholder.typicode.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we want to get data from the API, we need to make a POST request to the URL &lt;a href="https://jsonplaceholder.typicode.com/posts" rel="noopener noreferrer"&gt;https://jsonplaceholder.typicode.com/posts&lt;/a&gt; . We will do it using the Requests library. The Requests library allows us to easily make HTTP requests and process the received responses. First, let's install this library into the project:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install requests&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to connect the library and execute the request using the Post method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Connecting "requests" and "json" libraries
import requests
import json

# Using the get method of the requests library, we make an HTTP request
# to remote server for fetching data
# Documentation shows that the data is transmitted in JSON format
# We put the response from the server in the "res" variable 
res = requests.get('https://jsonplaceholder.typicode.com/posts/1')

# After through the "text" method we get a JSON string from the server response
text = res.text

# To convert a JSON string into a list with which we can already work,
# we need to use the "loads" method of the "json" library
print(json.loads(text))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus, we receive data from a remote server as a JSON string, translate this string into a Python 3 list, and after that we can work with data from the server as with a regular list.&lt;/p&gt;

&lt;p&gt;From this article, we learned what the JSON format is, why it was created, in what areas it is used, and also told how it can be used in Python 3.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>json</category>
      <category>beginners</category>
    </item>
    <item>
      <title>List in Python3 for beginners</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Thu, 06 Apr 2023 16:10:32 +0000</pubDate>
      <link>https://forem.com/ilyary/list-in-python3-for-beginners-29cl</link>
      <guid>https://forem.com/ilyary/list-in-python3-for-beginners-29cl</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. Briefly about lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A list is an ordered collection of different types of data. &lt;/p&gt;

&lt;p&gt;The data in a Python list can be of any type. For example, the list in Python can contain both integer data and string values. &lt;/p&gt;

&lt;p&gt;The elements in the list are in order, and their position is determined by the index. The index of the first position in the list is 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create lists
list = [1, 2, 3, 4, 7, 9]
list2 = [1, ‘str’, True, [1, 2]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Basic work with elements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Python allows you to access any element in a list and set the value of the elements using &lt;u&gt;square brackets&lt;/u&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Get a value from list
number = list[1]

# Set value
list[0] = 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Slicing in Python Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Slice notation in Python lists are some of the elements in the list that start and end at specific positions. Slice allows you to specify which element to start and finish extracting data from the list. This will return a new list of retrieved items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list[start, stop, step]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;start&lt;/strong&gt; – index of the element from which the extraction starts, by default it is 0;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;stop&lt;/strong&gt; - index of the end element. If not specified, then the slice is taken up to the last element;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;step&lt;/strong&gt; - sampling step. A negative value allows elements to be retrieved in reverse order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list[2:4] -&amp;gt; [3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. How to find out if there is an element in the list: the &lt;u&gt;in&lt;/u&gt; operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;in&lt;/strong&gt; operator in Python allows you to check if the element you are looking for is in a list. This operator iterates through the list, iterating over each element. If the list is large, then this can take a long time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = [1, 2, 3, 4, 7, 9]

7 in list # True
23 in list # False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Combining lists. Concatenation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lists in Python can be easily connected to each other using an extension method or simply adding a list using the '+' operator&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Using extend method
list.extend([45, 56, 67])

# Concatenation 
list3 = list + list2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Add an element to the list.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Python also provides list methods for adding new elements to a list. They are append and insert.&lt;/p&gt;

&lt;p&gt;The append method adds a new element to the end of the list. This new element is passed as an argument to the append method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list.append(67)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The type of the passed element can be anything. The method itself returns None. The list will be automatically enlarged by adding a new element. Unlike other programming languages, Python does this for us. &lt;/p&gt;

&lt;p&gt;Python also has an insert method that inserts a new element into a list at a given index position. The index is passed as the first argument to the insert method, and the new element is passed as the second argument. The main thing to remember is that the positions of elements in the list start from 0, and the type of the passed element can be anything. The index type must be integer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list.insert(4, 56)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both of this methods modify the list on which they are called and do not return anything. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Removing elements from a list using Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Python has a method for removing an element from a list by its value, not by index. This is the &lt;u&gt;remove&lt;/u&gt; method. This method accepts an argument that must match the value to be removed.&lt;/p&gt;

&lt;p&gt;For example, we have a list &lt;u&gt;numbers = [1, 2, 5, 6]&lt;/u&gt;. And we want to remove the number 5 from this list. We can use the remove method: &lt;u&gt;numbers.remove(5)&lt;/u&gt; . Now the number 5 will be missing from the list, because the remove method removed this element by its value. &lt;/p&gt;

&lt;p&gt;If you pass a non-existent value in the list to the argument, then a ValueError exception will be raised. &lt;/p&gt;

&lt;p&gt;This method returns None and modifies the list it was called on. &lt;/p&gt;

&lt;p&gt;Python has another method to remove elements. This is the &lt;u&gt;pop&lt;/u&gt; method. This method takes an optional one argument and is the index of the element to be removed. The &lt;u&gt;pop&lt;/u&gt; method returns the element to be removed. If you do not pass the index of the element to be removed, then this method removes the last element in the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Remove element at position 1
list.pop(1)
# Removing the last element
list.pop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;u&gt;pop&lt;/u&gt; and &lt;u&gt;remove&lt;/u&gt; methods modify the list they were called on.&lt;/p&gt;

&lt;p&gt;In conclusion, I would like to note that all the necessary operations with lists are already built into Python, which cover most of the cases in work, which makes working with lists very convenient.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>NestJS: Work with configuration</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Wed, 10 Aug 2022 07:38:00 +0000</pubDate>
      <link>https://forem.com/ilyary/nestjs-work-with-configuration-5fd6</link>
      <guid>https://forem.com/ilyary/nestjs-work-with-configuration-5fd6</guid>
      <description>&lt;p&gt;Application configuration is often understood as setting a particular state of application. The simplest example is running an application in development or production mode. For example, in development mode, we need the application to show us the maximum information about errors. But when we run the application in production, it is not the best idea to show such information to ordinary users.&lt;/p&gt;

&lt;p&gt;Also, the configuration means set up of credentials for working with the database and third-party services.&lt;/p&gt;

&lt;p&gt;We can keep such data in different files in different places of the application, but it will be hard to maintain in future. For example, when the login or password from the database are changed, we would need to change all that stuff in all files. &lt;/p&gt;

&lt;p&gt;Therefore, it is better to keep all configurations in one file or in one directory. But, you should also remember about security and avoid getting these files into the repo. Even if the repository is private.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using &lt;u&gt;.env&lt;/u&gt; files.&lt;/strong&gt;&lt;br&gt;
We can store configuration data in .js or .ts files. And exclude these files via &lt;u&gt;.gitignore&lt;/u&gt; from the repository. But usually environment variables are used for such cases. For this, &lt;u&gt;.env&lt;/u&gt; file is created in the root of the project and all the configuration data is written there in the "key = value" format.&lt;/p&gt;

&lt;p&gt;It will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PORT=3000
MONGO_ROOT_NAME=root
MONGO_ROOT_PWD=example
APP_NAME=Supershop
MONGO_URL=mongodb://user1:example@mongo:27017/dbname
SALT=43fdf6132sda8b94846d1a531d6fdffd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in order to protect the data from getting into the repository, we will write exceptions in &lt;u&gt;.gitignore&lt;/u&gt;, and also create a file with name &lt;u&gt;.env.example&lt;/u&gt; . It will be stored in the repository. Such a file will contain the required fields, but without values. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PORT=
MONGO_ROOT_NAME=
MONGO_ROOT_PWD=
APP_NAME=
MONGO_URL=
SALT=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file need to understand which env variables are used in application. After you clone project from repo, you will need just rename file to &lt;u&gt;.env&lt;/u&gt; and fill all fields.&lt;/p&gt;

&lt;p&gt;Next, we can use anywhere in our application the environment variables taken from this file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use configuration in NestJS.&lt;/strong&gt;&lt;br&gt;
NestJS has its own ways of working with &lt;u&gt;.env&lt;/u&gt; files. Lets take a look how we can use env variables in NestJS app.&lt;/p&gt;

&lt;p&gt;For this we need to install &lt;u&gt;@nestjs/config&lt;/u&gt; in our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @nestjs/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, in the Module's import field add &lt;u&gt;ConfigModule.forRoot()&lt;/u&gt; so that access to environment variables is available globally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.module.ts
import { ConfigModule } from '@nestjs/config';

// Other code

@Module({
  imports: [
    ConfigModule.forRoot(),
    // Another imports
  ],
  controllers: [AppController],
  providers: [AppService],
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;u&gt;controller&lt;/u&gt; constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ConfigService } from '@nestjs/config';

@Controller()
export class AppController {
  constructor(private readonly configService: ConfigService) {}

  // Other code....
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the same way, you can use &lt;u&gt;configService&lt;/u&gt; in other parts of the application.&lt;/p&gt;

&lt;p&gt;This is how basic configuration work looks like in a NestJS application.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>nestjs</category>
      <category>beginners</category>
    </item>
    <item>
      <title>NestJS - Middleware</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Tue, 28 Jun 2022 10:56:49 +0000</pubDate>
      <link>https://forem.com/ilyary/nestjs-middleware-18ki</link>
      <guid>https://forem.com/ilyary/nestjs-middleware-18ki</guid>
      <description>&lt;p&gt;On the back-end, tasks are often set to check something before processing the request from the client or to add any fields before the response will be sent to the client. Middleware help us with this.&lt;/p&gt;




&lt;p&gt;A Middleware is a function that is called before a route handler. Also, the Middleware can be called after the response is generated. Middlewares have access to the request and response objects. This function, as it were, intercepts the request/response and performs certain actions with it.&lt;/p&gt;

&lt;p&gt;By default, NestJS middleware is similar to ExpressJS middleware.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Middleware functions can perform the following tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;execute any code.&lt;/li&gt;
&lt;li&gt;make changes to the request and the response objects.&lt;/li&gt;
&lt;li&gt;end the request-response cycle.&lt;/li&gt;
&lt;li&gt;call the next middleware function in the stack.&lt;/li&gt;
&lt;li&gt;if the current middleware function does not end the request-response cycle, it must call next() to pass control to the next middleware function. Otherwise, the request will be left hanging.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Custom proxies in NestJS are just a class wrapped in an @Injectable decorator. But, in this class, it is necessary to implement the NestMiddleware interface. There are no such requirements for functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

@Injectable()
export class SimpleMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    // Your code...
    // Then call next function.
    next();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Middleware are registered in the configure method of the Module class. Modules that include Middleware must implement the NestModule interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { SimpleMiddleware } from './middleware/simple.middleware';
import { ProductsModule } from './cats/cats.module';

@Module({
  imports: [ProductsModule],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(SimpleMiddleware)
      .forRoutes('products');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how we can use our Middleware for specific routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;configure(consumer: MiddlewareConsumer) {
  consumer
    .apply(SimpleMiddleware)
    .forRoutes({ path: 'products', method: RequestMethod.GET });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;The MiddlewareConsumer is a helper class. It provides several built-in methods to manage middleware. All of them can be simply chained in the fluent style. The forRoutes() method can take a single string, multiple strings, a RouteInfo object, a controller class and even multiple controller classes. In most cases you'll probably just pass a list of controllers separated by commas.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With the exclude method, we can exclude the roots that should not be applied to the Middleware&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;configure(consumer: MiddlewareConsumer) {
  consumer
    .apply(SimpleMiddleware)
    .exclude(
      { path: 'products', method: RequestMethod.POST }
    )
    .forRoutes(ProductsController);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Sometimes we need to call multiple Middleware on specific routes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In order to bind multiple middleware that are executed sequentially, simply provide a comma separated list inside the apply() method:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;consumer.apply(cors(), helmet(), logger).forRoutes(ProductsController);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;I would also like to say about the possibility of using global Middlewares. To register them, we use the use method on the application instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const app = await NestFactory.create(AppModule);
// Some code
app.use(logger);
// Some code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;We usually use Middlewares to check the Api key, check the type of content in request, the presence of certain fields in the headers, user rights, etc.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>nestjs</category>
      <category>node</category>
    </item>
    <item>
      <title>Linux: systemD (overview + basic management)</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Thu, 16 Jun 2022 07:31:21 +0000</pubDate>
      <link>https://forem.com/ilyary/linux-systemd-overview-basic-management-2ipl</link>
      <guid>https://forem.com/ilyary/linux-systemd-overview-basic-management-2ipl</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;systemd is the system of initialization in many modern distributions based on the Linux kernel. It was developed by Red Hat Corporation in 2010. This system at one time replaced the init subsystem.&lt;/p&gt;

&lt;p&gt;systemd is built around the concept of modules (units) . Each module has a name, a type, and manages certain services.&lt;/p&gt;

&lt;p&gt;The main advantage of this system is the parallelism during boot process. It allows you to significantly speed up the launch of the entire operating system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpc6a3j8k949kd9adfe45.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpc6a3j8k949kd9adfe45.png" alt="Image description" width="800" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;systemd can control per-process execution environment, resource limit, working directory, root directory, ID, user, group, and more. Basically systemd is the parent of all processes and it controls the whole system.&lt;/p&gt;

&lt;p&gt;Although systemd allows you to load services faster and speed up the operation of the OS as a whole, it has a number of arguments against using this initialization system.&lt;/p&gt;

&lt;p&gt;The fact that this init system is responsible for such a large number of different tasks and processes, and also has huge powers in the system, has led many developers and system administrators to speak out strongly against this daemon, refusing to use it in favor of classical solutions.&lt;/p&gt;

&lt;p&gt;Linus Torvalds and Richard Stallman have also raised doubts against systemd.&lt;/p&gt;




&lt;h2&gt;
  
  
  Basic management
&lt;/h2&gt;

&lt;p&gt;For now in many Linux distributions, all services are currently managed by the init system - systemd.&lt;/p&gt;

&lt;p&gt;systemd have special tool which allow you to control services - &lt;strong&gt;systemctl&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Syntax of that tool:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl options command service&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Let consider the most commonly used commands:&lt;br&gt;
&lt;u&gt;start&lt;/u&gt; - start service&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl start apache&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;stop&lt;/u&gt; - stop service&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl stop apache&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;status&lt;/u&gt; - show service's status&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl status apache&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;enable&lt;/u&gt; - add service to autoload&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl enable apache&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;disable&lt;/u&gt; - delete service from autoload&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl disable apache&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;list-units&lt;/u&gt; - show all services&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl list-units --type service&lt;br&gt;
systemctl list-units --type service --state running&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;u&gt;kill&lt;/u&gt; - send a termination signal to a process is used in conjunction with options --signal and --kill-who&lt;/p&gt;

&lt;p&gt;&lt;u&gt;restart&lt;/u&gt; - restart service&lt;/p&gt;

&lt;p&gt;&lt;u&gt;try-restart&lt;/u&gt; - restart service if service was started&lt;/p&gt;

</description>
      <category>linux</category>
      <category>beginners</category>
      <category>systemd</category>
    </item>
    <item>
      <title>NestJS - Providers</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Sat, 11 Jun 2022 13:09:17 +0000</pubDate>
      <link>https://forem.com/ilyary/nestjs-providers-1oia</link>
      <guid>https://forem.com/ilyary/nestjs-providers-1oia</guid>
      <description>&lt;p&gt;In the &lt;strong&gt;MVP&lt;/strong&gt; in additional &lt;strong&gt;View&lt;/strong&gt; and &lt;strong&gt;Controller&lt;/strong&gt;, there are also &lt;strong&gt;Model&lt;/strong&gt;. &lt;strong&gt;Model&lt;/strong&gt; contain main and additional logic, and also contain logic for working with DB and third-party APIs. In NestJS, this function is assigned to &lt;strong&gt;Providers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Providers&lt;/strong&gt; in NestJS are registered in Modules they belong to. And also can be exported from the Module to be available in other parts of the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Module } from '@nestjs/common';

import { ProductsService } from './products.service';
import { ProductsController } from './products.controller';

@Module({
  controllers: [ProductsController],
  providers: [ProductsService],
})
export class ProductsModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One of the features of a provider is that the provider is injected, for example, into the controller's constructor for further application work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Controller, Get } from '@nestjs/common';

import { ProductsService } from './products.service';

@Controller('products')
export class ProductController {
  constructor(private productsService: ProductsService) {}

  @Get()
  getAllProducts(): Product[] {
    // Code...
    return this.productsService.getAll();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Providers are ES6 classes wrapped with the @Injectable() decorator, which is imported from '@nestjs/common'.&lt;/p&gt;

&lt;p&gt;The provider can be created using the CLI command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nest g service products&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';

import { Product } from './interfaces/product.interface';

@Injectable()
export class ProductsService {
  private readonly products: Product[] = [];

  getAll(): Product[] {
    // Some code...
    return this.products;
  }

  create(product: Product) {
    // Your Code...
  }

  update(id: number) {
     // Some code...
  }

  // Other methods...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus, the &lt;strong&gt;Module&lt;/strong&gt; is a separate part of the application with isolated logic. &lt;strong&gt;Controller&lt;/strong&gt; - the entry point to this Module, which is called when a request is received for a specific URL and calls the methods of the Provider. And the &lt;strong&gt;Provider&lt;/strong&gt; contains all the main and additional business logic necessary for the application to function.&lt;/p&gt;

&lt;p&gt;Thanks for your attention!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What new in ReactJS 18</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Thu, 09 Jun 2022 11:21:20 +0000</pubDate>
      <link>https://forem.com/ilyary/what-new-in-reactjs-18-1e54</link>
      <guid>https://forem.com/ilyary/what-new-in-reactjs-18-1e54</guid>
      <description>&lt;p&gt;ReactJS 18 became available March 29. There are a bunch of new features are come in new version of ReactJS. &lt;/p&gt;

&lt;p&gt;Many of this features are about improving performance and concurrency in ReactJS. About concurrency you can read this &lt;a href="https://github.com/reactwg/react-18/discussions/46#discussioncomment-846786" rel="noopener noreferrer"&gt;article&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Automatic batching
&lt;/h2&gt;

&lt;p&gt;Automatic batching for asynchronius functions. Batching it is when React groups multiple state updates into one re-render to improve performance. Without automatic batching we batch only updates within event handlers in React.&lt;/p&gt;
&lt;h2&gt;
  
  
  Strict Mode
&lt;/h2&gt;

&lt;p&gt;Also Strict Mode was updated . Now Strict Mode will show us in console warnings when we use depricated methods.&lt;/p&gt;
&lt;h2&gt;
  
  
  Suspense
&lt;/h2&gt;

&lt;p&gt;Update of Suspense component - now we can use this component with SSR. &lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  New hooks
&lt;/h2&gt;

&lt;p&gt;There are also new hooks in ReactJS 18.&lt;/p&gt;

&lt;p&gt;Hooks became available in ReactJS 16.8. They give us a ability of using state and other functionality of classe's components in functional components. There are some new hooks are come to us in ReactJS 18.&lt;/p&gt;
&lt;h3&gt;
  
  
  useTransition
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Returns a stateful value for the pending state of the transition, and a function to start it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The hook allows us to improve the performance of the application by wrapping the logic with a special function. In such function you can place a logic, which may get a lot of time. For example request to server.&lt;/p&gt;

&lt;p&gt;To work with this hook, we import useTransition from "react".&lt;/p&gt;

&lt;p&gt;useTarnsition returns two variables. First variable is a boolean variable. Second variable is a function which will start transition. This function, startTransition, we can import from "react", but it is not recomended to use method from "react" in functional components. It is better get this function from hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [isPending, startTransition] = useTransition();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function takes as an argument a callback function that is immediately called. While this callback function is running and before it completes, the boolean variablebecomes true. After all the logic inside the startTransition function is complete, the boolean variablebecomes false. And we can use this boolean variable in UI to show that something is going on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;startTransition(() =&amp;gt; {
  // Some functions
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This hook can significantly improve the UX of the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  useDeferredValue
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;useDeferredValue accepts a value and returns a new copy of the value that will defer to more urgent updates. If the current render is the result of an urgent update, like user input, React will return the previous value and then render the new value after the urgent render has completed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The hook takes an argument - data that needs to be cached now and updated only when all other changes have passed. Thus, the hook caches values that may not update urgently, and updates this value when more urgent changes pass. Like delayed rendering of certain values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const deferredPosts = useDeferredValue(posts);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hooks useTransition and useDeferredValue are interchangeable and should not be used together.&lt;/p&gt;

&lt;h3&gt;
  
  
  useId
&lt;/h3&gt;

&lt;p&gt;This hook generate one &lt;strong&gt;uniq id&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;useId is a hook for generating unique IDs that are stable across the server and client, while avoiding hydration mismatches.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const id = useId();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, you can use it as id for label and inputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;&amp;gt;
  &amp;lt;label htmlFor={id}&amp;gt;Do you like React?&amp;lt;/label&amp;gt;
  &amp;lt;input id={id} type="checkbox" name="react"/&amp;gt;
&amp;lt;/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useSyncExternalStore
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;useSyncExternalStore is a hook recommended for reading and subscribing from external data sources in a way that’s compatible with concurrent rendering features like selective hydration and time slicing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This hook is come from library "use-sync-external-store", which now is a part of ReactJS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;External store&lt;/strong&gt; it something outside of component -  websockets, redux store, global variables, DOM state, etc. We can subscribe to this store.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inner store&lt;/strong&gt; it is props, useState, useReducer, etc.&lt;/p&gt;

&lt;p&gt;This hook accept three arguments. All three arguments is callback functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*&lt;em&gt;subscribe *&lt;/em&gt;: It is a function to register a callback that is called whenever the store changes. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;getSnapshot&lt;/strong&gt;: It is function that returns the current value of the store. You can use it to check if the subscribed value has changed since the last time, it was rendered.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;getServerSnapshot(optional)&lt;/strong&gt;: It is function that returns the snapshot used during server rendering.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This hook returns new &lt;strong&gt;state&lt;/strong&gt;, which can we use in UI.&lt;/p&gt;

&lt;h3&gt;
  
  
  useInsertionEffect
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The signature is identical to useEffect, but it fires synchronously before all DOM mutations. Use this to inject styles into the DOM before reading layout in useLayoutEffect. Since this hook is limited in scope, this hook does not have access to refs and cannot schedule updates.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This hook act like the useLayoutEffect hook, but useInsertionEffect will run before useLayoutEffect and dont have access to refs. Hook accept callback function. &lt;/p&gt;



&lt;br&gt;
Well, in my opinion this is just the main new features. In ReactJS official documentation you can find all new changes which come in ReactJS 18.

&lt;p&gt;Thanks for your attention!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>NestJS: Modules</title>
      <dc:creator>Ilya R</dc:creator>
      <pubDate>Sun, 05 Jun 2022 06:33:50 +0000</pubDate>
      <link>https://forem.com/ilyary/nestjs-modules-37k1</link>
      <guid>https://forem.com/ilyary/nestjs-modules-37k1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Modules&lt;/strong&gt; are isolated parts of a NestJS application. Thanks to the modular system, you can easily expand the functionality of the application. Also, isolation makes it easier to debug code and keeps it cleaner. But, isolation can bring some difficulties.&lt;/p&gt;

&lt;p&gt;In NestJS, you can create a module using the CLI&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;nest g module products&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A module is a class wrapped in @Module decorator which is imported from '@nestjs/common'. Many applications written in NestJS use many modules, but there must be at least one - the root module.&lt;/p&gt;

&lt;p&gt;The @Module decorator passes certain metadata and takes an object with properties as an argument:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;imports&lt;/strong&gt; - list of imported modules - using this property, you can create a convenient structure of modules in the application;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;controllers&lt;/strong&gt; - a list of controllers that are used only in this module;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;providers&lt;/strong&gt; — providers used in this module;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;exports&lt;/strong&gt; - part of the providers used in this module, but which may be available in other parts of the application.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Module } from '@nestjs/common';

import { ProductsService } from './products.service';
import { ProductsController } from './products.controller';

@Module({
  controllers: [ProductsController],
  providers: [ProductsService],
})
export class ProductsModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every new module must be imported into the &lt;strong&gt;root App module&lt;/strong&gt; in order for it to be available in the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.module.ts

import { Module } from '@nestjs/common';

import { ProductsModule } from './products/products.module';

@Module({
  imports: [ProductsModule ],
})
export class AppModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, in NestJS it is possible to create a global module that can be used throughout the application. For this purpose, you need use the &lt;a class="mentioned-user" href="https://dev.to/global"&gt;@global&lt;/a&gt; decorator. This module must be registered once in the root module and can be used in all application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Module, Global } from '@nestjs/common';

import { CommonService } from './common.service';
import { CommonController } from './common.controller';


@Global()
@Module({
  controllers: [CommonController],
  providers: [CommonService],
})
export class CommonModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;The main thing to understand is that &lt;strong&gt;Modules&lt;/strong&gt; are parts of an application. Their purpose is to encapsulate and isolate these parts within themselves. For example, for the Product module, we can use ProductController and ProductService - they will include all the code related only to the Product module and will work with a specific entity. As for me, it would be convenient to create modules according to the entities from app's database.&lt;/p&gt;

&lt;p&gt;Thanks for your time!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>nestjs</category>
    </item>
  </channel>
</rss>
