<?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 Ross Baker on Medium]]></title>
        <description><![CDATA[Stories by Ross Baker on Medium]]></description>
        <link>https://medium.com/@rossabaker?source=rss-acf5522bab5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*SmdURKw83yGdLp0jyoVK5g.png</url>
            <title>Stories by Ross Baker on Medium</title>
            <link>https://medium.com/@rossabaker?source=rss-acf5522bab5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 15:24:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rossabaker/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[How to Create a Responsive Grid Layout With Under 10 Lines of CSS.]]></title>
            <link>https://medium.com/swlh/how-to-create-a-responsive-grid-layout-with-under-10-lines-of-css-3df58ce1707b?source=rss-acf5522bab5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3df58ce1707b</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Ross Baker]]></dc:creator>
            <pubDate>Wed, 09 Sep 2020 08:59:37 GMT</pubDate>
            <atom:updated>2020-10-01T00:10:10.946Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Codepen</strong></p><p><a href="https://codepen.io/r0ss26/pen/ExKQMyB">https://codepen.io/r0ss26/pen/ExKQMyB</a></p><p><strong>Demo</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*bM8uqhtLUDSeq5Yng1sEWQ.gif" /><figcaption>A simple responsive grid layout.</figcaption></figure><p>Creating a responsive grid layout is a common task which doesn’t need to be over-complicated. It can be done in under 10 lines of CSS without the need for media queries. In this blog post I will outline a quick and simple way to create a grid layout, with explanations for each CSS property used. Jump to the end if you just want to <a href="#e90d">see the code</a>.</p><p>The best part of this approach is that it’s completely dynamic, allowing you to add as many or as few items to the grid as necessary which is great for situations when the number of items in the grid might change.</p><h3>Markup</h3><p>For this tutorial we will use the following markup:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a226037b36ede578d816075fd7b9e0a6/href">https://medium.com/media/a226037b36ede578d816075fd7b9e0a6/href</a></iframe><h3>Flexbox Vs. Grid</h3><p>When attempting to create such a layout using only flex-box we run into a few problems. First of all, when the items wrap as the screen width is reduced, the width of the parent container does not adjust accordingly, resulting in the content not being centred, and you end up with the following situation, where there is excess space on one side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UQ5S1LZwG6aQtQPtlvTIFw.png" /></figure><p>A workaround for this problem might be to centre the content along the main axis with justify-content: centre on the parent element. This, however, leads to a further issue which occurs when there is an odd number of items — the final item will be displayed in the centre and not aligned within the grid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*V1gVEGJ5XGnxbs27dKAOwQ.png" /></figure><p>Flexbox is great for laying items out in a single dimension, such as horizontally or in a column, and while it is possible to use flexbox to wrap items across multiple rows, this can lead to unwanted behaviour as shown above. To get around this we can use CSS grid to create the layout, and if required we can use flexbox to position the entire grid on the page.</p><p>In order to achieve our desired layout we are going to make use of implicit columns in CSS grid. You might be familiar with explicitly laying out grid items by specifying the row and column, but in the next section I will go over how to display a variable number of columns and items to make our grid responsive and dynamic.</p><h3>Grid-template-columns</h3><p>The grid-template columns property is used on a grid container to specify the columns within the grid, for example to create two columns of 200 pixels wide, we would write:</p><pre>grid-template-columns: 200px 200px;</pre><p>We could write this more succinctly using the grid repeat function, which can be used to specify a column a repeated number of times, with this the above could be re-written as follows:</p><pre>grid-template-columns: repeat(2, 200px)</pre><h3>Responsiveness</h3><p>This approach only works if we know how many columns our grid will have, but becomes an issue when we want the number of columns to change as the screen size becomes smaller or wider.</p><p>One way to do this would be to use media queries and set 3 columns for large screens, 2 columns for medium screens and 1 column for small screens.</p><p>However, we can also make use of CSS grids auto-fit keyword which is available within the repeat function and replaces the explicit number. The previous example becomes:</p><pre>grid-template-columns: repeat(auto-fit, 200px)</pre><p>This provides us with the same responsive functionality with fewer lines of code and without having to worry about media queries and break points.</p><p>The concept here is that instead of defining a set number of columns, we set a width on the parent container, and the number of columns that can fit within that container will be calculated dynamically for us. As the screen size reduces, the number of columns will automatically reduce.</p><p>We can also utilise the minmax function for the column size to allow each column to grow or shrink to fill the available space, for example if we want each column to be at least 200px wide and at most take up the entire width of the parent container we could add the following:</p><pre>grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));</pre><p>In plain English this says ‘fill the screen with as many 200px wide columns as possible and then expand each column evenly to fill up any leftover space’.</p><p>Finally, to space the items out nicely we can add a gap of 15px by adding:</p><pre>grid-gap: 15px;</pre><h3>Grid Placement</h3><p>Now that we’ve got the grid set up, it is often the case that we want to place the entire grid in the centre of the screen — this is where flexbox becomes useful, by placing the grid in a container element we can set the following properties on the container to centre the grid:</p><pre>.container {<br>  display: flex;<br>  justify-content: centre;<br>}</pre><p>This gives us the final code.</p><p>HTML:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e978302f25ec3090395d4ad3fbddbe6a/href">https://medium.com/media/e978302f25ec3090395d4ad3fbddbe6a/href</a></iframe><p>CSS:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58b4104c55277f4250722f6a337cc399/href">https://medium.com/media/58b4104c55277f4250722f6a337cc399/href</a></iframe><p>Creating responsive grids doesn’t have to complicated, by using the repeat and auto-fit features of CSS grid we can avoid having to use media queries and our layout will look nice and be adaptable to all screen sizes. This technique can be adapted for a variety of layouts, so experiment and see what you can make!</p><p><em>I am a software developer and graduate of Coder Academy Sydney. Follow me on </em><a href="https://twitter.com/rossandrewbaker"><em>Twitter</em></a><em> to keep up with my journey.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3df58ce1707b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-create-a-responsive-grid-layout-with-under-10-lines-of-css-3df58ce1707b">How to Create a Responsive Grid Layout With Under 10 Lines of CSS.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Prototype Chain and Inheritance Explained From Scratch.]]></title>
            <link>https://levelup.gitconnected.com/javascript-prototype-chain-and-inheritance-explained-from-scratch-5f9d23f54f9?source=rss-acf5522bab5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f9d23f54f9</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[prototype-chain]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ross Baker]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 07:33:36 GMT</pubDate>
            <atom:updated>2020-06-24T21:27:02.883Z</atom:updated>
            <content:encoded><![CDATA[<p>Codepen for this tutorial <a href="https://codepen.io/r0ss26/pen/RwrpYjP?editors=1112">here</a>.</p><p>This article discusses how Object Oriented Programming patterns are implemented in JavaScript. In particular this article covers:</p><ul><li>Objects</li><li>Prototypal Inheritance</li><li>Function Constructors</li><li>The Protoype Chain</li><li>Subclass Inheritance</li></ul><h3>(Almost) Everything Is An Object</h3><p>One of the most fundamental concepts within JavaScript is the notion that “everything is an object”. In reality this is not completely true, because JavaScript also contains primitive values which are not objects. These primitive values are:</p><ul><li>Numbers</li><li>Strings</li><li>Booleans</li><li>undefined</li><li>Null</li></ul><p>However, these primitive values aside, everything <em>else</em> in JavaScript is an object. This includes:</p><ul><li>Arrays</li><li>Functions</li><li>Objects</li><li>Dates</li><li>Wrappers for Numbers, Strings and Booleans</li></ul><p>Before we go any further let’s clear up the distinction between an object and a primitive. Simply put, primitives do not have methods — they are just a value represented in memory. Objects on the other hand are collections of data and can store references to other entities. These entities (properties) may be primitives such as strings or numbers, or they could also be other objects (including functions).</p><h3>Prototypal Inheritance</h3><p>Inheritance in programming means that one object is based on another object and has access to that other objects properties and methods.</p><p>JavaScript implements prototypal inheritance, as opposed to classical inheritance such as in C or Java. This is an important distinction, as in classical inheritance models inheritance occurs when an <em>object instance</em> inherits from a <em>class</em> and a subclass can inherit from a parent class.</p><p>Prototypal inheritance on the other hand supports an object inheriting from <em>any other object</em> rather than from classes.</p><p>The defining feature of prototypal inheritance is that object instances have access to inherited properties and methods through the prototype chain. This is achieved through the fact that every object in JavaScript is automatically given a prototype property. When a child object is created that inherits from a parent object, the child has access to the parents prototype property. The proptotype property is itself an object and because children objects can access their parent objects prototype property, any properties and methods stored here are accessible by the child object.</p><p>For example, say we have a Vehicle object, we are going to use Vehicle to create <em>instances</em> of type Vehicle. In many other languages, Vehicle would be considered a class because it is a blueprint for creating instances of type Vehicle. However JavaScript has no concept of classes, instead Vehicle is a <em>constructor</em> - an Object used as a blueprint for creating other objects.</p><h3>Constructors, instances and the new keyword</h3><p>Let’s illustrate prototypal inheritance with an example.</p><p>Going back to the Vehicle constructor, how might this look? In JavaScript we use functions to implement constructors — these are aptly known as function constructors.</p><p>This is how we would implement the Vehicle class with a function constructor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d34ecb93f10901e6a9e520e8738aadc6/href">https://medium.com/media/d34ecb93f10901e6a9e520e8738aadc6/href</a></iframe><p>We could then use this function constructor to create a vehicle instance as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60bec5e718a91ef48d494e8912275094/href">https://medium.com/media/60bec5e718a91ef48d494e8912275094/href</a></iframe><p>The myVehicle variable now holds an instance of a Vehicle created using the Vehicle function constructor.</p><p>This is possible through the use of the new keyword.</p><p>The new keyword is used with a function constructor in order to create an instance. Behind the scenes the new keyword works via the following steps:</p><ol><li>Create a new empty object {} .</li><li>Set the this variable to be the empty object created in step 1.</li><li>Execute the function with the this keyword referencing the newly created object.</li></ol><p>With these steps we can create a vehicle with properties color weight and yearand the method honk.</p><p>But what about prototypes?</p><p>The way we have implemented Vehicle currently is not ideal. In this implementation we are not utilising the power of prototypes. Because we have defined the honk method within the constructor body, each new vehicle instance will have it&#39;s own separate copy of honk stored in memory. As honk is always the same function it doesn&#39;t make sense for each instance to store its own unique copy.</p><p><strong>This is where the power of prototypes come in.</strong></p><p>Remember that objects have access to their parent objects prototype property, so if we instead store the honk method in Vehicle&#39;s prototype property, all the instances will have access to it without needing to store their own copy.</p><p>We could implement this as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6b4e7e1da4906f5aaddae040a1c19ed/href">https://medium.com/media/a6b4e7e1da4906f5aaddae040a1c19ed/href</a></iframe><h3>The Prototype Chain</h3><p>As we saw in our previous example, our myVehicle instance is able execute the honk method, which is stored on the prototype property of the function constructor which was used to create it. This is possible because of the prototype chain.</p><p>Essentially, when the honk method is called, JavaScript will look at the calling objects properties, which in this case is myVehicle, for the method (or property) named honk. If this property is not found on the object, we move up one level of the prototype chain.</p><p>In order to establish the link between the object and it’s prototype, the __proto__ property of myVehicle is used. This __proto__ property is essentially a link to it&#39;s constructors prototype.</p><p>In general terms, an instances __proto__ property is a link to it&#39;s prototype (the prototype property of it&#39;s constructor).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*l43KDPcpZKHWdXhICtzqJA.jpeg" /><figcaption>A representation of the relationship between an object and it’s constructor.</figcaption></figure><p>We can demonstrate this in the console.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e39cd9fcb5e459917cbc252e8785f445/href">https://medium.com/media/e39cd9fcb5e459917cbc252e8785f445/href</a></iframe><p>So, through __proto__ we can access Vehicle.prototype to look for the honk method. And because we explicitly stored the honk method on the prototype we are able to execute it.</p><p>In this way, all instances of a Vehicle can access the honk method, without needing to store their own copy.</p><h3>Subclass Inheritance</h3><p>Now say we have a different constructor which is like Vehicle but more specific, such as a Motorcycle constructor. Motorcycle has all of the same properties and functionality as a Vehicle, but it also has an engineSize property and a refuel method.</p><p>Because a motorcycle shares the same properties as a Vehicle we can use inheritance to simplify our code. By making Motorcycle inherit from Vehicle we avoid having to specify the shared properties and methods twice.</p><p>Let’s take a look at how we might implement a Motorcycle subclass.</p><p><em>Note: Classes and subclasses are a feature of classical inheritance and not prototypal inheritance, which means that </em><em>Motorcycle is not actually a subclass. In JavaScript we the use the prototype chain in order to emulate classes and subclasses.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efab1a0fe34e1d987875d93fe799705c/href">https://medium.com/media/efab1a0fe34e1d987875d93fe799705c/href</a></iframe><p>To break this down step by step we will start with the last line where we create a new instance of Motorcycle. As we discussed earlier, a new empty object is created and then we call the Motorcycle function constructor with the value of this set to the new empty object.</p><p>Within the Motorcycle function constructor body we encounter the call method. Essentially what this line does is call theVehicle constructor function, passing in color, weight and year. The call method allows us to specify our own value for this, which when executed will be the new myMotorycle object.</p><p>This allows us to execute the Vehicle constructor, while setting the properties on the motorcycle instance. We then set the engineSize property as normal.</p><p>We are just missing one step. Currently motorcycle instances do not know how to access the Vehicles prototype property and thus cannot access the honk method.</p><p>To implement this we use the Object.create method. Object.create allows us to create a new object while specifying what the prototype of that object should be. The argument we pass in will be the prototype of the newly created object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4337506fde50ca706e723f1aaee8bab0/href">https://medium.com/media/4337506fde50ca706e723f1aaee8bab0/href</a></iframe><p>With this step we have connected the prototype chain.</p><p>The __proto__ property of Motorcycle.prototype will be set to Vehicle.prototypeand motorcycle instances can now access all of the properties and methods stored on the motorycle prototype as well as the vehicle prototype.</p><p>To demonstrate this, let’s add the refuel method to Motorcycles prototype.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/297dc2c793313e13f7372f7c0c8c5773/href">https://medium.com/media/297dc2c793313e13f7372f7c0c8c5773/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*KPmkmEzK6x1HpXcs92U_jg.png" /><figcaption>The Motorcycle prototype chain in the console.</figcaption></figure><h3>Conclusion</h3><p>The way JavaScript implements Object Oriented Programming differs from many other languages which use a class based system. By having a good grasp of prototypal inheritance, function constructors and the prototype chain you can take full advantage of the languages features and understand how JavaScript works under the hood.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f9d23f54f9" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/javascript-prototype-chain-and-inheritance-explained-from-scratch-5f9d23f54f9">JavaScript Prototype Chain and Inheritance Explained From Scratch.</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improve Your Git Productivity With VS Code]]></title>
            <link>https://blog.devgenius.io/improve-your-git-productivity-with-vs-code-aeed0c646796?source=rss-acf5522bab5------2</link>
            <guid isPermaLink="false">https://medium.com/p/aeed0c646796</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[vscode]]></category>
            <dc:creator><![CDATA[Ross Baker]]></dc:creator>
            <pubDate>Sun, 14 Jun 2020 07:11:56 GMT</pubDate>
            <atom:updated>2020-06-16T08:05:50.015Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*LyF7gnmrJfvP-97XHUdEEw.png" /></figure><p>When it comes to version control the most common way to interact with git is via the command line–often this is the most convenient and efficient way. However, if you want to increase your productivity VS Code has as number of built in features which can help you manage your workflow.</p><p>By default, VS Code has integrated support for git, although if you are using another source-control provider there are a number of extensions which offer the same or similar functionality. To find extensions for other source control providers you can search @category:&quot;scm providers&quot; in the extensions tab.</p><p>By taking advantage of VS Code’s built in source control features along side the command line you can:</p><ul><li>Increase your productivity.</li><li>Streamline your workflow.</li><li>Create cleaner commits.</li></ul><h3>Source Control Overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*Q68-o3xfaQmtpla24pwczQ.png" /><figcaption>The Source Control Tab</figcaption></figure><p>To begin with, the source control tab is where you will interact with VS code’s git features. This tab will show you an overview of any changes you have made in your current repository. These are split into categories — (unstaged) changes and staged changes.</p><p>A very useful feature of this is that you are able to view the changes made to a file side-by-side, so that you can quickly see what has been modified, removed or added in a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eYBsyQ7VB-AEUGRsTT2f-A.png" /><figcaption><em>VS Code changes/diff view — The file in the left pane is how it looked at the last commit, while the right pane shows the current status.</em></figcaption></figure><p>VS Code will highlight lines which have been modified so you can quickly see how a file has changed. Red lines indicate some text has been deleted, while the green lines indicate text has been added. In the above example you can quickly see side by side that the title has been changed, and a heading and paragraph has been added. On the very right, VS Code gives you an overview of the entire document with red and green blocks so that you can quickly navigate to find modifications in larger files. If you are viewing an unstaged change, you can edit the file directly from this editor on the right.</p><h3>File Status Indicators</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*2bNABuGXijY2WfdFyXUwng.png" /><figcaption>Status Indicators</figcaption></figure><p>From the explorer panel VS Code provides you with some indicators on the git status of files in your current folder. These are indicated by an uppercase letter to the right of the file.</p><ul><li>M: The file has been modified.</li><li>U: The file is not being tracked by git.</li><li>A: The file has been added for tracking but has not been modified.</li></ul><h3>Gutter Indicators</h3><p>Gutter indicators are a very useful tool for the following reasons:</p><ul><li>They allow you to see what changes have been made to a file as you are working on it.</li><li>They allow you to selectively add specific lines or blocks of code within a file to the staging area, meaning you can create cleaner and more specific commits.</li></ul><p>There are three different gutter indicator types:</p><ul><li>A red triangle means a line has been deleted.</li><li>A blue bar means a line has been modified.</li><li>A green bar means a line has been added.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*pL0UJxxasAy1az9lIAWGJA.png" /><figcaption>Gutter Indicators</figcaption></figure><p>Clicking on a gutter indicator will bring up a new window containing more information and options. The window will show you the changes that have been made to that specific block of code. The menu in the top right will give you options to revert these changes, or by clicking the plus in the top right you can stage those lines. This is useful if you want to commit only a specific block of code within a file, for example if you are still working on another part of the file, or you want to split multiple changes to a file into separate commits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVu-4QIlmmuqyicO1HEsTA.png" /><figcaption>Line-by-line changes.</figcaption></figure><h3>Merge Conflicts</h3><p>When you are merging code into a repository, for example when pulling down updated code from a remote repository or merging one branch into another, you may run into a merge conflict. Typically this occurs when a line or lines of code have been modified in both places e.g. the local and remote repository, or the master branch and another branch you are attempting to merge in to master.</p><p>In this case git is unable to tell which lines of code should be kept. In text editors such as VIM, this would be indicated with a series of characters separating the conflicts lines such as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*Ts-AvOrYtdIxmGfDsUspIQ.png" /><figcaption>A merge conflict in vim.</figcaption></figure><p>In this case you would need to manually remove the lines containing &lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD, ======= and &gt;&gt;&gt;&gt;&gt;&gt;&gt; test-2 as well as the change you want to remove e.g a paragraph.</p><p>However VS Code makes this process much simpler by automatically detecting merge conflicts and giving you options to merge them with the click of a button. Firstly the conflicts are highlighted, with the current changes in green and the incoming changes in blue. The options above the conflict allow you to keep either of the changes or both. You can also conveniently start a live share session if you need to pair program to get the conflict sorted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9QL6WEzBuZAkpTocpBDyPA.png" /><figcaption>A merge conflict in VS Code.</figcaption></figure><h3>Conclusion</h3><p>By using VS Code’s built in source control features you can conveniently manage your workflow and increase your productivity. To get the most out of VS Code source control you can use these integrated features alongside the git command line interface.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aeed0c646796" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/improve-your-git-productivity-with-vs-code-aeed0c646796">Improve Your Git Productivity With VS Code</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Your Ruby on Rails App Using Heroku]]></title>
            <link>https://medium.com/@rossabaker/deploy-your-ruby-on-rails-app-using-heroku-d468453fa2f8?source=rss-acf5522bab5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d468453fa2f8</guid>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Ross Baker]]></dc:creator>
            <pubDate>Sat, 09 May 2020 11:01:37 GMT</pubDate>
            <atom:updated>2020-05-17T07:31:18.258Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUOknyEHrQ6wGqynmp__Eg.jpeg" /></figure><h3>What is Heroku?</h3><p>Heroku is a flexible cloud platform for hosting your web applications. Originally supporting only Ruby, you can now utilise this Platform as a Service (PaaS) to deploy applications written in a range of languages. In this post I will go over all the basics you need to get your Rails app up and running on a live Heroku server, as well as some tips for debugging when things go wrong</p><p><strong>Note: </strong>Heroku supports the PostgreSQL database management system — if your rails application uses sqlite or another DBMS, you can follow my guide to switch it to PostgreSQL (<a href="https://medium.com/@rossabaker/switch-your-rails-app-from-sqlite-to-postgresql-a0474a29af20">https://medium.com/@rossabaker/switch-your-rails-app-from-sqlite-to-postgresql-a0474a29af20</a>).</p><h3>Step 1 — Signing up for a Heroku account and setting up your app.</h3><p>If you don’t already have a Heroku account, you will need to go to <a href="https://signup.heroku.com/">https://signup.heroku.com/</a> and create an account. Once you have signed up and set a password you will be taken to the get started page. From here we can create our new Heroku app. click on Create a new app, this will take you to the app setup page where you can give your new app a name and set the location. You should set the location to the nearest continent you expect your users to access the application from to ensure the fastest load times. It’s important to note that the name of your app will be used to create your URL. If you named your app “rails” — your URL would be rails.herokuapp.com.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*oUzRVIGKqcrPRGU1RSgbmg.png" /></figure><h3>Step 2 — The Heroku Command Line Interface.</h3><p>You can deploy your app directly from the command line, or from a GitHub repository. This post will cover both methods, if you choose to deploy from GitHub it is still useful to install the Heroku Command Line Interface (CLI) so that you can check your server logs and interact with your database straight from the command line.</p><p>If you are on Windows or MacOS you can head to <a href="https://devcenter.heroku.com/articles/heroku-cli#download-and-install">https://devcenter.heroku.com/articles/heroku-cli#download-and-install</a>. Download the installer and follow the install wizard.</p><p>If you prefer the command line, on macOS you can use homebrew package manager by running brew tap heroku/brew &amp;&amp; brew install heroku. On Linux using snap package manager run sudo snap install --classic heroku.</p><p>Now, login to your Heroku account from the command line by running heroku login - you will be prompted to open a web browser to log in to your Heroku account. Once logged in you now have access to your Heroku account and commands from the command line. Now you are ready to deploy your app!</p><h3>Step 3— Set Your Master Key on Heroku</h3><p>If you have any credentials in your credentials.yml file such as an Amazon Web Services Key or another API Key, you will need to set your master key so that Heroku can correctly decrypt them. To do this run in your terminal:</p><p>heroku config:set RAILS_MASTER_KEY=&lt;your-master-key&gt;</p><p>Replacing &lt;your-master-key&gt; with the the string found in the app/config/master.key file.</p><h3>Step 4— Deploying your app from the command line.</h3><p>From the command line navigate into the directory that contains your ruby on rails application. If you don’t already have one for your project, initialize a new git repository with git init (Ruby on Rails 5.1 or later will do this for you automatically when you create an app).</p><p>Now setup your Heroku app as a remote repository with the command heroku git:remote -a your_app_name_here. Now we can push to production!</p><p>Run git add . from your rails directory and then git commit -m &quot; your commit message&quot;to commit your latest changes. Next push to heroku by running git push heroku master - this will push your master branch to your Heroku server. Now head over to your URL (your_app_name.herokuapp.com) and check out your live site!</p><p>Whenever you want to update your app, just push your code with git to the heroku remote as you did in the previous step.</p><h3>Step 5 (Optional) — Github Integration.</h3><p>Integrating your Heroku app with GitHub allows you to automatically deploy each time you push your code to GitHub, saving you from having to push separately to Heroku. To get started log in to your Heroku dashboard from a web browser and click on your application. Go to the deploy tab, and under deployment method click on GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TYJUDLUdipLPT-DWP3jj3w.png" /></figure><p>If you haven’t already, you will be asked to connect to GitHub by logging in. After you have authenticated with your GitHub account, enter the name of your GitHub repository and click connect. Now all you need to do is click on the Enable automatic deploys button and select a branch, typically this will be the master branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9UK4dZdoiboyWDpbo-Y7w.png" /></figure><p>That’s it! From now on any time you push code to the master branch on GitHub your updated code will be deployed live on Heroku.</p><h3>Debugging</h3><h3>Build Logs</h3><p>Whenever you deploy your code Heroku will record a build log — if anything goes wrong during the deployment process you can find the specific error message here. To access the build logs from the Heroku dashboard go to the activity tab in your application, from the activity feed you can click “view build log” next to any build. Here is an example of a build log with the error that occurs if your app is configured with sqlite instead of postgreSQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zg7kFvZVyyWbqmtmHPl4aw.png" /></figure><h3>Heroku Server Logs</h3><p>If you have any errors on your Heroku site you can view them from the Heroku CLI the same way you would view errors when running the server locally. To access them you can run heroku logs from the command line. This will display the last 100 lines logged by your Heroku server. To specify the number of lines to display use the -n flag e.g. heroku logs -n 200 to see the last 200 lines.</p><h4>Real Time Server Logs</h4><p>To view your server log output in real time run heroku logs –tail. This command will display your recent logs and leave the command running, displaying the real time output.</p><h3>Interacting with your Heroku Database</h3><p>Once you have for your Heroku app up and running you may want to perform tasks on the database. For example any time you push a change to Heroku that requires a database migration you will need to migrate your production database as well. You can perform Rake commands on your production server by using the following syntax: heroku run rake db:command. So to migrate your production server the command would be heroku run rake db:migrate. It&#39;s important to do this whenever a change gets pushed with new migration files.</p><p>You can run other common rake commands in the same way, with an important exception being any commands which directly drop or create databases, such as rake db:reset or rake db:setup. If for some reason you really do need to drop your production database, you can reset it from within the Heroku dashboard or you can run heroku pg:reset from the command line. Be careful though, as this will delete all the data from your production database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d468453fa2f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Switch your Rails app from sqlite to PostgreSQL]]></title>
            <link>https://medium.com/@rossabaker/switch-your-rails-app-from-sqlite-to-postgresql-a0474a29af20?source=rss-acf5522bab5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0474a29af20</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Ross Baker]]></dc:creator>
            <pubDate>Sat, 09 May 2020 10:59:41 GMT</pubDate>
            <atom:updated>2020-05-09T10:59:41.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JV_Kl5rk0M9BPW9ZB9ch3Q.jpeg" /></figure><p>When you create a new Ruby on Rails application with the rails new command your application will use a sqlite database by default. This is fine for development however if you plan on deploying your application you should be using a more robust database such as PostgreSQL. Many hosting platforms such as Heroku do not support sqlite. In this post I will guide you through the steps to switch your Ruby on Rails application from sqlite to postgreSQL.</p><p>(Note: You can read more on why sqlite is a bad fit for Heroku at their devcenter: <a href="https://devcenter.heroku.com/articles/sqlite3">https://devcenter.heroku.com/articles/sqlite3</a>)</p><p>If there is any chance that you will deploy your application it is typically much easier to start off with a PostgresSQL database. You can do this by initializing your rails app with the command ruby new app_name -d postgresql. However, if you have been developing with sqlite there are a few modifications you will need to make to switch to postgreSQL.</p><h3>Step 1 — Install PostgreSQL</h3><p>First things first you will need to install PostgreSQL on your local computer, the process differs depending on your operating system. If you are on MacOS you can install with homebrew, or APT on Linux. There is also a graphical installer available for Windows. You can follow the official installation guide by selecting your operating system at <a href="https://www.postgresql.org/download/">https://www.postgresql.org/download/</a> and following the steps for your preferred method.</p><h3>Step 2 — Update your Gemfile</h3><p>Once you have PostgreSQL installed, update your Gemfile within your application by removing the sqlite gem and adding in the postgreSQL gem.</p><p>Change:</p><pre># Use sqlite3 as the database for Active Record<br>gem &#39;sqlite3&#39;</pre><p>To:</p><pre># Use postgresql as the database for Active Record<br>gem &#39;pg&#39;</pre><p>Now run bundle install to install the postgreSQL gem, this will update your Gemfile.lock (which will be used in production).</p><h3>Step 3 — Update your database configuration file.</h3><p>Update your database.yml file in order to configure your application with PostgreSQL.</p><p>Change:</p><pre>default: &amp;default<br>  adapter: sqlite3<br>  pool: &lt;%= ENV.fetch(&quot;RAILS_MAX_THREADS&quot;) { 5 } %&gt;<br>  timeout: 5000<br>​<br>development:<br>  &lt;&lt;: *default<br>  database: db/development.sqlite3<br>​<br>test:<br>  &lt;&lt;: *default<br>  database: db/test.sqlite3<br>​<br>production:<br>  &lt;&lt;: *default<br>  database: db/production.sqlite3<br>​</pre><p>To:</p><pre>default: &amp;default<br>  adapter: postgresql<br>  encoding: unicode<br>  # For details on connection pooling, see Rails configuration guide<br>  # <a href="http://guides.rubyonrails.org/configuring.html#database-pooling">http://guides.rubyonrails.org/configuring.html#database-pooling</a><br>  pool: &lt;%= ENV.fetch(&quot;RAILS_MAX_THREADS&quot;) { 5 } %&gt;<br>​<br>development:<br>  &lt;&lt;: *default<br>  database: YOUR_APP_NAME_HERE_development<br>​<br>test:<br>  &lt;&lt;: *default<br>  database: YOUR_APP_NAME_HERE_test<br>​<br>production:<br>  &lt;&lt;: *default<br>  database: YOUR_APP_NAME_HERE_production<br>  username: YOUR_APP_NAME_HERE<br>  password: &lt;%= ENV[&#39;YOUR_APP_NAME_HERE_DATABASE_PASSWORD&#39;] %&gt;<br>​</pre><p>Replacing all instances of YOUR_APP_NAME_HERE with the the name you gave your rails app when you initialized it with rails new app_name.</p><h3>Step 4 — Reset your database.</h3><p>This step will erase your sqlite database, make sure you have backed up any important data. A good seeds.rb file will help you populate your new database.</p><p>Run rails db:migrate:reset to delete your sqlite database and re-setup with PostgreSQL. Then run rails s to start the server and visit localhost:3000.Your rails app should now be up and running on a production ready database management system!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0474a29af20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the purpose of attr_accessor in Ruby?]]></title>
            <link>https://medium.com/@rossabaker/what-is-the-purpose-of-attr-accessor-in-ruby-3bf3f423f573?source=rss-acf5522bab5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bf3f423f573</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[methods]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Ross Baker]]></dc:creator>
            <pubDate>Wed, 18 Mar 2020 23:16:06 GMT</pubDate>
            <atom:updated>2020-03-19T10:34:21.779Z</atom:updated>
            <content:encoded><![CDATA[<p>After spending the last couple of weeks at <a href="https://medium.com/u/2f5a8250e367">Coder Academy</a> learning a ton about the Ruby programming language, I decided to dive deeper into the purpose of the attr_accessor method, what it does and how it works.</p><p>If you have been utilising this method without fully understanding its purpose, then hopefully this post will help clear things up!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_MO-0EKkLiMlEPbGrqUyog.jpeg" /></figure><p>To begin, let’s take a ‘Car’ class as an example. In Ruby we might define such a class as follows:</p><pre># Define a car class<br>class Car<br>   def initialize(make, color) <br>      @make = make<br>      @color = color<br>   end<br>end</pre><p>And then, create a new object of type Car:</p><pre># Create a car object<br>my_car = Car.new(&quot;Toyota&quot;, &quot;Red&quot;)</pre><p>This seems okay so far. When we create our my_car object, the initialize function will execute, setting the instance variables @make and @color to the strings &quot;Toyota&quot; and &quot;Red&quot; respectively.</p><p>But what happens if we try and print one of these attributes to the console?</p><pre>&gt; puts my_car.make<br>&gt; Traceback (most recent call last):<br>attr.rb:30:in `&lt;main&gt;&#39;: undefined method `make&#39; for #&lt;Car:0x000055955171fde0 @make=&quot;Toyota&quot;, @color=&quot;Red&quot;&gt; (NoMethodError)</pre><p>Hmm..this returns an undefined method error. Why is this the case when we have clearly set the make property?</p><p>This is because Ruby differs from some other languages when it comes to using dot notation to access object properties. In Ruby, . is used specifically for accessing object <em>methods</em>. It can&#39;t be used for accessing properties directly.</p><p>To get around this, we can define a new method (with the same name as the property) that does one thing: return the property that we want to access. Such a method is known as a <em>getter</em> method — its sole purpose is to <em>get</em> the value of the property and return it. Going back to our Car class, such methods for accessing our make and color variable would look like this:</p><pre>class Car<br>   def initialize(make, color) <br>      @make = make<br>      @color = color<br>   end<br>    <br>   # Getter methods <br>   def make<br>      return @make <br>   end<br>    <br>   def color<br>      return @color <br>   end<br>end<br>​<br>my_car = Car.new(&quot;Toyota&quot;, &quot;Red&quot;)</pre><pre>&gt; puts my_car.make<br>&gt; &quot;Toyota&quot;<br>&gt; puts my_car.color<br>&gt; &quot;Red&quot;</pre><p>Great! Now we can access the <em>instance variables</em> make and color with the .operator.</p><p>But let’s say our car got a paint job and we now want to change/update the color property. We might try to assign a new value to color as follows:</p><pre>&gt; my_car.color = &quot;Blue&quot;<br>&gt; Traceback (most recent call last):<br>attr.rb:38:in `&lt;main&gt;&#39;: undefined method `color=&#39; for #&lt;Car:0x0000563966e13930 @make=&quot;Toyota&quot;, @color=&quot;Red&quot;&gt; (NoMethodError)<br>Did you mean?  color</pre><p>Another undefined method error! Why can&#39;t assign a new value to this property?</p><p>Well, our color <em>getter</em> method will not allow us to update a variable, as it&#39;s only job was to return the value. As we now want to change it&#39;s value, it turns out we need to create another method to handle that (appropriately known as a <em>setter</em> method). In this case, the color= method, as this is the method that gets called when we try to assign the value. This method takes the new value as an argument and updates the instance variable. For example, setter methods for our Car class may look like:</p><pre>class Car<br>   def initialize(make, color) <br>      @make = make<br>      @color = color<br>   end<br>    <br>   # Getter methods<br>   def make<br>      return @make <br>   end<br>    <br>   def color<br>      return @color <br>   end<br>    <br>   # Setter methods<br>   def make=(new_make)<br>      @make = new_make <br>   end<br>    <br>   def color=(new_color)<br>      @color = new_color <br>   end<br>end</pre><p>We now have access to the make= andcolor= methods, which take an argument and assign it to the objects <em>instance variable</em> which we specify inside the <em>setter</em> method. Now, if we try and update our car objects color variable, we will no longer get an error!</p><pre>&gt; my_car.color = &quot;Blue&quot;<br>&gt; puts my_car.color<br>&gt; &quot;Blue&quot;</pre><h3>attr_reader, attr_writer &amp; attr_accessor</h3><p>You might be thinking that needing to create separate functions for each attribute that we want to be able to read and update is quite tedious — and it is. To make this process quicker and simpler Ruby includes some methods in its core API to help out.</p><h3>attr_reader</h3><p>The attr_reader method takes the names of the objects attributes as arguments and automatically creates <em>getter</em> methods for each! We can replace our <em>getter</em> methods with attr_reader and our car class definition becomes much simpler:</p><pre>class Car<br>   attr_reader :make, :color # &lt;-- Getter methods<br>    <br>   def initialize(make, color) <br>      @make = make<br>      @color = color<br>   end<br>    <br>   # Setter methods<br>   def make=(new_make)<br>      @make = new_make <br>   end<br>    <br>   def color=(new_color)<br>      @color = new_color <br>   end<br>end</pre><h3>attr_writer</h3><p>The same goes for <em>updating</em> our objects properties. For this however, we need to use the attr_writer method. This method works similarly to attr_reader, except that it will automatically create <em>setter</em> methods for our class. Replacing our setter methods in our Car class with attr_writer would look like this:</p><pre>class Car<br>   attr_reader :make, :color<br>   attr_writer :make, :color # &lt;-- Setter methods<br>    <br>   def initialize(make, color) <br>      @make = make<br>      @color = color<br>   end<br>end</pre><h3>attr_accessor</h3><p>This has cleaned up our class definition significantly and saved us a lot of time and lines of code writing out separate <em>getter</em> and <em>setter</em> methods for each instance variable.</p><p>However, when using the attr_reader and attr_writer methods, we still have to repeat all of the property names for each method twice.</p><p>This is where the attr_accessor method comes in handy and allows us to take it one step further, creating all of the <em>getter</em> <em>and</em> setter methods in a single line as follows:</p><pre>class Car<br>   attr_acceessor :make, :color # &lt;-- Creates both getter and setter             methods<br>    <br>   def initialize(make, color) <br>      @make = make<br>      @color = color<br>   end<br>end</pre><p>And that is why you will often see attr_accessor in Ruby classes!</p><h3>Recap</h3><p>attr_reader and attr_writer in Ruby allow us to access and modify instance variables using the . notation by creating <em>getter</em> and <em>setter</em> methods automatically. These methods allow as to access instance variables from outside the scope of the class definition. attr_accessor combines the functionality of these two methods into a single method.</p><h3>Bonus: Why use symbols and not strings in attr_accessor?</h3><p>You may be wondering why attr_reader, attr_writer and attr_accessor take symbols as their arguments.</p><p>The short and somewhat unsatisfying answer is that this is because the ruby documentation specifies that these methods should take symbols as their arguments! You can also use a string, however Ruby will just convert it to a symbol.</p><p>Stay tuned for a blog post about when and why to use symbols in Ruby!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bf3f423f573" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>