<?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 Derya Tanriverdi on Medium]]></title>
        <description><![CDATA[Stories by Derya Tanriverdi on Medium]]></description>
        <link>https://medium.com/@deryatanriverdi?source=rss-ca5c63b23b26------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*7IcioAnizPwl7v_P_uB4Sg.jpeg</url>
            <title>Stories by Derya Tanriverdi on Medium</title>
            <link>https://medium.com/@deryatanriverdi?source=rss-ca5c63b23b26------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:08:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deryatanriverdi/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[Understanding Closures in JavaScript]]></title>
            <link>https://medium.com/geekculture/understanding-closures-in-javascript-89317cec37e4?source=rss-ca5c63b23b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/89317cec37e4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[closures-functions]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Derya Tanriverdi]]></dc:creator>
            <pubDate>Fri, 23 Apr 2021 18:07:45 GMT</pubDate>
            <atom:updated>2021-04-27T14:10:25.686Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_LfZDKWFLLEkWerlrXvFng.jpeg" /><figcaption>Photo credits : Code Geek</figcaption></figure><p>The concept of closure is one of the topics in JavaScript that may be hard to wrap your head around. However they can be extremely useful once you get the hang of them! They can help you add a lot of reusable functionality to any web application. This helps us to save time when an application compiles and runs. So what is a closure you ask, well I am going to explain you by first breaking it down into smaller pieces, and go step by step to understand exactly what it is.</p><h3>What is a closure ?</h3><p>An explanation by MDN Web Docs:</p><blockquote>“A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.”</blockquote><h3>Let’s talk about Scopes</h3><p>Scopes determine the accessibility ( or visibility ) of variables. And there are 2 types:</p><ul><li>Local Scopes</li><li>Global Scopes</li></ul><h3>Local Scope</h3><p>Variables declared within a JavaScript function belongs to its LOCAL scope. They can only be accessed within that function. Local variables are created when a function starts, and deleted when the function is completed.</p><pre>function myFunction() {</pre><pre>    var count = 0;</pre><pre>    console.log(count);</pre><pre>};</pre><pre>myFunction(); =&gt; 0 </pre><pre>console.log(count); =&gt; ReferenceError: count is not defined<br>                       count is declared within myFunction&#39;s <br>                       scope, therefore it is not eligible <br>                       outside of that function.</pre><p>You can even reuse common variables names (count, index, current, value, etc) in different scopes without causing errors:</p><pre>function myFunction() {<br><br>    // &#39;myFunction&quot; function scope<br>    // This count variable belongs here, and it will log 0<br><br>    let count = 0;<br><br>    console.log(count);<br>};<br><br>function someFunction(){<br><br>    // &#39;someFunction&quot; function scope<br>    // This count variable belongs here, and it will log 1<br><br>    let count = 1;<br><br>    console.log(count);<br>};<br><br>myFunction(); =&gt; 0<br>someFunction(); =&gt; 1</pre><h3>Global Scope</h3><p>Variables declared outside a function, belongs to GLOBAL scope. All scripts and functions on a web page can then access it.</p><pre>let carName = &quot;Volvo&quot;;<br><br>console.log(carName); =&gt; &quot;Volvo&quot;<br><br>function myFunction() {<br><br>  // Code written inside this function can also use carName, <br>     because carName belongs to Global Scope<br><br>  console.log(carName);<br><br>};<br><br>myFunction(); =&gt; &quot;Volvo&quot;</pre><p>This is great but we can do so much more with scopes!</p><h3>Nesting Scopes</h3><p>Let’s play around a bit and put one scope inside another! This is called nesting:</p><pre>function outerFunction(){<br><br>    // The outer scope<br><br>    let outerVar = &quot;Outer variable&quot;;<br><br>   function innerFunction(){<br><br>       // The inner scope<br>       // The variables of the outer scope are accessible inside the inner scope <br><br>       console.log(outerVar);<br><br>   }<br><br>   innerFunction();<br><br>}<br><br>outerFunction(); =&gt; &quot;Outer variable&quot;</pre><p>Let’s take a look at it the code above and go step by step to understand how the code runs:</p><ul><li>A function called outerFunction() is defined with a variable of outerVar and function of innerFunction() in its body.</li><li>The innerFunction() runs a console log of our outerVar.</li><li>Since there is no declaration of outerVar within innerFuction(), JavaScript will consider outerVar same variable declared in outerFunction(). However, if we were to create another outerVar within our innerFunction(), our innerFunction() would defer to that variable first.</li></ul><p>Here is another example:</p><pre>let myGlobal = 0;<br><br>function myFunction() {<br><br>  let myVar = 1;<br><br>  console.log(myGlobal); // =&gt; It will log 0<br><br>  function innerOfFunction() {<br><br>    let myInnerVar = 2;<br><br>    console.log(myVar, myGlobal); // =&gt; I will log 1 0<br><br>    function innerOfInnerOfFunction() {<br><br>      console.log(myInnerVar, myVar, myGlobal); // =&gt; It will log <br>                                                      2 1 0 <br><br>    }<br><br>    innerOfInnerOfFunction();<br><br>  }<br><br>  innerOfFunction();<br><br>}<br><br>myFunction(); =&gt; 0 <br>                 1 0<br>                 2 1 0</pre><p>Let’s take a look at the code above line by line:</p><ol><li>The variable myGlobal is declared in the Global Scope and its value is 0.</li><li>Next myFunction() is declared.</li><li>Within myFunction()&#39;s scope the variable myVar is declared with a value of 1.</li><li>Inside of myFunction() another function innerOfFunction() is declared with a variable of myInnerVar with in it&#39;s scope with a value of 2.</li><li>We then declare another function inside innerofFunction() called innerOfinnerOfFunctoion()( example names are tricky!) which console logs the variables: myGlobal, myVar, and myInnerVar. Because it is nested under both myFunction() and then innerOfFunction(),it can access all of the variables above it.</li><li>innerOfFunction() then finishes by invoking innerOfInnerOfFunction().</li><li>Finally myFunction() closes by invoking innerOfFunction() which will run all of the code nested within it.</li></ol><p><em>The outer scopes have no knowledge of variables within the inner scopes, and the inner scopes(if nested) knows about the variables in its outer scopes.</em></p><h3>So what really is a closure?</h3><p>The lexical environment allows us to access the variables statically of the outer scopes. We can continue to nest variables and functions under one another, however we have not yet created a closure. There’s just one step until the closure!</p><p>Take a look at this code:</p><pre>function outerFunction(){<br><br>  let counter = 0;<br><br>  function innerFunction(){<br><br>    console.log(counter+=1); <br><br>   }<br><br>  innerFunction(); <br>}</pre><pre>outerFunction(); // =&gt; 1 <br>outerFunction(); // =&gt; 1 counter didn&#39;t change because<br>                       everytime. outerFunction() is called,<br>                       it sets the counter to 0, and adds 1 to it.</pre><p>Currently, innerFunction() is being invoked within outerFunction(). Let&#39;s change that, and instead of invoking the function simply return the function.</p><p>Let’s add the changes:</p><pre>function outerFunction(){<br><br>    let counter = 0;<br><br>    function innerFunction(){<br><br>      console.log(counter+=1); // Let&#39;s increment the counter<br><br>    }<br><br>    return innerFunction; // Note that we are not invoking the<br>                             function, but just returning it. <br><br>}</pre><p>By returning the innerFunction() we can now save the outer function to different variables which will be its own instance of that function:</p><pre>let invokeFirst = outerFunction() // =&gt; ƒ innerFunction(){<br><br>      console.log(counter+=1); // Le…<br><br>// outerFunction() invoked the first time<br><br>let invokeSecond = outerFunction() // =&gt; ƒ innerFunction(){<br><br>      console.log(counter+=1); // Le…<br><br>// outerFunction() invoked the first time<br><br>// By setting the invokeFirst and invokeSecond variables to<br>   outerFunction, its value becomes result of innerFunction.<br><br><br>invokeFirst() // =&gt; 1 invokeFirst() invoked the first time<br>invokeFirst() // =&gt; 2 invokeFirst() invoked the second time<br>invokeFirst() // =&gt; 3 invokeFirst() invoked the third time<br><br>invokeSecond() // =&gt; 1 invokeSecond() invoked the first time</pre><p>Let us examine go over what happens when invokeFirst() is executed the first time:</p><ol><li>Variable counter is created, and it’s value is set to 0 inside of outerFunction().</li><li>outerFunction() invoked and runs only once when it is saved to the variables invokeFirst() and invokeSecond().</li><li>JavaScript knows that variable counter no longer exists. Since counter is part of the outerFunction(), counter would only exist while the outerFunction() is in execution. Since the outerFunction() finished execution long before we invoked invokeFirst(), any variables within the scope of the outer function cease to exist, and hence variable counter no longer exists.</li></ol><h3>But, how does it work really ?</h3><p>The inner function can access the variables of the enclosing function due to closures in JavaScript. In other words, the inner function preserves the scope chain of the enclosing function at the time the enclosing function was executed, and thus can access the enclosing function’s variables.</p><p>Still confused? A simpler way to put it is that when we save our outerFunction() to a new variable it runs once, it sets its variables and executes what is inside it and then returns the innerFunction(). Now when we invoke our new variable as a function it runs the inner function only. The innerFunction() remembers everything the outerFunction()passed to it and then executes its own code. Anything not passed to the innerFunction() will now be outside of its scope. Let&#39;s a take look at what that means:</p><pre>function outerFunction(){<br><br>    let counter = 0;<br><br>    let anotherVar = &quot;something&quot; // This won&#39;t be remembered by<br>                                    innerFunction(), because <br>                                    outerFunction() returns the <br>                                    function of innerFunction() <br>                                    and innerFunction() doesn&#39;t <br>                                    use anotherVar. Therefore, <br>                                    it will be forgotten.<br><br>    function innerFunction(){<br><br>      console.log(counter+=1); // Let&#39;s increment the counter<br><br>   }<br><br>    return innerFunction;<br><br>}</pre><h3>Popular use cases for closures</h3><ul><li>Handle eventListeners</li><li>Private methods</li><li>Functional programming</li></ul><h3>Handle eventListeners</h3><pre>const myButton = document.getElementById(&quot;myButton&quot;);<br>const button = document.getElementById(&quot;button&quot;);<br><br>const myfunc = () =&gt; {<br><br>  let clicked = 0;<br><br>  const inner = () =&gt; {<br><br>    return clicked +=1;<br><br>  };<br><br>  return inner;<br><br>};<br><br>let callback = myfunc();<br><br>myButton.addEventListener(&quot;click&quot;, function handleClick() {<br><br>  myText.innerText = `You clicked ${callback()} times`;<br><br>});</pre><p><strong>Why is it useful here?</strong></p><p>Here everytime we set myFunc() to a new variable it will provide us with a new clicked value starting at 0. This makes it reusable for a variety of different event listeners. Imagine adding likes to a social media page, or an applauding functionality.</p><h3>Private methods</h3><p>We can emulate private methods using closures. Private methods provide us a great way to manage our global namespace and limit access to code.</p><pre>let counter = (function() {<br><br>  let privateCounter = 0;<br><br>  function changeBy(val) {<br><br>    privateCounter += val;<br><br>  }<br><br>  return {<br><br>    increment: function() {<br><br>      changeBy(1);<br><br>    },<br><br>    decrement: function() {<br><br>      changeBy(-1);<br><br>    },<br><br>    value: function() {<br><br>      return privateCounter;<br><br>    }<br><br>  };<br><br>})();<br><br>console.log(counter.value());  // 0.<br><br>counter.increment();<br>counter.increment();<br>console.log(counter.value());  // 2.<br><br>counter.decrement();<br>console.log(counter.value());  // 1.</pre><p>In the code above we are doing a few things. First, we are creating a private variable (privateCounter with a value of 0) and a private function (changeBy() which adds a value to the privateCounter variable). Both of these are private because we are not passing them to our statement. Second, our return statement we are creating an anonymous wrapper which contains three public objects: increment, decrement and value. The increment and decrement call on the changeBy() function to change the value of the the privateCounter by 1 or -1. The value simply returns the value of our privateCounter. The objects returned here can then be accessed by calling on our counter and calling on one of the keys of the function we wish to run( ex: counter.value())</p><h3>Functional programming</h3><p>This is a really useful concept that we can use to help us avoid having to write the same code over and over again. We can create functional programming that, in turn, create utility functions we can use any time we find ourselves repeatedly writing similar code.</p><pre>function division(a) {<br><br>  return function runDivision(b) {<br><br>    return b / a;<br><br>  }<br>  <br>}<br><br>const divideByTwo= division(2);<br>divideByTwo(4); // =&gt; 2<br>divideByTwo(6); // =&gt; 3<br><br>const divideByThree = division(3);<br>tridivideByThree(3); // =&gt; 1<br>tridivideByThree(9); // =&gt; 3</pre><h3>Conclusion</h3><p>If you find yourself reusing the same blocks of code over and over again closures are a great way to create reusable functions that can be placed where you need them!</p><h3>Resources</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures">MDN</a></li><li><a href="https://www.w3schools.com/js/js_function_closures.asp">W3Schools</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89317cec37e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/understanding-closures-in-javascript-89317cec37e4">Understanding Closures in JavaScript</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick tutorial to make a responsive web site with CSS]]></title>
            <link>https://deryatanriverdi.medium.com/quick-tutorial-to-make-a-responsive-web-site-with-css-e89032a573da?source=rss-ca5c63b23b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/e89032a573da</guid>
            <category><![CDATA[responsive-web-design]]></category>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[media-queries]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Derya Tanriverdi]]></dc:creator>
            <pubDate>Sun, 15 Dec 2019 03:57:41 GMT</pubDate>
            <atom:updated>2019-12-15T21:34:50.035Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cD-LQ1ycDqyKu9q7dBSV9g.png" /></figure><p>In this blog post, I will be talking about <em>responsive web designing</em>, what it is, how to use it.</p><p><strong>What is responsive design, anyway ?</strong></p><blockquote><strong>Responsive web design</strong> (<strong>RWD</strong>) is an approach to <a href="https://en.wikipedia.org/wiki/Web_design">web design</a> that makes web pages render well on a variety of devices and window or screen sizes.</blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Responsive_web_design"><em>Wikipedia</em></a></blockquote><p>So, it is pretty big deal if you want your web site to be looking good on all devices.</p><p><strong>Where to start?</strong></p><p>To have responsive design, &lt;meta&gt; element has to be set like this:</p><pre>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;</pre><p>This will set the viewport of your page, which will give the browser instructions on how to control the page’s dimensions and scaling.</p><p><strong>Where to write your code ?</strong></p><p>CSS! I prefer to write my CSS code in an external file, it keeps my code cleaner. For more information about external CSS, <a href="https://medium.com/@deryatanriverdii/css-structure-ca8aa4cc1a0e">click here</a>!</p><p>First let’s check it out how a web page would look without responsive design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*E8ZhJBeSa9Sni9BfXXO0Jg.gif" /><figcaption>Not so pretty</figcaption></figure><p>To make our page responsive, we are going to need media queries. The syntax we will be using is:</p><pre>h1{<br> font-size: 35px;<br>}</pre><pre>@media screen and (max-width: 700px) {<br>  h1{<br>   font-size: 25px<br>  }<br>} =&gt; This tells the browser that when screen is 700px and below, h1 element font-size = 25px </pre><pre>@media screen and (min-width: 700px) {<br>  h1{<br>   font-size: 45px<br>  }<br>}</pre><pre>=&gt; This tells the browser that until screen is 700px and above, h1 element font-size = 45px</pre><p>So let’s make a responsive web site!</p><pre>html file;</pre><pre>&lt;div class=&quot;main-div&quot;&gt;<br>     &lt;div class=&quot;box&quot;&gt; Box - 1&lt;/div&gt;<br>     &lt;div class=&quot;box&quot;&gt; Box - 2&lt;/div&gt;<br>     &lt;div class=&quot;box&quot;&gt; Box - 3&lt;/div&gt;<br>     &lt;div class=&quot;box&quot;&gt; Box - 4&lt;/div&gt;<br>     &lt;div class=&quot;box&quot;&gt; Box - 4&lt;/div&gt;<br>&lt;/div&gt;</pre><pre>css file;</pre><pre>.main-div{<br>margin-top: 10%;<br>display: flex;<br>justify-content: left;<br>color: white;<br>text-align: center;<br>}</pre><pre>.box{<br>width: 25%;<br>height: 250px;<br>border: 1px solid black;<br>background-color: teal;<br>padding-top: 5%;<br>}</pre><pre>@media screen and (max-width: 700px){<br>   .main-div{<br>    display: block;<br>   }<br>   .box{<br>    width: 100%;<br>    height: 80px;<br>   }<br>}</pre><pre>@media screen and (max-width: 414px){<br>   .main-div{<br>   display: block;<br>   }<br>   .box{<br>    width: 100%;<br>    height: 50px;<br>   }<br> }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*N_KhAxqQGjXmt827NOmD_A.gif" /><figcaption>This is the outcome, no more shrinking!</figcaption></figure><p><strong>Take advantage of Google Chrome Tools!</strong></p><p>Click inspect, and select this option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*b9A7EQMtJyr_UqgmPu7X3g.png" /><figcaption>Blue phone / tablet icon</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Qj7oNxPdiaCHen2JAefshQ.gif" /><figcaption>Play around with it!</figcaption></figure><p><strong>Things to keep in mind</strong></p><p>1- Image width should be always set with % instead of px.</p><p><strong>px vs %</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IUB0lkwZR08GPy0ArzglBw.gif" /><figcaption>img{ width: 500px;}</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*4Z0hfblQSs4lqbatQcdEBw.gif" /><figcaption>img{ width: 100%;}</figcaption></figure><p>2- The text size can be set with a “vw” unit, which means the “viewport width”. That way the text size will follow the size of the browser window.</p><p><strong>px vs vw</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Y3rkF1o1YheqQBsY3-KXIA.gif" /><figcaption>h1{font-size: 50px;}</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Qer9kpfdjTKlzPJ2-hYelw.gif" /><figcaption>h1{font-size: 10vw;}</figcaption></figure><p>Thank you for reading it, hope you liked it!</p><p>For more information, I recommend these websites:</p><ul><li><a href="https://www.w3schools.com/css/css_rwd_intro.asp">w3schools.com</a></li><li><a href="https://www.tutorialspoint.com/css/css_responsive.htm">https://www.tutorialspoint.com/css/css_responsive.htm</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e89032a573da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Secret To Rails: Creating a Secret Key in Your Rails API]]></title>
            <link>https://deryatanriverdi.medium.com/the-secret-to-rails-creating-a-secret-key-in-your-rails-api-fd7540318045?source=rss-ca5c63b23b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd7540318045</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[credentialing-software]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Derya Tanriverdi]]></dc:creator>
            <pubDate>Mon, 25 Nov 2019 03:17:53 GMT</pubDate>
            <atom:updated>2019-11-25T03:27:28.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*Nb5kOC5J150xbJucdj4kcA.png" /></figure><p>In this blog post, I will be talking about Rails Credentials, and why it is super important.</p><p><strong>Github is a friend of Software Developers, but hackers are not…</strong></p><p>We can all agree that Github is an amazing platform. It allows Software Developers to publish their amazing works, potential employers who have your resume to stalk your repositories. It sounds all good, which it is, but what happens when you put sensitive information into your app? Without taking the right security steps, it will be like leaving an open invitation for hackers, who are like lions waiting for their next meal.</p><p><strong>So how can you protect yourself?</strong></p><p>One of the ways to protect your information is using Rails Credentials.</p><p>This is an explanation from Rails documentary;</p><blockquote>Added config/credentials.yml.enc file to store production app secrets. It allows saving any authentication credentials for third-party services directly in repository encrypted with a key in the config/master.key file or the RAILS_MASTER_KEY environment variable. This will eventually replace Rails.application.secrets and the encrypted secrets introduced in Rails 5.1. Furthermore, Rails 5.2 <a href="https://github.com/rails/rails/pull/30940">opens API underlying Credentials</a>, so you can easily deal with other encrypted configurations, keys, and files. You can read more about this in the <a href="https://guides.rubyonrails.org/security.html#custom-credentials">Securing Rails Applications</a> guide.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*pKHR2U-zbk7rqpbaA8lpyw.png" /><figcaption>credentials.yml.enc is located within config folder</figcaption></figure><p>If you go to credentials.yml.enc, you will see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xlt2d223KNRnSxZbJ4ufVA.png" /></figure><p>But this is not the place where you store your information.</p><p><strong>Now is the fun part, how to use it?</strong></p><p><strong>Step-1</strong></p><p>Open your terminal, and find where your Rails API located.</p><p>And run this command;</p><pre>EDITOR=&quot;code --wait&quot; rails credentials:edit</pre><p><em>Note : code stands for text editor; atom, subl etc.</em></p><p>This will open this;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wHdVTRPPFo6m_cbBfuV-iQ.png" /><figcaption>This is the file where the key / value pairs can be saved.</figcaption></figure><p>Notice that, you can’t see 3112.credentials.yml file within directory, that is because it is not located anywhere in your app. This is really cool!</p><p><strong>Step-2</strong></p><p>You can now add key / value pairs ;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-38R1kU1w2aX4FPi-NT8g.png" /><figcaption>You can name it however you want.</figcaption></figure><p><strong>Step-3</strong></p><p>Now just close the 3112.credentials.yml file, then go to your terminal, you will see;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*VCYyx6T7D5zy0X6kn_ijNg.png" /></figure><p><strong>Step-4</strong></p><p>First let’s make test run in terminal.</p><pre>$ rails c</pre><pre>$ Rails.application.credentials </pre><pre>#=&gt;&lt;ActiveSupport::EncryptedConfiguration:0x00007f834c868fb8 @key_path=#&lt;Pathname:/Users/flatironschool/Desktop/Projects/NutriTrack-App(Mod-5)/Backend-NutriTrack/config/master.key&gt;, @content_path=#&lt;Pathname:/Users/flatironschool/Desktop/Projects/NutriTrack-App(Mod-5)/Backend-NutriTrack/config/credentials.yml.enc&gt;, @env_key=&quot;RAILS_MASTER_KEY&quot;, @raise_if_missing_key=false</pre><pre>$ Rails.application.credentials.secret_key <br>#=&gt; &quot;secretkey&quot;</pre><p><strong>Step-5</strong></p><p>Now that you know how to get your secret information, you can pass it anywhere it’s needed ;</p><pre>def encoded_token(payload)</pre><pre>   JWT.encode(payload, secret_key, &quot;HS256&quot;)</pre><pre>end<br></pre><pre>def secret_key</pre><pre>    Rails.application.credentials.secret_key</pre><pre>end</pre><p>And that’s it! Your data is safe, but still protect yourself, don’t leave your computer out in the open.</p><p><strong><em>Resource;</em></strong></p><p><a href="https://guides.rubyonrails.org/5_2_release_notes.html#credentials"><em>https://guides.rubyonrails.org/5_2_release_notes.html#credentials</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd7540318045" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS SELECTORS]]></title>
            <link>https://deryatanriverdi.medium.com/css-selectors-a1b79c2b4167?source=rss-ca5c63b23b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1b79c2b4167</guid>
            <category><![CDATA[css-selectors]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[stylesheets]]></category>
            <dc:creator><![CDATA[Derya Tanriverdi]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 01:07:22 GMT</pubDate>
            <atom:updated>2023-06-02T16:36:51.760Z</atom:updated>
            <content:encoded><![CDATA[<h3>CHAINING CSS SELECTORS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*tW_vGNZG3wmsrmBE1KW5yA.png" /></figure><p>Recently, I wrote a blog post about CSS: what it is, the way it is structured, tools that could be helpful, and some great resources.<em> </em>In this blog post, I will be focusing on chaining CSS selectors.</p><p><strong>What is CSS selectors?</strong></p><p>In CSS, selectors are patterns used to select the element(s) you want to style.</p><p><strong>Basic Selectors:</strong></p><ul><li>*{property:value;} /* will match all the elements of the document. */</li><li>p{property:value;} /* will match any &lt;p&gt; element</li><li>.classname{property:value;} /* for example, .index will match any element that has a class of &quot;index&quot;. */</li><li>#idname{property:value} /* for example, #header will match the element that has the ID &quot;header&quot;. */</li><li>[attr] [attr=value] [attr~=value] [attr|=value] [attr^=value] [attr$=value] [attr*=value] /* for example, [autoplay] will match all elements that have the autoplay attribute set (to any value). */</li></ul><p><strong>Chaining selectors</strong></p><p>There are so many ways to chain selectors. I will be focusing on ones that are most commonly used.</p><ul><li><strong>.classname1.classname2</strong></li></ul><pre>&lt;div class=&quot;name1 name2&quot;&gt;...&lt;/div&gt;</pre><pre>&lt;style&gt;</pre><pre>.name1.name2{property:value;} /* Selects all elements with both <em>name1</em> and <em>name2</em> set within its class attribute */</pre><pre>&lt;/style&gt;</pre><ul><li><strong>.classname1 .classname2</strong></li></ul><pre>/* <strong>Be careful</strong>, if there is a space between them ( .classname1 .classname2 ), then CSS will select all elements with <em>name2</em> that is a child of an element with <em>name1 */</em></pre><pre>&lt;div class=”name1&quot;&gt;<br> &lt;div class=”name2&quot;&gt;<br> …<br> &lt;/div&gt;<br>&lt;/div&gt;</pre><pre>&lt;style&gt;</pre><pre>.name1 name2{property:value;} </pre><pre>&lt;/style&gt;</pre><ul><li><strong>element, element</strong></li></ul><pre>&lt;div&gt; ... &lt;/div&gt;<br>&lt;p&gt; ... &lt;/p&gt;</pre><pre>&lt;style&gt;</pre><pre>div, p{property:value;} /* Selects all &lt;div&gt; elements and all &lt;p&gt; elements */</pre><pre>&lt;/style&gt;</pre><ul><li><strong>element element</strong></li></ul><pre>/* <strong>Be careful</strong>, if there is a space between them instead of comma ( element element ), then CSS will select all &lt;p&gt; elements inside &lt;div&gt; elements<em> */</em></pre><pre>&lt;div&gt;<br> &lt;p&gt;<br> …<br> &lt;/p&gt;<br>&lt;/div&gt;</pre><pre>&lt;style&gt;</pre><pre>div p{property:value;} </pre><pre>&lt;/style&gt;</pre><ul><li><strong>element&gt;element</strong></li></ul><pre>&lt;div&gt;<br> &lt;p&gt;  /* This will be selected */<br> …<br> &lt;/p&gt;<br>&lt;/div&gt;</pre><pre>&lt;p&gt; ... &lt;/p&gt; /* This won&#39;t be selected */<br></pre><pre>&lt;style&gt;</pre><pre>div&gt;p{property:value;} /* Selects all &lt;p&gt; elements where the parent is a &lt;div&gt; element */</pre><pre>&lt;/style&gt;</pre><ul><li><strong>element+element</strong></li></ul><pre>&lt;div&gt; <br> &lt;p&gt; /* This won&#39;t be selected */<br>   ...<br> &lt;/p&gt;<br>&lt;/div&gt;</pre><pre>&lt;p&gt; ... &lt;/p&gt; /* This will be selected */<br>&lt;p&gt; ... &lt;/p&gt; /* This won&#39;t be selected */</pre><pre>&lt;style&gt;</pre><pre>div+p{property:value;} /* Selects all &lt;p&gt; elements that are placed immediately after &lt;div&gt; elements */</pre><pre>&lt;/style&gt;</pre><ul><li><strong>[attribute^=value]</strong></li></ul><pre>&lt;a href=&quot;https...&quot;&gt;&lt;/a&gt;</pre><pre>&lt;style&gt;</pre><pre>a[href^=&quot;https&quot;]{property:value;} /* Selects every &lt;a&gt; element whose href attribute value begins with &quot;https&quot; */</pre><pre>&lt;/style&gt;</pre><ul><li><strong>[attribute$=value]</strong></li></ul><pre>&lt;a href=&quot;... .pdf&quot;&gt;&lt;/a&gt;</pre><pre>&lt;style&gt;</pre><pre>a[href$=&quot;.pdf&quot;]{property:value;} /* <br>Selects every &lt;a&gt; element whose href attribute value ends with &quot;.pdf&quot; */</pre><pre>&lt;/style&gt;</pre><ul><li><strong>::before</strong></li></ul><pre>&lt;p&gt; Paragraph 1 &lt;/p&gt;<br>&lt;p&gt; Paragraph 2 &lt;/p&gt;</pre><pre>&lt;style&gt;</pre><pre>p::before{content: &quot;Read this:&quot;} /* <br>Inserts something before the content of each &lt;p&gt; element */</pre><pre>&lt;/style&gt;</pre><pre>Output =&gt; Read this: Paragraph 1<br>          Read this: Paragraph 2</pre><p>You can find the full list <a href="https://www.w3schools.com/cssref/css_selectors.asp"><strong>here</strong></a></p><p>Hope you find this blog post helpful. See you next time!</p><p>Resources:</p><ul><li><a href="https://www.w3schools.com/cssref/css_selectors.asp"><strong>w3.schools.com</strong></a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors"><strong>developers.mozilla.org</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1b79c2b4167" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOW TO USER localStorage TO KEEP USER LOGGED IN AND OUT]]></title>
            <link>https://deryatanriverdi.medium.com/how-to-user-localstorage-to-keep-user-logged-in-and-out-8fd1e6e46712?source=rss-ca5c63b23b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fd1e6e46712</guid>
            <category><![CDATA[login]]></category>
            <category><![CDATA[localstorage]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[sign-in]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Derya Tanriverdi]]></dc:creator>
            <pubDate>Sun, 06 Oct 2019 23:14:45 GMT</pubDate>
            <atom:updated>2019-10-07T18:14:36.881Z</atom:updated>
            <content:encoded><![CDATA[<h4>HOW TO USE localStorage TO KEEP USER LOGGED IN AND OUT WITH JAVASCRIPT</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*R3vPme_qIiWXR_w7u6G7NQ.png" /></figure><p>In this blog post- I will talk about what localStorage is and how it is beneficial when it comes to keeping the user logged in and out.</p><p>On my recent school project, I decided to have a login feature- so that the user can be signed in until they log out. The caveat wast that this vanilla JS assignment prohibited using authentication and authorization tools for the sake of time. Without any useful tool, you can end up writing long lines of code- and potentially lose your sanity. So big shoutout to my coach for letting me know about localStorage!</p><p><strong>What is localStorage?</strong></p><p>LocalStorage is a type of web storage that allows JavaScript websites and apps to store and access data right in the browser with no expiration date. This means the data stored in the browser will persist even after the browser window has been closed.</p><p><strong>Syntax</strong></p><p>localStorage.id = &lt;number to set up&gt;</p><p>There are more ways to use localStorage, but I will be focusing how to retrieve id.</p><p><strong>So, how we do it?</strong></p><p>When a user signs up, the id will be taken and stored like so;</p><pre>function postFetchForSignUp() {<br>  let nameInput = document.querySelector(&quot;#name&quot;)<br>  let usernameInput = document.querySelector(&quot;#username&quot;)<br>  <strong>fetch(&#39;</strong><a href="http://localhost:3000/users&#39;"><strong>http://localhost:3000/users&#39;</strong></a><strong>, { // First, we make a Post fetch request where we want to store our users.</strong><br>    method: &#39;POST&#39;,<br>    headers: {<br>      &#39;Content-Type&#39;:&#39;application/json&#39;,<br>      &#39;Accept&#39;:&#39;application/json&#39;<br>    },<br>    body: JSON.stringify({<br>      name: nameInput.value,<br>      username: usernameInput.value<br>    })<br>  })<br>  .then(res=&gt;res.json())<br>  .then(user =&gt; {<br>    <strong>localStorage.clear() // If there was a user signed in, this will                                   </strong></pre><pre><strong>                         // clear it up</strong><br>    <strong>localStorage.id = user.id  // Then we can store the id we got </strong><br>    slapUser(user)<br>    logOutButton()<br>  })<br>}</pre><p>When the user signs in, the id will be taken in and stored:</p><pre>signInButton.addEventListener(&#39;click&#39;, e =&gt; {<br>  signInForm()<br>  let form = signDiv.querySelector(&#39;.sign-in&#39;)<br>  let usernameInput = document.querySelector(&quot;#username&quot;)<br>  form.addEventListener(&#39;submit&#39;, e=&gt;{<br>    e.preventDefault()<br>    <strong>fetch(&#39;</strong><a href="http://localhost:3000/users&#39;"><strong>http://localhost:3000/users&#39;</strong></a><strong>) // We make a get fetch    // request where users are stored</strong><br>    .then(res=&gt;res.json()) <br>    .then(usersArray =&gt; { <br> <strong>     let user = usersArray.find(function(user){ <br>          return user.username === usernameInput.value // Then we        // check if there is a user with a value given</strong><br>        })<br>      if (user){<br>        signDiv.innerHTML = &quot;&quot;<br>        slapUser(user)<br>        <strong>localStorage.id = user.id // If there is so, we then store // it</strong><br>        logOutButton()<br>        writeReview()<br>      }<br>    })<br>  })<br>})</pre><p>When user logs out, the localStorage will be cleared like so;</p><pre>function logOutButton(){<br> let logOutButton = document.createElement(&quot;button&quot;)<br> logOutButton.className = &quot;log-out-button&quot;<br> logOutButton.innerText = &quot;Log Out&quot;<br> signDiv.append(logOutButton)<br> logOutButton.addEventListener(&#39;click&#39;, e=&gt;{<br>  <strong> localStorage.clear() // We clear localStorage like so</strong><br> })<br>}</pre><p>Here is a quick localStorage demo on console;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*CirdC96G2fz8pNlJvxXbog.gif" /></figure><p>I hope this blogpost is useful, and it will help you as much as it did for me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fd1e6e46712" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Structure]]></title>
            <link>https://deryatanriverdi.medium.com/css-structure-ca8aa4cc1a0e?source=rss-ca5c63b23b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca8aa4cc1a0e</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Derya Tanriverdi]]></dc:creator>
            <pubDate>Sun, 08 Sep 2019 01:27:56 GMT</pubDate>
            <atom:updated>2023-06-02T16:32:39.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LyBuhTipRUFm0ylOSyp2eQ.jpeg" /></figure><p><em>In this blog post, I will be talking about CSS; what it is, the way it is structured, tools could be helpful, and some great resources.</em></p><p><strong><em>CSS is a language</em></strong></p><p><em>CSS aka ‘Cascading Style Sheet’ is a language that describes the style of an HTML document. Without a CSS, HTML is just a plain text from top to bottom. It’s pretty boring .</em></p><p><strong><em>CSS Syntax</em></strong></p><p>selector {property:value;}</p><pre>h1 {<br>   color: #36CFFF; <br>}</pre><p><strong><em>CSS Comments</em></strong></p><pre>/* A one-line comment */</pre><p><strong><em>There are 3 ways to write CSS codes</em></strong></p><ul><li><em>Inline CSS</em></li></ul><pre>&lt;p style=&quot;color: blue; font-size: 46px;&quot;&gt;</pre><p><em>An inline style may be used to apply a unique style for a single element. </em><a href="https://www.w3schools.com/css/tryit.asp?filename=trycss_howto_inline"><strong><em>Try it!</em></strong></a></p><ul><li><em>Internal CSS</em></li></ul><pre>&lt;head&gt;<br>&lt;style type=&quot;text/css&quot;&gt;<br><br>    h1 {<br>            color:#fff<br>            margin-left: 20px;<br>       }<br><br>    p {<br>        font-family: Arial, Helvetica, Sans Serif;     <br>       }<br><br>&lt;/style&gt;<br>&lt;/head&gt;</pre><p><em>An internal style sheet may be used if one single HTML page has a unique style. </em><a href="https://www.w3schools.com/css/tryit.asp?filename=trycss_howto_internal"><strong><em>Try it!</em></strong></a></p><ul><li><em>External CSS</em></li></ul><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang = &quot;en-US&quot;&gt;<br> &lt;head&gt;<br> &lt;meta charset = &quot;UTF-8&quot;&gt;<br> &lt;title&gt;externalStyle.html&lt;/title&gt;<br> &lt;link rel = &quot;stylesheet&quot;<br>   type = &quot;text/css&quot;<br>   <strong>href = &quot;mystyle.css&quot; /&gt;</strong><br> &lt;/head&gt;<br>&lt;/html&gt;</pre><p><em>With an external style sheet, you can change the look of an entire website by changing just one file! Each HTML page must include a reference to the external style sheet file inside the &lt;link&gt; element, inside the head section. </em><a href="https://www.w3schools.com/css/tryit.asp?filename=trycss_howto_external"><strong><em>Try it!</em></strong></a></p><p><em>An external style sheet must be saved with a .css extension and the external .css file should not contain any HTML tags.</em></p><p><em>Here is what the </em><strong><em>“mystyle.css” </em></strong><em>file looks like:</em></p><pre>body{<br>  width:100%;<br>  color:25px;<br>}</pre><pre>p{<br>  color:red;<br>}</pre><p><strong><em>It is cascaded</em></strong></p><p><em>CSS reads the codes from top-to-bottom. So order of your codes matters.</em></p><pre>h1{color:red;} /* This won&#39;t be implemented!*/<br>h1{color:blue;}</pre><p><strong><em>It has specificities</em></strong></p><ul><li><em>An element selector is less specific — it will select all elements of that type that appear on a page — so will get a lower score.</em></li><li><em>A class selector is more specific — it will select only the elements on a page that have a specific </em><em>class attribute value — so will get a higher score.</em></li><li><em>An id selector is even more specific — it will select only the elements on a page that have a specific </em><em>id attribute — so will get one more step higher score.</em></li></ul><pre><em>.css file</em></pre><pre>#main-paragraph { <br>    color: red; <br>}</pre><pre>.secondary-paragraph { <br>    color: green; <br>}<br>        <br>p { <br>    color: blue; <br>}</pre><pre><em>.html file<br></em>&lt;p id=&quot;main-paragraph&quot;&gt;This is my paragraph.&lt;/p&gt;<br>&lt;p class=&quot;secondary-paragraph&quot;&gt;This is my secondary paragraph.&lt;/p&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*g14-sJkaK1edAsCz9kIoYQ.png" /><figcaption>as it’s seen; p {color:blue;} is not implemented.</figcaption></figure><ul><li><em>!important has the highest specificity of all — The </em><em>!important rule overrides that particular property. It is almost not recommended!</em></li></ul><pre><em>.css file</em></pre><pre>p{<br>  color:red !important;<br>  color:25px;<br>}</pre><pre>#thing{<br>  color:green;<br>}</pre><pre><em>.html file</em></pre><pre>&lt;p id=&quot;thing&quot;&gt;Will be RED.&lt;/p&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*yBHBbwxnFIZ57SQYbohPhg.png" /></figure><p><em>If you wanna test some CSS codes =&gt; </em><a href="https://codesandbox.io/s/vanilla"><strong><em>codesandbox</em></strong></a></p><p><strong><em>The way HTML tags are categorized does matter</em></strong></p><p><em>HTML elements historically were categorized as either “block-level” element or “inline” elements. Inline elements are those which only occupy the space bounded by the tags defining the element, instead of breaking the flow of the content and block element takes the entire line left-to-right.</em></p><p><em>Why this matters?</em></p><p><em>Often time, we can forget this categorization and try to change the size of inline element. But inline element’s border size can’t be changed unless we write a code like so;</em></p><pre>/* &lt;a&gt; is a inline-element*/</pre><pre>a{<br>display:inline-block; <br>}</pre><p><em>Da da da da, now we can change inline element’s size!</em></p><pre>a{<br>display:inline-block; <br>width: 100px;<br>height: 50px;<br>}</pre><p><strong><em>Google Inspect tool is pretty handful</em></strong></p><p><em>With Google inspect tool, we can check the element’s sizes, css codes that implemented. Here is a quick demonstration;</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FWRLomz7yyagChcS04z%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FWRLomz7yyagChcS04z%2F200w_d.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FWRLomz7yyagChcS04z%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="271" frameborder="0" scrolling="no"><a href="https://medium.com/media/5238406ed28480674e716492b19adbce/href">https://medium.com/media/5238406ed28480674e716492b19adbce/href</a></iframe><p><strong><em>Giving borders to your element is gonna save you!</em></strong></p><p><em>Google Inspect tool by far is amazing, but there is another way to see size of the elements. Understanding of element’s size will help you huge!</em></p><p><em>Here is how you can do it;</em></p><pre>selector {<br>border:1px solid black;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Ic2ZuHxU16u3iYtWwhZmQ.png" /></figure><p><strong><em>There are many helpful resources!</em></strong></p><p><em>Here are some great resources I’ve got help from;</em></p><ul><li><a href="https://www.w3schools.com/css/default.asp"><em>w3schools.com</em></a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS"><em>MDN web docs</em></a></li><li><a href="https://css-tricks.com/"><em>CSS-Tricks</em></a></li><li><a href="https://stackoverflow.com/questions/tagged/css"><em>Stack</em><strong><em>overflow</em></strong></a></li></ul><p><em>And many more…</em></p><p><em>CSS can be tricky, but it is yet one of my favorite language!</em></p><p><em>I hope you enjoyed my blog post, see you next time!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca8aa4cc1a0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>