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.mzph.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…