<?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: Tejas</title>
    <description>The latest articles on Forem by Tejas (@tejasgk).</description>
    <link>https://forem.com/tejasgk</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%2F435960%2F3abd0203-afa6-4284-ae97-82a7c221dc39.jpg</url>
      <title>Forem: Tejas</title>
      <link>https://forem.com/tejasgk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tejasgk"/>
    <language>en</language>
    <item>
      <title>How the Hell C++ Templates Work ?</title>
      <dc:creator>Tejas</dc:creator>
      <pubDate>Mon, 04 Dec 2023 16:47:51 +0000</pubDate>
      <link>https://forem.com/tejasgk/how-the-hell-c-templates-work--4n2e</link>
      <guid>https://forem.com/tejasgk/how-the-hell-c-templates-work--4n2e</guid>
      <description>&lt;p&gt;Hey there, Welcome to a guide on C++ templates! 🎉 In this article, we will explore the ins and outs of using C++ templates and delve into the reasons why they are powerful for developers. Whether you are a seasoned programmer or starting your coding journey, templates in C++ are essential for writing efficient and reusable code. Let's roll up our sleeves and dive right in! 💪💻&lt;/p&gt;

&lt;p&gt;C++ templates are a powerful feature that allows programmers to define generic types and functions. They provide a way to write code that can be used with different data types without sacrificing performance or code readability. Templates in C++ essentially enable us to write code once and use it with multiple types, saving us from writing repetitive code for each specific type. 🔧✨&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Templates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Function templates are one aspect of C++ templates that make them incredibly useful. Imagine you need to write a function that swaps the values of two variables, but you want the flexibility to swap integers, floating-point numbers, or even custom data types without writing separate swap functions for each. Here's where function templates come to the rescue. 🔄🔀&lt;/p&gt;

&lt;p&gt;Let's take a look at a simple example of a function template that swaps two values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
void swap(T&amp;amp; a, T&amp;amp; b) {
    T temp = a;
    a = b;
    b = temp;
}

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

&lt;/div&gt;



&lt;p&gt;In the code snippet above, the typename T denotes a placeholder type that can be substituted with any desired type. This function template can be used with various data types, such as int, float, or even user-defined classes. The compiler automatically generates the appropriate code for each type, eliminating the need to write multiple swap functions. 🤝🔧&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class Templates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While function templates are incredibly powerful, C++ templates go even further with class templates. Class templates allow us to define classes that are generic and can work seamlessly with different types. This gives us the ability to write reusable code that can be applied to a wide range of scenarios. 📦💡&lt;/p&gt;

&lt;p&gt;Let's consider a simple example of a class template called Stack, which represents a stack data structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
class Stack {
private:
    std::vector&amp;lt;T&amp;gt; elements;
public:
    void push(const T&amp;amp; value) {
        elements.push_back(value);
    }

    void pop() {
        if (!elements.empty()) {
            elements.pop_back();
        }
    }

    T top() const {
        if (!elements.empty()) {
            return elements.back();
        }
        throw std::runtime_error("Stack is empty!");
    }
}

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

&lt;/div&gt;



&lt;p&gt;In the code snippet above, we define a template class called Stack that can be instantiated with any data type. This flexibility allows us to create stacks of integers, strings, or even complex user-defined objects. The class methods are defined in the same way as for any regular class, but they can work seamlessly with different types. 📚🔧&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use C++ Templates? ❓&lt;/strong&gt;&lt;br&gt;
Now that we have a good understanding of what C++ templates are, let's explore some compelling reasons why you would want to use them in your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Reusability ♻️&lt;/strong&gt;&lt;br&gt;
One of the primary advantages of using C++ templates is code reusability. Templates enable us to write generic code that can adapt to different data types. This eliminates the need to write repetitive code for each specific type, resulting in more concise and maintainable codebases. By leveraging templates, you can achieve a significant reduction in code duplication and increase overall development productivity. 🔄🔀💼&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Optimization ⚡&lt;/strong&gt;&lt;br&gt;
Contrary to popular belief, C++ templates do not incur runtime overhead. The compiler generates specialized versions of the template code for each data type used. This process, known as template instantiation, eliminates the need for runtime type checks and ensures optimal performance as if you were writing dedicated code for each type individually. Templates effectively bridge the gap between code flexibility and performance, making them an excellent choice for performance-critical applications. 🚀🔧&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type Safety 🔒&lt;/strong&gt;&lt;br&gt;
Another significant benefit of C++ templates is the inherent type safety they offer. With templates, the compiler performs rigorous type checking at compile-time, preventing type-related errors and promoting robust code. Any mismatches or inconsistencies in types are caught during compilation, eliminating the risk of runtime errors due to type mismatches. Templates enforce strict type correctness, resulting in highly reliable and bug-free code. 🧰✅&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion ✅&lt;/strong&gt;&lt;br&gt;
C++ templates are a powerful tool in a programmer's arsenal. They allow us to write generic code that can adapt to various data types while maintaining high performance and type safety. Function templates and class templates provide the flexibility to create reusable code that saves us from the redundant task of writing type-specific code. By leveraging C++ templates, you can enhance code reusability, optimize performance, and ensure type safety in your programs. So go ahead and harness the power of C++ templates in your projects to unlock a new level of efficiency and elegance in your code. Happy coding! 🚀💻😊&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>coding</category>
      <category>codenewbie</category>
      <category>programming</category>
    </item>
    <item>
      <title>Generating functions in Javascript</title>
      <dc:creator>Tejas</dc:creator>
      <pubDate>Sat, 25 Nov 2023 18:37:11 +0000</pubDate>
      <link>https://forem.com/tejasgk/generating-functions-in-javascript-e61</link>
      <guid>https://forem.com/tejasgk/generating-functions-in-javascript-e61</guid>
      <description>&lt;h2&gt;
  
  
  Lazy Evaluation
&lt;/h2&gt;

&lt;p&gt;What if I told you that you can be lazy and productive at the same time? In the world of programming, lazy evaluation is a technique that allows you to defer the evaluation of an expression until it is absolutely necessary. In the context of Javascript, this means that you can delay the execution of a function until the result is needed.&lt;/p&gt;

&lt;p&gt;Lazy evaluation can be extremely useful in scenarios where you are dealing with complex and resource-intensive computations. By deferring the execution of a function until it is actually required, you can optimize the performance of your code and avoid unnecessary calculations.&lt;/p&gt;

&lt;p&gt;But how does lazy evaluation actually work in Javascript? Well, it all comes down to the concept of generating functions. A generating function is a special type of function that returns an iterator object instead of a concrete value. This iterator can then be used to generate values on demand, only when they are needed.&lt;/p&gt;

&lt;p&gt;Let's take a closer look at how lazy evaluation using generating functions can be implemented in Javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using generators in Javascript
&lt;/h3&gt;

&lt;p&gt;In Javascript, generators provide an elegant solution for implementing lazy evaluation. Generators are functions that can be paused and resumed, allowing you to control the flow of execution. They are defined using the &lt;code&gt;function*&lt;/code&gt; syntax and yield values using the &lt;code&gt;yield&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;Here is a simple example of a generating function that generates an infinite sequence of numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;generateNumbers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how the &lt;code&gt;generateNumbers&lt;/code&gt; function is defined using the &lt;code&gt;function*&lt;/code&gt; syntax. Inside the function, we use a &lt;code&gt;while&lt;/code&gt; loop to generate an infinite sequence of numbers. The &lt;code&gt;yield&lt;/code&gt; keyword is used to yield the next value in the sequence.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lazy evaluation in action
&lt;/h3&gt;

&lt;p&gt;Now that we have our generating function, let's see how we can use it to implement lazy evaluation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generateNumbers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="c1"&gt;// and so on...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create an instance of the &lt;code&gt;generateNumbers&lt;/code&gt; generator by calling the function. We can then use the &lt;code&gt;next()&lt;/code&gt; method to retrieve the next value in the sequence. Since the sequence is infinite, we can keep calling &lt;code&gt;next()&lt;/code&gt; indefinitely to generate as many numbers as we need.&lt;/p&gt;

&lt;p&gt;By using a generating function, we can ensure that the numbers are only generated when we actually need them. This can be especially useful when dealing with large datasets or expensive computations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Asynchronous Programming
&lt;/h2&gt;

&lt;p&gt;In the fast-paced world of web development, asynchronous programming is a crucial technique for building responsive and efficient applications. Asynchronous programming allows you to execute multiple tasks concurrently, without blocking the main thread.&lt;/p&gt;

&lt;p&gt;In Javascript, asynchronous programming is commonly achieved using callbacks, promises, and async/await syntax. These techniques allow you to perform time-consuming operations, such as making API requests or accessing a database, without blocking the execution of the rest of your code.&lt;/p&gt;

&lt;p&gt;But how does asynchronous programming relate to generating functions? Well, generating functions can be a powerful tool for managing asynchronous operations in an elegant and intuitive way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Asynchronous generators
&lt;/h3&gt;

&lt;p&gt;In Javascript, asynchronous generators combine the power of generating functions with the flexibility of asynchronous programming. An asynchronous generator is a function that returns an asynchronous iterator object, allowing you to generate values asynchronously.&lt;/p&gt;

&lt;p&gt;Here is an example of an asynchronous generating function that fetches data from an API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Failed to fetch data:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;fetchData&lt;/code&gt; function uses the &lt;code&gt;async function*&lt;/code&gt; syntax to define an asynchronous generating function. Inside the function, we use the &lt;code&gt;await&lt;/code&gt; keyword to fetch data from an API and yield each item asynchronously.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managing asynchronous tasks with generators
&lt;/h3&gt;

&lt;p&gt;By using asynchronous generators, we can simplify the management of asynchronous tasks in our code. We can use the &lt;code&gt;for-await-of&lt;/code&gt; loop to iterate over the values generated by an asynchronous generator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataGenerator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;dataGenerator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create an instance of the &lt;code&gt;fetchData&lt;/code&gt; asynchronous generator and iterate over the values using the &lt;code&gt;for-await-of&lt;/code&gt; loop. The loop automatically awaits each value before running the next iteration, ensuring that the asynchronous tasks are executed in the correct order.&lt;/p&gt;

&lt;p&gt;Asynchronous generators provide a convenient way to handle asynchronous operations in a sequential and readable manner. They simplify the complexity of managing callbacks or chaining promises, making our code more maintainable and easier to understand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Infinite Sequences
&lt;/h2&gt;

&lt;p&gt;From the concept of lazy evaluation to the power of asynchronous programming, generating functions have proven to be a versatile tool in Javascript. Another fascinating aspect of generating functions is their ability to produce infinite sequences.&lt;/p&gt;

&lt;p&gt;In mathematics, an infinite sequence is a sequence that continues indefinitely without an endpoint. In the context of generating functions, we can create infinite sequences of values using a combination of lazy evaluation and recursion.&lt;/p&gt;

&lt;p&gt;Let's explore how we can implement infinite sequences using generating functions in Javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fibonacci sequence
&lt;/h3&gt;

&lt;p&gt;One of the most famous examples of an infinite sequence is the Fibonacci sequence. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;fibonacci&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;fibonacci&lt;/code&gt; generating function uses a &lt;code&gt;while&lt;/code&gt; loop to yield the next number in the Fibonacci sequence infinitely. The values are generated lazily, ensuring that the computations are only performed when necessary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using infinite sequences
&lt;/h3&gt;

&lt;p&gt;Now that we have our infinite sequence of Fibonacci numbers, let's see how we can use it in our code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fibonacci&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 0&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="c1"&gt;// and so on...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create an instance of the &lt;code&gt;fibonacci&lt;/code&gt; generator and use the &lt;code&gt;next()&lt;/code&gt; method to retrieve the next value in the sequence. As with other generating functions, the values are generated on-demand, allowing us to work with infinite sequences efficiently.&lt;/p&gt;

&lt;p&gt;Infinite sequences can be a powerful tool in various scenarios, such as generating random numbers, simulating complex systems, or even creating an endless stream of jokes (if you're feeling particularly quirky). The possibilities are limited only by your imagination!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Generating functions in Javascript offer a unique approach to lazy evaluation, asynchronous programming, and infinite sequences. By harnessing the power of generating functions, you can optimize performance, simplify asynchronous operations, and create fascinating endless streams of values.&lt;/p&gt;

&lt;p&gt;Whether you need to generate values on-demand, handle asynchronous tasks gracefully, or explore the infinite realm of mathematical sequences, generating functions have got you covered. So go ahead, embrace the magic of generating functions in Javascript, and let your code reach new heights of elegance and efficiency!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Git cheatsheet</title>
      <dc:creator>Tejas</dc:creator>
      <pubDate>Tue, 11 Jul 2023 17:11:45 +0000</pubDate>
      <link>https://forem.com/tejasgk/git-cheatsheet-jl6</link>
      <guid>https://forem.com/tejasgk/git-cheatsheet-jl6</guid>
      <description>&lt;h1&gt;
  
  
  Git Cheatsheets and Tricks
&lt;/h1&gt;

&lt;p&gt;Git is a powerful and versatile version control system that has become an essential tool for software development teams and individual developers alike. In this article, we'll cover some Git cheatsheets and tricks that will help you improve your Git skills.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Cheatsheets
&lt;/h2&gt;

&lt;p&gt;A Git cheatsheet is a quick reference guide that summarizes the most commonly used Git commands and their usage. Here are some common Git commands that you might find on a Git cheatsheet:&lt;/p&gt;

&lt;h2&gt;
  
  
  Initialize a repository
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git init                # Initialize a new repository&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone a repository
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git clone &amp;lt;repository_url&amp;gt;   # Clone an existing repository&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with branches
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch                  # List all branches
git branch &amp;lt;branch_name&amp;gt;    # Create a new branch
git checkout &amp;lt;branch_name&amp;gt;  # Switch to a branch
git merge &amp;lt;branch_name&amp;gt;     # Merge a branch into the current branch
git branch -d &amp;lt;branch_name&amp;gt; # Delete a branch

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Commiting changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git status               # Show the status of your changes
git add &amp;lt;file_name&amp;gt;      # Stage changes for commit
git add .                # Stage all changes for commit
git commit -m "message"  # Commit staged changes with a message

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  pulling and pushing changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin &amp;lt;repository_url&amp;gt;  # Add a remote repository
git push -u origin &amp;lt;branch_name&amp;gt;        # Push changes to a remote repository
git pull origin &amp;lt;branch_name&amp;gt;           # Pull changes from a remote repository

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  View commit history and differences
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log             # Show commit history
git diff            # Show differences between current changes and previous commit
git diff &amp;lt;commit&amp;gt;   # Show differences between current changes and a specific commit

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Undoing changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset &amp;lt;file_name&amp;gt;    # Unstage changes for a specific file
git reset                # Unstage all changes
git checkout &amp;lt;file_name&amp;gt; # Discard changes for a specific file
git checkout .           # Discard all changes
git revert &amp;lt;commit&amp;gt;      # Undo a commit by creating a new commit with the opposite changes

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  tags
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset &amp;lt;file_name&amp;gt;    # Unstage changes for a specific file
git reset                # Unstage all changes
git checkout &amp;lt;file_name&amp;gt; # Discard changes for a specific file
git checkout .           # Discard all changes
git revert &amp;lt;commit&amp;gt;      # Undo a commit by creating a new commit with the opposite changes

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  stash
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash        # Stash changes
git stash list   # List all stashes
git stash apply  # Apply the most recent stash
git stash drop   # Drop the most recent stash

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>My Programming journey</title>
      <dc:creator>Tejas</dc:creator>
      <pubDate>Mon, 01 May 2023 16:35:01 +0000</pubDate>
      <link>https://forem.com/tejasgk/my-programming-journey-1ne0</link>
      <guid>https://forem.com/tejasgk/my-programming-journey-1ne0</guid>
      <description>&lt;p&gt;Alright so here you are welcome to this blog where I tell you what I had been doing for past few years. In this blog, I will be sharing my experiences, challenges, and successes as I navigate the vast and ever-evolving world of programming. Through this blog, I hope to connect with like-minded individuals and inspire others to pursue their own programming journeys. So, sit back, grab a cup of coffee, and join me on this exciting adventure!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's see how it all started,&lt;/strong&gt;&lt;br&gt;
It was a dark and stormy night, and I was procrastinating on YouTube, watching funny cat videos when, out of nowhere, I stumbled upon a channel called &lt;a href="https://www.youtube.com/user/Brackeys"&gt;Brackeys&lt;/a&gt;. Little did I know that this was going to change my life forever. I downloaded Unity and started following Brackeys' tutorials, feeling like a pro at first, but then slowly realizing that I had no idea what I was doing. &lt;/p&gt;

&lt;p&gt;Little did I know I was stuck in tutorial hell for two whole F**king years!!&lt;/p&gt;

&lt;h2&gt;
  
  
  1st PU
&lt;/h2&gt;

&lt;p&gt;I gave up on unity and started trying everything.  Literally everything . From Python to Rust, from Django to Flask, and from silly websites to Discord bots. I even dabbled in competitive programming, failing over and over again. &lt;/p&gt;

&lt;h2&gt;
  
  
  🔐 down
&lt;/h2&gt;

&lt;p&gt;But guess where I landed? In the land of PHP! Yup, you heard that right. I saw a YouTube recommendation from &lt;a href="https://www.youtube.com/yahoobaba"&gt;Yahoo baba&lt;/a&gt; and I watched a PHP playlist by Yahoo Baba and spent half of my lockdown building a social media app called Orkut. Why Orkut, you ask? Well, I liked the name, okay? It was vanilla PHP, but I did manage to add authentication and basic CRUD operations, which I called "posts".&lt;/p&gt;

&lt;p&gt;In the second half of lockdown, I moved on to Laravel and Vue.js, and that's when I built &lt;a href="https://github.com/tejas-gk/waddle"&gt;Waddle&lt;/a&gt; , a monolithic application. This was the first project I did without relying too much on tutorials, and let's just say that I finally got out of tutorial hell.&lt;/p&gt;

&lt;h2&gt;
  
  
  College
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1st year
&lt;/h2&gt;

&lt;p&gt;I went to college and met a &lt;a href="https://github.com/Deveesh-Shetty"&gt;Legend&lt;/a&gt; . Everyone might either be jack of all trades and master of none or master of one but never both . But this guy is master of all trades. With him on my side we completed many cool projects together. It sure does help when your friends have same interest as you.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is always a bigger fish &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VQ3okVl5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tw1bovwykv3x9bwpjjpe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VQ3okVl5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tw1bovwykv3x9bwpjjpe.png" alt="Markdown previewer" width="800" height="391"&gt;&lt;/a&gt;&lt;br&gt;
This is markdown previewer built with alpine js&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZP5LfBsx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfcktnkbdnyn05ym5m9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZP5LfBsx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfcktnkbdnyn05ym5m9k.png" alt="weather app" width="800" height="402"&gt;&lt;/a&gt;&lt;br&gt;
weather app&lt;/p&gt;

&lt;p&gt;After all these projects I thought I could build Waddle even better So I built Guild with nextjs on frontend and Laravel on backend. I also discovered Tailwind around this time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mV755Ne0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwbp7wfid2x2fwsq5tvx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mV755Ne0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwbp7wfid2x2fwsq5tvx.png" alt="Guild" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a responsible human being, I also tried my best to pass in college. It wasn't easy though, especially when I had to balance my coursework with my programming projects. &lt;/p&gt;

&lt;p&gt;One time, I stayed up all night to finish a coding project, and by the time I submitted it, the sun was already up. I looked like a zombie with dark circles under my eyes, and my teacher probably thought I was pulling an all-nighter partying. Little did he know that I was just having a coding marathon with myself.&lt;/p&gt;

&lt;h2&gt;
  
  
  2nd year
&lt;/h2&gt;

&lt;p&gt;We collaborated in a team of 3 members to develop a project for a specific company and designed and implemented APIs to create Realtime location-based system using leafletjs resulting in winning 1st place in the competition showcasing project to company&lt;br&gt;
Hackathon &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qLM3399k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rae6xecvm3bz8xtkceb7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qLM3399k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rae6xecvm3bz8xtkceb7.jpeg" alt="Devhost hackathon" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;yeah that guy on the right is me. We spent around 30 hours without sleep just working on project. Our hard work paid off and more importantly we got lots of experience and knowledge on team work&lt;/p&gt;

&lt;p&gt;I started hopping into frontend &lt;a href="https://www.frontendmentor.io/profile/tejas-gk"&gt;Frontend mentor&lt;/a&gt; was a major help to me without which I wouldn't have gotten better at frontend.&lt;br&gt;
actually most of my small projects can be found here in &lt;a href="https://github.com/tejas-gk/UiLib"&gt;UILib&lt;/a&gt;&lt;br&gt;
Here are some other things built thanks to frontend mentor&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EV4M9JCm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nzyjhud89gsd6h85lkzb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EV4M9JCm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nzyjhud89gsd6h85lkzb.png" alt="rock paper scissors" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  rock paper scissors
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U1gvt_X8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mp31db71k4yfx8lmcaz1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U1gvt_X8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mp31db71k4yfx8lmcaz1.png" alt="space tourism" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  space tourism
&lt;/h5&gt;

&lt;p&gt;I know I still have a long way to go before I become the programming wizard I aspire to be. I'm still nowhere near where I want to be.&lt;/p&gt;

&lt;p&gt;So, there you have it, folks. My  programming journey that started with me watching YouTube videos and ended up with me building cool projects.&lt;/p&gt;

&lt;p&gt;Hope you enjoyed the ride as much as I did!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>discuss</category>
      <category>writing</category>
    </item>
  </channel>
</rss>
