<?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 Georgi Georgiev on Medium]]></title>
        <description><![CDATA[Stories by Georgi Georgiev on Medium]]></description>
        <link>https://medium.com/@gjorgiev?source=rss-ca76579d8123------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Fa8CnBrMjlfYDOgAqiuZXw.jpeg</url>
            <title>Stories by Georgi Georgiev on Medium</title>
            <link>https://medium.com/@gjorgiev?source=rss-ca76579d8123------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:43:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gjorgiev/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[Building a simple calculator using React.JS]]></title>
            <link>https://gjorgiev.medium.com/building-a-simple-calculator-using-react-js-ebbc4163dda3?source=rss-ca76579d8123------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebbc4163dda3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Georgi Georgiev]]></dc:creator>
            <pubDate>Tue, 26 Jan 2021 22:10:15 GMT</pubDate>
            <atom:updated>2021-01-26T22:23:03.521Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Create A Simple Calculator Web App Using React.JS</h3><p>In this article, I am going to explain how did I create a simple calculator using React. There might be bugs, but this is only for learning purposes and training the basic concepts of React.</p><p>Recently I went through the main concepts of React library from Facebook, and I was amazed by the simplicity and clearness of React.</p><p>Let’s dive into the project!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*Ja0Hz3OSh7c1VMt0UJ765w.png" /><figcaption>Final project — Calculator Web App</figcaption></figure><h3>Step 1: Break The UI Into Components</h3><p>First, we need to determine what is Component in the case. In this example we can see that Button could be a separate component, then we will have to put all the buttons together, so we will have the Keypad component. Next, we see on the top we’ll need a place to show the expression and result, that will be the Display component. In the end, we need to put it all together, so we named the last component as Calculator, you can name it whatever you want, that could be the App component also.</p><p>Components</p><ol><li>Calculator — main component containing all the rest</li><li>Display — contains the display area on the top</li><li>Button — represents each button on the keypad</li><li>Keypad — in this component we will put all the buttons</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*j61IR5UhuhYdMpqWTIoRSQ.png" /><figcaption>Components represented as boxes</figcaption></figure><h3>Step 2: Build A Static Version in React</h3><p>Start with the easiest possible solution without implementing the interactivity and state. We only need to write the components with their basic render functions, that way it is easier to work.</p><p>I’ve decided to start with the Button component because there is no other component inside it, so I don’t need to deal with composition even before implementing the parent component, you will see what I am talking about when we write the Keypad component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c7b3817126958610e3cbe226e8372aa/href">https://medium.com/media/9c7b3817126958610e3cbe226e8372aa/href</a></iframe><p>Then we write the Display component</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e63e93bdf5deba114a0e69a727772a32/href">https://medium.com/media/e63e93bdf5deba114a0e69a727772a32/href</a></iframe><p>The next component is Keypad, this one is using {this.props.children} as a way to render anything which will be written inside it, this could be any other component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bf9746afaad26bd419f450437e77329/href">https://medium.com/media/5bf9746afaad26bd419f450437e77329/href</a></iframe><p>Finally, we will write a basic version of the Calculator component, here we are only implementing the render() function to have the structure of the app, then we will think about the state and where should it live.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acce26ab763f8130a6b1cfc7e395654b/href">https://medium.com/media/acce26ab763f8130a6b1cfc7e395654b/href</a></iframe><p>You can also see how we used the Keypad component in composition with the Button component.</p><h3>Step 3: Identify and Implement The State</h3><p>First, we ask ourselves, which components will be sharing a state? In our case, that is the Button and the Display components, and they are both living in the Calculator component, so that’s where we will implement the state.</p><p>As a state, we are going to need only one parameter, and that is the data or expression which is shown on the display by pressing the buttons.</p><p>Here is the full Calculator component implemented with state and needed functions to manipulate the state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a809b945607031809b67b39c64952c24/href">https://medium.com/media/a809b945607031809b67b39c64952c24/href</a></iframe><p>This is a very simple example of React app, but we used most of the main concepts, like the composition of components, passing parameters from parent to child component, storing the state, etc…</p><p>I hope I did explain the process, you can also check the full source code on GitHub: <a href="https://github.com/gjorgiev/calculator-reactjs">https://github.com/gjorgiev/calculator-reactjs</a></p><p>If you have any suggestions or questions please let me know in the comments.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebbc4163dda3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guess my number game in Racket]]></title>
            <link>https://gjorgiev.medium.com/guess-my-number-game-in-racket-3b47fe15a652?source=rss-ca76579d8123------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b47fe15a652</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[racket]]></category>
            <category><![CDATA[lisp]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[learn-programming]]></category>
            <dc:creator><![CDATA[Georgi Georgiev]]></dc:creator>
            <pubDate>Fri, 03 Feb 2017 18:12:21 GMT</pubDate>
            <atom:updated>2017-02-03T21:45:43.573Z</atom:updated>
            <content:encoded><![CDATA[<p>The first game we will write is one of the simplest and oldest games around. It’s the classic Guess My Number game. In this game, the player thinks of a number between 1 and 100 . Our program will then figure out that number by repeatedly making guesses and asking the player if his/her number is bigger or smaller than the current guess.</p><p>The following piece shows what a game might look like in the interactions panel if the player chose 18 :</p><h4>&gt; (guess)<br>50<br>&gt; (smaller)<br>25<br>&gt; (smaller)<br>12<br>&gt; (bigger)<br>18</h4><p>The above interactions involve three different kinds of expressions: (guess) ,<br>(smaller) , and (bigger) . You can probably imagine what they mean. The first one tells the program to start guessing; the second one says that the guess is too high, so a smaller number needs to be guessed; and the third one commands the program to look for a bigger number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*ehZkirBGdzH09B9acsOk3A.png" /></figure><p>Everything to the immediate right of “ ( ” is a function, which means that we are dealing with three functions here: guess , smaller , and bigger. All you need to do is define these functions, and you have programmed yourself a first game. The player calls these functions in the interactions panel, starting with the guess function.</p><p>Now, let’s think about the strategy behind this simple game. The basic steps are as follows:<br>• Determine or set the upper and lower limits of the player’s number.<br>• Guess a number halfway between those two numbers.<br>• If the player says the number is smaller, lower the upper limit.<br>• If the player says the number is bigger, raise the lower limit.</p><p>By cutting the range of possible numbers in half with every guess, the program can quickly home in on the player’s number. Cutting the number of possibilities in half at each step is called a binary search. As you may know, binary search is frequently used in programming because it is remarkably effective at finding answers quickly. Even if we played the game with numbers between 1 and 1,000,000, a binary strategy could guess the right number in about 10 guesses.</p><p>At this point, you know almost everything there is to know about the game. We just need to introduce a few more Racket mechanics, and you will have Guess My Number going.</p><p><strong>2.2 Defining Variables</strong><br>As the player calls the functions that make up our game, the program will need to update the lower and upper limits at each call. One way to do so is to store the limits in variables and to change the values of the variables during the game. For Guess My Number, we’ll need to create two new variables called lower and upper .</p><p>The way to create a new variable is with define :<br>&gt; (define lower 1)<br>&gt; lower<br>1<br>&gt; (define upper 100)<br>&gt; upper<br>100</p><p>We weren’t completely honest with you. In addition to functions, it is also possible that “ ( ” is followed by a keyword, such as define . Expressions that start with a keyword work in their own special way, depending on the particular keyword. You’ll just need to remember the rules for each keyword. Fortunately, there is only a very small number of them.</p><p>The define keyword is quite important for understanding Racket programs, as it is used to define variables and functions. Here we are using it to define variables. The first part of the define expression is the name of the variable, and the second is an expression that produces the value we want the variable to have.</p><p>What may surprise you is that a definition does not evaluate to anything. Don’t worry. We will explain. Oh, and do place those two definitions where they belong — in the definitions panel.</p><p><strong>2.3 Basic Racket Etiquette</strong><br>Racket ignores spaces and line breaks when it reads code. This means you could format your code in any crazy way but still get the same result:</p><h4>&gt; (<br>define<br>lower 1)<br>&gt; lower<br>1</h4><p>Because Racket code can be formatted in such flexible ways, Racketeers have conventions for formatting programs, including when to use multiple lines and indentation. We’ll follow common conventions when writing examples in this book, and you’re better off mimicking them. However, we’re more interested in writing games than discussing source code indentation rules, so we won’t spend too much time on coding style in this book.</p><p>#|<br>NOTE: Pressing the “Tab” key in DrRacket automatically indents your<br>code to follow common convention. You can auto-indent a chunk of code<br>by highlighting it and then pressing the “Tab” key. You can auto-<br>indent an entire Racket program just by pressing Command+i on a Mac<br>or Ctrl+i on Windows and *nix.<br>|#</p><p><strong>2.4 Defining Functions in Racket</strong><br>Our Guess My Number program defines guess to start the game and responds to requests for either smaller or bigger guesses. In addition to these three functions, we also define a function called start that starts the game for a different range of numbers.</p><p><em>Like variables, functions are defined with define :<br>(define (function-name argument-name …)<br> function-body-expression<br> function-body-expression<br>…)</em></p><p>First, we specify the name of the function and the names of its arguments and put all of them in a pair of parentheses. Second, we follow it up with the expressions that comprise the function’s logic.<br>The dots mean that the preceding entity occurs an arbitrary number of times: zero times, one time, two times, and so on. It is thus possible that a function may have zero arguments, but it must have at least one expression in its body.</p><p><strong>A Function for Guessing</strong><br>The first function we’ll define is guess . This function uses the values of the lower and upper variables to generate a guess of the player’s number. In our definitions panel, its definition looks like this:</p><h4>(define (guess)<br>(quotient (+ lower upper) 2))</h4><p>To indicate that the function does not take any arguments, we place a closing parenthesis directly after the function name guess.</p><p>#|<br>NOTE: Although you don’t need to worry about indentation or line<br>breaks when entering code snippets, you must be sure to place paren-<br>theses correctly. If you forget a parenthesis or put one in the wrong<br>place, you’ll most likely get an error; if you don’t, you’re in trou-<br>ble. But there’s no need to worry: as you have probably noticed by<br>now, DrRacket helps you with this task.<br>|#</p><p>Guess what this function does. As discussed earlier, the computer’s best guess in this game is a number halfway between the two limits. To accomplish this, we choose the average of the two limits. If the average number ends up being a fraction, we choose the nearest whole number.<br>We implement this in the guess function by first adding the numbers that represent the upper and lower limits. The expression (+ lower upper) adds together the value of those two variables. We then use the quotient function to divide the sum in half to get an integer.</p><p>Let’s see what happens when we call our new function after clicking “Run”:</p><p><strong>&gt; (guess)<br>50</strong></p><p>Since this is the program’s first guess, the output we see when calling this function tells us that everything is working as planned. The program picked the number 50, right in between 1 and 100.</p><p>When programming in Racket, you’ll almost always write functions that won’t explicitly print values on the screen. Instead, they’ll simply return the value calculated in the body of the function, and DrRacket prints it for you. For instance, let’s say we wanted a function that just returns the number 5. Here’s how we could write the return-five function:</p><p><strong>(define (return-five)<br>5)</strong></p><p>Because the value calculated in the body of the function evaluates to 5 , calling (return-five) in the interactions panel returns 5 , and DrRacket prints that:</p><p><strong>&gt; (return-five)<br>5</strong></p><p>This is how guess is designed; we see this calculated result on the screen not because the function displayed the number, but because this is a feature of DrRacket’s interactions panel.</p><p>#|<br>NOTE: If you’ve used other programming languages before, you may<br>remember needing to write something like “return” to cause a value<br>to be returned. This is not necessary in Racket. The final value<br>calculated in the body of the function is returned automatically.<br>|#</p><p><strong>Functions for Closing In</strong><br>Now we’ll write our smaller and bigger functions, which update the upper and lower variables when necessary. Like guess , these functions are defined with the define form.<br>Let’s start with smaller :</p><p><strong>(define (smaller)<br>(set! upper (max lower (sub1 (guess))))<br>(guess))</strong></p><p>First, we use define to start the definition of any new function. Because smaller takes no parameters, the parentheses are wrapped tightly around smaller . Second, the function body consists of two expressions, one per line.<br>Third, the function uses a set! expression to change the value of a variable. In general, a set! expression has the following shape:</p><p><strong>(set! variable expression)</strong></p><p>The purpose of<strong> set!</strong>, pronounced “set bang,” is to evaluate the expression and set the variable to the resulting value. With this in mind, we can see that the set! expression in the definition of smaller first computes the new maximum number, and then it assigns that number to upper , giving us the new upper bound.</p><p>Since we know the maximum number must be smaller than the last guess, the biggest it can be is one less than that guess. The code (sub1 (guess)) calculates this value.</p><p>It calls our guess function to get the most recent guess, and then it uses the function <strong>sub1</strong> to subtract 1 from the result. By taking the max of lower and (sub1 (guess)) , we ensure that bigger is never smaller than lower .</p><p>Finally, we want our smaller function to show the player a new guess. We do so by putting a call to guess as the final expression in the function body. This time, guess calculates the new guess using the updated value of upper.<br>The bigger function works in the same manner as smaller , except that it raises the lower value instead:</p><p><strong>(define (bigger)<br>(set! lower (min upper (add1 (guess))))<br>(guess))</strong></p><p>After all, if the player calls the bigger function, she is saying that her number is bigger than the previous guess, so the smallest it can now be is one more than the previous guess. The function add1 simply adds 1 to the value returned by guess .</p><p>Here we see our functions in action, with the number 56 as the player’s number:</p><p><strong>&gt; (guess)<br>50<br>&gt; (bigger)<br>75<br>&gt; (smaller)<br>62<br>&gt; (smaller)<br>56</strong></p><p><strong>The Main Function</strong><br>It is practical to have one main function that starts — or restarts — the whole application. Placing the definition of the main function at the top of the definitions panel also helps readers understand the purpose of the program.<br>For Guess My Number, this is a simple feat:</p><p><strong>(define (start n m)<br>(set! lower (min n m))<br>(set! upper (max n m))<br>(guess))</strong></p><p>As you understand by now, start takes two arguments, which are the numbers we want to set as the lower and upper bounds. By using the max and min functions, we cut down on the instructions that we need to give any player. It suffices for a player to put in any two numbers in any order, and the function can determine the lower and upper bounds.</p><p>For example, you could start the game using a small range of numbers, like this:</p><p><strong>&gt; (start 1 30)<br>15</strong></p><p>#|<br>NOTE: As we continue to more challenging games, you will see how<br>a main function makes our games much more user friendly.<br>|#</p><p>The other functions continue to work as advertised:</p><p><strong>&gt; (bigger)<br>23<br>&gt; (smaller)<br>19</strong></p><p>Now go ahead and do some guessing yourself.</p><p><strong>Resume — Chapter Checkpoint</strong><br>In this chapter, we discussed some basic Racket forms. Along the way, you learned how to do the following:<br>• Use define to define a variable or function.<br>• Use set! to change the value of a variable.<br>• Use the interactions panel for experimentation.<br>• Copy and paste successful experiments to the definitions panel.</p><p>Thank you for your time!</p><p>This tutorial was rewritten from the book Realm of Racket Learn to program, One Game at a Time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b47fe15a652" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>