top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Writer's pictureAjibola Salami

9 Ways to Embed Code Snippets on your Data Science Blog Posts

Imagine if a food blogger shared a recipe for making, say, Spaghetti Bolognese with clear images of the ingredients and finally the pasta dish. You probably would smack your lips while scrolling through the page, internalizing how to prepare yours with the highlighted steps. Now imagine if she went a step further and added short videos of exactly how the ingredients were mixed together and cooked before the eventual dish... Even yummier!


Well, maybe that would not change much if you were a food expert yourself. But the point of putting out the information was not for food aficionados to just nod and pass. It was for those who wish to learn the recipe. And for them, seeing just the ingredients is not likely to be enough; rather, how they were mixed together to make the food would go a long way. And that's the same effect the addition of code snippets has on data science blog posts: authenticity.



Yes, we do this already, most data science bloggers and writers, through various means. So the purpose of this article is just to highlight some of the tools that we use for sharing these code snippets and point out a few features you may look out for depending on the peculiarity of your writing.




Native Embedding Tool

Online website builders usually come with several plug-ins, either self-developed, open-source or third-party, and the site owner can just easily add different functionalities. So, code snippet is one these resources a data science blogger can use to their advantage. It can be found in the post toolbar with the icon >- and it is a very easy and stable solution.


Its downside is the completely static view and limited syntax highlighting.

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)
print(factorial(5))


Bearing the generic name for text-uploading and -sharing tools, Pastebin has been around for a while, if not the oldest. It is a very simple and straightforward solution for embedding your code snippets on any site while supporting several languages. For more flexibility, however, you would need to sign up. Below is a code snippet from the app:


Perhaps the most popular code sharing platform, Github Gist is probably what every Github user would first think of when they need to embed their code snippets. And who codes today without Github? Away from its very simplified and user-friendly interface, Gist enjoys the version control power of Git (as expected) and can be forked and cloned as every other repository. It is definitely the go-to code sharing platform for anyone who does a lot of collaborative coding.

Datapane is a Python library, and as a user, I know the tool is basically meant for sharing plots and data on any site. However, catering for sharing the code that generates these plots and data is just as important. If you are a fan of a little bit of aesthetics, Datapane would definitely be on your list because of its other features. For instance, your code can be wrapped around plots and tables in pages and dropdowns and thus be made sort of interactive.


Yes, sharing code snippets gives blogs and articles much more authority, but does the code snippet actually work? Well, to verify, the code can be copied and run elsewhere. But would that not be a teeny bit stressful? That's where sharing runnable code snippets, and Replit, comes in.


Aside from giving users the power to actually run the embedded code, Replit allows code modification. And what could be more fun than playing with a code sample to try out different results? It also works with Github and as such your code snippets can be versioned. Its IDE functionalities also make it very versatile. However, one major downside is that Replit is not completely free.



This is another platform that allows embedding runnable code snippet. Like Replit, you can tweak the embedded code and version your snippets on Github. Unlike Replit, however, it is open-source and can be improved upon to suit your taste. It also gives the option of displaying code result either in terminal or in a custom block mode. Simple user-interface that requires no sign-up to start creating snippets. You definitely want to check it out.


Codeshare comes with various themes and a friendly code editor. Though its video chat option may be redundant for sharing your code on a website, it may be handy when it comes to sharing video code snippets. To enjoy this feature and privacy option though, an upgrade is required.


This is a simple pastebin with over hundred syntax highlighting. It would have been perfect if submitting the code to be shared doesn't come with ads framing the bottom as this can cause some form of distraction to a reader.


Control C is more or less a tool for sharing plain text rather than code snippets as it comes with no syntax highlighting. Similar to Paste2, it would be better if the embedded code snippets are not framed with ad images.


Which of these should you choose?

What to choose should be how best the tool serves your purpose. Since all the 9 tools are both sharable and embeddable, and have syntax highlighting features (except Control C), you may want to ask questions like, Does it support runnable code snippets? Is sign-in required before use? Does the embedded code snippet come with ads? Using these three questions, the table below should give a simple comparison of the tools.

​Tool

​Runnability

Sign-in

Embedded Ads

​Native tool

No

No

No

​Pastebin

​No

No

No

​Github Gist

​No

No

No

​Datapane

No

Yes

No

​Replit

​Yes

Yes

No

​Techio

Yes

No

No

Codeshare

No

Yes

Yes

Paste2

No

No

Yes

Control C

No

No

Yes

This obviously is a tip of the iceberg as there are countless tools for embedding code snippets on websites. So tell me, what tool have I missed out that is worth a mention?


Thanks for reading!



0 comments

Recent Posts

See All

Comments


bottom of page