New Ways of Sharing Code Blocks for Data Scientists

Share the interactive code blocks to impress your colleagues or post it on social media.



New Ways of Sharing Code Blocks for Data Scientists
Image by Starline | Freepik

 

What are code blocks?

Code blocks are a few lines of code. They might contain functions of extracting datasets, scripts to automate tasks, or data manipulation class. Instead of sharing the entire project, you can share a few lines of code to explain things effectively. 

Why do we share snippets of code?

Sharing code blocks can provide additive benefits to your project presentation, gaining attraction on social media, creating interactive data reports, and writing blogs.

How can we share?

Many DevOps platforms provide code-sharing services such as GitHub, Gitlab, Kaggle, and Colab. We will also learn about new services such as Deepnote, Carbon, and Google Addon to improve our workflow. 

 

Deepnote

 
Deepnote provides sharing of embedding blocks, which includes an option to show both code and output of the Jupyter cell. Embedding block is one of my favorite things about Deepnote; I use it for Medium blogs, WordPress websites, creating Google Docs presentations, and creating posts on social media. In short, this is my go-to tool for sharing snippets of the code.

To share your code, you need to click on the specific Jupyter cell and then click on the share block button. 

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

In the share block option, you can select which part to include and what type of link to paste. Some websites only work with Embed block code and some work with Share block. 

 

"For Medium blogs and social media posts, I use Share block link."

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

The Embed code block shows the Python code and exploding donut chart about Indian female celebrities' causes of death.  

 

 

We can also add interactivity in the blog, so the readers can play with different options. The Gif below is from Towards AI blog about the yearly consumption of alcoholic drinks. We can play the animation and hover over to see exact numbers. 

 

New Ways of Sharing Code Blocks for Data Scientists
Gif by author | Towards AI

 

Deepnote Embedded Cell is not limited to creating charts or interactive graphs. We can also create an entire dashboard using Plotly and share it across the internet. 
 
 

Kaggle

 
Kaggle also provides sharing of Embed cells but it comes with limitations. To share your Jupyter cell, you need to make your Kaggle Notebook public, and the embed link works with fewer websites. It doesn't work with Medium or WordPress. You need to make significant changes to your website to make this work.

Go to the cell that you want to share and then click on the embed cell option. You can also link your cell directly but the link will redirect you to this notebook. 

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

The Embed Notebook option contains various options and links that we can use to share the single cell or entire notebook.

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

Colab

 
Google Colab only provides link sharing which can take you to a publicly shared notebook and to a specific cell. It is for the people who are working on large notebooks and want to communicate information about specific code blocks. 

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

GitHub Gist

 
GitHub Gist is a code-sharing tool used by many developers and engineers. You will find machine learning tutorials containing GitHub Gist explaining the model architecture or model training. 

GitHub Gist has a faster loading time and can be integrated with any blog or website. The downside is that you cannot share the output of the code. First, you need to create the gist by pasting the code and then copying the Embed link as shown below. 

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

The code block looks clean with syntax highlighting and clean formatting. 

For comparison, we can see both Deepnote cell and GitHub Gist. They both look clean and interactive with syntax highlighting. 

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

Carbon

 
Carbon is an online tool for creating visually appealing code blocks Images. It is used by social media influencers, data scientists, and data educators. Carbon is my go-to tool for sharing code with a wider audience. Carbon provides you with various themes options, different languages, and edition options to create a code block that works for you. The output of the code block is in PNG or SVG.

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author | Carbon

 

Carbon accurately highlights syntax to provide good readability. There are no limitations to it. You can even share it on Instagram or set a code block as your blog’s cover photo.

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

GitLab Snippet

 
GitLab Snippet is similar to GitHub Gist but instead of going to another website. We can create code snippets within the project and share them with the team. Similarly, you can use snippets on Medium blogs, websites, and social media applications. In my opinion, GitLab provides a complete developers ecosystem where everything is available within the project.

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

Google Docs Add-on

 
Google Docs Add-on code-blocks provide syntax highlighting in multiple color themes. It is quite similar to Carbon in terms of options but, instead of creating images, it changes your fonts within Google Docs. I use it for creating tutorials, writing reports, and creating drafts for a blog. Your editor will be quite impressed with the code highlighting as it improves your visual presentation. 

 

New Ways of Sharing Code Blocks for Data Scientists
Image by author

 

Conclusion

 
The developers, social media influencers, or technical bloggers use these tools to engage with their audience. In this blog, we have learned about Deepnote, Kaggle, Colab, GitHub Gists, Carbon, Gitlab Snippets, and Google Docs Add-on. These tools are used for sharing technical information via code. Some of them are easily integrated with other applications whereas others provide output with the code.

My favorite tool is Deepnote embed code block, it integrates with my workflow, and I use it everywhere from blogs to social media posts. The only backdrop of these tools is slow loading time. If you like this blog and want to keep learning about amazing tools then follow me on LinkedIn.

 
 
Abid Ali Awan (@1abidaliawan) is a certified data scientist professional who loves building machine learning models. Currently, he is focusing on content creation and writing technical blogs on machine learning and data science technologies. Abid holds a Master's degree in Technology Management and a bachelor's degree in Telecommunication Engineering. His vision is to build an AI product using a graph neural network for students struggling with mental illness.