<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Naveesha Kavindi on Medium]]></title>
        <description><![CDATA[Stories by Naveesha Kavindi on Medium]]></description>
        <link>https://medium.com/@naveeshakavindi?source=rss-daa0a5fe5ee6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zl6xGoF_vKsvMBg3gKiAhw.jpeg</url>
            <title>Stories by Naveesha Kavindi on Medium</title>
            <link>https://medium.com/@naveeshakavindi?source=rss-daa0a5fe5ee6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 20 May 2026 12:53:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naveeshakavindi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[5 Essential React Hooks]]></title>
            <link>https://medium.com/@naveeshakavindi/5-essential-react-hooks-4594cdb215f7?source=rss-daa0a5fe5ee6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4594cdb215f7</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Naveesha Kavindi]]></dc:creator>
            <pubDate>Fri, 20 Sep 2024 02:40:40 GMT</pubDate>
            <atom:updated>2024-09-20T02:40:40.191Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*odpazv2aPQGLKblQPL9Idw.jpeg" /></figure><ol><li>useState</li></ol><ul><li><strong>Definition</strong>: A hook that lets you add state (data that changes) to your function components.</li><li><strong>Explanation</strong>: Think of useState like a special variable that keeps its value even when your component re-renders. You can update it, and when it changes, React updates the UI for you.</li><li><strong>Example</strong>: If you want a counter in your app, useState will help you store and update the current count.</li></ul><pre>import { useState } from &#39;react&#39;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0); // count starts at 0<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increase&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Counter;</pre><p>2. useEffect</p><ul><li><strong>Definition</strong>: A hook for side effects in your components, such as fetching data or updating the DOM.</li><li><strong>Explanation</strong>: It allows you to run code after the component renders. For example, if you want to fetch data when the component first loads, you can use useEffect. It can also run cleanup functions, like removing event listeners when the component is removed.</li></ul><pre>import { useEffect, useState } from &#39;react&#39;;<br><br>function DataFetcher() {<br>  const [data, setData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    // Fetch data when component mounts<br>    fetch(&#39;https://jsonplaceholder.typicode.com/posts/1&#39;)<br>      .then(response =&gt; response.json())<br>      .then(json =&gt; setData(json));<br>  }, []); // Empty array means it runs only once<br><br>  return &lt;div&gt;Data: {data ? data.title : &#39;Loading...&#39;}&lt;/div&gt;;<br>}<br><br>export default DataFetcher;</pre><p>3. useContext</p><ul><li><strong>Definition</strong>: A hook that lets you share data between components without passing props down manually at every level.</li><li><strong>Explanation</strong>: Imagine you want to share a theme (dark mode or light mode) across many parts of your app. Instead of passing the theme down through every component, useContext allows you to grab it directly wherever you need it.</li></ul><pre>import { createContext, useContext } from &#39;react&#39;;<br><br>const ThemeContext = createContext(&#39;light&#39;);<br><br>function App() {<br>  return (<br>    &lt;ThemeContext.Provider value=&quot;dark&quot;&gt;<br>      &lt;Toolbar /&gt;<br>    &lt;/ThemeContext.Provider&gt;<br>  );<br>}<br><br>function Toolbar() {<br>  return &lt;ThemedButton /&gt;;<br>}<br><br>function ThemedButton() {<br>  const theme = useContext(ThemeContext);<br>  return &lt;button style={{ backgroundColor: theme === &#39;dark&#39; ? &#39;#333&#39; : &#39;#FFF&#39; }}&gt;Theme Button&lt;/button&gt;;<br>}<br><br>export default App;</pre><p>4. useRef</p><ul><li><strong>Definition</strong>: A hook that allows access and manipulation of DOM elements or persists a value across renders without causing a re-render.</li><li><strong>Explanation</strong>: It’s like a box that holds something — a DOM element, a value, or any object. The value inside doesn’t cause re-renders when changed, and you can access or modify it as needed. It’s handy for interacting with input fields or keeping track of previous values.</li></ul><pre>import { useRef } from &#39;react&#39;;<br><br>function TextInputFocus() {<br>  const inputRef = useRef(null);<br><br>  const handleClick = () =&gt; {<br>    inputRef.current.focus(); // Focuses the input when button is clicked<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input ref={inputRef} type=&quot;text&quot; placeholder=&quot;Focus me!&quot; /&gt;<br>      &lt;button onClick={handleClick}&gt;Focus the input&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default TextInputFocus;</pre><p>5. useMemo</p><ul><li><strong>Definition</strong>: A hook that memoizes a computed value so that it doesn’t get recalculated unless its dependencies change.</li><li><strong>Explanation</strong>: If you have expensive calculations in your component, useMemo it helps to remember the result unless the inputs (dependencies) change. This makes your app faster by avoiding unnecessary calculations on every render.</li></ul><pre>import { useState, useMemo } from &#39;react&#39;;<br><br>function ExpensiveCalculation() {<br>  const [num, setNum] = useState(0);<br><br>  const factorial = useMemo(() =&gt; {<br>    console.log(&#39;Calculating factorial...&#39;);<br>    const calculateFactorial = (n) =&gt; (n &lt;= 0 ? 1 : n * calculateFactorial(n - 1));<br>    return calculateFactorial(num);<br>  }, [num]); // Only recalculates when &#39;num&#39; changes<br><br>  return (<br>    &lt;div&gt;<br>      &lt;input<br>        type=&quot;number&quot;<br>        value={num}<br>        onChange={(e) =&gt; setNum(Number(e.target.value))}<br>      /&gt;<br>      &lt;p&gt;Factorial: {factorial}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default ExpensiveCalculation;</pre><p>These hooks help efficiently manage component behavior, state, and lifecycle in React applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4594cdb215f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The AI Renaissance: When Algorithms Paint, Compose, and Write]]></title>
            <link>https://medium.com/@naveeshakavindi/the-ai-renaissance-when-algorithms-paint-compose-and-write-8169cdefa5e4?source=rss-daa0a5fe5ee6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8169cdefa5e4</guid>
            <category><![CDATA[the-ai-revolution]]></category>
            <category><![CDATA[ai-renaissance]]></category>
            <dc:creator><![CDATA[Naveesha Kavindi]]></dc:creator>
            <pubDate>Sun, 11 Aug 2024 01:43:51 GMT</pubDate>
            <atom:updated>2024-08-11T01:43:51.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LbTXlcqRl8svaPKCFqmecw.png" /></figure><p>Imagine a world where Beethoven’s 10th symphony exists, painted portraits come to life, and Shakespeare pens a new sonnet. Welcome to the AI Renaissance, where silicon dreams become creative realities.</p><p><strong>The Digital Mozart</strong></p><p>AI composers are striking up the band in concert halls across the digital landscape. OpenAI’s MuseNet channels the spirits of classical maestros, while Amper Music lets you play DJ with an AI band at your fingertips. But it’s not just about mimicry — these digital Mozarts are composing original scores that could excite even the most seasoned conductor’s baton.</p><p>Spotify and Apple Music have turned their AI into the world’s most attentive listeners, analyzing your toe-taps and head-bobs to serve your next favorite track. Meanwhile, LANDR’s AI is the new mixing board wizard, mastering tracks faster than you can say “Grammy nomination.”</p><p><strong>When Pixels Paint Masterpieces</strong></p><p>Move over, paintbrushes — neural networks are the new tools of the trade. Generative Adversarial Networks (GANs) are the dynamic duo of the art world, with one AI creating and another critiquing in an endless dance of digital creativity. The result? Artworks that can fool even the most discerning critic.</p><p>Case in point: Edmond de Belamy, the AI-generated portrait that crashed the traditional art party, selling for a cool $432,500 at Christie’s. It’s not just about creating new art, though. AI is also the art world’s new restoration expert, breathing digital life into faded masterpieces and filling in the blanks of history’s fragmented artworks.</p><p><strong>The Algorithm Authors</strong></p><p>In the realm of literature, AI is penning tales that could make even the most prolific authors do a double-take. OpenAI’s GPT-3 is the new kid on writer’s block, churning out stories, poems, and articles faster than you can say “writer’s block.” While it may not be winning Pulitzers just yet, it’s certainly giving aspiring writers a run for their money.</p><p>But fear not, human wordsmiths! AI is here to be your trusty sidekick too. Grammarly is the eagle-eyed editor that never sleeps, while other AI writing assistants are like having a team of literary consultants at your fingertips, helping you craft prose that pops and sizzles.</p><p><strong>The Great Creative Debate</strong></p><p>As AI steps into the spotlight of the creative stage, it’s stirring up quite a debate in artistic circles. On one side, we have the democratization of art — anyone with a computer can now be a composer, painter, or author. On the flip side, questions of originality, authorship, and the value of human creativity are swirling like van Gogh’s Starry Night.</p><p>Will AI-generated masterpieces flood the market, or will they inspire human artists to reach new creative heights? The jury’s still out, but one thing’s for sure — the collaboration between human ingenuity and artificial intelligence is painting a future that’s anything but boring.</p><p><strong>The Final Brushstroke</strong></p><p>As we stand at the easel of the future, paintbrush in one hand and neural network in the other, the canvas of possibility stretches endlessly before us. AI isn’t here to replace the artist but to amplify the art. It’s a new tool in our creative toolkit, pushing the boundaries of imagination and redefining what it means to create.</p><p>So, whether you’re a traditionalist or a tech enthusiast, buckle up. The AI Renaissance is here, and it’s turning the art world on its head — one algorithm at a time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8169cdefa5e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Data Structures]]></title>
            <link>https://medium.com/@naveeshakavindi/basic-data-structures-3bc3eaf6ef65?source=rss-daa0a5fe5ee6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bc3eaf6ef65</guid>
            <category><![CDATA[basic-data-structures]]></category>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[stack]]></category>
            <dc:creator><![CDATA[Naveesha Kavindi]]></dc:creator>
            <pubDate>Fri, 26 Jul 2024 02:42:21 GMT</pubDate>
            <atom:updated>2024-07-26T02:42:21.490Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JLiW0oIFRycL_6Phf6z7Q.png" /></figure><h4>1. Arrays</h4><p><strong><em>Definition:</em></strong></p><p>An <a href="https://www.w3schools.com/dsa/dsa_data_arrays.php"><strong>Array</strong></a><strong> </strong>is a collection of elements identified by an index or key. It is a linear data structure that stores elements of the same type in a contiguous block of memory.</p><p><strong><em>Characteristics:</em></strong></p><p>· Fixed size: The size of the array must be specified at the time of creation.</p><p>· Index-based: Each element can be accessed using its index.</p><p>· Homogeneous: All elements in an array are of the same type.</p><p><strong><em>Advantages:</em></strong></p><p>· Fast access to elements using an index.</p><p>· Efficient use of memory for homogeneous data.</p><p><strong><em>Disadvantages:</em></strong></p><p>· Fixed size limits flexibility.</p><p>· Insertion and deletion operations can be costly to need for shifting elements.</p><p><strong><em>Use case:</em></strong></p><p>· Storing a collection of items where fast access is required.</p><p>· Implementing other data structures like lists, stacks, and queues.</p><p><strong><em>Operations:</em></strong></p><p>· Accessing Elements: ‘array [index]’</p><p>· Insertion: Adding elements (usually at the end or by shifting elements).</p><p>· Deletion: Removing elements (usually by shifting elements)</p><p>· Traversal: Iteration over all elements.</p><pre>public class ArrayExample {<br>    public static void main(String[] args) {<br>        // Declaration and Initialization<br>        int[] array = {1, 2, 3, 4, 5};<br><br>        // Accessing elements<br>        System.out.println(&quot;Element at index 2: &quot; + array[2]);<br><br>        // Insertion (adding an element at the end)<br>        int[] newArray = new int[array.length + 1];<br>        System.arraycopy(array, 0, newArray, 0, array.length);<br>        newArray[array.length] = 6;<br><br>        // Deletion (removing element at index 2)<br>        for (int i = 2; i &lt; newArray.length - 1; i++) {<br>            newArray[i] = newArray[i + 1];<br>        }<br>        int[] finalArray = new int[newArray.length - 1];<br>        System.arraycopy(newArray, 0, finalArray, 0, newArray.length - 1);<br><br>        // Traversal<br>        System.out.print(&quot;Array elements: &quot;);<br>        for (int element : finalArray) {<br>            System.out.print(element + &quot; &quot;);<br>        }<br>    }<br>}</pre><h4>2. Linked List</h4><p><strong><em>Definition:</em></strong></p><p>A <a href="https://www.w3schools.com/dsa/dsa_theory_linkedlists.php"><strong>Linked List</strong></a> is a linear data structure where each element(node) contains data and a reference (or link) to the next node in the sequence.</p><p><strong><em>Type:</em></strong></p><p>· Singly Linked List: Each node points to the next node.</p><p>· Doubly Linked List: Each node points to both the next and previous nodes.</p><p>· Circular Linked List: the last node points back to the first node.</p><p><strong><em>Advantages:</em></strong></p><p>· Dynamic size: Can grow or shrink as needed.</p><p>· Efficient insertion and deletion operations compared to arrays.</p><p><strong><em>Disadvantages:</em></strong></p><p>· No direct access to elements; must traverse from the head. Extra memory is required for storing references.</p><p><strong><em>Use Cases:</em></strong></p><p>§ Implementing complex data structures like stacks, queues, and graphs. Managing dynamic memory allocation.</p><p><strong><em>Operations:</em></strong></p><p>· Insertion: Adding a new node at the beginning, end, or a specific position.</p><p>· Deletion: Removing a node from the beginning, end, or a specific position.</p><p>· Traversal: Iterating over all nodes.</p><p>· Searching: Finding a node with a specific value.</p><pre><br>class Node {<br>    int data;<br>    Node next;<br>    <br>    Node(int data) {<br>        this.data = data;<br>        this.next = null;<br>    }<br>}<br><br>public class LinkedListExample {<br>    Node head;<br><br>    // Insertion at the end<br>    public void insert(int data) {<br>        Node newNode = new Node(data);<br>        if (head == null) {<br>            head = newNode;<br>        } else {<br>            Node temp = head;<br>            while (temp.next != null) {<br>                temp = temp.next;<br>            }<br>            temp.next = newNode;<br>        }<br>    }<br><br>    // Deletion from a specific position<br>    public void delete(int position) {<br>        if (head == null) return;<br>        Node temp = head;<br>        if (position == 0) {<br>            head = temp.next;<br>            return;<br>        }<br>        for (int i = 0; temp != null &amp;&amp; i &lt; position - 1; i++) {<br>            temp = temp.next;<br>        }<br>        if (temp == null || temp.next == null) return;<br>        temp.next = temp.next.next;<br>    }<br><br>    // Traversal<br>    public void traverse() {<br>        Node temp = head;<br>        while (temp != null) {<br>            System.out.print(temp.data + &quot; &quot;);<br>            temp = temp.next;<br>        }<br>    }<br><br>    public static void main(String[] args) {<br>        LinkedListExample list = new LinkedListExample();<br>        list.insert(1);<br>        list.insert(2);<br>        list.insert(3);<br>        list.insert(4);<br>        System.out.print(&quot;Linked List: &quot;);<br>        list.traverse();<br><br>        list.delete(2);<br>        System.out.print(&quot;\nAfter Deletion: &quot;);<br>        list.traverse();<br>    }<br>}</pre><h4>3. Stack</h4><p><strong><em>Definition:</em></strong></p><p>A <a href="https://www.w3schools.com/dsa/dsa_data_stacks.php"><strong>stack </strong></a>is a linear data structure that follows the Last In, First Out (LIFO) principle. The element that is added last is the first to be removed.</p><p><strong><em>Advantages:</em></strong></p><ul><li>Simple and efficient implementation.</li><li>Useful for managing function calls and recursion.</li></ul><p><strong><em>Disadvantages:</em></strong></p><ul><li>Limited access to elements (only the top element is accessible).</li></ul><p><strong><em>Use Cases:</em></strong></p><ul><li>Expression evaluation and syntax parsing.</li><li>Undo mechanisms in text editors.</li><li>Backtracking algorithms (e.g., navigating mazes).</li></ul><p><strong><em>Operations:</em></strong></p><ul><li>Push: Adding an element to the top of the stack.</li><li>Pop: Removing the top element from the stack.</li><li>Peek/Top: Accessing the top element without removing it.</li><li>Is Empty: Checking if the stack is empty.</li></ul><pre>import java.util.Stack;<br><br>public class StackExample {<br>    public static void main(String[] args) {<br>        Stack&lt;Integer&gt; stack = new Stack&lt;&gt;();<br><br>        // Push operation<br>        stack.push(1);<br>        stack.push(2);<br>        stack.push(3);<br><br>        // Pop operation<br>        System.out.println(&quot;Popped element: &quot; + stack.pop());<br><br>        // Peek operation<br>        System.out.println(&quot;Top element: &quot; + stack.peek());<br><br>        // Traversal<br>        System.out.print(&quot;Stack elements: &quot;);<br>        for (Integer element : stack) {<br>            System.out.print(element + &quot; &quot;);<br>        }<br><br>        // Check if stack is empty<br>        System.out.println(&quot;\nIs stack empty? &quot; + stack.isEmpty());<br>    }<br>}</pre><h4>4. Queues</h4><p><strong><em>Definition:</em></strong></p><p>A <a href="https://www.w3schools.com/dsa/dsa_data_queues.php"><strong>queue</strong></a><strong> </strong>is a linear data structure that follows the First In, First Out (FIFO) principle. The element that is added first is the first to be removed.</p><p><strong><em>Types:</em></strong></p><ul><li>Simple Queue: Basic FIFO structure.</li><li>Circular Queue: The last position is connected back to the first position to form a circle.</li><li>Priority Queue: Each element is assigned a priority, and elements are removed based on priority.</li></ul><p><strong><em>Advantages:</em></strong></p><ul><li>Simple and efficient implementation for FIFO operations.</li><li>Useful for managing tasks and processes in order.</li></ul><p><strong><em>Disadvantages:</em></strong></p><ul><li>Limited access to elements (only front and rear elements are accessible).</li></ul><p><strong><em>Use Cases:</em></strong></p><ul><li>Managing tasks in multi-tasking systems.</li><li>Handling requests in web servers.</li><li>Implementing breadth-first search (BFS) in graphs.</li></ul><p><strong><em>Operations:</em></strong></p><ul><li>Enqueue: Adding an element to the end of the queue.</li><li>Dequeue: Removing the front element from the queue.</li><li>Front: Accessing the front element without removing it.</li><li>Rear: Accessing the last element.</li><li>Is<strong> </strong>Empty: Checking if the queue is empty.</li></ul><p>Understanding these basic <a href="https://www.w3schools.com/dsa/index.php">data structures</a> is fundamental for solving complex problems efficiently. Arrays, linked lists, stacks, and queues each have unique characteristics, advantages, and use cases, making them suitable for different scenarios in programming and software development. Mastery of these data structures will provide a strong foundation for learning more advanced data structures and algorithms.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bc3eaf6ef65" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>