github gists 101使代碼共享漂亮

If you’ve been going through Medium, looking at technical articles, you’ve undoubtedly seen little windows that look like the below:

如果您一直在閱讀Medium,并查看技術文章,那么您無疑會看到類似于以下內容的小窗口:

def hello_there(x):print('Hello there, ' + x)

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.

這些被稱為Github Gists。 要點是一種以簡潔易懂的方式與他人共享代碼或數據摘錄的簡便方法。 在本文中,您將看到顯示創建的函數,查詢表或其他小數據(例如偷偷看數據框)的方法。 這些信息由GitHub作為存儲庫托管。 使用gist具有利用具有輕量級且易于共享的嵌入功能的GitHub存儲庫的所有好處。

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.前往Github Gists (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.

有兩種方法可以訪問Github.com的要點部分。 第一種方法是讓您轉到Gist.Github.com ,它將帶您進入新的gist創作。 或者,您可以瀏覽您的Github主頁。

Image for post
The Github homepage lets you get there two ways
Github主頁讓您到達那里的兩種方式

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.

底部的紅色箭頭指向我的個人資料照片,它是您到達存儲庫或要點的方式。 我們暫時將其忽略,而在談論編輯舊要點時將其保留。 頂部的箭頭指向加號,它會導致創建存儲庫,要點或項目-這就是我們首先要看的那個。 單擊加號后,您會看到一個下拉菜單。

Image for post
The new gist link allows you to create a brand new gist
新的gist鏈接可讓您創建全新的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.

    Filename + Extension ( 文件名+擴展名) —如果要下載,它將在其中命名文件。 在這里,您可以聲明所用編程語言的擴展名。

  3. Code Box — This is where you enter/paste the code/data you want to display.

    代碼框 -在此輸入/粘貼要顯示的代碼/數據。

2.創建代碼段 (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
我通過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.

擴展名非常重要。 您可以放入.txt.py.html之類的內容 。 這樣可以通知讀者使用的是哪種語言-如果尚不清楚,則可以使用適當的擴展名下載文件。 無論您是否進行擴展,要旨都是可行的-但最好的“實踐會創造更好的工作機會” —保羅·托雷斯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.

我將設置設為公開,以便可以在網站上的搜索中找到要點。 但是,您可以選擇創建無法搜索的秘密要點-這些要點仍然可以與您可以分發的鏈接共享。

3.創建CSV表 (3. Creating a CSV Table)

The next feature we look at is the creation of tables using gists. Gists are not only for showing snippets of code. You can also display small shots of data in them. I say small because as of the publishing of this article, I have not found a method of entering data beyond copy and paste or manual entry.

我們要看的下一個功能是使用要點創建表。 要點不僅用于顯示代碼片段。 您也可以在其中顯示少量數據。 我之所以這么說是因為,在撰寫本文時,我還沒有找到一種可以復制和粘貼或手動輸入數據的方法。

The first step is to start a new gist and edit the file name so that it ends in .csv. This tells the website that you are going to be entering in values for the column index and cells separated by commas. Make sure that each column name is separated by a comma and each subsequent row is ordered in the same was as the column names.

第一步是啟動新的摘要并編輯文件名,使其以.csv結尾。 這告訴網站您將要輸入列索引的值以及用逗號分隔的單元格。 確保每個列名都用逗號分隔,并且每個后續行的排序順序與列名相同。

Image for post
Make sure to write the words as you would want them to appear
確保寫出您希望它們出現的單詞

Looking at the picture above, we can see that the first row of entries are the column names. The second row is the first observation in the data. All of the entries have to be separated by a comma and they all have to be in the order of the column names in the first row. This continues on for the entirety of the table.

看上圖,我們可以看到條目的第一行是列名。 第二行是數據中的第一個觀察值。 所有條目都必須用逗號分隔,并且它們都必須按照第一行中列名的順序排列。 對于整個表格,此操作繼續進行。

Don’t worry about segmentation of the cells or the font of the column names — the website does it for you.

不必擔心單元格的分割或列名稱的字體-網站會為您完成。

Now, let’s take a look at the finished table.

現在,讓我們看一下完成的表。

Each observation is segmented into a different row and each feature is segmented into its own cell. As we said before, the formatting of the font was done automatically when the column names are bolded and placed at the top of their columns.

每個觀察值都被劃分為不同的行,并且每個特征都被劃分為自己的單元格。 如前所述,當列名加粗并放在其列的頂部時,字體的格式會自動完成。

One very helpful feature is the Search Box on the top of the table. It’s not accessible from the embedding but it is on the website. You can search the table and it returns only the values you designate.

一個非常有用的功能是表格頂部的搜索框 。 無法通過嵌入進行訪問,但可以在網站上找到。 您可以搜索該表,它僅返回您指定的值。

4.在中部部署要點 (4. Deploying Gists on Medium)

Now we can talk about showing these gists to the world.

現在我們可以談論向世界展示這些要旨。

Right here on Medium, it is as simple as clicking on the + on the next paragraph potion and clicking the <> option. After pasting the gist’s url, press enter.

就在此處,在Medium上,只需單擊下一個段落部分上的+并單擊<>選項即可。 粘貼要點的網址后,按Enter鍵。

Check out the gif.

查看gif。

演示地址

Quick video of the process of embedding on Medium
嵌入媒體過程的快速視頻

5.查找或編輯以前的要點 (5. Finding or Editing Previously Made Gists)

If you go back to your Github homepage, to the right of the create button is your picture. That dropdown menu is going to give you links to your profile and settings — but more importantly your repos, projects, and gists.

如果您返回Github主頁,則創建按鈕右側為您的圖片。 該下拉菜單將為您提供個人資料和設置的鏈接,但更重要的是您的存儲庫,項目和要旨。

Click on the link for Your gists.

單擊您的概要的鏈接。

Image for post
This is where you look for already created repos and gists
在這里尋找已創建的倉庫和要點

At which point, you will be taken to a page listing all of your gists.

屆時,您將進入一個列出所有要點的頁面。

Image for post
My three most recently updated gists
我最近更新的三個要點

Click on one and you will be able to edit. Any gist you edit will update any embedding you have elsewhere. This is a very handy feature in case you spot a mistake or want to format the code in a more pleasing way. Instead of having to visit each embedding, you can just update the gist and it will do the work for you.

單擊一個,就可以進行編輯。 您編輯的要點將更新您在其他地方的任何嵌入。 如果發現錯誤或想要以更令人愉悅的方式格式化代碼,這是一個非常方便的功能。 無需訪問每個嵌入,您只需更新要點,它將為您完成工作。

Thanks for reading. I hope this helps you distribute the beautiful code I know you will write.

謝謝閱讀。 希望這可以幫助您分發我知道您會編寫的漂亮代碼。

Connect with me on LinkedIn here.

在此處通過LinkedIn與我聯系。

For more information about the projects these gists came from, check out my Github here. And you can check out the articles these gists came from below:

有關這些要點來自的項目的更多信息,請在此處查看我的Github 。 您可以查看以下要點的文章:

翻譯自: https://towardsdatascience.com/github-gists-101-making-code-sharing-pretty-163d9321a0af

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389438.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389438.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389438.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

loj #6278. 數列分塊入門 2

題目 題解 區間修改&#xff0c;詢問區間小于c的個數。分塊排序&#xff0c;用vector。至于那個塊的大小&#xff0c;好像要用到均值不等式 我不太會。。。就開始一個個試&#xff0c;發現sizsqrt(n)/4時最快&#xff01;&#xff01;&#xff01;明天去學一下算分塊復雜度的方…

基于Netty的百萬級推送服務設計要點

1. 背景1.1. 話題來源最近很多從事移動互聯網和物聯網開發的同學給我發郵件或者微博私信我&#xff0c;咨詢推送服務相關的問題。問題五花八門&#xff0c;在幫助大家答疑解惑的過程中&#xff0c;我也對問題進行了總結&#xff0c;大概可以歸納為如下幾類&#xff1a;1&#x…

莫煩Pytorch神經網絡第五章代碼修改

5.1動態Dynamic import torch from torch import nn import numpy as np import matplotlib.pyplot as plt# torch.manual_seed(1) # reproducible# Hyper Parameters INPUT_SIZE 1 # rnn input size / image width LR 0.02 # learning rateclass…

鮮為人知的6個黑科技網站_6種鮮為人知的熊貓繪圖工具

鮮為人知的6個黑科技網站Pandas is the go-to Python library for data analysis and manipulation. It provides numerous functions and methods that expedice the data analysis process.Pandas是用于數據分析和處理的Python庫。 它提供了加速數據分析過程的眾多功能和方法…

VRRP網關冗余

實驗要求?1、R1創建環回口&#xff0c;模擬外網?2、R2&#xff0c;R3使用VRRP技術?3、路由器之間使用EIGRP路由協議? 實驗拓撲? 實驗配置??R1(config)#interface loopback 0R1(config-if)#ip address 1.1.1.1 255.255.255.0R1(config-if)#int e0/0R1(config-if)#ip addr…

網頁JS獲取當前地理位置(省市區)

網頁JS獲取當前地理位置&#xff08;省市區&#xff09; 一、總結 一句話總結&#xff1a;ip查詢接口 二、網頁JS獲取當前地理位置&#xff08;省市區&#xff09; 眼看2014又要過去了&#xff0c;翻翻今年的文章好像沒有寫幾篇&#xff0c;忙真的或許已經不能成為借口了&#…

大熊貓卸妝后_您不應錯過的6大熊貓行動

大熊貓卸妝后數據科學 (Data Science) Pandas is used mainly for reading, cleaning, and extracting insights from data. We will see an advanced use of Pandas which are very important to a Data Scientist. These operations are used to analyze data and manipulate…

數據eda_關于分類和有序數據的EDA

數據eda數據科學和機器學習統計 (STATISTICS FOR DATA SCIENCE AND MACHINE LEARNING) Categorical variables are the ones where the possible values are provided as a set of options, it can be pre-defined or open. An example can be the gender of a person. In the …

PyTorch官方教程中文版:PYTORCH之60MIN入門教程代碼學習

Pytorch入門 import torch""" 構建非初始化的矩陣 """x torch.empty(5,3) #print(x)""" 構建隨機初始化矩陣 """x torch.rand(5,3)""" 構造一個矩陣全為 0&#xff0c;而且數據類型是 long &qu…

Flexbox 最簡單的表單

彈性布局(Flexbox)逐漸流行&#xff0c;越來越多的人開始使用&#xff0c;因為它寫Css布局真是太簡單了一一、<form>元素表單使用<form>元素<form></form>復制代碼上面是一個空的表單&#xff0c;根據HTML標準&#xff0c;它是一個塊級元素&#xff0c…

CSS中的盒子模型

一.為什么使用CSS 1.有效的傳遞頁面信息 2.使用CSS美化過的頁面文本&#xff0c;使頁面漂亮、美觀&#xff0c;吸引用戶 3.可以很好的突出頁面的主題內容&#xff0c;使用戶第一眼可以看到頁面主要內容 4.具有良好的用戶體驗 二.字體樣式屬性 1.font-family:英…

jdk重啟后步行_向后介紹步行以一種新穎的方式來預測未來

jdk重啟后步行“永遠不要做出預測&#xff0c;尤其是關于未來的預測。” (KK Steincke) (“Never Make Predictions, Especially About the Future.” (K. K. Steincke)) Does this picture portray a horse or a car? 這張照片描繪的是馬還是汽車&#xff1f; How likely is …

PyTorch官方教程中文版:入門強化教程代碼學習

PyTorch之數據加載和處理 from __future__ import print_function, division import os import torch import pandas as pd #用于更容易地進行csv解析 from skimage import io, transform #用于圖像的IO和變換 import numpy as np import matplotlib.pyplot a…

css3-2 CSS3選擇器和文本字體樣式

css3-2 CSS3選擇器和文本字體樣式 一、總結 一句話總結&#xff1a;是要記下來的&#xff0c;記下來可以省很多事。 1、css的基本選擇器中的:first-letter和:first-line是什么意思&#xff1f; :first-letter選擇第一個單詞&#xff0c;:first-line選擇第一行 2、css的偽類選…

mongodb仲裁者_真理的仲裁者

mongodb仲裁者Coming out of college with a background in mathematics, I fell upward into the rapidly growing field of data analytics. It wasn’t until years later that I realized the incredible power that comes with the position. As Uncle Ben told Peter Par…

優化 回歸_使用回歸優化產品價格

優化 回歸應用數據科學 (Applied data science) Price and quantity are two fundamental measures that determine the bottom line of every business, and setting the right price is one of the most important decisions a company can make. Under-pricing hurts the co…

Node.js——異步上傳文件

前臺代碼 submit() {var file this.$refs.fileUpload.files[0];var formData new FormData();formData.append("file", file);formData.append("username", this.username);formData.append("password", this.password);axios.post("http…

用 JavaScript 的方式理解遞歸

原文地址 1. 遞歸是啥? 遞歸概念很簡單&#xff0c;“自己調用自己”&#xff08;下面以函數為例&#xff09;。 在分析遞歸之前&#xff0c;需要了解下 JavaScript 中“壓棧”&#xff08;call stack&#xff09; 概念。 2. 壓棧與出棧 棧是什么&#xff1f;可以理解是在內存…

PyTorch官方教程中文版:Pytorch之圖像篇

微調基于 torchvision 0.3的目標檢測模型 """ 為數據集編寫類 """ import os import numpy as np import torch from PIL import Imageclass PennFudanDataset(object):def __init__(self, root, transforms):self.root rootself.transforms …

大數據數據科學家常用面試題_進行數據科學工作面試

大數據數據科學家常用面試題During my time as a Data Scientist, I had the chance to interview my fair share of candidates for data-related roles. While doing this, I started noticing a pattern: some kinds of (simple) mistakes were overwhelmingly frequent amo…