<?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 Shane Lonergan on Medium]]></title>
        <description><![CDATA[Stories by Shane Lonergan on Medium]]></description>
        <link>https://medium.com/@sptlonergan?source=rss-7180ca6ebbd6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*QxRugOtx_uY3fB7tEpg9gQ.jpeg</url>
            <title>Stories by Shane Lonergan on Medium</title>
            <link>https://medium.com/@sptlonergan?source=rss-7180ca6ebbd6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 15:48:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sptlonergan/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[What Even is REST?]]></title>
            <link>https://medium.com/weekly-webtips/what-even-is-rest-7c31d88846a1?source=rss-7180ca6ebbd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c31d88846a1</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Shane Lonergan]]></dc:creator>
            <pubDate>Thu, 09 Apr 2020 14:28:58 GMT</pubDate>
            <atom:updated>2020-05-28T18:25:47.613Z</atom:updated>
            <content:encoded><![CDATA[<h4>De-mystifying one of programming’s most notorious acronyms</h4><figure><img alt="What is REST?" src="https://cdn-images-1.medium.com/max/1024/1*ZVmb_WePlYo01GwGjOBVdw.jpeg" /><figcaption>Image of the word REST</figcaption></figure><p>Welcome to my new series, <strong>What Even Is?</strong> In this series I will be examining common programming concepts that I have encountered and used throughout my learning so far, but that I didn’t always fully grasp. For the first post in this series, I thought that REST would be the perfect concept. The first programming language I learned was Ruby, and of course, Rails came soon after. The way I learned to build my first web server was through RESTful convention, and I understood how to build RESTFful APIs mainly through the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview">HTTP Protocol</a>. I knew how to follow the convention for RESTful routes, but after a while, I began to wonder if I really understood what REST was. As it turns out, I didn’t! So I set out to learn. In this article, I will walk through what I found out.</p><h3>So, What is REST?</h3><p>REST is an architectural style for building APIs. This essentially means that it is a series of rules or standards for the interaction between a client and a server. Even more simply, it is a guide for how your browser and server should talk to one another.</p><h3>What is the origin of REST?</h3><p>REST was introduced in 2000 by computer scientist Roy Fielding as part of his <a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm">PhD dissertation</a>. Fielding was also deeply involved in the early development of the World Wide Web and was a principal author of the original HTTP specification.</p><h3>What is the purpose of REST?</h3><p>The goal of REST was to create a web standard for client-server architecture. This standard would provide a roadmap for developers building new APIs, as well as making it easier to learn how to use others. REST helps unify API’s and reduce variation, and thus additional learning, across the web.</p><h3>How does REST work?</h3><p>REST stands for REpresentational State Transfer. This means that when we make a request to a RESTful API, the server will <em>transfer</em> a <em>representation</em> of the <em>state</em> of the requested information. For example, if I were to use Twitter’s API to fetch a single user, it would return a snapshot of the state of that user, including their information, tweets, likes, followers, etc.</p><h3>What are the fundamentals of REST?</h3><p>There are 6 constraints for RESTful APIs:</p><ol><li>Uniform Interface</li><li>Client-Server Separation</li><li>Stateless</li><li>Layered System</li><li>Cacheable</li><li>Code-on-demand (optional)</li></ol><p>In order for an API to be RESTful, it must follow at least the first 5 of these constraints. Let&#39;s take a deeper look at each of them:</p><h4>Uniform Interface</h4><p>This means that the request to a RESTful API should look the same no matter its point of origin. Whether it is coming from a Chrome browser, a Python script, or a Linux server, all RESTful requests should have the same structure.</p><h4>Client-Server Separation</h4><p>The server and the client exist in separate worlds. They can only interact through requests, which can only be made by the client, and responses, which can only be sent by the server in response to a request. Essentially, the server must simply sit and wait for a request from the client. Only then can it take action and send back the relevant information.</p><h4>Stateless</h4><p>The server does not remember anything about the user who calls upon it. It only knows what is sent in the request. Thus, each individual request will contain everything the server needs to know to execute the request and send a response. The server has no knowledge of what is happening client-side, and vice versa.</p><h4>Layered System</h4><p>The server and client are unaffected by the number of layers between themes. For example, there could be a security layer, a caching layer, and a load balancing layer, but none of these should affect how the client and server communicate.</p><h4>Cacheable</h4><p><a href="https://restfulapi.net/caching/">Caching</a> is essentially the process of storing frequently-accessed data so that you don’t have to constantly be asking your server to find it and give it to you. Server responses must, implicitly or explicitly, be identified as cacheable or non-cacheable. If it is cacheable, it should include some sort of version number, and the client should know whether or not their version is up-to-date.</p><h4>Code-On-Demand</h4><p>Clients should be able to request code from the server which, when received, can be executed by the client. This code can take many forms, such as a JavaScript script or Java applet. This constraint is optional, and thus is not required for an API to be considered RESTful.</p><h3>Congrats!</h3><p>Viola! If your API follows the first 5 of these conventions, it is officially RESTful. Hopefully, you now have a deeper understanding of REST and RESTful convention. Thank you so much for reading, and keep your eyes out for the next article in the “What even is…” series!</p><h3>References</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Glossary/REST">REST — MDN Docs</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview">HTTP — MDN Docs</a></li><li><a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm">Chapter 5: Representation State Transfer — Roy Fielding</a></li><li><a href="https://restfulapi.net/caching/">Cacheing — restfulapi</a></li><li><a href="https://www.codecademy.com/articles/what-is-rest">What is Rest? — Codecademy</a></li><li><a href="https://medium.com/extend/what-is-rest-a-simple-explanation-for-beginners-part-1-introduction-b4a072f8740f">What is REST — A Simple Explanation for Beginners, Part 1 — Shif Ben Avraham</a></li></ul><h3>Further Reading</h3><ul><li><a href="http://restcookbook.com/Miscellaneous/rest-and-http/">Are HTTP and REST the same thing?</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview">HTTP</a></li><li><a href="http://www.restular.com/">RESTular: a Sinatra routing resource</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c31d88846a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/what-even-is-rest-7c31d88846a1">What Even is REST?</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tracking User Streaks in Ruby]]></title>
            <link>https://levelup.gitconnected.com/tracking-user-streaks-in-ruby-a49e90ce46a1?source=rss-7180ca6ebbd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a49e90ce46a1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Shane Lonergan]]></dc:creator>
            <pubDate>Sun, 02 Feb 2020 03:20:02 GMT</pubDate>
            <atom:updated>2020-02-02T19:20:41.326Z</atom:updated>
            <content:encoded><![CDATA[<h4>Maintain user engagement through daily habit-tracking</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ov0UdO8OowCzTX37bVraVg.jpeg" /><figcaption>image of habit tracking journal from <a href="https://unsplash.com/">https://unsplash.com/</a></figcaption></figure><p>From Duolingo to Headspace, many of the most popular apps today track users’ “streaks”. By keeping track of the number of days in a row a user has logged in and completed a task, these apps aim to create a beneficial habit for the user, while simultaneously insuring an active daily user base. With habit-tracking apps <a href="https://www.vox.com/the-goods/2019/1/2/18158989/habit-tracking-apps-new-years-resolutions">exploding</a> in popularity, evidence seems to indicate that desire to keep a streak going will indeed motivate a person to do a task they might not otherwise.</p><p>With streaks being such a popular feature, a <a href="https://medium.com/@avijitklodh">friend</a> and I decided to try and incorporate it into a recent project we were working on. The application walked a user through the steps of a <a href="https://www.wimhofmethod.com/">Wim Hof</a> breathing cycle, and we wanted to display the number of days in a row they had completed at least one cycle.</p><h3>The goal</h3><p>Track the number of consecutive days a logged-in user completed a breathing cycle, and display that number on the home page of our application. When the user completes a new session on a consecutive day for the first time, that number should update immediately.</p><h3>The solution</h3><p>After a few unsuccessful attempts at using gems or code-snippets, we decided it would be easier and a better learning experience to write our own code. We also opted to track the streaks in the back end, because Ruby makes working with dates and times simpler. Here is the final version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9r1Rh0-7t5LwEVqtH1jEeg.jpeg" /><figcaption>screenshot of code sample <a href="https://gist.github.com/shanelonergan/b86a6704ca1e7d7c9a4a610c8f363ee6">(https://gist.github.com/shanelonergan/b86a6704ca1e7d7c9a4a610c8f363ee6</a>)</figcaption></figure><h3>The breakdown</h3><p>Our application is built on a ruby-on-rails back-end, with a vanilla JavaScript front end. There are two models: User and Session. A Session <em>belongs to</em> a User, and a User <em>has many</em> Sessions.</p><h4>Step 1: Set up relationships</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L9lErb0cDmPKl_-63YJ4Fw.jpeg" /><figcaption>screenshot of code sample, lines 1–2</figcaption></figure><p>First we need to create a Ruby class of User, which inherits from ApplicationRecord, a rails model that includes the <a href="https://guides.rubyonrails.org/active_record_basics.html">Active Record</a> ORM (more on Object-Relational-Mappers <a href="https://blog.bitsrc.io/what-is-an-orm-and-why-you-should-use-it-b2b6f75f5e2a">here</a>). We can then add the ActiveRecord syntax for a has-many relationship as seen on line 2. This allows us to access all of a User&#39;s sessions by simply calling .sessions on in instance of a User. Additionally, Active Record relationships can take a second argument, <a href="https://edgeguides.rubyonrails.org/association_basics.html#scopes-for-belongs-to">scope</a>, which allows us to customize the SQL query. We will want to haver our array ordered from most recent date to least recent date, which can be accomplished if we query for <strong><em>descending</em></strong> order:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9b246b4f91f5f2dd0f15d68068e01ea/href">https://medium.com/media/a9b246b4f91f5f2dd0f15d68068e01ea/href</a></iframe><h4>Step 2: Define an instance method</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pjsMF8o4vXdd3Q6Vq-ibkg.jpeg" /><figcaption>screenshot of code sample, lines 1–10</figcaption></figure><p>Next, we need to create an instance method, streak, that we can call on an instance of a User to get their streak. Inside this method, we will declare a a couple local variables we will need later in the function. First, lets set streak_count to 0. We should also define today for readability. Ruby allows us to easily find and format the current day using Time.now.to_date. Time.now will return a date in a long format:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b4d422ed88706594425449a980629d2/href">https://medium.com/media/7b4d422ed88706594425449a980629d2/href</a></iframe><p>Since we only want to keep track of days, we can get rid of all of the extraneous information using to_date. This will return a simple, readable date format.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fedc984bec38bec178d278c3caa336b/href">https://medium.com/media/0fedc984bec38bec178d278c3caa336b/href</a></iframe><h4>Step 3: Create an array of dates</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G0mfIdoeOIVMCtyi8XbKrw.jpeg" /><figcaption>screenshot of code sample, lines -16</figcaption></figure><p>In order to make sure that multiple sessions in the same day will not count towards the streak, we want to create an array only containing the unique dates. We will do this in two steps:</p><ol><li>Using the enumerable method .map, we can create an array of dates converted from the created-at timestamp for every session.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26103278094e5ab337689b170652f45f/href">https://medium.com/media/26103278094e5ab337689b170652f45f/href</a></iframe><p>2. Apply .uniq to that array to ensure it only includes unique dates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d959a7c55f2a2f1eb6b990c1a2348263/href">https://medium.com/media/d959a7c55f2a2f1eb6b990c1a2348263/href</a></iframe><p>Finally, we need to establish a default value for the streak_count, 0. We now have most of the variables we will need to calculate the streak!</p><h4>Step 3: Calculate the streak</h4><p>For this step, we will take advantage of the Ruby enumerable method reduce. If you are not familiar with reduce, I would recommend checking out this <a href="https://mixandgo.com/learn/what-is-a-ruby-reducer">great article</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8FPG-bbI8ffi-1mNEDsVjw.jpeg" /><figcaption>screenshot of code sample, lines 1–34</figcaption></figure><p>Lets walk through this method. The basic structure of a reducer in pseudocode looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3187121281e2ec84030566c248889fa1/href">https://medium.com/media/3187121281e2ec84030566c248889fa1/href</a></iframe><p>Typically, the accumulator (conventionally called the memo) is the return value of the method. For example, if you were calculating the sum of an array of numbers, it would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d2a8c2ebaeed198e33200f2a30c57eb/href">https://medium.com/media/7d2a8c2ebaeed198e33200f2a30c57eb/href</a></iframe><p>However, for our method, we need to track two different variables: the current streak value, and the date of the <em>last consecutive session</em>. This is because we are counting in reverse chronological order, starting with today’s date. Lets break it down:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/587ceecdbc5d1e230d1902f156c595c1/href">https://medium.com/media/587ceecdbc5d1e230d1902f156c595c1/href</a></iframe><p>Here we are calling reduce on the unique dates array, and passing in today, which we defined in step 2, as starting value for the memo. Then we are defining a local variable, yesterday, as the reformatted date of the day before the memo.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b713295dcb8e71395eb1ce2bca6d02e/href">https://medium.com/media/8b713295dcb8e71395eb1ce2bca6d02e/href</a></iframe><p>Finally, we want to create an <em>if</em> statement that determines when to increment the streak count. If the user had finished a session today, then date will be equal to today during first iteration through the array; we would want to increment then. For each following iteration, we want to check if date is equal to yesterday. If it is, that means that the user has finished a session three days in a row, and so we should increment again. This will continue to increment as long as the next date in the array is the day prior to the current date we are iterating over. This works because we ordered the sessions array in descending order based on their created_at attributes, as mentioned above.</p><p><strong>important:</strong> Don’t forget to return the streak count at the end of the streak method, or else the return value will be the final memo from our reducer.</p><h4>Congrats! You can now calculate user streaks in your rails application</h4><p>This code should be modifiable to work with any Active Record model with a <em>has_many</em> relationship. Good luck tracking all those streaks!</p><p>Below is the final code with comments included, and you can check out the app this code was written for <a href="https://shanelonergan.github.io/breathe/">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWCoOLTUWXR1jNEEKUEdQw.jpeg" /><figcaption>screenshot of code sample with comments</figcaption></figure><h3>GitHub Gist</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afd0a873b0c1bf0046ff1364b59dddeb/href">https://medium.com/media/afd0a873b0c1bf0046ff1364b59dddeb/href</a></iframe><p>Thank you for reading! If you enjoyed the article, feel free to follow me here on medium or on twitter <a href="https://twitter.com/shane__lonergan">@shane__lonergan</a>.</p><h3>References</h3><ul><li><a href="https://www.vox.com/the-goods/2019/1/2/18158989/habit-tracking-apps-new-years-resolutions">Habit-tracking apps are the latest self-improvement trend. But do they work?</a></li><li><a href="https://www.wimhofmethod.com/">Wim Hof Method</a></li><li><a href="https://guides.rubyonrails.org/active_record_basics.html">Active Record Basics</a></li><li><a href="https://blog.bitsrc.io/what-is-an-orm-and-why-you-should-use-it-b2b6f75f5e2a">What is an ORM and Why You Should Use it</a></li><li><a href="https://mixandgo.com/learn/what-is-a-ruby-reducer">What is a Ruby Reducer?</a></li><li><a href="https://edgeguides.rubyonrails.org/association_basics.html#scopes-for-Belongs-to">Scopes for belongs_to</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a49e90ce46a1" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/tracking-user-streaks-in-ruby-a49e90ce46a1">Tracking User Streaks in Ruby</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[How Would You Build document.getElementsByClassName From Scratch?]]></title>
            <link>https://medium.com/better-programming/building-javascript-from-scratch-5caf5e7cc464?source=rss-7180ca6ebbd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5caf5e7cc464</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Shane Lonergan]]></dc:creator>
            <pubDate>Sat, 25 Jan 2020 20:13:29 GMT</pubDate>
            <atom:updated>2020-01-29T21:01:47.301Z</atom:updated>
            <content:encoded><![CDATA[<h4>A look at an interesting interview question</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o0L2M4H7xMQgY69sa-hM-w.png" /><figcaption>screenshot of code sample</figcaption></figure><p>I’m currently diving into my first job search as a software engineer and I recently had a mock technical interview. The interview was for JavaScript and consisted of two questions. The first was a fairly standard algorithm question, but the second was quite interesting: I was asked to build the document.getElementByClassName method from scratch — as if it didn&#39;t exist.</p><p>I found it enlightening to build out a method that I’d used so many times before. It improved my understanding of both DOM manipulation and JavaScript as a whole. In this article I will walk you through the solution I came up with.</p><h3>Goal</h3><p>The goal is to create a functionally equivalent version of <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName">document.getElementByClassName</a>. In order to do this, our new function needs the following features:</p><ul><li>It can be called on any HTML element.</li><li>It takes one argument, a string, containing any number of class names.</li><li>It returns all elements that match all the class names passed in.</li><li>It returns only elements that are children of the element the function was called on</li></ul><h3>Example</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e56d39d24fb81edd4bdbd0084995c349/href">https://medium.com/media/e56d39d24fb81edd4bdbd0084995c349/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71c95a3e70f1cd65c413ec9e0a64c4b3/href">https://medium.com/media/71c95a3e70f1cd65c413ec9e0a64c4b3/href</a></iframe><h3>Plan</h3><p>First, we need to create a conceptual plan for our function:</p><ol><li>Create an array to store all the elements that are a match.</li><li>Check all direct descendants of the main element for the class name. If any do, add them to the array.</li><li>Check all of those children’s children the same way.</li><li>Repeat until there are no more children.</li></ol><p>Based on this plan, we need to create a recursive helper function, or a function that calls itself within its own definition, to check all elements beneath the primary. We will call this helper function within the main function. The return value of the main function should be an array of elements, which we will declare as an empty array at the top, and add elements to as we move along.</p><p>We have a solid plan. Let’s get coding!</p><h3>Code</h3><h4>Step 1: Set up the main function</h4><p>Here we will define our main function. In the body, we will define two variables: elements, an array into which all elements with matching class names will be added; firstChildren, all the children of the element the function is called on. For the latter, we can take advantage of JavaScript&#39;s method, which returns an <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection">HTMLCollection</a> containing all child elements of the node upon which it is called. This HTMLCollection can be treated as an array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f31d1c9a637067e48f3987554c23c63/href">https://medium.com/media/2f31d1c9a637067e48f3987554c23c63/href</a></iframe><h4>Step 2: Write the recursive helper function</h4><p>A <a href="https://javascript.info/recursion">recursive function</a> is a function which calls itself within the definition, while a helper function is a function that abstracts some code to make it both re-usable and more readable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73c2ef416fc80bc476a08d167074a0a1/href">https://medium.com/media/73c2ef416fc80bc476a08d167074a0a1/href</a></iframe><h4>Step 3: Put it all together</h4><p>Now we want to call the checkChildren method on each of the firstChildren. After this function runs, our elements array should contain all the matching elements!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79c491bce93b985ba303d4c9ed407921/href">https://medium.com/media/79c491bce93b985ba303d4c9ed407921/href</a></iframe><h4>Step 4: Add to the HTML Element prototype</h4><p>Finally, for us to be able to call this function on any HTML Element, we need to add it to the HTML element <a href="https://medium.com/better-programming/prototypes-in-javascript-5bba2990e04b">prototype</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5159f1c3538ea40bbbd277cf9b079bd8/href">https://medium.com/media/5159f1c3538ea40bbbd277cf9b079bd8/href</a></iframe><p>Just like that, we’re done! Our new method getElementsByClassName2 now has the same functionality as the original getElementsByClassName. I hope you found this process as interesting and informative as I did.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5caf5e7cc464" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/building-javascript-from-scratch-5caf5e7cc464">How Would You Build document.getElementsByClassName From Scratch?</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to CSS Frameworks]]></title>
            <link>https://medium.com/swlh/a-beginners-guide-to-css-frameworks-7bdfb9a1acb0?source=rss-7180ca6ebbd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bdfb9a1acb0</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shane Lonergan]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 00:01:01 GMT</pubDate>
            <atom:updated>2019-10-21T00:01:01.775Z</atom:updated>
            <content:encoded><![CDATA[<h4>An introduction to some of the most popular ways to get your website looking good and fast.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1b1Squ5deh9lpyV-EZ8Xng.jpeg" /><figcaption>Logos from left to right: Bootstrap, Foundation, Materialize, Bulma</figcaption></figure><p>CSS frameworks are an extremely popular front-end development tool. They can allow developers without vast CSS and JavaScript experience to create beautiful, interactive websites. However, when I decided to use a CSS framework for the first time, it is easy to become overwhelmed by the number of options out there. This article will provide an introduction to CSS frameworks in general, as well as a few of the most popular options available.</p><h3>What is a CSS Framework?</h3><p>A CSS framework is a combination of design best-practices and standardized class systems that provide a basic structure for styling a web page. Practically, they are usually an external stylesheet that you link to, giving you a grid system to layout content and a collection of CSS classes to style elements with. Often, frameworks will also provide whole components, which are chunks of HTML that come pre-styled with CSS. These can range from simple buttons to entire forms or navigation bars. Some frameworks also come with font and icon libraries, as well as JavaScript files for animations and interactivity.</p><h3>Popular Frameworks</h3><h4>1. Bootstrap</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JS8kIIfp3Q36hix1Ntiysw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKPSGupEathExiUsbgUMmA.png" /><figcaption>On right: Bootstrap’s landing page, On left: Bootstrap example template</figcaption></figure><p>Originally developed at Twitter to create consistency among internal projects, <a href="https://getbootstrap.com/">Bootstrap</a> has grown to become one of the most popular CSS frameworks, often being the default choice for many developers. It offers a wide variety of page templates and UI components (chunks of HTML you can add to your code) and tons of styling options for everything. Bootstrap also offers templates that include JavaScript for interactivity and animations. While it’s relatively simple to get started on, the massive amount of options can make it easy to get lost in as a beginner. Bootstrap has also become so ubiquitous that some developers worry websites styled with it won’t stand out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cyPcDJNQAbA35HosEBF8TQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpSMvwE9fOSYyPVOx2Ljmg.png" /><figcaption>On left: Foundation home page, On Right: Foundation example template</figcaption></figure><h4>2. Foundation</h4><p><a href="https://foundation.zurb.com/">Foundation</a> is an industrial-grade CSS framework favored by large companies such as eBay, Disney, and Mozilla. While some think it isn’t as aesthetically pleasing as Bootstrap out of the box, it is one of the most powerful frameworks available. This is because it takes a minimalist approach to style pre-built components, allowing designers more room to customize the final product. Foundation is the most complex framework on this list, and I wouldn’t recommend it for beginners. However, Foundation does offer <a href="https://courses.zurb.com/">certification courses</a>(at a cost), if you have some prior front-end experience and are looking to dive into something more sophisticated.</p><h4>3. Materialize</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ISHrpqgwyXM_LxL7N3wcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8PORNdkRY4y1-YwbOKIfA.png" /><figcaption>On left: Materialize home page, On Right: Materialize example template</figcaption></figure><p><a href="https://materializecss.com/">Materialize CSS</a> is built on Google’s <a href="https://material.io/design/">Material design principles</a>. Material is one of the most popular design languages, with most of Google’s applications, including YouTube and Google Drive, being built on its principles. If you are going for the look and feel of google and android, this is likely the framework for you.</p><h4>4. Bulma</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZwE9xH3EfKc8FfNOh3kLrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LwupKtRPmnTyQySyFZ8bYg.png" /><figcaption>On left: Bulma home page, On Right: Bulma example template</figcaption></figure><p><a href="https://gist.github.com/shanelonergan/bulma.io">Bulma</a> is an up-and-coming lightweight CSS-only framework. Bulma is extremely beginner-friendly, with intuitive class names and easy-to-follow startup tutorial. I also think Bulma is one of the most beautiful CSS frameworks straight out of the box, with a clean and colorful aesthetic. Additionally, the community is very passionate, so you can find a lot of helpful guides and code snippets to guide you along the way. Since Bulma is CSS only, you will need to provide your own JavaScript if needed.</p><h4>5. Skeleton</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZURyG66KU4crZoL2UkYKg.png" /><figcaption>Skeleton home page</figcaption></figure><p><a href="http://getskeleton.com/">Skeleton</a> is the most lightweight CSS framework I know of, so much so that it doesn’t actually call itself a framework, rather a boilerplate. Skeleton’s codebase comes in at ~400 lines and is meant to be more of a starting point than a complete UI toolkit. It is designed to be used for smaller projects that don’t require the utility of larger frameworks and includes a basic grid layout and a handful of HTML elements to get your project on its feet. Skeleton is great for a first CSS framework, or for experienced developers who are looking to maximize efficiency and want to eliminate every line of excess code.</p><h3>Getting started</h3><p>Once you have decided on a framework, it is time to get started. I would recommend building a practice project to familiarize yourself with the framework’s various classes, templates, and workflows. Each framework’s respective website usually has a guide to installation and getting started, and once you are up and running, feel free to check out some of the tutorials below. Have fun creating beautiful, interactive websites with your newfound CSS framework skills!</p><h3>Further Resources</h3><ul><li><a href="https://www.youtube.com/watch?v=5GcQtLDGXy8">Bootstrap Beginner Crash Course — Traversy Media (not up to date for Bootstrap 4)</a></li><li><a href="https://www.bootstrapdash.com/bootstrap-4-tutorial/introduction/">Bootstrap 4 Tutorial — Bootstrap Dash</a></li><li><a href="https://scotch.io/tutorials/make-material-design-websites-with-the-materialize-css-framework">Make Material design websites with the material CSS framework — Narayan Prusty</a></li><li><a href="https://scrimba.com/g/gbulma">Learn Bulma CSS for free — Scrimba</a></li></ul><h3>Frameworks</h3><ul><li><a href="https://getbootstrap.com/">Bootstrap</a></li><li><a href="https://foundation.zurb.com/">Foundation</a></li><li><a href="https://materializecss.com/">Materialize CSS</a></li><li><a href="http://bulma.io/">Bulma</a></li><li><a href="http://getskeleton.com/">Skeleton</a></li></ul><h3>References</h3><ul><li><a href="https://geekflare.com/best-css-frameworks/">Best CSS Frameworks</a></li><li><a href="https://scotch.io/bar-talk/6-popular-css-frameworks-to-use-in-2019#toc-tailwind-css">6 Popular CSS frameworks to use in 2019</a></li><li><a href="https://material.io/design/">Material</a></li><li><a href="https://en.wikipedia.org/wiki/Material_Design">Material Design</a></li><li><a href="https://en.wikipedia.org/wiki/Bootstrap_(front-end_framework)">Bootstrap (front-end-framework)</a></li><li><a href="https://courses.zurb.com/">Zurb University</a></li></ul><h3>Logos</h3><ul><li><a href="https://miro.medium.com/max/1024/1*9HanDsRU11ZMsgDGJwN96w.png">Bootstrap</a></li><li><a href="https://mpng.pngfly.com/20190324/ztz/kisspng-foundation-portable-network-graphics-css-framework-5c97929dcc4892.7984600015534373418368.jpg">Foundation</a></li><li><a href="https://aitorriba.com/images/frameworks/materialize.svg">Materialize CSS</a></li><li><a href="https://github.com/jgthms/bulma/blob/master/docs/images/bulma-icon.png">Bulma</a></li></ul><p><em>Originally published at </em><a href="http://shanelonergan.github.io/"><em>shanelonergan.github.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bdfb9a1acb0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/a-beginners-guide-to-css-frameworks-7bdfb9a1acb0">A Beginner’s Guide to CSS Frameworks</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[How to Make a Beautiful Personal Website Quickly]]></title>
            <link>https://medium.com/better-programming/how-to-make-a-beautiful-personal-website-quickly-cab115866134?source=rss-7180ca6ebbd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/cab115866134</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[jekyll]]></category>
            <category><![CDATA[website]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Shane Lonergan]]></dc:creator>
            <pubDate>Fri, 20 Sep 2019 17:21:20 GMT</pubDate>
            <atom:updated>2019-09-27T22:29:00.602Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using Jekyll and Github Pages to create and host a great looking website, for free</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bMV4d71xGuwOvVahLoXpZQ.jpeg" /><figcaption>Jekyll logo: the word jekyll in lowercase cursive with a red bubbling test tube at the right side</figcaption></figure><p><strong>tl;dr: </strong><a href="https://jekyllrb.com/">Jekyll</a> is a Ruby gem that allows you to create custom static websites. It is simple and customizable, offering a wide variety of themes for blogs, personal websites, portfolios, and more. You can use Jekyll in conjunction with <a href="https://pages.github.com/">Github Pages</a> to create and host your own website for free, fast.</p><p><strong>Before you begin</strong>: This guide assumes some basic Ruby, HTML/CSS, and Git experience. It will still be possible to follow without, but it may require a bit of extra research. Start by following the instructions under Set Up Your Environment, below. If you get stuck, I have added some articles that I found helpful in Further Reading, at the end of the piece.</p><p>Creating your personal website can often be a daunting task. There are a ton of options for a variety of skill levels, from using Wix or WordPress templates to coding one from scratch. Building from scratch gives you the most control over the end product; using a template can get you up and running quickly with the lowest learning curve. If you have a little bit of coding experience, something in the middle might actually be the best option.</p><p>One way to create a simple, beautiful website quickly is to use Jekyll and then deploy it for free on GitHub Pages. Jekyll is a ruby gem which is great for creating personal websites and blogs, and it’s what I used to make my own blogging site. It offers a variety of themes, is extremely customizable, and most importantly, it is fast!</p><p>In this piece, I’ll walk you through creating and deploying your own personal website using Jekyll and Github Pages.</p><h3>Set Up Your Environment (Optional)</h3><p><strong>Note:</strong> I specify terminal commands in this article with a $. If you are copying these commands directly, only copy the text following the $.</p><ol><li>Download a text editor if you don’t already have one. I use Atom, but a lot of people really love Visual Studio Code as well.</li><li>Create a GitHub account. Git is a version control software</li><li>Install <a href="http://osxdaily.com/2018/03/07/how-install-homebrew-mac-os/">Homebrew</a></li></ol><pre>$ /usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</pre><p>4. Install Ruby and Bundler</p><pre>$ brew install ruby<br>$ gem install bundler</pre><p>Jekyll is a Ruby gem, which is essentially a library of code created by a group of dedicated programmers and released, for free, to us. It is open source, which means that it’s maintained by more amazing programmers who volunteer their time to keep great software free and accessible.</p><p>Getting started with Jekyll is super simple. Before making a custom site, it can be helpful to make a sample site first. To do that, enter the following commands in your terminal:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b0eec6d96ad9d0d4e170d88584f4b3c/href">https://medium.com/media/8b0eec6d96ad9d0d4e170d88584f4b3c/href</a></iframe><p>Now, open up your web browser and go to http://localhost:4000. TaDa! You have a website up and running! Take a browse through this website to familiarize yourself with the basic Jekyll theme.</p><h3>Make a Custom Jekyll Project</h3><p>Now that you have created your first Jekyll site, you will want to take a look at the themes and decide which one you want to use for your own. You can find all of the themes available at <a href="https://jekyllthemes.io/">jekyllthemes.io</a>. There is a wide variety of beautiful free and paid themes designed for blogs, portfolios, landing pages, and more. Once you have decided on your theme, it is time to dive in.</p><h4>Step 1. Open the theme on your local computer</h4><ol><li>Navigate the GitHub page for the theme of your choice (there should be a link in the description):</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjd_3PqZegID8VVfzSW4-g.jpeg" /><figcaption>Screenshot of a Jekyll theme website, with an arrow pointing to a button labeled “get Flexible-Jekyll on GitHub”</figcaption></figure><p>2. Fork the repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzJx0B4HrzU_Ajgu1-KqmQ.jpeg" /><figcaption>Screenshot of the Flexible-Jekyll GitHub page with an arrow pointing to the “fork” button at the upper right-hand corner</figcaption></figure><p>3. Copy the clone link:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6hNahNiyGkgDNI3vKFbew.jpeg" /><figcaption>Screenshot of the forked Flexible-Jekyll repository with an arrow pointing to the clone link in a dropdown from the “clone or download” button</figcaption></figure><p>4. Clone the repo into your local folder:</p><pre>$ cd ..<br>$ cd jekyll-projects<br>$ git clone &quot;paste-your-link-here&quot;</pre><p>5. Navigate into the project folder:</p><pre>$ cd theme-name-here</pre><p>6. Run your server:</p><pre>$ jekyll serve</pre><p>Now you can browse your template on http://localhost:4000.</p><h4>Step 2. Customize the project with your own information</h4><p>In your project directory, you should see a file called _config.yml. Click on that file to open it, and you will see a document with all of the stock information in it. You can replace this placeholder text with all of your personal information, and it will show up on your web page. If you want to add any images, drag and drop them into the img folder. Then just provide the file name in the config file, and you are good to go!</p><p>If you have HTML/CSS skills, you can also dive into the _layouts or css folders to customize even further. For example, I wanted to add a subtitle to my posts and wasn&#39;t satisfied with how it looked in markdown, so I added some custom HTML.</p><h4>Step 3. Add your content</h4><p>If you are creating a personal blog, there should be a couple of sample posts. To create a new post, create a new file in the _posts folder. You will have to write your posts in markdown, which might be new. However, don&#39;t despair! Markdown is actually a fantastic and simple way to create great-looking text files. Check out the <a href="https://www.markdownguide.org/cheat-sheet/">Markdown Cheat Sheet</a> to get started. Next, copy and paste the header from one of the sample posts, and update it with your post&#39;s info. Now, all that is left is the easy part: Write your post!</p><h3>Host Your Website on GitHub Pages</h3><p>So, you have finished writing your posts and adding all of your content, and your website looks fantastic in your local browser. Congratulations! That is no small feat. Now it’s time to get it up and running for the world to see. Hosting your website can seem like a complicated process, but GitHub makes it super easy.</p><h4>Step 1. Rename your project</h4><p>In order for a project to be hosted a personal site on GitHub pages, it needs to follow a specific title syntax: <em>username</em>.github.io, where <em>username</em> is your GitHub username. You can change the title directly from your text editor by control-clicking on the project folder and selecting rename.</p><h4>Step 2. Commit and push your changes to Github</h4><p>Follow the following steps if you are not already familiar with git to save this version of your project to your GitHub Profile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fb8e6e0ed6162d4311a4f2cbd772043/href">https://medium.com/media/3fb8e6e0ed6162d4311a4f2cbd772043/href</a></iframe><h4>Step 3. Check out your live website!</h4><p>Go to <a href="http://www.*username*.github.io/">www.<em>username</em>.github.io</a> to view your website. Congratulations! You have created and hosted your own personal website. That is no easy feat, so be proud of yourself, and send that link to all your friends!</p><p>There is a ton more you can do to customize your website once you are finished. You can add a custom URL, custom error pages, and more! Check out the GitHub pages documentation in the references below to learn more. Additionally, if you love Jekyll, consider <a href="https://opencollective.com/jekyll/contribute">contributing</a> to help their team keep it running.</p><p>Thank you for reading!</p><h3>References</h3><ul><li><a href="https://jekyllrb.com/">Jekyll</a></li><li><a href="https://jekyllthemes.io/">Jekyll Themes</a></li><li><a href="https://pages.github.com/">GitHib Pages</a></li></ul><h3>Further Reading</h3><ul><li><a href="https://atom.io/">Atom</a></li><li><a href="http://osxdaily.com/2018/03/07/how-install-homebrew-mac-os/">How to Install Homebrew on Mac</a></li><li><a href="https://www.ruby-lang.org/en/documentation/installation/">Installing Ruby</a></li><li><a href="https://guides.rubygems.org/what-is-a-gem/">What is a Gem?</a></li><li><a href="https://opensource.com/resources/what-is-git">What is Git?</a></li><li><a href="https://www.markdownguide.org/cheat-sheet/">Markdown Cheat Sheet</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cab115866134" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-make-a-beautiful-personal-website-quickly-cab115866134">How to Make a Beautiful Personal Website Quickly</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating new bash commands and aliases]]></title>
            <link>https://medium.com/swlh/creating-new-bash-commands-and-aliases-c9272fd589c4?source=rss-7180ca6ebbd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9272fd589c4</guid>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Shane Lonergan]]></dc:creator>
            <pubDate>Mon, 02 Sep 2019 00:00:00 GMT</pubDate>
            <atom:updated>2019-09-11T05:28:26.883Z</atom:updated>
            <content:encoded><![CDATA[<h4>Streamline your workflow with custom terminal commands</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cMLbIq7p7g3nejWg.jpg" /><figcaption>Screenshot of a custom terminal command executing</figcaption></figure><blockquote><strong>tl;dr:</strong> Custom bash commands are keywords that you can explicitly define to either execute a new function or shorten an existing command. These commands are extremely versatile and customizable, allowing you to tailor them to increase your productivity. Once they are defined in your .bash_profile document, you will be able to call on them in any new terminal session.</blockquote><p>As a young programmer, interacting with my computer through the terminal (or bash) can still sometimes feel foreign and clunky. I am in my fifth week at Flatiron School’s Software Engineering program, and we work through a lot of labs as part of the curriculum. In order to work on each lab, I would have to follow a series of steps just to open it:</p><ol><li>Fork it from the Github page</li><li>Clone it into a local directory</li><li>Navigate into the lab folder</li><li>Bundle install the proper Ruby gems (for Ruby/ Ruby on Rails labs)</li><li>Open the project in my text editor</li></ol><p>Five steps just to get the lab open on my computer! After a while, I realized that there had to be a better way. As it turns out, this all can be streamlined into one easy step. Enter custom bash commands.</p><p><strong>In this article I will walk through creating custom bash commands in Unix-based operating systems (Mac OS and Linux).</strong> These are custom commands you can input in your bash/terminal that either shorten an existing command or execute a pre-defined series. Some examples of what you can accomplish are:</p><ul><li>Easily navigate into a directory with a long file path</li><li>Git add, commit, push, and merge with one command.</li><li>Easily bundle install, migrate, and seed a newly opened project.</li><li>Download a mp3 version of a youtube video from your terminal.</li><li>Whatever else you can think of!</li></ul><h4>Adding custom commands can be done in just 4 easy steps:</h4><h3>1. Open your bash profile document</h3><p>Each time you open a new terminal session, it loads up your preferences from a hidden document. Files related to the terminal are typically hidden, or invisible. These files have a . at the beginning of their name, don&#39;t show up in finder searches, and are usually stored in the root directory. For our purposes we only need to know how to view, open, and create these files, but for more information see the further reading below. In order to view these files, enter the following commands in your terminal:</p><pre>$ cd ~<br>$ ls -a</pre><p>The first command navigates to the root directory (if not already there), and the second prints out all of the files saved there. You should see a file named .bash_profile. Go ahead and open that in any text editor. You could add your custom commands anywhere in this document, but in the spirit of readable code we will want to create a new document with all of our new commands, and simply link to that document in our bash profile.</p><h3>2. Create a custom commands file</h3><p>To create a new invisible file, enter the following command in your terminal:</p><pre>$ touch ~/.custom_bash_commands.sh</pre><p>Open this up in your preferred text editor, and add the following code:</p><pre>#!/bin/bash<br><br># greet the user<br>function greet() {<br>      echo ‘Hello’ $1‘!’<br>}</pre><p>Once you have saved that file, we need to test if it works. To make this command available, enter the following:</p><pre>source ~/.my_custom_commands.sh</pre><p>Now try out the new command:</p><pre>$ greet Shane</pre><p>You should see Hello Shane! (or whatever name you give as an argument), printed out. Congrats! You have just made your first custom bash command. However, using the above would require you to run the source command every time you opened a new terminal. If we link to this file in our bash profile, our new commands will come pre-loaded in every new terminal session.</p><h3>3. Link to the file in your bash profile</h3><p>Back in your .bash_profile document, add the same command we ran earlier, source ~/.my_custom_commands.sh, anywhere you would like. This will simply run that source command, linking to your custom commands, every time you open a new terminal. To access these commands, you can either run source ~/.bash_profile or close your terminal and open up a new session.</p><h3>4. Write your custom commands!</h3><p>There are two ways to create a custom command: aliases and functions. An alias usually shortens an existing command, while a function can chain multiple commands together.</p><p>Alias:</p><p>alias gcl=&quot;git clone&quot;</p><p>Function:</p><pre>function lazygit() {<br>		git add .<br>		git commit -m &quot;$1&quot;<br>		git push origin master<br>}</pre><p>If you are passing any arguments into the function, the first parameter will be stored in $1. For multiple parameters, they will be stored in $2, $3, and so on. You could technically accomplish this function with an alias as well:</p><pre>alias lazygit=&quot;git add . &amp;&amp; git commit -m &#39;$1&#39; &amp;&amp; git push origin master”</pre><p>It is up to you which method to use, but I find the function method to be more readable. Now go ahead and save your bash profile, and open up a new terminal to test your functions.</p><h3>Congratulations! You have just created your own custom bash commands!</h3><p>Have fun diving deep into the world of shell scripting. There is a lot more you can accomplish, such as using loops and conditions to create versatile new functions. Below is the first custom function I added to my terminal, and the one that led me down the path of writing this very article!</p><pre>function boom {<br> reponame=${1##*/};<br> reponame=${reponame%.git};<br> git clone &quot;$1&quot; &quot;$reponame&quot;;<br> cd &quot;$reponame&quot;;<br> bundle install;<br> atom .<br>}</pre><h4>Note:</h4><p>This guide is written primarily for MacOS users. It should work for any UNIX based operating system (such as Linux), but if you are experiencing any issues I suggest looking into whether your computer uses a login or non-login shell. If non-login, replacing .bash_profile with .bashrc (run control) in the above instructions should work. Additionally, the instructions in this article will work for some non-bash shells, but you will need to source your custom command file (step 3) in your respective shell profile document. For Zsh, you can simply add the same command in your .zshrc document.</p><h4>References:</h4><ul><li><a href="https://medium.com/devnetwork/how-to-create-your-own-custom-terminal-commands-c5008782a78e">How to create your own custom Terminal commands</a></li><li><a href="https://ryanstutorials.net/bash-scripting-tutorial/bash-script.php">What is a bash script?</a></li><li><a href="https://ryanstutorials.net/bash-scripting-tutorial/bash-script.php">What is the difference between .bash_profile and .bashrc?</a></li><li><a href="http://patorjk.com/software/taag/#p=display&amp;f=Graffiti&amp;t=Type%20Something%20">ASCII Art generator</a></li></ul><h4>Further Reading:</h4><ul><li><a href="https://nektony.com/how-to/show-hidden-files-on-mac">Show hidden files and folders on mac</a></li><li><a href="https://www.unixmen.com/non-login-shell-login-shell/">Non-login shell and Login Shell</a></li></ul><p><em>Originally published at </em><a href="https://shanelonergan.github.io/streamline-your-workflow-with-custom-bash-commands/"><em>https://shanelonergan.github.io</em></a><em> on September 2, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9272fd589c4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/creating-new-bash-commands-and-aliases-c9272fd589c4">Creating new bash commands and aliases</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>
    </channel>
</rss>