These are called Github Gists. A gist is an easy way to share excerpts of code or data with others in a clean and reader friendly way. In this article, you’ll see ways to display a function you’ve created, a query into a table, or some other small piece of data (like a sneak peek at a dataframe). These bits of information are hosted by GitHub as a repository. Using gist has all the benefits of utilizing a GitHub repository with a lightweight and easy to share embedding feature.

Not only are they cleaner but they allow coders who have vision issues a chance to read through your code using accessibility options.

For now, let’s go through the basics:

1. Getting to Github Gists

There are two ways of getting to the gists portion of Github.com. The first way is for you to go to **_Gist.Github.com _**and it will take you to the new gist creation. Or you can go through your Github home page.

Image for post

The Github homepage lets you get there two ways

The bottom red arrow, pointing at my profile picture, is how you would get to your repositories or gists. We’ll ignore that one for now and leave it for when we talk about editing old gists. The top arrow, pointing to the plus sign, leads to creating repos, gists, or projects — and that is the one we will be looking at first. After you click on the plus sign, you’ll see a dropdown menu.

The new gist link allows you to create a brand new gist

That will bring you to the page below. Note how you have several fields to fill out.

Image for post

Blank template for a new gist

  1. Description Box — This will be the title and unofficial name of the gist
  2. Filename + Extension — This is going to be where you name the file, in case of download. It is also the place you declare an extension for the programming language you have used.
  3. Code Box — This is where you enter/paste the code/data you want to display.

2. Creating a Code Snippet

From here it’s all plug and play. Let’s try to create a gist with a snippet of code we want to showcase — and I have just the one.

Below I have a snippet of code written out to impute data from a recent linear regression project I finished. It was written to impute the number of bedrooms a house may have using the bathrooms and square footage of living space of a given house.

Image for post

Snippet of Code I created through gists.github.com

The extension is very important. You can put things like .txt.py or .html. This notifies the reader what language it was written in — if it is not clear already, and it allows the file to be downloaded with the appropriate extension. The gist works whether you put an extension on it or not — but best ‘practices make better job opportunities’ — Paul Torres 2020.

After simply copy and pasting the code into the window and filled out the description and the file name.

I set the settings to public so that the gist could be found in a search on the website. However, you have the option of making a secret gist that cannot be searched — these gists can still be shared with links you can hand out.

#code #github #python #git #data-science

Github Gists 101: Making Code Sharing Pretty
1.45 GEEK