<?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 Shivam Kaushik on Medium]]></title>
        <description><![CDATA[Stories by Shivam Kaushik on Medium]]></description>
        <link>https://medium.com/@shivamkaushikofficial?source=rss-7eddc48545b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*zozzT94OFlB8Ag4JbT36_A.jpeg</url>
            <title>Stories by Shivam Kaushik on Medium</title>
            <link>https://medium.com/@shivamkaushikofficial?source=rss-7eddc48545b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 17:34:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivamkaushikofficial/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[Learn to Build a Masonry Gallery Layout Using Pure CSS]]></title>
            <link>https://medium.com/better-programming/learn-to-build-a-masonry-gallery-layout-using-pure-css-50331dbc1e15?source=rss-7eddc48545b------2</link>
            <guid isPermaLink="false">https://medium.com/p/50331dbc1e15</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Shivam Kaushik]]></dc:creator>
            <pubDate>Wed, 04 Dec 2019 00:52:12 GMT</pubDate>
            <atom:updated>2019-12-04T00:52:12.601Z</atom:updated>
            <content:encoded><![CDATA[<h4>Build a CSS grid like Pinterest</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YtncfH3ytlGBpwm5lMkNQw.png" /></figure><p>Today, I’m going to show you how you can build a complex masonry grid using CSS Grid. CSS Grid has changed the way we design our layouts and we’re going to build a fun project using its features.</p><p>If you feel rusty with CSS Grid or you feel the need to brush up, I suggest you read through this <a href="https://css-tricks.com/snippets/css/complete-guide-grid/">article</a>. In any case, I’ll explain every code I’ll introduce to build our project.</p><p>Alright. Let’s dive in.</p><h3><strong>What We Will Build</strong></h3><p>This is what our layout will look like at the end of the article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hU28ZdQ6TXFURS1WNlOGUA.png" /></figure><p>Looks interesting? If it does, continue on.</p><p>This is where CSS Grid really shines as it allows you to place and align your grid items to your liking and it can get as complex as you like.</p><h3>Things to Keep in Mind Before We Start Building the Grid</h3><ol><li>Calculate the smallest grid cell that you want to have in your grid, i.e. the smallest image you want to have in your grid.</li><li>A cell is determined by the number of rows (height) and the number of columns (width) it spans.</li><li>The smallest cell size will determine how complex your grid will be.</li><li>Calculate the number of columns and rows based on the smallest cell</li></ol><h3>Let’s Start Building</h3><p>Let’s first create a barebone HTML file that will eventually house our masonry grid. You can fork the base project from <a href="https://github.com/KaushikShivam/masonry-grid/tree/02f3e1a189f0c00ab36edb70c2dd65e67aad6e5b">GitHub</a>.</p><p>Let’s now look at the basic declarations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84adf84323eafd972e2cfc4ad5fb510d/href">https://medium.com/media/84adf84323eafd972e2cfc4ad5fb510d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4eea3dc69a3095334cec101cd2189398/href">https://medium.com/media/4eea3dc69a3095334cec101cd2189398/href</a></iframe><p>The first code snippet contains basic CSS resets and it defines .masonry selector to display as a grid. The second code snippet contains a section that will act as a grid and will eventually contain all the grid items.</p><p>Let’s make a couple of observations here.</p><ol><li>We’ve set the grid height and width to be 100vh and 100vw respectively so our grid takes up all the available screen size. You can customize it to your needs.</li><li>Grid columns/rows declaration: <br>grid-template-columns: repeat(16, 1fr) — This defines how many columns our grid will have. The repeat function lets us create multiple columns (16 in our case) with the same size. 1fr means that each of the 16 columns will have 1 fraction (fr) of the available width. <br>The same goes for the grid-row-columns: repeat(14, 1fr) declaration. <br>So, now we have a grid with 16 columns and 14 rows. You can change it according to your needs.</li><li>In our HTML file, we only have one grid cell, the figure element. We have nested our img tag under a figure tag. More on that later.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_kC8ZrwXbr0cvgtZhuquig.png" /></figure><p>This is how our grid looks right now. The image is overlapping the grid container as the image is huge.</p><p>This is why we have wrapped the image inside a figure tag. Images don’t work well with the grid cells as they have an aspect ratio that they conform to. The figure tag will now act as the grid cell and we can set the image to adjust inside it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97f6abcd45ebf3c933791f3b8f454be7/href">https://medium.com/media/97f6abcd45ebf3c933791f3b8f454be7/href</a></iframe><p>Adding the above styles to the img adjusts the image to conform to the bounds of the cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*0T0OHz3E0CinLhuyvndLYw.png" /></figure><h3>Finally, Let’s Lay Out Our Grid Cells</h3><p>Defining the grid columns and rows gave us access to the grid (column and row) tracks that we can now use to span the cell however we want.</p><p>You can visualize it better with the CSS Grid inspector. You can turn it on using this <a href="https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Examine_grid_layouts">Mozilla document</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Ilxn1BAdSVDPJbNIcFK5Q.png" /></figure><p>As you can see, the grid column tracks span from 1 to 17, giving us a total of 16 columns. Similarly, the grid row tracks span from 1 to 15 giving us 14 rows.</p><p>Let’s layout our first grid cell.</p><p>Now, we want our cell to span five columns wide and five columns high. We can define this using the CSS grid’s grid-row and grid-column properties.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/149c2f2db3e18c77d7f96ef0732a34c9/href">https://medium.com/media/149c2f2db3e18c77d7f96ef0732a34c9/href</a></iframe><p>Let’s look at the grid-column property first. We provide it with two values.</p><p>The first property defines the column track we want our cell to start spanning from and the second value defines the end. The same goes for the grid-row property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RBpA8NzNccgC5Jx1oEHQcg.png" /></figure><p>The cell now spans five columns wide and five columns high. There are a lot of different ways to provide values to grid-column and grid-row and you can read about them <a href="https://css-tricks.com/snippets/css/complete-guide-grid/">on CSS Tricks</a>.</p><p>Similarly, we can layout the rest of our cells. As a challenge, you can add more grid cells to your markup and try laying them out.</p><p>For the sake of brevity, I am including the code I wrote to build the masonry gallery I showed in the beginning.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f82a94b04fedace6b81fd4bfad097e92/href">https://medium.com/media/f82a94b04fedace6b81fd4bfad097e92/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e08a4218893808f0e801c3fd21016a4/href">https://medium.com/media/9e08a4218893808f0e801c3fd21016a4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJNEp5a09UH9BYOlYBTlcQ.png" /></figure><p>This is how the layout looks now. With the current knowledge, you can build even more complex grids. This was just an example to illustrate the basics of CSS Grids.</p><p>You can find the repo for this project <a href="https://github.com/KaushikShivam/masonry-grid">on GitHub</a>. If you have any questions, feel free to reach out to me.</p><p>That’s all, folks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50331dbc1e15" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/learn-to-build-a-masonry-gallery-layout-using-pure-css-50331dbc1e15">Learn to Build a Masonry Gallery Layout Using Pure CSS</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[How To Implement a Linked List Using JavaScript]]></title>
            <link>https://medium.com/better-programming/how-to-implement-a-linked-list-using-javascript-387729416a5b?source=rss-7eddc48545b------2</link>
            <guid isPermaLink="false">https://medium.com/p/387729416a5b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shivam Kaushik]]></dc:creator>
            <pubDate>Fri, 22 Nov 2019 23:20:33 GMT</pubDate>
            <atom:updated>2019-11-22T23:20:33.552Z</atom:updated>
            <content:encoded><![CDATA[<h4>Dive into a useful data structure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*typvDGtljh_06e3Da7ciLw.png" /></figure><p>Today, I’m going to show you how to implement a singly linked list and all its common functions from scratch. (Doubly linked list implementation coming very soon!)</p><h3>What Exactly Is a Singly Linked List?</h3><p>It’s an ordered data structure used to store values just like an array.</p><p>However, it has some key differences. Unlike an array, a linked list has no indices. Instead, a linked list contains <em>nodes</em> that are pointing to the next element using <em>pointers</em>.</p><p>A node<strong> </strong>contains a value (a number, string, or anything for that matter) and a pointer that references the next node. If there’s no next node, it points to null.</p><p>Let’s quickly implement a node that we’ll use for our linked list implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/155b660f3fc7daba6c556faf2ced50b5/href">https://medium.com/media/155b660f3fc7daba6c556faf2ced50b5/href</a></iframe><p>A linked list has a Head property, a Tail property, and an optional length<strong> </strong>property to keep track of the elements. The Head is the first node of the linked list and the Tail is the last.</p><p>To be able to access any node in the list, we start off with the node at the Head and traverse the list using the node’s next property and so on until we reach the node we’re looking for.</p><p>Refer to this <a href="https://visualgo.net/en/list">resource</a> to better visualize the traversal.</p><h3>Linked List Implementation</h3><p>Now that all the technical jargon is out of the way, let’s finally implement the linked list.</p><h4>Basic implementation</h4><p>We’ll start by defining a class that takes in the following values in the constructor:</p><ul><li>head points to the first node and is currently set to null.</li><li>tail points to the last node and is currently set to null.</li><li>length contains the list’s length and is set to 0 initially.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6523bba1a559161c34fc9da613bf19a/href">https://medium.com/media/c6523bba1a559161c34fc9da613bf19a/href</a></iframe><p>Let’s now implement the common functions associated with the linked list. It helps to keep the same <a href="https://visualgo.net/en/list">resource</a> as listed above open, to better understand and visualize each function explained in the following section.</p><p><strong>Important</strong>:<strong> </strong>All the functions implemented below are defined inside the LinkedList class that we’ve just created. I’ll be sharing the gists of each function separately for readability.</p><p>Here’s a link on <a href="https://github.com/KaushikShivam/LinkedList-js">GitHub</a> for the complete implementation.</p><h4><strong>Push function</strong></h4><p>Just like an array, the push function takes in a value and assigns it to the end of the list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/637e61f0b658aed877dcd8bd556f0e61/href">https://medium.com/media/637e61f0b658aed877dcd8bd556f0e61/href</a></iframe><ul><li>The push function takes a value and creates an instance node with it.</li><li>It then checks if the head property is not null. If it is, that means that there’s no element (node) on our list. So, if there’s no element on our list, the function assigns the newly created node to the head and the tail property.</li><li>There, if the head property is not null (i.e. there are elements (nodes) on our list), it sets the tail&#39;s next property to point to the newly created node, as well as set the new tail to point to the newly created node.</li><li>Finally, it increments the length property by 1.</li></ul><h4>Pop function</h4><p>The pop function, like an array, removes an element (node) from the end of the list. However, it requires us to traverse through the whole list as there are no indices.</p><p>We traverse through the whole list until we reach the second last node. We then set its next property to null and set it to be our new tail. Let’s see it in code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b52ba558a3d8daefe60d03790da41b0/href">https://medium.com/media/7b52ba558a3d8daefe60d03790da41b0/href</a></iframe><ul><li>The function returns undefined if the list is empty. You can optionally return null as well.</li><li>It then loops through the list until it reaches the tail. It also keeps track of the previous item as that we set to be our new tail.</li><li>When it reaches the tail, it assigns the second-last time that we are keeping track of to be our new tail.</li><li>It then decrements the length of the list by 1.</li><li>Finally, it returns the popped item.</li><li><strong>Edge case</strong>— Check if all items are popped off. If they are, set the head and tail to be null.</li></ul><h4><strong>Unshift function</strong></h4><p>It’s a simple function that adds an element to the start of a list.</p><ul><li>It creates a node with the value that’s passed to the function.</li><li>If sets the head and tail to point to this node if the list is empty.</li><li>Otherwise, it sets the current head to point to this node’s next property and sets this node to be the new head.</li><li>Finally, it increments the length by 1.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40e7675975cf33e06777abf73d2cd539/href">https://medium.com/media/40e7675975cf33e06777abf73d2cd539/href</a></iframe><h4><strong>Shift function</strong></h4><p>This function is also pretty simple. It removes the first element of the list and returns it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/858f571f153ae0f6f965dd33f44a3825/href">https://medium.com/media/858f571f153ae0f6f965dd33f44a3825/href</a></iframe><ul><li>It returns undefined if the list is empty. You can optionally return null.</li><li>Store the current head and set the new head to point to the current head’s next property.</li><li>Decrement the length by 1.</li><li>Finally, return the removed element.</li></ul><h4>Get function</h4><p>The get function takes a number (an index) and loops through the list until it finds the node at that index and returns it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e0185341855fdc74698eaa3780ebe44/href">https://medium.com/media/7e0185341855fdc74698eaa3780ebe44/href</a></iframe><ul><li>If the passed index is out of bounds, return undefined. You can optionally return null.</li><li>Iterate through the list until it reaches the specified index and returns the node at that index.</li></ul><h4>Set function</h4><p>The set function takes an index and a value. It then assigns that value at the specified index.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/367d0b67a4500f3956cba899f517f565/href">https://medium.com/media/367d0b67a4500f3956cba899f517f565/href</a></iframe><ul><li>It used the get method to find the node at the specified index.</li><li>Assigns the value of the node if it is found and returns true.</li><li>Otherwise, returns false.</li></ul><h4>Insert function</h4><p>The insert function takes an index and a value just like the set function. Unlike the set function, though, it inserts the value at the specified index.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31115fccae5770b3f210f11f0fce0b73/href">https://medium.com/media/31115fccae5770b3f210f11f0fce0b73/href</a></iframe><ul><li>If the index is out of bounds, return undefined.</li><li>It pushes the node with the provided value to the end of the list if the index is the same as the length. We’ll use our push function here for our convenience.</li><li>It pushes the node with the provided value to the beginning of the list if the index is 0. We’ll use our unshift function here for our convenience.</li><li>Otherwise, it gets the element <em>before</em><strong> </strong>the specified index and assigns its next property to our new node with the specified value.</li><li>It then assigns the next property of the new node to point to the next property of the element <em>before</em><strong> </strong>the specified index.</li><li>Finally, it increments the length by 1 and returns true.</li></ul><h4>Remove function</h4><p>The remove function takes in an index and removes the value at the specified index.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e915554a857def9ac3a22056fc3ad8c9/href">https://medium.com/media/e915554a857def9ac3a22056fc3ad8c9/href</a></iframe><ul><li>If the index is out of bounds, it returns undefined.</li><li>It removes the node from the end of the list if the index points to the last element’s index. We’ll use our pop function here for our convenience.</li><li>It removes the node from the beginning of the list if the index is 0. We’ll use our shift function here for our convenience.</li><li>Otherwise, it gets the element <em>before</em><strong> </strong>the specified index and assigns its next property to point to the next property of the node at the specified index!</li><li>Finally, it decrements the length by 1 and returns the removed node.</li></ul><h3>Where to Go From Here</h3><p>Phew! That’s about it.</p><p>There’s a lot that we could have implemented or improved. But if you understand these common functions, you’ll be able to do most of it on your own.</p><ul><li>Go through the explanations and try to implement it on your own.</li><li>Refer to <a href="https://visualgo.net/en/list">VisuAlgo</a> to better understand and visualize how each function works.</li><li>Also, read through <a href="https://medium.com/@mckenziefiege/arrays-linked-lists-and-big-o-notation-486727b6259b">this article</a> for a big-O analysis and comparison with arrays.</li></ul><h3>Conclusion</h3><p>Here’s the <a href="https://github.com/KaushikShivam/LinkedList-js">GitHub repo</a> for the complete linked implementation. Feel free to comment below if you have any doubts and I’ll try my best to clarify it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=387729416a5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-implement-a-linked-list-using-javascript-387729416a5b">How To Implement a Linked List Using JavaScript</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[How To Create and Publish Your Own Ruby Gem From Scratch]]></title>
            <link>https://medium.com/better-programming/how-to-create-and-publish-your-own-ruby-gem-from-scratch-92ec8419c104?source=rss-7eddc48545b------2</link>
            <guid isPermaLink="false">https://medium.com/p/92ec8419c104</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[rubygems]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby-on-rails-development]]></category>
            <dc:creator><![CDATA[Shivam Kaushik]]></dc:creator>
            <pubDate>Tue, 24 Sep 2019 14:00:07 GMT</pubDate>
            <atom:updated>2019-09-24T14:01:13.302Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Create and Publish Your Own Ruby Gem From Scratch</h3><h4>Building a gem that generates a random text</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*ZgXExMvcrs2YQ6xZ8lUf0Q.jpeg" /></figure><p>Today, I’m going to show you how you can create and publish your very own Ruby gem.</p><p>We’re going to build a gem that generates a random greeting text along with the User’s name (E.g. “Bonjour, John”).</p><p>You can use it from anywhere in your Rails application.</p><p>The gem’s functionality is pretty basic . This is only meant to be a guide; a step-by-step process, if you will. Once you’ve got the process down, you can create anything you like!</p><p>Let’s dive in.</p><h3>Setting Up the Files</h3><p><em>This tutorial assumes that you already have </em><a href="https://github.com/bundler/bundler"><em>bundler</em></a><em> installed on your system. If you don’t please </em><a href="https://github.com/bundler/bundler"><em>install it</em></a><em> before continuing.</em></p><p>Navigate to the local directory you want to create the gem in.</p><p>Run the following command in your terminal to create all the files necessary to create a gem:</p><pre>bundle gem random_greeting_generator</pre><p>I chose random_greeting_generator for the name of my gem but you can (and should) give it any name you like. A good rule of thumb is to make sure that the name is unique, otherwise you’ll have conflicts when publishing the gem.</p><p>You can check the name availability by going to <a href="https://rubygems.org/">RubyGems.org</a> and make sure that no gem with the same name exists:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xm7gu8sefz_k_suRHDix2Q.png" /><figcaption>Searching for “random_greeting_generator” yields no results</figcaption></figure><p>Finally, running the bundle command creates the necessary files for us to start building our gem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*Urbb6c3Vze-xCX2is-bDlw.png" /><figcaption>Generated files after running “bundle gem random_greeting_generator”</figcaption></figure><h3>Let’s Start Building!</h3><p>Let’s navigate to the root of the generated directory and open up the random_greeting_generator.gemspec file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qubErsRrjWYhq965ltJm6g.png" /></figure><p>The gem generator has pre-configured a lot of settings for you but there are some to-dos, as highlighted in the screenshot, that you need to complete for it to compile properly.</p><p>These are pretty straight forward:</p><ul><li>Summary</li><li>Description</li><li>Homepage</li></ul><p>Now, navigate into the lib/random_greeting_generator<strong> </strong>directory and create a generator.rb file. This file will hold the logic for our gem:</p><pre>module RandomGreetingGenerator<br>  class Generator<br>    def self.random_greeting name <br>      greetings = [&quot;Hello&quot;,&quot;Bonjour&quot;,&quot;Hola&quot;,&quot;Guten tag&quot;,<br>        &quot;Hej&quot;,&quot;Salve&quot;,&quot;Nǐ Hǎo&quot;,&quot;Xin chào&quot;,&quot;Hei&quot;,&quot;Ahoj&quot;<br>      ]<br>      # Creates a random greeting string<br>      &quot;#{greetings.sample}, #{name}&quot;<br>    end<br>  end<br>end</pre><p>Add this code to lib/random_greeting_generator/generator.rb.</p><p>Next, we import this module to the random_greeting_generator.rb<strong> </strong>file in the lib directory:</p><pre>require &quot;random_greeting_generator/version&quot;<br>require &quot;random_greeting_generator/generator&quot;<br><br>module RandomGreetingGenerator<br>  <br>end</pre><p>Now, you need to edit the .gitignore<strong> </strong>file and add all the files with the .gem extension that should be ignored.</p><pre>/.bundle/<br>/.yardoc<br>/_yardoc/<br>/coverage/<br>/doc/<br>/pkg/<br>/spec/reports/<br>/tmp/<br><br># Ignore all files with the .gem extension<br>*.gem</pre><p>Update your README.md<strong> </strong>and add a proper description and usage instructions.</p><p>Finally, create a repository on <a href="https://github.com/">Github</a> and push your local repo remotely.</p><h3>Generate the Gem!</h3><p>Finally, let’s run the command to generate the gem!</p><p>Navigate to your root directory and run the following command in the terminal:</p><pre>gem build random_greeting_generator.gemspec</pre><p>If all goes well, you’ll see the results printed out in your terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*hpJxUeGQVINb-aG3xg_UIA.png" /></figure><h3>Publishing Our Gem to RubyGems.org!</h3><p>Head over to <a href="https://rubygems.org/">RubyGems.org</a> and create your account. Once you’re logged in, go to the <a href="https://rubygems.org/profile/edit">edit profile</a> page and you will find a curl command under the API Access section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*4YEjRVfqp8uO4mwazeI8eQ.png" /></figure><p>Copy the curl command and run it in terminal to get all the useful commands you’ll need to publish your gem. Provide your password if you’re prompted for it.</p><p>Once it’s installed, navigate to your gem’s root directory and run the following command:</p><pre>bundle exec rake release</pre><p>You might get an error if you don’t have rake installed:<strong><br></strong>Could not find gem ‘rake (~&gt; 10.0)’ in any of the gem sources listed in your Gemfile.</p><p>In that case, run bundle install<strong> </strong>as suggested then re-run the above command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*-ScZVABnFiNAWZSErqymqQ.png" /><figcaption>Gem successfully created and pushed to RubyGems.org</figcaption></figure><p>If all goes well, you’ll see successful messages as in the screenshot above.</p><p>Head over to your <a href="https://rubygems.org/">RubyGems.org</a> profile page and you’ll see your newly created Gem file!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RpHvOlDpeOEXXGsZeT1X0A.png" /></figure><p>Congratulations! You now have your new Gem published for the world to see and use. Comment on the article if you are getting any errors and I’ll try my best to help you fix it.</p><h3>Resources</h3><p>Find the repo for this guide <a href="https://github.com/KaushikShivam/random_greeting_generator">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92ec8419c104" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-create-and-publish-your-own-ruby-gem-from-scratch-92ec8419c104">How To Create and Publish Your Own Ruby Gem 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>
    </channel>
</rss>