<?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>DEV Community: Tanzeel Ur Rehman</title>
    <description>The latest articles on DEV Community by Tanzeel Ur Rehman (@tanxeel).</description>
    <link>https://dev.to/tanxeel</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%2F429518%2F115e0564-a532-43c1-9474-a8c980a77a5c.png</url>
      <title>DEV Community: Tanzeel Ur Rehman</title>
      <link>https://dev.to/tanxeel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanxeel"/>
    <language>en</language>
    <item>
      <title>Rust for JavaScript Developers</title>
      <dc:creator>Tanzeel Ur Rehman</dc:creator>
      <pubDate>Thu, 22 Dec 2022 12:25:39 +0000</pubDate>
      <link>https://dev.to/tanxeel/rust-for-javascript-developers-4578</link>
      <guid>https://dev.to/tanxeel/rust-for-javascript-developers-4578</guid>
      <description>&lt;p&gt;If you're a JavaScript developer looking to learn Rust, here are some key points to keep in mind:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Rust is a statically typed language, which means that you have to specify the types of variables and function arguments when you declare them. This can be a bit of a change if you're used to the dynamically typed nature of JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rust has a strong focus on safety and performance. It has a number of features, such as ownership and borrowing, that help ensure that your code is correct and efficient.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rust has a very low-level control over system resources, similar to C or C++. This can be both a strength and a weakness, as it allows you to write highly optimized code but also requires a deeper understanding of how the language and the system work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rust has a growing ecosystem, with a number of useful libraries and tools available. Its package manager, Cargo, makes it easy to manage dependencies and build projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rust has a friendly and helpful community, with many resources available for learning the language. The Rust programming language book is a great place to start, as are the Rust by Example and Rustlings exercises.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Overall, Rust is a powerful and expressive language that can be a great addition to a JavaScript developer's toolkit. It takes some time to get used to its unique features, but the investment can pay off in terms of both code quality and performance.&lt;/p&gt;

&lt;p&gt;Here are a few examples of Rust code that might be familiar to a JavaScript developer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rust
fn add(x: i32, y: i32) -&amp;gt; i32 {
    x + y
}

let result = add(1, 2);
println!("The result is {}", result);

// JavaScript
function add(x, y) {
  return x + y;
}

const result = add(1, 2);
console.log(`The result is ${result}`);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rust
fn say_hello(name: &amp;amp;str) {
    println!("Hello, {}!", name);
}

say_hello("Alice");

// JavaScript
function sayHello(name) {
  console.log(`Hello, ${name}!`);
}

sayHello("Alice");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rust
let mut x = 5;
x = 10;

// JavaScript
let x = 5;
x = 10;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rust
let y: i32 = "5".parse().unwrap();

// JavaScript
const y = parseInt("5", 10);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope these examples give you a sense of how Rust code looks and works.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Custom hooks in React.js</title>
      <dc:creator>Tanzeel Ur Rehman</dc:creator>
      <pubDate>Wed, 21 Dec 2022 12:42:11 +0000</pubDate>
      <link>https://dev.to/tanxeel/custom-hooks-in-reactjs-o2</link>
      <guid>https://dev.to/tanxeel/custom-hooks-in-reactjs-o2</guid>
      <description>&lt;p&gt;In React, a hook is a function that allows you to "hook into" React features from a function component. There are several built-in hooks provided by React, such as &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Custom hooks are a way for you to extract component logic into reusable functions. They allow you to abstract logic that can be shared between multiple components into a single, reusable function.&lt;/p&gt;

&lt;p&gt;Here is an example of a custom hook that manages a form input state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';

function useInput(initialValue) {
  const [value, setValue] = useState(initialValue);

  function handleChange(event) {
    setValue(event.target.value);
  }

  return {
    value,
    onChange: handleChange
  };
}

export default useInput;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This custom hook can be used in a form component 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;import React from 'react';
import useInput from './useInput';

function Form() {
  const email = useInput('');
  const password = useInput('');

  return (
    &amp;lt;form&amp;gt;
      &amp;lt;input type="email" {...email} /&amp;gt;
      &amp;lt;input type="password" {...password} /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The useInput hook manages the state for the email and password inputs, and the &lt;code&gt;handleChange&lt;/code&gt; function updates the value of the input when the user types in it. The &lt;code&gt;...email&lt;/code&gt; and &lt;code&gt;...password&lt;/code&gt; syntax is the object spread operator, which spreads the properties of the &lt;code&gt;email&lt;/code&gt; and &lt;code&gt;password&lt;/code&gt; objects as props for the corresponding input elements.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>help</category>
    </item>
    <item>
      <title>Understanding JavaScript Promises</title>
      <dc:creator>Tanzeel Ur Rehman</dc:creator>
      <pubDate>Tue, 20 Dec 2022 20:14:44 +0000</pubDate>
      <link>https://dev.to/tanxeel/understanding-javascript-promises-4c57</link>
      <guid>https://dev.to/tanxeel/understanding-javascript-promises-4c57</guid>
      <description>&lt;p&gt;A promise is like a special kind of present. Imagine you're 5 years old and you really want a new toy. You ask your mom for a new toy and she says, "I promise I'll get you a new toy, but it might take some time to find the perfect one. In the meantime, you can do other things and play with your other toys."&lt;/p&gt;

&lt;p&gt;In this situation, your mom's promise is like a special kind of present that she's going to give you in the future. You might not have the toy right now, but you know that your mom will get it for you eventually.&lt;/p&gt;

&lt;p&gt;A JavaScript Promise is a special kind of object that helps you deal with something called "asynchronous code." Asynchronous code is code that takes some time to run, like when you are waiting for a website to load or a file to download.&lt;/p&gt;

&lt;p&gt;Promises make it easier to work with asynchronous code by giving you a way to say "when this task is finished, do this thing." For example, you might have a Promise that says "when the file finishes downloading, log a message to the console."&lt;/p&gt;

&lt;p&gt;To use a Promise, you first need to create one. You can do this by calling the Promise constructor and passing it a function that has two arguments: &lt;code&gt;resolve&lt;/code&gt; and &lt;code&gt;reject&lt;/code&gt;. The &lt;code&gt;resolve&lt;/code&gt; function is called when the asynchronous task is successfully completed, and the &lt;code&gt;reject&lt;/code&gt; function is called if there is an error.&lt;/p&gt;

&lt;p&gt;Here's an example of a Promise that waits for a file to download:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const downloadPromise = new Promise((resolve, reject) =&amp;gt; {
  // Start the download
  const file = startDownload();

  // Wait for the download to finish
  file.on('finish', () =&amp;gt; {
    // The download was successful, so call resolve
    resolve();
  });

  file.on('error', (error) =&amp;gt; {
    // There was an error, so call reject
    reject(error);
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have created a Promise, you can use its &lt;code&gt;then&lt;/code&gt; method to specify what should happen when the asynchronous task is completed. The &lt;code&gt;then&lt;/code&gt; method takes two arguments: a function to call if the Promise is resolved, and a function to call if the Promise is rejected.&lt;/p&gt;

&lt;p&gt;Here's an example of using the &lt;code&gt;then&lt;/code&gt; method with the &lt;code&gt;downloadPromise&lt;/code&gt; from above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;downloadPromise.then(
  () =&amp;gt; {
    console.log('The download was successful!');
  },
  (error) =&amp;gt; {
    console.log(`There was an error: ${error}`);
  }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>microservices</category>
      <category>frontend</category>
      <category>architecture</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Integrate Elastic Search with Node.js</title>
      <dc:creator>Tanzeel Ur Rehman</dc:creator>
      <pubDate>Sun, 18 Dec 2022 19:18:24 +0000</pubDate>
      <link>https://dev.to/tanxeel/integrate-elastic-search-with-nodejs-4f5h</link>
      <guid>https://dev.to/tanxeel/integrate-elastic-search-with-nodejs-4f5h</guid>
      <description>&lt;p&gt;Elasticsearch is a powerful search engine that can be easily integrated into a Node.js application to provide advanced search functionality. Here's how you can do it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the Elasticsearch library: The first step is to install the Elasticsearch library for Node.js using the npm package manager. You can do this by running the following command in your terminal:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install elasticsearch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.&lt;br&gt;
 Connect to the Elasticsearch cluster: Next, you'll need to create a client object that can connect to your Elasticsearch cluster. You can do this by importing the Elasticsearch library and creating a new client object, 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;const { Client } = require('elasticsearch');
const client = new Client({
  host: 'localhost:9200',
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;br&gt;
 Index some data: Now that you're connected to the Elasticsearch cluster, you can start indexing some data. You can do this using the index() method, 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;client.index({
  index: 'my-index',
  type: 'my-type',
  body: {
    title: 'My Document',
    content: 'This is the content of my document',
  },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.&lt;br&gt;
 Search for data: Once you've indexed some data, you can use the Elasticsearch query language to search for specific documents. You can do this using the search() method, 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;client.search({
  index: 'my-index',
  type: 'my-type',
  body: {
    query: {
      match: {
        title: 'my document',
      },
    },
  },
}).then((response) =&amp;gt; {
  console.log(response.hits.hits);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the basic steps for integrating Elasticsearch with a Node.js application. Of course, there are many more advanced features that you can use, such as aggregations, faceting, and more. You can learn more about these features in the Elasticsearch documentation.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
