<?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: almokhtar bekkour</title>
    <description>The latest articles on DEV Community by almokhtar bekkour (@almokhtar).</description>
    <link>https://dev.to/almokhtar</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%2F100438%2Ff1c839dc-45e2-4100-aa46-ceac937f3161.jpg</url>
      <title>DEV Community: almokhtar bekkour</title>
      <link>https://dev.to/almokhtar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/almokhtar"/>
    <language>en</language>
    <item>
      <title>create a modal component with stimulus js</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Sun, 11 Dec 2022 15:21:26 +0000</pubDate>
      <link>https://dev.to/almokhtar/create-a-modal-component-with-stimulus-js-n59</link>
      <guid>https://dev.to/almokhtar/create-a-modal-component-with-stimulus-js-n59</guid>
      <description>&lt;p&gt;Here is an example of how you could create a modal component with Stimulus.js:&lt;/p&gt;

&lt;p&gt;// controllers/modal_controller.js&lt;br&gt;
import { Controller } from "stimulus"&lt;/p&gt;

&lt;p&gt;export default class extends Controller {&lt;br&gt;
  static targets = ["overlay", "content", "closeButton"]&lt;/p&gt;

&lt;p&gt;open() {&lt;br&gt;
    this.overlayTarget.classList.add("is-active")&lt;br&gt;
    this.contentTarget.classList.add("is-active")&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;close() {&lt;br&gt;
    this.overlayTarget.classList.remove("is-active")&lt;br&gt;
    this.contentTarget.classList.remove("is-active")&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;toggle() {&lt;br&gt;
    this.overlayTarget.classList.toggle("is-active")&lt;br&gt;
    this.contentTarget.classList.toggle("is-active")&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;// Event handler for the "click" event on the close button&lt;br&gt;
  closeButtonClick(event) {&lt;br&gt;
    event.preventDefault()&lt;br&gt;
    this.close()&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;This modal component uses a few classes to control its visibility:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;is-active: shows the modal
is-inactive: hides the modal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To use this component in your HTML, you would need to add the following markup:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="#"&amp;gt;Close&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This will create a modal with an overlay, a content area, and a close button. When the close button is clicked, it will call the closeButtonClick method on the modal controller, which will hide the modal.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Merge Two Binary Trees by doing Node Sum (Recursive and Iterative) javascript</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Sun, 11 Dec 2022 14:42:53 +0000</pubDate>
      <link>https://dev.to/almokhtar/merge-two-binary-trees-by-doing-node-sum-recursive-and-iterative-javascript-50cd</link>
      <guid>https://dev.to/almokhtar/merge-two-binary-trees-by-doing-node-sum-recursive-and-iterative-javascript-50cd</guid>
      <description>&lt;p&gt;To merge two binary trees by doing a node sum, you can use either a recursive or an iterative approach. Here is how you could implement this using each approach in JavaScript:&lt;/p&gt;

&lt;p&gt;Recursive approach&lt;/p&gt;

&lt;p&gt;Create a function that takes two binary trees as arguments and returns their merged tree.&lt;/p&gt;

&lt;p&gt;In the function, check if one of the trees is null. If so, return the other tree.&lt;/p&gt;

&lt;p&gt;If both trees are non-null, create a new node with the value equal to the sum of the values of the two nodes.&lt;br&gt;
Set the left child of the new node to the result of merging the left children of the two nodes.&lt;/p&gt;

&lt;p&gt;Set the right child of the new node to the result of merging the right children of the two nodes.&lt;/p&gt;

&lt;p&gt;Return the new node.&lt;/p&gt;

&lt;p&gt;Here is an example of what the main parts of your solution might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node {
  constructor(value) {
    this.value = value
    this.left = null
    this.right = null
  }
}

function mergeTrees(t1, t2) {
  if (t1 == null) return t2
  if (t2 == null) return t1

  const node = new Node(t1.value + t2.value)
  node.left = mergeTrees(t1.left, t2.left)
  node.right = mergeTrees(t1.right, t2.right)

  return node
}

const t1 = ...
const t2 = ...
const mergedTree = mergeTrees(t1, t2)

// display the merged tree
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Modify a binary tree to get Preorder traversal using right pointers only</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Sun, 11 Dec 2022 14:38:29 +0000</pubDate>
      <link>https://dev.to/almokhtar/modify-a-binary-tree-to-get-preorder-traversal-using-right-pointers-only-5b6p</link>
      <guid>https://dev.to/almokhtar/modify-a-binary-tree-to-get-preorder-traversal-using-right-pointers-only-5b6p</guid>
      <description>&lt;p&gt;To modify a binary tree to perform a preorder traversal using only the right pointers, you will need to make some changes to the tree structure and the traversal algorithm. Here is one way you could approach this problem:&lt;/p&gt;

&lt;p&gt;In the binary tree, add a new pointer to each node that points to the node's rightmost descendant (or null if the node has no right descendants). This pointer will be used during the traversal instead of the node's right pointer.&lt;/p&gt;

&lt;p&gt;Write a function to perform the preorder traversal. This function should start at the root node and visit the nodes in the following order: the root, the root's left child, the root's left child's left child, etc. until it reaches a leaf node.&lt;/p&gt;

&lt;p&gt;At each step of the traversal, the function should use the new rightmost descendant pointer to move to the next node in the traversal. If the current node has no rightmost descendant, the function should backtrack to the nearest ancestor that has a rightmost descendant and move to that descendant.&lt;/p&gt;

&lt;p&gt;The traversal should continue until it has visited all of the nodes in the tree.&lt;/p&gt;

&lt;p&gt;Here is an example of what the main parts of your solution might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
class Node {
  constructor(value) {
    this.value = value
    this.left = null
    this.right = null
    this.rightmost = null // new pointer to rightmost descendant
  }
}

class BinaryTree {
  // initialize the tree and set the root node

  traversePreorder() {
    // perform a preorder traversal using only the rightmost pointers

    // return the list of nodes visited in preorder
  }
}

const tree = new BinaryTree(...)
const preorder = tree.traversePreorder()

// display the preorder traversal

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

&lt;/div&gt;



&lt;p&gt;You may need to modify the tree structure and the traversal algorithm depending on the specific requirements of your problem.&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>8 ruby metaprogramming examples</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Sun, 11 Dec 2022 14:11:07 +0000</pubDate>
      <link>https://dev.to/almokhtar/8-ruby-metaprogramming-examples-3e19</link>
      <guid>https://dev.to/almokhtar/8-ruby-metaprogramming-examples-3e19</guid>
      <description>&lt;p&gt;Metaprogramming is a powerful technique in the Ruby programming language that allows developers to write code that can manipulate or generate other code at runtime. Here are ten examples of metaprogramming in Ruby:&lt;/p&gt;

&lt;p&gt;Defining methods dynamically: Ruby allows developers to define methods on the fly using the define_method method. This can be useful for creating methods with similar behavior but different names, or for defining methods based on user input.&lt;/p&gt;

&lt;p&gt;Using "method missing" to handle undefined methods: Ruby allows developers to define a special method named "method_missing" that is invoked whenever an undefined method is called. This can be used to provide a default behavior for undefined methods, or to implement functionality such as method overloading.&lt;/p&gt;

&lt;p&gt;Using "constant missing" to handle undefined constants: Similar to method_missing, Ruby also allows developers to define a "constant_missing" method that is invoked whenever an undefined constant is accessed. This can be used to implement lazy loading or other advanced behavior.&lt;/p&gt;

&lt;p&gt;Using "class_eval safe" to define methods on classes: Ruby's class_eval method allows developers to define methods on a class, but it can also be dangerous because it allows arbitrary code to be executed. The class_eval_safe method provides a safer alternative that allows developers to define methods without the risk of executing arbitrary code.&lt;/p&gt;

&lt;p&gt;Using "instance_eval" to define methods on instances: The instance_eval method allows developers to define methods on a specific instance of an object, rather than on the object's class as a whole. This can be useful for creating methods that are specific to a particular instance, or for defining methods that use instance variables.&lt;/p&gt;

&lt;p&gt;Using "define_singleton_method" to define methods on singleton classes: Ruby allows developers to define methods on the "singleton class" of an object, which is a special class that is associated with a specific instance of an object. This can be useful for creating methods that are specific to a particular instance, or for defining methods that use instance variables.&lt;/p&gt;

&lt;p&gt;Using "eval" to execute code dynamically: The eval method allows developers to execute Ruby code that is defined as a string at runtime. This can be useful for implementing features such as a command-line interface or a scripting language within a Ruby application.&lt;/p&gt;

&lt;p&gt;Using "send" to invoke methods dynamically: The send method allows developers to invoke a method on an object by name, rather than by statically calling the method. This can be useful for implementing functionality such as dynamic dispatch or method overloading.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>coding</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Check if string is palindrome without String#reverse</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Sat, 18 Sep 2021 13:15:44 +0000</pubDate>
      <link>https://dev.to/almokhtar/check-if-string-is-palindrome-without-string-reverse-3bpl</link>
      <guid>https://dev.to/almokhtar/check-if-string-is-palindrome-without-string-reverse-3bpl</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def palindrome?(str)
  reversed_str = ''
  i = str.length - 1
  while i &amp;gt;= 0
    reversed_str += str[i]
    i -= 1
  end
  reversed_str == str
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;specs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe "palindrome?" do
    it "should accept a string as an arg" do
      expect { palindrome?("tot") }.to_not raise_error
    end

    context "when the string is the same forwards and backwards" do
      it "should return true" do
        expect(palindrome?("tot")).to eq(true)
        expect(palindrome?("racecar")).to eq(true)
        expect(palindrome?("madam")).to eq(true)
        expect(palindrome?("aa")).to eq(true)
        expect(palindrome?("a")).to eq(true)
      end
    end

    context "when the string is not the same forwards and backwards" do
      it "should return false" do
        expect(palindrome?("cat")).to eq(false)
        expect(palindrome?("greek")).to eq(false)
        expect(palindrome?("xabcx")).to eq(false)
      end
    end

    it "should not use String#reverse" do
      expect_any_instance_of(String).to_not receive(:reverse)
      palindrome?("tot")
    end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ruby</category>
      <category>palindrome</category>
    </item>
    <item>
      <title>Real Time Markdown Preview (35 lines of code)!!</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Sat, 12 Sep 2020 12:04:08 +0000</pubDate>
      <link>https://dev.to/almokhtar/real-time-markdown-preview-35-lines-of-code-422l</link>
      <guid>https://dev.to/almokhtar/real-time-markdown-preview-35-lines-of-code-422l</guid>
      <description>&lt;p&gt;As The title Said, just 35 lines of code i made a markdown real time preview with sinatra and jquery and Github markdown Gem, this is the source code as screenshots.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/almokhtarbr/ruby-scripts/blob/master/markdown/markdown.rb"&gt;source code github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rxn_yRlv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m6uzfjtzqnskvcw0j2wg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rxn_yRlv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m6uzfjtzqnskvcw0j2wg.png" alt="Screenshot 2020-09-12 at 12.45.55"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eRYDcnei--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/at91y4ylnlojdq9f13pu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eRYDcnei--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/at91y4ylnlojdq9f13pu.png" alt="Screenshot 2020-09-12 at 12.46.32"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TudAwATY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ebij1f0jvf8u48vw171o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TudAwATY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ebij1f0jvf8u48vw171o.png" alt="Screenshot 2020-09-12 at 12.57.46"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
    </item>
    <item>
      <title>I just want to write code!</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Sun, 06 Sep 2020 21:13:00 +0000</pubDate>
      <link>https://dev.to/almokhtar/i-just-want-to-write-code-17oj</link>
      <guid>https://dev.to/almokhtar/i-just-want-to-write-code-17oj</guid>
      <description>&lt;p&gt;I used to be under the impression that the job of a software developers was just to write code. I know I’m not alone in having been guilty of thinking that way.&lt;/p&gt;

&lt;p&gt;The fact is that a majority of our time in the software development field is spent dealing with people, not with computers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you want to be a good software developer, you have to learn to deal effectively with people&lt;/strong&gt;(even if writing code is the part of your job you enjoy the most).&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://twitter.com/almokht01385206/status/1302709890562035712?ref_src=twsrc%5Etfw"&gt;click Here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>career</category>
      <category>productivity</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Hidden Feature Rails</title>
      <dc:creator>almokhtar bekkour</dc:creator>
      <pubDate>Mon, 24 Aug 2020 17:03:46 +0000</pubDate>
      <link>https://dev.to/almokhtar/hidden-feature-rails-5h7j</link>
      <guid>https://dev.to/almokhtar/hidden-feature-rails-5h7j</guid>
      <description>&lt;p&gt;Often, we discover an edge case, or know we want to improve some aspect of our code, but don’t have the time or energy to get to it right now. Hopefully we document these notes somewhere, but even if we do document them, there are some problems.&lt;br&gt;
If we use an external task manager, these tasks could get out of sync with the actual codebase. And unless you leave a file and line number, you might not remember where exactly the issue is.&lt;br&gt;
You might leave comments in your code, but those will inevitably be forgotten and ignored.&lt;/p&gt;

&lt;p&gt;Rails comes with a hidden feature to help with managing your list of to-dos. As you’re writing code, you can leave one of these three notes:&lt;/p&gt;




&lt;p&gt;"#TODO: handle edge case where x happens"&lt;br&gt;
"#FIXME: this breaks under x condition"&lt;br&gt;
"#OPTIMIZE: this takes 5 database queries"&lt;/p&gt;




&lt;p&gt;And then, running rake notes (or rn if you’re making use of the aliases in the Aliases for Common Rails Commands section) will enumerate every note you’ve left in your code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh1ldxwk0wtxzihekjhon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh1ldxwk0wtxzihekjhon.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While you still have to take the initiative to go back and refactor your code, this will at least give a quick overview of what’s left to be done in your application and where to find it.&lt;/p&gt;

&lt;p&gt;Don’t like the default TODO, FIXME and OPTIMIZE? You can also enumerate custom annotations:&lt;/p&gt;

&lt;p&gt;rake notes:custom ANNOTATION=NOTE&lt;/p&gt;

</description>
      <category>rails</category>
    </item>
  </channel>
</rss>
