Featured Post

Set up machine learning and deep learning on AWS

Here is the simple instructions to set up a EC2 instance to run machine learning and deep learning on AWS 1.  Run an EC2 instance from ...

Dec 30, 2020

Ways to format the code snippet and tables in the blog

 


I'm trying to embed the Python code into the the blog posts. I have played around the format and found there is no good support in blogger to fulfill this task. After a deep dive, I have found two ways to embed the code snippet in a good format. 

One way is to use the HTML format site - http://hilite.me/.  Here is a sample Python code to judge if a number is null or not.

# import numpy
import numpy as np

# function to judge if a number is null
def is_null(x):
   return x != x

# test samples
is_null(np.nan)
is_null(2)

Or you are not comfortable to use HTML, simply copy and paste the code below in the HTML view and modify it in the Compose view.

<!-- HTML --><div style="background: #f0f0f0; overflow:auto;width:auto;border:None gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #60a0b0; font-style: italic"># print</span>
<span style="color: #007020; font-weight: bold">print</span>(<span style="color: #4070a0">&quot;All About Python&quot;</span>)
</pre></div>

The output of the above embedding.

# modify the code here
print("All About Python")

The other way is to use gist - https://gist.github.com/. Here are the steps to create the formatted code in the gist. An example of Python code is showed below.

  1. Sign up a account with GitHub if you don't have it
  2. Enter the file name with proper extension. For example, I use isnull.py as the file name
  3. Copy or type your code
  4. Select "Create public gist" and click on it. Now the code is ready to share
  5. Choose "Embed" and Copy the link address and paste in the blog editor in HTML mode.

To add tables to the blog, it's easier to use tableizer to format table in HTML code. It's simply to copy the table from the excel sheet to the tableizer and choose the proper font size, color, and font style. Click on the "Tableize it!" and copy the HTML, and paste it in the HTML view. An example is showed below.

DateOpenHighLowClose
10/18/19128.34129.21127.38129.12
10/27/19128.21129.39127.1129.31
10/26/19127.31128.21127.03128.12
10/25/19126.41127.56125.98127.21

1 comment:

  1. Amazing article,Surely, you must have done great research for this article. I learned a lot from it. Thanks for sharing this article.
    by cognex is the AWS Training in Chennai

    ReplyDelete