<?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 Batoul Alkarim on Medium]]></title>
        <description><![CDATA[Stories by Batoul Alkarim on Medium]]></description>
        <link>https://medium.com/@batoulalkarim1?source=rss-d0d295c41763------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7duYVmIyxAztbukXgGDyvQ.jpeg</url>
            <title>Stories by Batoul Alkarim on Medium</title>
            <link>https://medium.com/@batoulalkarim1?source=rss-d0d295c41763------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:26:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@batoulalkarim1/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[JavaScript: isPalindrome]]></title>
            <link>https://medium.com/@batoulalkarim1/javascript-ispalindrome-c8a8a6605c53?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8a8a6605c53</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[conditional-statements]]></category>
            <category><![CDATA[for-loop]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 18:58:17 GMT</pubDate>
            <atom:updated>2023-08-21T18:58:17.801Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Beginners Walkthrough</blockquote><p>I’m currently refreshing my JS skills and I came across one of my favorite functions, so let’s talk about it! This walk through assumes you know the absolute basics of JavaScript, including the different data types.</p><p><em>(A palindrome is a word that is spelled the same way backwards as it is forwards. RACECAR is a palindrome and so is KAYAK.)</em></p><p>Here you’ll see the completed isPalindrome function, we’re going to break it down line by line!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*daNLWE6n2noPv1v-Fr1Qig.png" /><figcaption>Completed isPalindrome Function</figcaption></figure><h3>🔨 Breakdown:</h3><p>Our isPalindrome function is meant to be re-usable, so we won’t be specifying the exact string it takes in. Instead, we enter the parameter <strong>string.</strong></p><p>🔬On line 2 we are initializing a variable named <strong>reversed </strong>and setting it equal to an empty string. We did that because we’re going to take whatever string the user gives us, and literally reverse it, letter by letter. After we’ve assembled the entire reversed word, we’re going to check it against the word the user provided us. If the words are identical, boom!! We’ve got ourselves a palindrome! If not, then we’re going to return <strong>false.</strong></p><p>🔬On line 3 we create a <strong>for loop</strong>. This loop has 3 expressions, separated by semi colons. Line 3 is basically saying:</p><ul><li><strong>let i = string.length -1; </strong>: This is the opposite of the for loops we’re used to. We’re used to initializing the index (<strong>i) </strong>to 0. When we set this expression we’re telling the program to start our indexing at the very last value of the string provided us, instead of the first value. Example: let’s say our string is the word <strong>&quot;Dog&quot;</strong>. If our expression was initializing the index (<strong>i</strong>) to 0 like we normally would, we would be interacting with the letter “<strong>D”</strong> first. Since we are targeting the last index in the string, we are going to interact with the letter <strong>“G”</strong> first. This is going to make reversing our string incredibly easier than other methods.</li><li><strong>i &gt;= 0;</strong> : This expression is our conditional. We are telling the program, as long as the index we’re interacting with is greater than or equal to the zeroeth index, keep running this loop. I had to think about this for a second when I first started coding because… what even is that. But it actually makes sense because we start counting everything in code (array elements, objects, string characters, etc.) at 0, not 1. For example, here’s an array with three elements: <strong>const animals = [&quot;dog&quot;, &quot;cat&quot;, &quot;bird&quot;];</strong> You would think “dog” is the first element, but it’s technically the zeroeth element. “cat” is the element at index 1. It’s a little tricky, but you’ll catch the hang of it!</li><li><strong>i--;</strong> : This is our last expression and all this is telling the program is to count backwards by 1. So if our word has 6 characters, we are going to start at the final letter, and each time the loop runs, we’re going to go backwards one letter!</li></ul><p>🔬On line 4, we’re officially interacting with a single character, since we set our conditionals/expressions in line 3. Let’s breakdown what this line means and does: <strong>reversed += string[i]</strong></p><ul><li><strong>reversed : </strong>this is the empty string we initiated on line 2. (We initiated it with the word <strong>let </strong>so that we can mutate it later on, and that’s exactly what we’re about to do.)</li><li><strong>+= : </strong>this operator is shorthand. It’s actually the exact same as saying: <strong>reversed = reversed + string[i]</strong>. So we’re telling our program to take our <strong>reversed </strong>string (which is empty on the first loop) and to add the character we’re interacting with to that string.</li><li><strong>string[i]</strong> : this is the specific character we’re interacting with from our string. Since we set our three expressions to read the string backwards, this value will be the last character of our string on the first iteration of our loop!</li></ul><p>And that was really all of the heavy lifting right there! All that’s left is our if statement that checks if the words are identical or not!</p><pre>if (reversed === string) {<br>    return true;<br> } else {<br>    return false;<br>}</pre><p>After our for loop has gone through every letter in our string, (the one that the user passed to the function in line 1), and added it to our <strong>reversed</strong> string, we should have the whole word backwards. This <strong>if statement</strong> checks if our two words are identical, and returns true if they are, and false if they aren’t.</p><p>That’s our isPalindrome function in action! I hope you learned something new! Happy Coding :)</p><h3>Stay Tuned!</h3><p>If you enjoy my content or would like to learn more about me, you can visit my socials!</p><p><a href="https://www.batoulalkarim.com/">Website</a> 🌸 <a href="https://www.instagram.com/batoulalkarim/">Instagram</a> 🌸 <a href="https://github.com/batoulalkarim">Github</a> 🌸 <a href="https://www.linkedin.com/in/batoulalkarim/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8a8a6605c53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[$$ Ruby Currency Converter $$]]></title>
            <link>https://blog.devops.dev/ruby-currency-converter-bfa6702d1fbb?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfa6702d1fbb</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Thu, 18 May 2023 16:40:04 GMT</pubDate>
            <atom:updated>2023-08-21T18:53:22.932Z</atom:updated>
            <content:encoded><![CDATA[<p>A step-by-step guide to building a Currency Converter in Ruby</p><p>This walkthrough will guide you through the process of building a Currency Converter with Ruby. We’ll utilize the Open Exchange Rates API to fetch real-time exchange rates, enabling users to convert their currency to any desired type. Follow along on your end!</p><h3>Step 1: Setting Up the Project</h3><p>To begin, create a new directory and initialize a new Ruby project like this:</p><pre>mkdir currency-converter<br>cd currency-converter<br>touch main.rb</pre><p>Then, open main.rb in a text editor.</p><h3>Step 2: Fetch Exchange Rates</h3><p>Before we can start coding, we need to get an API key from Open Exchange Rates. These are the steps:</p><ul><li>Navigate to <a href="https://openexchangerates.org/signup">this website</a>, and click the blue “Free Plan” text.</li><li>Fill out the form and hit continue. You should be redirected to your Dashboard.</li><li>In the navigation bar, click “App IDs”.</li><li>You should already see an APP ID generated for you. It will be a string of letters and numbers. Copy that string of characters, that is your API key.</li></ul><p>Now we can code!</p><p>Now back in main.rb, add this code:</p><pre>require &#39;json&#39;<br>require &#39;net/http&#39;<br><br>def fetch_exchange_rate(base_currency, target_currency)<br>  api_key = &#39;YOUR_API_KEY&#39;  # Replace with your actual API key<br>  url = &quot;https://openexchangerates.org/api/latest.json?app_id=#{api_key}&quot;<br>  uri = URI(url)<br>  response = Net::HTTP.get(uri)<br>  rates = JSON.parse(response)[&#39;rates&#39;]<br><br>  base_rate = rates[base_currency]<br>  target_rate = rates[target_currency]<br><br>  if base_rate &amp;&amp; target_rate<br>    conversion_rate = target_rate / base_rate<br>    return conversion_rate<br>  else<br>    return nil<br>  end<br>end</pre><p>The ‘fetch_exchange_rate’ function takes in two parameters” <strong>base_currency </strong>and <strong>target_currency. </strong>It fetches the latest exchange rates from the API and calculates the conversion rate between the two currencies.</p><p><strong>**Make sure to replace ‘YOUR_API_KEY’ with your actual API key**</strong></p><h3>Step 3: Converting Currency</h3><p>Now we need to write a function to perform the currency conversion based on the exchange rates. We’re going to add a function named <strong>convert_currency </strong>to main.rb :</p><pre>def convert_currency(amount, base_currency, target_currency)<br>  conversion_rate = fetch_exchange_rate(base_currency, target_currency)<br>  <br>  if conversion_rate<br>    converted_amount = amount * conversion_rate<br>    return converted_amount.round(2)<br>  else<br>    return nil<br>  end<br>end</pre><p>The <strong>convert_currency </strong>function takes in three parameters: amount, base_currency, and target_currency. It calls the <strong>fetch_exchange_rate </strong>function to get the conversion rate and then performs the conversion. We return the converted amount and round it to 2 decimal places.</p><h3>Step 4: User Interaction</h3><p>Great! We have the core functions in place, but we still need a (very simple) user interface for the currency-converter. In our main.rb file, add this code snippet:</p><pre>def prompt(message)<br>  print &quot;#{message}: &quot;<br>  gets.chomp<br>end<br><br>def run_converter<br>  amount = prompt(&#39;Enter the amount to convert&#39;)<br>  base_currency = prompt(&#39;Enter the base currency&#39;)<br>  target_currency = prompt(&#39;Enter the target currency&#39;)<br><br>  converted_amount = convert_currency(amount.to_f, base_currency.upcase, target_currency.upcase)<br><br>  if converted_amount<br>    puts &quot;#{amount} #{base_currency} is equal to #{converted_amount} #{target_currency}&quot;<br>  else<br>    puts &quot;Currency conversion is not available for the specified currencies.&quot;<br>  end<br>end<br><br>run_converter</pre><p>We have a <strong>promp</strong>t function that takes in a message and stores the user’s entered value. The <strong>run_converter</strong> function uses our prompt function and saves the value to our three variables: <strong>amount</strong>, <strong>base_currency</strong>, and <strong>target_currency</strong>.</p><p>Annnnnnd, we’re done!!</p><p>To use your program, open up your terminal (making sure you’re in the right directory) and enter this command:</p><pre>ruby main.rb</pre><p>You should now be prompted to enter the amount to convert! It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2kHSoHQ4XTUMHVQY5_UqQ.png" /><figcaption>Fin!</figcaption></figure><p>Congratulations! 🎉 You just learned how to build a Currency Converter with Ruby!</p><p>If you choose to take it a step further and integrate a front-end, please reach out to me via LinkedIn and show it to me!</p><p>Happy Coding :)</p><h3>Stay Tuned!</h3><p>If you enjoy my content or would like to learn more about me, you can visit my socials!</p><p><a href="https://www.batoulalkarim.com/">Website</a> 🌸 <a href="https://www.instagram.com/batoulalkarim/">Instagram</a> 🌸 <a href="https://github.com/batoulalkarim">Github</a> 🌸 <a href="https://www.linkedin.com/in/batoulalkarim/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfa6702d1fbb" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/ruby-currency-converter-bfa6702d1fbb">$$ Ruby Currency Converter $$</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[♦️ Ruby Basics ♦️]]></title>
            <link>https://blog.devops.dev/%EF%B8%8F-ruby-basics-%EF%B8%8F-21b304c89692?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/21b304c89692</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[to-do-app]]></category>
            <category><![CDATA[gemfile]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Wed, 17 May 2023 14:02:53 GMT</pubDate>
            <atom:updated>2023-08-21T18:53:46.347Z</atom:updated>
            <content:encoded><![CDATA[<p>A to-do app built with pure Ruby- no Rails.</p><p>This is a walkthrough of how to build a very basic to-do app with Ruby. We’ll be implementing add, read, and delete actions, and i’ll give you all the commands needed to actually build it on your end.</p><h3>Step 1: Setting Up the Project</h3><ol><li>Make sure you have Ruby installed on your computer. You can check the version by running <strong>ruby -v</strong> in your terminal.</li><li>Create a new directory for your project and navigate to it.</li></ol><ul><li>mkdir to-do-app</li><li>cd to-do-app</li></ul><p>3. Initialize a new Ruby project by creating a Gemfile. In your directory, run this command:</p><pre>touch Gemfile</pre><p>4. Open the Gemfile using a text editor (I use VSCode) and add this line of code to it:</p><pre>source &#39;https://rubygems.org&#39;</pre><p>5. Save the Gemfile and run the following command to install the required dependencies:</p><pre>bundle install</pre><h3>Step 2: Creating the Task Class</h3><ol><li>Create a new file called task.rb in your project directory.</li><li>Open task.rb in a text editor and define the <strong>Task </strong>class like this:</li></ol><pre>class Task<br>  attr_accessor :title, :completed<br><br>  def initialize(title)<br>    @title = title<br>    @completed = false<br>  end<br><br>  def complete<br>    @completed = true<br>  end<br><br>  def to_s<br>    status = @completed ? &quot;[X]&quot; : &quot;[ ]&quot;<br>    &quot;#{status} #{@title}&quot;<br>  end<br>end</pre><p>Step 3: Implementing the App Logic</p><ol><li>Create a new file called app.rb in your project directory.</li><li>Open app.rb in a text editor and add the following code to set up the basic app structure:</li></ol><pre>require_relative &#39;task&#39;<br><br>class App<br>  def initialize<br>    @tasks = []<br>  end<br><br>  def add_task(title)<br>    task = Task.new(title)<br>    @tasks &lt;&lt; task<br>  end<br><br>  def list_tasks<br>    @tasks.each { |task| puts task }<br>  end<br><br>  def complete_task(index)<br>    @tasks[index].complete if index &lt; @tasks.length<br>  end<br>end<br><br>app = App.new<br><br># Main application loop<br>loop do<br>  puts &quot;Enter a command: (add/list/complete/quit)&quot;<br>  command = gets.chomp.downcase<br><br>  case command<br>  when &quot;add&quot;<br>    puts &quot;Enter task title:&quot;<br>    title = gets.chomp<br>    app.add_task(title)<br>  when &quot;list&quot;<br>    app.list_tasks<br>  when &quot;complete&quot;<br>    puts &quot;Enter task index:&quot;<br>    index = gets.chomp.to_i<br>    app.complete_task(index)<br>  when &quot;quit&quot;<br>    break<br>  else<br>    puts &quot;Invalid command&quot;<br>  end<br>end</pre><p>Step 4: Running the App</p><ol><li>Open a terminal and navigate to your project directory.</li><li>Run this command to start the to-do app:</li></ol><pre>ruby app.rb</pre><p>3. Follow the prompts in the terminal to add tasks, list tasks, mark tasks as complete, and exit the app.</p><p>Congratulations! You have successfully built a basic to-do app using Ruby.</p><p>You should be able to add, read, or delete tasks through your terminal! You can even mark a task as “complete” by putting an X next to it (that’s what our def complete_task method does). The image below is an example of what you should be able to see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgu8p9ZEaIjYAE5bOgMs3w.png" /></figure><p>As you can see, I added three tasks to my to-do list, and I completed the laundry task by accessing it’s index.</p><p>It’s that simple!</p><h3>Stay Tuned!</h3><p>If you enjoy my content or would like to learn more about me, you can visit my socials!</p><p><a href="https://www.batoulalkarim.com/">Website</a> 🌸 <a href="https://www.instagram.com/batoulalkarim/">Instagram</a> 🌸 <a href="https://github.com/batoulalkarim">Github</a> 🌸 <a href="https://www.linkedin.com/in/batoulalkarim/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21b304c89692" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/%EF%B8%8F-ruby-basics-%EF%B8%8F-21b304c89692">♦️ Ruby Basics ♦️</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn How to Read Binary Code in Less Than 5 Minutes]]></title>
            <link>https://medium.com/@batoulalkarim1/how-to-read-binary-code-a-5-minute-lesson-c2327f101fef?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2327f101fef</guid>
            <category><![CDATA[binary-code]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[binary]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 20:22:40 GMT</pubDate>
            <atom:updated>2023-08-21T18:54:08.556Z</atom:updated>
            <content:encoded><![CDATA[<p>By the end of this article you’re going to know how to read and write binary code. It is insanely easy and a cool piece of knowledge to teach your friends!</p><h3>What is Binary?</h3><ul><li>It’s an ON and OFF system of counting. 0s represent OFF and 1s represent ON. You can also think of it as Yes and No.</li><li>Each digit in binary can have 2 values- making the base 2. (It’s okay if this doesn’t make sense- you will see how it is implemented below)</li></ul><h3>How Does It Work?</h3><p>To the naked eye, all we see is 1s and 0s, but they actually translate into symbols (lowercase letters, uppercase letters, and different characters). How?</p><p>Let’s look at an example of an 8 digit binary number:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*UfgD_LHCQpxS_II-yxxDMw.png" /><figcaption>8 digit binary number</figcaption></figure><ul><li>We read binary code from <strong>right to left.</strong></li><li>Because it is a base 2 system, each digit is 2 to the power of n. n represents the placement of that number.</li><li>The 1s and 0s are only telling us if we are using that value or not. 0s mean we are not using it and 1s mean we are. Reference the image below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fwHyvdwd9EiMNVvHcBhxw.png" /></figure><p>As you can see from the image above, each number has a yes or no value represented by either a red X or a green checkmark. We are only going to use the values of the green checkmarks to find out what symbol these 8 numbers represent!</p><p>So let’s do some quick math:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8O9Ko-_nBUclLWMfmtZRg.png" /></figure><p>All we did here was take the values of the green checkmarks to get their number value- remember the green checkmarks represent the ON (or yes) values.</p><p>We then added up those numbers to get a total of 33.</p><p>Now we can take 33 and look it up in the <strong>American Standard Code for Information Interchange </strong>or ASCII chart for short. (When people say they want to write something in Binary what they mean is how to spell things with ASCII).</p><p>Take a look at the chart below and look for 33 under the <strong>decimal column. </strong>Then take a look at what value 33 represents under the <strong>ASCII column:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*991O-k1HGnpe4_j-9QQ26g.png" /><figcaption>This Chart is from <a href="https://web.alfredstate.edu/faculty/weimandn/miscellaneous/ascii/ascii_index.html">Alfred State</a></figcaption></figure><p><strong>You did it!</strong></p><p>Our 8 digit binary code example represents the exclamation point symbol: !</p><p>It is truly that easy!</p><p>Let’s try a harder example by making a word. This will be our first letter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSV9T3t25Xzzc5iYArzjFA.png" /><figcaption>Finding ON and OFF values based on 0s and 1s</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vau5O8LWKF-jY2CMRj0BRg.png" /><figcaption>Calculating the ON values</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vP4hAye0uVkrK4KiWu3MVQ.png" /><figcaption>Adding all ON values to get our decimal number then converting it into a letter using the ASCII table.</figcaption></figure><p>And this will be our second letter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jnLpWaDx8A1iIQd5nEtcUA.png" /><figcaption>Finding ON and OFF values based on 0s and 1s</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sNgQocHDfHya3s5kX3Rclw.png" /><figcaption>Calculating the ON values</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HRSQh4cUVGEaAEtcPhHN8w.png" /><figcaption>Adding all ON values to get our decimal number then converting it into a letter using the ASCII table.</figcaption></figure><p>If we put it all together…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*THJfNZyad3f0cZ3Fxy4YEQ.png" /><figcaption>Binary code for “Woo!”</figcaption></figure><p>You should get the word “Woo!” as in Woo!<strong> You did it!!</strong></p><p>I hope this helped you learn how to read and write binary code! Happy Coding :)</p><h3>Stay Tuned! 💫</h3><p>If you enjoy my content or would like to learn more about me, you can visit my socials!</p><p><a href="https://www.batoulalkarim.com/">Website</a> 🌸 <a href="https://www.instagram.com/batoulalkarim/">Instagram</a> 🌸 <a href="https://github.com/batoulalkarim">Github</a> 🌸 <a href="https://www.linkedin.com/in/batoulalkarim/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2327f101fef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Mint an NFT from Code (Pt. 2)]]></title>
            <link>https://coinsbench.com/how-to-mint-an-nft-from-code-pt-2-e851ae961983?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/e851ae961983</guid>
            <category><![CDATA[ipfs]]></category>
            <category><![CDATA[nft-minting]]></category>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Tue, 10 Jan 2023 17:28:15 GMT</pubDate>
            <atom:updated>2023-08-21T18:54:43.329Z</atom:updated>
            <content:encoded><![CDATA[<p>By the end of this tutorial you will be able to mint as many NFT’s as you want by using the simple smart contract we wrote in the<strong> </strong><a href="https://medium.com/@batoulalkarim1/how-to-create-an-nft-on-ethereum-cd96f22f15f6"><strong>How to Create an NFT on Ethereum</strong></a> tutorial! I will also show you how to view your very own NFT in your Metamask wallet! 🦊</p><p>I am following along with the Alchemy course, they have done an incredible job of explaining the steps to minting an NFT- I have adopted their explanations here.</p><h3>Quick Review: What is Minting?</h3><p>Minting an NFT is the act of publishing a unique instance of a token (in our case ERC721) on the blockchain. In part 1 we wrote and deployed a smart contract to the Goerli network that allows us to mint our own NFTs!</p><p>Today we are going to be <strong>creating the Mint NFT Script</strong>- Let’s get to the fun stuff!</p><h3>Step 1: Using Ethers, Create an Alchemy Provider</h3><p>Using the same repository from part 1, we need to open our scripts folder and create a new file called <strong>mint-nft.js</strong>. We will be using the ethers library to connect to the Alchemy Provider. Add this code to your new file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5MGuOMjx_yxWSvsX37GJkA.png" /></figure><p><strong>NOTE</strong>: Notice how on lines 5 and 8 we are using a variable named API_KEY and not API_URL like we did in Part 1. Just go to your .env file and add this variable, it should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CvA3fV59aD_FOxB28DT4g.png" /><figcaption>.env file</figcaption></figure><h3>Step 2: Get your Contract ABI ✍🏼</h3><p>ABI is short for Application Binary Interface. An ABI is an interface to interact with our smart contract. It’s needed so that we can point to a specific function call that we want to evoke and get a guarantee tthat the function will return the data in the format we are expecting. Thats a big bite to swallow- let’s see how its used!</p><p>Hardhat automatically generates an ABI for us and saves it in the MyNFT.json file- for us to use it, we’ll need to parse out the contents by adding this line of code to our <strong>mint-nft.js </strong>file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxOAzYOv1ItBBp34_bMJOg.png" /></figure><p>If you want to see the ABI you can console.log it like I did on line 11. To see the ABI printed to the console you can run this command in your terminal:</p><pre>node scripts/mint-nft.js</pre><h3>Step 3: Set the metadata of your NFT using IPFS 💫</h3><p>IPFS stands for Interplanetary File System. An IPFS is a decentralized protocol and peer-to-peer network for storing and sharing data in a distributed file system. The IPFS we will be using is called Pinata.</p><p>Our smart contract has a function called <strong>mintNFT</strong> and that function takes in a parameter named <strong>tokenURI. tokenURI </strong>should resolve to a JSON document that describes the NFT’s metadata- which is literally what brings the NFT to life!</p><p>Pinata is going to be where we store our NFT asset and metadata so that we can guarantee our NFT is truly decentralized. If you don’t have a Pinata account, you can create one <a href="https://app.pinata.cloud/signup">here</a>. (it’s free!!)</p><p>Once you have made your account follow these steps to upload your NFT:</p><ul><li>Click the blue <strong>Upload</strong> button</li><li>Pick any image you like and upload it to pinata - this will be the image asset for your NFT.</li><li>After you uploaded successfully, Pinata will provide you with a hash or CID. Copy that hashcode.</li></ul><p>To ensure your upload was successful go to <strong>https://gateway.pinata.cloud/ipfs/&lt;your-hash-here&gt;</strong></p><p>If you see your image, it was successful!</p><p>We need to upload one more file to pinata- but we need to create it first!</p><p><strong>In your root directory: </strong>make a new file named <strong>nft-metadata.json</strong> and add the following code to that file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OIxheaFV5tTk1kWdIRBMaA.png" /></figure><p>Change the data in the json! Add or remove attributes if you like. If you’re coding along make this NFT your own! I decided to make an astronaut bear that lives on Saturn, because why not!</p><p>Once you have finished customizing your NFT, save the file and upload it to Pinata. You’ll use the same steps we used to upload the image asset.</p><h3>Step 4: Create a Signer and an Instance of the Contract ✍🏼</h3><p>We need to define an ethers <strong>Signer </strong>in order to be able to call our functions! To do this we will use our wallet’s private key. To define a contract instance we will need to use the contract’s deployed address, the contract ABI, and the Signer!</p><p>In the <strong>mint-nft.js </strong>file, add this code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJtqjn73pVvXiiSFmf02yA.png" /></figure><p>On line 19 you can see that we have a contract address. We got this address when we deployed our contract in Part 1. If you don’t have that anymore no worries- you can simply re-deploy your smart contract and copy paste the address OR you can look it up on Etherscan.</p><h3>Final Step: Calling the mintNFT function ☎️</h3><p>Last step!! So by now we have uploaded two files to Pinata, our image asset and our <strong>metadata.json</strong> file. We need to get the hashcode (CID) of the metadata file we uploaded.</p><p>To check that it was successfully uploaded, copy that code and paste it into this URL :</p><p>htttps://gateway.pinata.cloud/ipfs/&lt;metadata-hashcode-here&gt;</p><p>You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m2n0L7pXWOBshyQBrZsWbQ.png" /></figure><p>Now that we know it’s been successfully uploaded, we need to call mintNFT function in our <strong>mint-nft.js </strong>file. This is how we’ll do that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-cYlc-W-14iBVj4bor-Qw.png" /></figure><p>Your entire <strong>mint-nft.js </strong>file should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U40y0kJ7WilcmZRrxpHMdw.png" /><figcaption>Completed mint-nft.js file</figcaption></figure><p>We’re all set!! It’s time to mint! Head to your terminal and enter the following command:</p><pre>node scripts/mint-nft.js</pre><p>Your terminal should print something like this:</p><pre>NFT Minted! Check it out at: https://goerli.etherscan.io/tx/0x4716adf0785dfe25fb0c56e04f49aa96cfbebb5f9ea1def9822140ccbf11e526</pre><p>If you follow the URL that was printed you will be able to checkout your NFT mint on Etherscan!</p><p>You can also view your NFT on OpenSea by searching your contract address at this website: <strong>testnets.opensea.io</strong> (because we did all of this on the Goerli testnet).</p><p>You can see my Bearstronomer NFT <a href="https://testnets.opensea.io/assets/goerli/0x07b9d66be59a5e7c2891c5e3e53fef27136680ac/1">here</a>!</p><p>Using the mint-nft.js file you can mint as many NFT’s as you want! Just make sure you are passing in a new tokenURI describing the NFTs metadata — otherwise you’re going to have a bunch of copies of the same NFT with different ID’s.</p><h3>🦊Bonus! View your NFT in your Metamask Wallet 🦊</h3><p>First of all- Congratulations on minting your own NFT!! This step is super easy so lets get to it.</p><p>You’ll need to have Metamask downloaded on your phone and be logged in to the same wallet we used to mint our NFT.</p><h3>Set your network to Goerli</h3><p>At the top of the app press the wallet icon and change your network to Goerli. Since we minted our NFT on the Goerli testnet, we’ll only be able to view it there.</p><h3>Add your NFT to Metamask🦊</h3><p>In the Metamask app, you should see a tab that says NFTs on the right side. Press <strong>Import NFTs. </strong>You should be prompted to enter an address and an ID. The address is going to be the smart contract address and the ID you can find on Etherscan based on the transaction hash!</p><p>Give it a moment, you may even need to refresh a few times- but it will be there!</p><p>Congratulations! You can now view the NFT that you minted in your very own wallet!! I hope this article has helped you get a better understanding of the basics of minting and using IPFS to create an NFT!</p><h3>STAY TUNED! 💫</h3><p>In Part 3 of this series we will go over how to set a price on your NFT and how to create an ERC-1155 Token!</p><p>If you enjoy my content or would like to learn more about me, you can visit my socials!</p><p><a href="https://www.batoulalkarim.com/">Website</a> 🌸 <a href="https://www.instagram.com/batoulalkarim/">Instagram</a> 🌸 <a href="https://github.com/batoulalkarim">Github</a> 🌸 <a href="https://www.linkedin.com/in/batoulalkarim/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e851ae961983" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/how-to-mint-an-nft-from-code-pt-2-e851ae961983">How to Mint an NFT from Code (Pt. 2)</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create an NFT on Ethereum]]></title>
            <link>https://medium.com/@batoulalkarim1/how-to-create-an-nft-on-ethereum-cd96f22f15f6?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd96f22f15f6</guid>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[hard-hat]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Fri, 06 Jan 2023 18:24:51 GMT</pubDate>
            <atom:updated>2023-08-21T18:55:15.604Z</atom:updated>
            <content:encoded><![CDATA[<p>By the end of this tutorial you will know how to write and deploy a Non Fungible (ERC721) Token smart contract using Ethereum and IPFS.</p><p>This is a <strong>10 step walk through</strong> and should take you less than 20 minutes to complete if you choose to follow along. Alchemy does an incredible job of explaining the steps to create an NFT in their <a href="https://docs.alchemy.com/docs/how-to-create-an-nft">tutorial</a>, I have adopted their explanations here.</p><p><strong>Prerequisites:</strong></p><ol><li>You need to have both Node.js(&gt;14) and npm on your local machine.</li><li>You need to create a free <a href="https://university.alchemy.com/">Alchemy</a> account</li><li>Have the Metamask extension installed in your browser</li></ol><h3>STEP 1:</h3><ul><li>After you have created your free Alchemy account, navigate to the Apps drop down menu and click “Create App”.</li><li>Provide a name and description.</li><li>For the Chain, select Ethereum and for Network select Goerli.</li><li>Click the ‘Create App’ button</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HjO5y_W6srDLS-sA4MBTQg.png" /><figcaption>Alchemy Create App- Step 1</figcaption></figure><h3>STEP 2: Create a Metamask Wallet 🦊</h3><p>If you don’t already have Metamask installed to your browser you can do so <a href="https://metamask.io/download/">here</a>.</p><p>Once you have downloaded Metamask make sure to make a new account.</p><p>The final part to this step is to ensure you switch your network to the <strong>Goerli Test Network.</strong></p><p>NOTE: If you do not see Goerli Test Network as an option you may need to follow these steps:</p><ul><li>Open your Metamask wallet and click on your avatar in the top right corner.</li><li>Press Settings</li><li>Press Advanced</li><li>Scroll down and navigate to “Show test networks” and toggle that to <strong>ON.</strong></li></ul><h3>STEP 3: Get Faucet GoerliEth 💸</h3><p>Faucet Eth is just fake Eth we can use to execute transactions. Since we’ll be working on the Goerli test network, we’ll need GoerliEth.</p><p>To get your free Eth you’ll need to have an Alchemy account (which you do by now) and to navigate to this website. Login with your Alchemy account and enter your wallet address. Boom, you’re done!</p><p>Go to this link to get your GoerliEth:</p><p><a href="https://goerlifaucet.com/">https://goerlifaucet.com/</a></p><h3>STEP 4: Create a Node Project</h3><p>In your command line all you need to type are these two commands:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*dTuS37bffDF9ts1M2o19tA.png" /></figure><p>After these commands successfully execute, we are in a good position to install Hardhat.</p><h3>STEP 5: Create a Hardhat Project ⛑</h3><p>Hardhat is a development environment to help you compile, deploy, test, and debug your smart contracts. It is used to help devs create dApps<strong> locally</strong> before deploying them to a live chain.</p><p>In your terminal, run these two commands:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*jSKrMvj7xvA2CC4qAQ1T0w.png" /></figure><p>You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*Svkobly5bsPoPN-4FHXjPQ.png" /></figure><p>You want to select: <strong>Create a JavaScript project </strong>and then agree to all of the default settings (project root, adding a .gitignore, and installing all sample project dependencies).</p><p>If you want to check that everything is running properly, run:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*Jq3IZRxtDMoB7ODhndpsuQ.png" /></figure><p>Finally, now that we have our hardhat dev environment configured, we just need to install the <strong>OpenZeppelin </strong>contract package. This is going to give us access to all of the ERC721 implementations (which is the standard for NFTs). You can install OpenZeppelin by executing this command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*KMdhFcF5Y6LHvRAmFinATQ.png" /></figure><h3>STEP 6: Write the Smart Contract ✍🏼</h3><p>Alright! Half way done and we’re ready to do the fun stuff. Open up the project in your favorite code editor and navigate to the <strong>contracts </strong>folder. There, you need to create a new file called <strong>MyNFT.sol.</strong></p><p>This is what will be in that file, we’ll break down the code line by line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eWi_thUgOQXJRY5o3vIAZQ.png" /></figure><p>In lines 4–6 we imported three OpenZeppelin smart contract classes:</p><ul><li><strong>@openzeppelin/contracts/token.ERC721/extensions/ERC721URIStorage.sol</strong> : this contains the implementation of the ERC721 standard which our NFT smart contract will inherit. This is because if we want our NFT to be valid, it must adhere to all the methods of the ERC721 standard. To learn more about inherited ERC721 functions, you can look <a href="https://eips.ethereum.org/EIPS/eip-721">here</a>.</li><li><strong>@openzeppelin/contracts/utils/Counters.sol</strong> : this import is providing us with a counter that can only increase or decrease by one. Our smart contract uses this counter to keep track of the total number of NFTs we have minted and sets the unique ID to our new NFT.</li><li><strong>@openzeppelin/contracts/access/Ownable.sol : </strong>this import is setting up access control. This means that only the owner of the smart contract (you) can mint an NFT. If you want anyone who interacts with this contract to be able to mint an NFT you can remove this import and remove the word <strong>Ownable </strong>on line <strong>8 </strong>and remove <strong>onlyOwner</strong> on line <strong>16.</strong></li></ul><p>In lines 8–27 we have our custom NFT smart contract. It’s pretty short, it only has a counter, constructor, and one function. We were able to have such a short contract because we implemented most of the methods needed to create an NFT using OpenZeppelin.</p><p>Finally, on line 14 we have our function <strong>mintNFT() </strong>which is what allows us to actually mint! This function takes in two variables:</p><ol><li><strong>address recipient: </strong>this is specifying the address that will receive the NFT that was just minted</li><li><strong>string memory tokenURI: </strong>this is a string that should resolve to a JSON document that describes the NFT’s metadata. An NFT’s metadata is very important because it’s what brings the NFT to life with attributes like name, description, image, and any others.</li></ol><p>Our mintNFT() function will essentially call some methods from the inherited ERC721 library and ultimately return a number that represents the ID of the new NFT.</p><h3>STEP 7: Connecting Alchemy and Metamask to your Project 🫱🏻‍🫲🏼</h3><p>We now have a Metamask account, Alchemy account, and our very own smart contract. We need to connect the three.</p><p>Every transaction from your wallet requires a signature and that signature is verified using your wallets <strong>private key. </strong>To give our smart contact permission we can store our private key and Alchemy API key in an environment file.</p><p><strong>NOTE:</strong> Be very careful if you are pushing your work up to github. Your private key is only for you and should never be shared with anyone. We are going to be putting it in a .env file so ensure that your .env file is in your .gitignore file or your wallet may be compromised.</p><p>You need to install the <strong>dotenv package</strong> in your project directory. You can do this by running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*5UnVU_ICWOkasNNep3E_MQ.png" /></figure><p>You can now create your <strong>.env </strong>file in your root directory. It should be named exactly <strong>.env, </strong>nothing else.</p><p>You need to get your Metamask private key, if you don’t know how to do that, follow <a href="https://metamask.zendesk.com/hc/en-us/articles/360015289632-How-to-Export-an-Account-Private-Key">these instructions.</a></p><p>You will also need your API key from Alchemy, to do that:</p><ul><li>Head to the Alchemy dashboard and under the <strong>Apps</strong> tab, select your App that you created earlier.</li><li>On the top left select <strong>View Key</strong></li><li>Copy your API KEY to the clipboard.</li></ul><p>Now you can fill out your .env file. It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*YkW7OihsF9EqOByLdLHRcQ.png" /></figure><p>NOTE: you can copy the API_URL and just paste your API key at the end where it says “your-api-key”</p><h3>STEP 8: Update your hardhat.config.js File ⛑</h3><p>We have added some new plugins and dependencies so we need to update our<strong> hardhat.config.js</strong> file so that our project knows all about them! This is what your updated file should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*57dZjYf8KiX8usXMqBtQQA.png" /></figure><h3>STEP 9: Write the Deployment Script ✍🏼</h3><p>Now it’s time to add our last file!</p><p>Under the scripts/ folder you should already see a deploy.js file. Remove it’s contents and replace it with the code from below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yl4mXkGb5ItrDW3MEKX-PA.png" /></figure><p>Hardhat has a Contracts tutorial where they do a great job of explaining what each of these lines do. You can read it <a href="https://hardhat.org/tutorial/testing-contracts#writing-tests">here</a>, but for now I will give the explanation Alchemy provided:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*b2qG31RdBcFZWhyrLGTsuA.png" /></figure><blockquote>A ContractFactory in ethers.js is an abstraction used to deploy new smart contracts, so MyNFT here is a factory for instances of our NFT contract. When using the hardhat-ethers plugin, ContractFactory and Contract instances are connected to the first signer by default.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8v1pSIuyiTHYUdqYcnPTg.png" /></figure><p>Calling deploy() on a ContractFactory will start the deployment and return a <strong>Promise</strong> that resolves to a <strong>Contract. </strong>This is the object that has a method for each of our smart contract functions.</p><h3>STEP 10: Deploy the Contract 🚀</h3><p>We made it to the final step!! We’re finally ready to deplloy the smart contract! In your terminal, ensure you are at the root directory and run this command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*mo7bvCsoXKOEIDj3QxJxqg.png" /><figcaption>Command to execute deployment</figcaption></figure><p>You should see something like this displayed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*5j3eNOnTtetHfL8nK2Oslw.png" /></figure><p>Now, if you go to <a href="https://goerli.etherscan.io/">Goerli Etherscan</a> and search the address that was just displayed in your terminal (that is your contract address), you should see that your contract was successfully deployed! The transaction will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oauDDrA8ekXEPIMZWRGlgA.png" /></figure><p>The <strong>From </strong>address should match your Metamask account address, and the <strong>TO </strong>address should say <strong>Contract Creation.</strong></p><p>CONGRATULATIONS!! 🎉 🎊 🍾 You just deployed your NFT smart contract tot the Ethereum chain!</p><p>If you want to understand more about whats going on “under the hood”, you can do so by navigating back to your Alchemy dashboard and clicking “Explorer”.</p><p>Here you’re going to see a bunch of JSON-RPC calls that Hardhat/Ethers made for us when we called the .deploy() function.</p><p>The two important ones to note are <strong>eth_sendRawTransaction, </strong>which is the request to actually write our smart contract on the the Goerli chain, and <strong>eth_getTransactionByHash, </strong>which is the request to read information about our transaction given the hash.</p><h3>STAY TUNED! 💫</h3><p>In Part 2 we will actually be interacting with our smart contract by minting an NFT!</p><p>If you enjoy my content or would like to learn more about me, you can visit my socials!</p><p><a href="https://www.batoulalkarim.com/">Website</a> 🌸 <a href="https://www.instagram.com/batoulalkarim/">Instagram</a> 🌸 <a href="https://github.com/batoulalkarim">Github</a> 🌸 <a href="https://www.linkedin.com/in/batoulalkarim/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd96f22f15f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner’s Guide to Big O Notation]]></title>
            <link>https://medium.com/@batoulalkarim1/beginners-guide-to-big-o-notation-eaff76712053?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaff76712053</guid>
            <category><![CDATA[big-o-notation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[big-o]]></category>
            <category><![CDATA[time-complexity]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Thu, 14 Jul 2022 16:07:02 GMT</pubDate>
            <atom:updated>2023-08-21T18:56:01.119Z</atom:updated>
            <content:encoded><![CDATA[<p>What is Big O Notation? Answers and Examples!</p><p><strong>What is it and why do we need to know it?</strong></p><p>Big O Notation is used to describe the worst case scenario when it comes to the performance of an algorithm. There are other notations that describe the average and best-case scenario of an algorithm, but since we’re programmers, we’re gonna focus on the worst case and do our best to avoid it. Big O Notation is a lot- but hopefully these examples break down the basics!</p><p><strong>So then Why Big O?</strong></p><p>Big O is important because it provides us the ability to evaluate your code and not only solve our problems efficiently, but also determine what the best way to solve the problem is. It’s also more likely than not going to come up in technical interviews!</p><p>Below you’ll find a very handy chart that describes the different types of Big O Notation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RnWbE6kD5Dn_39axoR2uAg.png" /><figcaption>Big-O Complexity Chart</figcaption></figure><p>Don’t freak out- I know this can be overwhelming if you’ve never seen some of this crazy syntax! It’s totally OK if you don’t know what’s going on, we’re gonna break it down:</p><h3><strong>O (1)</strong></h3><p>O(1) is our first example of Big O Notation and it simply means that the operation will execute in a constant amount of time, regardless of the size of our input. A good question to ask yourself is how many operations does my function require if the size of my array is increased from 100 to 1,000 or even 10,000?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*oGPldwMSbQysRYcNZsRMdg.png" /><figcaption>An Example of O(1) — Constant Time Complexity</figcaption></figure><p>This is a super simple function. It’s going to take ourArray, find the element located at index 3, and log it to the console. Since we’re literally only grabbing a single element from ourArray, it doesn’t matter how big the size of the array gets, it will always take constant time- or <strong>O(1).</strong></p><h3><strong>O(n)</strong></h3><p>O(n) is the most common Big O Notation. We say code has the time complexity of O(n) or it takes Linear Time when the number of inputs increases, and the number of operations increases linearly. Let’s break that down:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*_iEp3EEX5kNAWtXCgzvpWA.png" /><figcaption>Example of O(n) Notation</figcaption></figure><p>What we’re trying to see here is how the runtime of function ‘findTheSum’ grows, as the input increases. What would happen if our array had 1 item? or 100 items? or even 10,000 items, does the efficiency of this function increase?</p><p>This is pretty self explanatory, but our function is going to loop through our array depending on the amount of items in it. So 10 items, it’ll loop 10 times, and so on.</p><p>We say the above code has the time complexity of O(n) because the number of operations increases with the input. Here, <strong>n</strong> simply means that the Big O depends on the number of inputs.</p><h3><strong>O(N²)</strong></h3><p>With O(n), the number of operations it performs is determined in <em>direct </em>proportion to the input.</p><p>With <strong>O(N²), </strong>the number of operations scales in proportion to the <em>square</em> of the input. This Notation is common with algos that use nested loops/iterations.</p><p>Let’s take a look at an example of a nested loop and break this down:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*1yVSDHT3olKdki4BDVLxew.png" /><figcaption>Example of O(n²)</figcaption></figure><p>Here, we are trying to find the sum of every pair in this array. We have an outer loop and an inner loop. We’re performing <strong>n </strong>operations of the inner loop and are operating on the outer loop <strong>n </strong>times. Meaning- we are performing a total of <strong>i * j </strong>operations. Since we are using the same input we could write: <strong>n * n, </strong>a.k.a., <strong>n².</strong></p><h3><strong>O(2^n)</strong></h3><p>***We want to avoid this at all costs. In interviews and in coding this time complexity is something we want to <strong>avoid. O(2^n) </strong>represents an algorithm that <strong>doubles </strong>with each addition to the input.</p><p>The growth here is exponential! For example, if we have n = 2 inputs, then it will perform 4 times, and if we have n = 4, it performs 16 times. This is because 2 x 2 x 2 x 2 = 16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*-61ph6avkxCsclqq769iVw.png" /><figcaption>Example of O(2^n)- Bad, Bad, Bad!!</figcaption></figure><p>Think about this- if our input was 10, this function would perform 2¹⁰ operations… if you do that math that’s <strong>1024 times!!! ~yikes~</strong></p><p><strong>O(log n)</strong></p><p>Ahhh, logarithms. We haven’t talked about that yet and that’s only because it’s a litttttle tricky. We typically see log when we’re searching through a set of data.</p><p>The easiest way to illustrate O(log n) is with <strong>Binary Search. </strong>Binary search is a super simple searching algorithm. It can only be used on data thats already been sorted. Once the data is sorted, the binary search will repeatedly divide the search interval in half. It always starts in the middle of the data set, if that value is less than what we’re searching for, it will chop the first half of the dataset. It then moves to the middle of what’s left of our dataset and repeats this process until we have our targeted element or value.</p><p>This type of data search is extremely beneficial when you’re working with large sets of data, because it literally discards half the data each time it searches.</p><p>Let’s try to visualize this:</p><p>Let’s say you have your yearbook. The school you went to has exactly 1000 students, and you’re trying to find your picture. You open up the year book to the middle page, which is the Junior class, but you’re a senior. You know the first half of the book is going to be Freshmen and Sophomores. The binary search will literally rip out the pages with Freshmen and Sophomores and leave you with 500 pages, the Juniors and Seniors.</p><p>We open the book again to the middle and now we’re at the very first Senior, Alfonzo Alexander. Knowing you’re going to be on the right side of this data set, the binary search will cut the yearbook in half again, and leave you with just seniors.</p><p><strong>With just two iterations, you’ve chopped 3/4 of the data set.</strong></p><p>In roughly 10 or 11 iterations, we’ll have gone through a dataset with 1000 elements, and found our target value. This is called <strong>logarithmic time complexity, or O(log n).</strong></p><p>Let’s say you went to an even bigger high school with 2000 students. It would only take <strong>one more </strong>iteration to chop 1000 elements. That’s pretty efficient if you ask me! This is a great representation of how the time complexity of Binary Search is <strong>O(log n)</strong>.</p><h3><strong>That was A LOT!</strong></h3><p>But you did it! Now you know the basics of Big O Notation and time complexity. There’s still so much to learn and dive into, but now you have the foundation you need to dive a little deeper! Hope this helped!!</p><p>Below I’ve linked my Github and LinkedIn incase you are interested in viewing some of my work or getting to know more about how I got here! 😁</p><h3>Stay Tuned!</h3><p>If you enjoy my content or would like to learn more about me, you can visit my socials!</p><p><a href="https://www.batoulalkarim.com/">Website</a> 🌸 <a href="https://www.instagram.com/batoulalkarim/">Instagram</a> 🌸 <a href="https://github.com/batoulalkarim">Github</a> 🌸 <a href="https://www.linkedin.com/in/batoulalkarim/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaff76712053" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React JS: Components and Props]]></title>
            <link>https://medium.com/@batoulalkarim1/react-js-components-and-props-1b19cd2ab188?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b19cd2ab188</guid>
            <category><![CDATA[components]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[props]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 01:52:48 GMT</pubDate>
            <atom:updated>2022-06-21T01:53:04.263Z</atom:updated>
            <content:encoded><![CDATA[<p>A beginners guide to components and props</p><h4><strong>Function and Class Components</strong></h4><p>A component can be thought of as a JavaScript function — it accepts a single “props” object as the argument, and returns a React element. The props object contains data from the parent component. We are literally just passing the data to our current component. Below is an example of a valid React component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*ZH106U0nislcGLbjbjogaw.png" /><figcaption>This is an example of a “function component”</figcaption></figure><p>There are two ways to define a React component. The first is a “function component” (like we did above), and the other way is to use an ES6 class:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*XyZB7vjocivnIkzJwcpb4Q.png" /><figcaption>This is an example of an ES6 class</figcaption></figure><p>Some components can be user-defined- this is what a user defined component looks like incase you haven’t seen one before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*vzJqfmo-7Ah9I5ODBMVhPw.png" /><figcaption>This component is depending on the name property value to fill out it’s text</figcaption></figure><p>The React tree of components represents a hierarchical data structure. In other words, props and attributes can be passed down to “children” components, or can be passed up to their “parent” components.</p><p>Below i’ve added an image pointing out what parts of an app can be individual components. As you can see, number 3 is the lime green box with the categories “Name” and “Price”. Inside of number 3 we have the number 4 and 5, each of these represent a component. We have two implementations of the 4’s (Headings): Sporting Goods and Electronics, and we have 6 implementations of the 5&#39;s(Items): Football, Baseball, Basketball, iPod Touch, iPhone 5, and Nexus 7. This is a pretty good representation of how we can make reusable components and work smarter not harder!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/0*o6W3KpCmFP5oWZN6.png" /><figcaption>An example of how to lay out your components</figcaption></figure><h4>OKAY- Back To Props</h4><p>Props are what we get when React sees a user-defined element, React will then pass JSX attributes and children to this component as an object. For Example, the SayHello component below renders “Hello, Batoul” on the page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*VM_T2CszS2FTTUjsmhtFkw.png" /><figcaption>This component returns a &lt;h1&gt;Hello, Batoul&lt;/h1&gt; element.</figcaption></figure><p><strong>Note: Component names always start with a capital letter. </strong>If you make a component and start its name with a lowercase letter, React will treat it like a DOM tag instead of a component. An example of this is &lt;div /&gt; represents an HTML div tag, but &lt;SayHello /&gt; represents an entire component and requires you to import it so it’s in scope.</p><h4>Composing Components</h4><p>One component can render many other components. Common components that are rendered inside a parent component include: buttons, forms, a chat screen, a nav bar, and various input fields.</p><p>Here is an example of an App component rendering sayHello multiple times:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*4wCB25YlLUIAb7S9R3P_xw.png" /><figcaption>The App component rendering multiple different versions of our SayHello component</figcaption></figure><h4>Don’t Be Afraid To Split Components</h4><p>You could have a very hectic heavy component, or just want cleaner code- either way, consider splitting your components into smaller components. Consider this YelpReview component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*cDuBRbOmbydXWFzpHFI8gA.png" /><figcaption>The YelpReview component before we clean it up</figcaption></figure><p>This component accepts an author object, text (string), and a date all as props. It has a lot of nesting which can make it a little difficult to change and reuse any individual part of it. We can create a few components and clean this up like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*M3_aHrUx9mAgRexlu5juAQ.png" /><figcaption>Avatar component</figcaption></figure><p>The Avatar in our Yelp Review doesn’t need to know that it’s being rendered or even where it’s being rendered, so we are able to give the component a more generic name for its props. From the Avatars point of view, it belongs to a user, the user doesn’t become an author until they post a review. React Docs recommend naming props from the component’s POV rather than the context it’s being used in- so that’s exactly what we’re gonna do!</p><p>Now the YelpReview component can be simplified a little bit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*83CJpTAbyA1qyRlH7K9anA.png" /><figcaption>We created a re-usable Avatar component and got rid of our &lt;img /&gt; tag</figcaption></figure><p>I bet we could clean this code up a bit more by extracting a UserInfo component… and I bet we could make that UserInfo component render our Avatar component so we only have to import UserInfo into YelpReview…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*ynpRhUz5-oRYg7GMUTGZ8g.png" /><figcaption>The UserInfo component holding our Avatar component</figcaption></figure><p>This is why components are so great. We have so many options on the layout. We took the Avatar component out of the YelpReview component and put it in our UserInfo component. Our YelpReview is way cleaner now! We could go even further and make a Date component, but I think you get the idea by now! This is what the finished YelpReview component should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*A8tyjgWEI8Sbx2-UN33szg.png" /><figcaption>We replace the entire userInfo &lt;div&gt;&lt;/div&gt; with this new UserInfo component</figcaption></figure><p>Extracting components might seem like busy work in the beginning- but it reeeeally pays off to have reusable components with larger scaled apps. React Docs say it’s a a good rule of thumb to make a component out of the items in your UI you use several times (Button, Panel, Avatar).</p><h4>Final Note on Props:</h4><p>Props are Read-Only; meaning whether your component is declared as a function or a class, it is not allowed to modify it’s own props. There are two functions we want to think about right now: pure and impure.</p><p>This is a pure function because it does not try to change its inputs and always returns the same result for the same inputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*VSfbuyhardpqg7NSiTIS7A.png" /><figcaption>An example of a pure function</figcaption></figure><p>This is an impure function because it is changing it’s own input:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*NJt98Z3XLBG-QmU1BgVtfQ.png" /><figcaption>An example of an impure function</figcaption></figure><p>React has one strict rule:</p><p><strong>All React components must act like pure functions with respect to their props. </strong>(And that’s straight from the React Docs 👀)</p><p>This is where <strong>state </strong>comes in. State allows React components to change their output over time- this is in response to many things like: actions the user takes, responses from the network, and anything else that doesn’t violate the rule. However, I won’t be covering state in this post- if you’re interested in learning more about JSX, props, and components- check out the React Docs:</p><p><a href="https://reactjs.org/docs/components-and-props.html">Components and Props - React</a></p><p>And if you want to learn about implementing state, follow this link👇🏼</p><p><a href="https://reactjs.org/docs/state-and-lifecycle.html">State and Lifecycle - React</a></p><p>Finally, I’m linking the Github repo to my OpenSea Clone. I used tailwind css at the top of my files, but it might be helpful for you to see my component structure and how I reused multiple components. Thanks for reading, hope this helps!</p><p><a href="https://github.com/batoulalkarim/Opensea-Blockchain-Clone">GitHub - batoulalkarim/Opensea-Blockchain-Clone</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b19cd2ab188" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Active Record Associations]]></title>
            <link>https://medium.com/@batoulalkarim1/active-record-associations-1b9e9867283c?source=rss-d0d295c41763------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b9e9867283c</guid>
            <category><![CDATA[database-relationships]]></category>
            <category><![CDATA[many-to-many]]></category>
            <category><![CDATA[one-to-many]]></category>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Batoul Alkarim]]></dc:creator>
            <pubDate>Fri, 01 Apr 2022 14:26:12 GMT</pubDate>
            <atom:updated>2022-04-01T14:26:12.748Z</atom:updated>
            <content:encoded><![CDATA[<p>One To Many And Many To Many Relationships</p><p><strong>Why Active Record?</strong></p><p>Active Record associations make it easy to establish relationships between our models without having to write a bunch of SQL- there are two types of relationships you should know about: <strong>one-to-many, </strong>and <strong>many-to-many.</strong></p><p><strong>One To Many Associations</strong></p><p>The one-to-many relationship creates either a <strong>has-many</strong> or <strong>belongs-to </strong>association in Active Record. Lets build a one-to-many relationship between two models: <strong>organizations </strong>and <strong>reviews. </strong>Our database will be set so that an organization <strong>has many </strong>reviews, and each review <strong>belongs to </strong>a specific organization.</p><p>By writing our two migrations and using the right Active Record macros we should be able to:</p><ol><li>ask an organization about its reviews</li><li>ask a review about its organization.</li></ol><p>Here’s what our Entity Relationship Diagram looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMXB4ssmG6Sh2uvJxaA1IQ.png" /><figcaption>one-to-many ERD</figcaption></figure><p>To build these associations we’ll need Active Record migrations and macros.</p><p>To create a migration you will need to run this code:</p><p><strong>bundle exec rake db:create_migration NAME=create_organizations</strong></p><p>This will create a migration file in your text editor, here is what we would write for our specific example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*u_bqqgZeOy6BWssoHsQrKQ.png" /><figcaption>**notice we don’t add an ID- Active Record takes care of that for us</figcaption></figure><p>We’ll do the same process for our Reviews table:</p><p><strong>bundle exec rake db:create_migration NAME=create_reviews</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*_btN3QlRBxoowey4p17Tqg.png" /></figure><p>The Active Record macros we’ll be using are <strong>has_many </strong>and <strong>belongs_to. </strong>Your two classes should be set up in a models folder. We know that an organization has many reviews — and that a review belongs to an organization, so this should be very easy for us! This is what our classes will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*8pCpf1ZAt9WFbEjmRDqRKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*tk3q5IoRxwvIcO3QOCUaqg.png" /></figure><p>And that’s it! Below I’ve attached a link that can shed a bit more light on Active Record Associations in Ruby:</p><p><a href="https://guides.rubyonrails.org/association_basics.html">https://guides.rubyonrails.org/association_basics.html</a></p><p>Very straight forward and easy to understand- now <strong>many-to-many </strong>might take a little bit more effort to grasp the concept. Lets give it a shot:</p><p><strong>Many To Many Relationships with Active Record</strong></p><p>The <strong>many-to-many </strong>relationship involves three or more Active Record migrations (tables). You will still need to use our macros <strong>has_many </strong>and <strong>belongs_to </strong>depending on the structure of your tables, but now we’re introducing <strong>has_many through:.</strong></p><p>We’ll continue with the example from above, except this time we’ll add a volunteers table. This is what our ERD looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKCJjRWJAVBhm8oJLXuglw.png" /></figure><p>We’ll need to create a new migration like we did twice before for our new table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*rn-imi1cHlMsU4m2Odv1ag.png" /></figure><p>Now that we have all of our migrations, we’ll need to update our two previous tables’ macros to account for our new table. We now know that Review not only <strong>belongs_to </strong>organization, but it also <strong>belongs_to </strong>volunteer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*yUJ7jRfMf8Ho2qBpLUDTww.png" /></figure><p>We’ve already established our Organization class <strong>has_many</strong> reviews, but it also <strong>has_many :volunteers, through: reviews. </strong>Let’s update our code to show our new association:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*pM8YldjrEE11meZHAzT2vw.png" /></figure><p>We can now use Active Record to go <strong>through </strong>the join model, Review, from the Organization model, to return the associated volunteers, without writing any SQL!</p><p>Important things to note about the <strong>has_many</strong> macro:</p><ol><li>The order you place your macros in matters. You have to place the first has_many that references the join table <strong>above </strong>the second <strong>has_many</strong> that goes through the join table because Active Record wont know to go <strong>through </strong>the reviews table until you create the <strong>has_many :reviews</strong> association.</li><li>When calling <strong>has_many, </strong>we’re passing in a symbol that refers to the table name in our database as the first argument. The second argument is a key-value pair where the key is the <strong>through </strong>option, and the value is the <strong>:reviews </strong>symbol, which refers to the #reviews method from the first <strong>has_many.</strong></li></ol><p>That was a mouth full.</p><p>Our very last step in this many-to-many relationship is to set up the inverse relationship:</p><ol><li>A volunteer <strong>has_many </strong>reviews</li><li>A volunteer <strong>has_many </strong>organizations, <strong>through </strong>reviews.</li></ol><p>Our update code looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*JlktRFHBXll8Qg7_fglORA.png" /></figure><p>And that right there is how you implement a many-to-many relationship using Active Record and zero SQL! The one-to-many and many-to-many relationships are the most common when working with relational databases. By leveraging “convention over configuration”, we’re able to quickly set up complex associations between multiple models with just a few lines of code!</p><p>I hope this helped!</p><p>Below I have attached a link to a more detailed description of many-to-many associations:</p><p><a href="https://guides.rubyonrails.org/association_basics.html#methods-added-by-has-many">https://guides.rubyonrails.org/association_basics.html#methods-added-by-has-many</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b9e9867283c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>