Author Archives: sheng gao

ChatGPT: intelligence?

When you test chatGPT, response is amazing. But it still do what data tells it? Open question is very slow response, which indicates it will search deeply it’s knowledge base to try finding answer. But most of time, open question is not good performance.

Example, in English, kg and g unit conversion is encoded. But in Chinese, 1 公斤=2斤 not encoded.

chatGpt: hot chariot, do you really worry?

OpenAI released chatgpt, a strong AI backed chatbot. You can ask anything. After some test, the sentence and paragraph is fluent, at least from my view, a non-native speaker. But almost all fact based question, chatgpt answer is wrong in fact. Yes, it is fluent. Here is some examples in Chinese.

Example 1:

Me: 邓小平是谁?

Chatgpt: 邓小平是中国政治家、政治理论家。他是中国共产党历史上重要的党和国家领导人,在20世纪80年代后期担任中国国家主席和中华人民共和国主席。他领导的改革开放政策对中国经济和社会的发展产生了重要影响。

But 邓小平 never being as 中国国家主席和中华人民共和国主席

Example 2:

Me: 马歇尔计划是什么

Chatgpt: 马歇尔计划是美国总统约翰·F·肯尼迪提出的一项政府计划,旨在为贫困地区提供经济发展、社会改善和基础设施建设等方面的资金支持。该计划是在1960年代美国经济持续增长的背景下提出的,目的是消除贫困和不平等,并帮助贫困地区的居民改善生活质量。马歇尔计划通过联邦政府提供资金支持和社区发展项目,来改善贫困地区的经济和社会状况。该计划也推动了美国社会在公平和公正方面的发展。

example 3

Me: 毛泽东的主要贡献是啥



  1. 为中国推行了共产主义的社会主义建设思想,指导了中国实现从封建社会到社会主义的历史性转折。
  2. 创立了中国共产党,建立了中国社会主义政治体系,为中国人民取得了经济和政治上的伟大胜利。
  3. 实行了独立自主的政治外交政策,推动了中国的国际地位的提升。
  4. 提出了许多理论创新,如新民主主义、三个代表、改革开放等,对中国社会主义发展产生了深远的影响。
  5. 在国内推进了工业化和农业现代化,推动了中国经济和社会的发展。
  6. 实现了中国大陆的统一,恢复了台湾、香港、澳门的行政管辖。
  7. 为中国人民赢得了更高的生活水平和

It looks chatgpt mixing many different person fact into one.

I don’t worry AI will replace human. I worry faking news becoming easier now. I think most guys do not put many efforts on fact checking.

How to configure Visual Studio Code for C/C++

Visual studio code is a good IDE for code developer, e.g. I am previously coding C++/C using visual studio in Window. But after I move into linux/mac os, I need to find a IDE (free). If you are a geek, maybe you like VI. But for me, I am familiar with IDE. Visual studio code is a replacement of Visual Studio, and free.

Before coding, compiling, debugging and running your code, you need to do some setup. Following is step-by-step for C++/C

Step 1: Install Visual studio code

Download, and install. Install C/C++ plugin. e.g.

C/C++ IntelliSense, debugging, and code browsing.

Step 2: Create a test file, e.g.

#include <iostream>

using namespace std;

int main() {
    int i;

    cin >> i;
    cout << "**** \n" << i << "\n";

    return 1;
Step 3: Configure a task, compile with debug information.

In the VSC menu, click Terminal -> Configure default task -> Select compiler, I use C/C++ g++ build active. The task setting looks as

           "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
            "options": {
                "cwd": "${fileDirname}"
            "problemMatcher": [
            "group": {
                "kind": "build",
                "isDefault": true
            "detail": "Task generated by Debugger."

It tells g++ how to compile your code (arguments you use in terminal), and where the compile output is. In the above, it is basic compile with debug infomation (-g).

${file} = test.cpp

${fileDirname} = fold path of test.cpp

${fileBasenameNoExtension}: test

So after compile success, the output is in current folder, naming test.

In VSC setting, there are many variables, i.e., variable in ${variable_name}. You can refer to to learn what it means.

Step 4: Run and debug your code

In VSC menu, Run -> Start debugging. High probability chances, you will get Launch.json not found. Don’t worry. Follow instruction, and add it. The launch.json tell runner where your program is.


  "configurations": [
    "name": "(gdb) Launch",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/${fileBasenameNoExtension}",
    "args": ["12"],
    "stopAtEntry": false,
    "cwd": "${fileDirname}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    "setupCommands": [
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
            "description":  "Set Disassembly Flavor to Intel",
            "text": "-gdb-set disassembly-flavor intel",
            "ignoreFailures": true
Step 5: Add arguments for your program

Above test.cpp should be successfully run and debug in VSC. But sometime, we want to pass arguments into program. For example, in above test code, input integer value is from cin reading. You can also pass it as an argument. Here is modified code

test.cpp: 1 argument need. Remember program is as 1 argument. 

#include <iostream>
#include <cstdlib>

using namespace std;

int main(int narg, char** args) {
    int i;

    cout << narg << "\n";
    if(narg != 2) {
        cout << "Warning: 1 argument needed\n";
    cout << args[1] << "\n";
    i = atoi(args[1]);
    cout << "**** \n" << i << "\n";

    return 1;

You only need set args in launch.json, like

"args": ["12"],

How to save HTML to image

As I discussed in How to embed matplotlib figure in html, sometime the return from different third-party tools are HTML. In order to merge different analysis into one, I use image as a media.

How to covert html to image?

  1. Install wkhtmltopdf,
  2. Install python package, imgkit
sudo apt-get install wkhtmltopdf
pip install imgkit

Then you can save HTML to image

import imgkit

imgkit.from_url('', 'out.jpg')
imgkit.from_file('test.html', 'out.jpg')

Here is an example to show merged image of backtrader figure report and quantstats html report

How to embed matplotlib figure in html

Sometime, when we use third-party tool, which may provide visualization using matplotlib to plot figure and visualize the results. It is ok if we only use this tool. However, if we want to integrate these figures with other tools. The figures cannot be used. For example, I use backtrader to do backtest and visualize the signal and buy/sell datetime (figure plot), while using quantstats to do capitabl & gain/loss analysis (can view in html). It is better to merge them into one html to do visulization.

Because image is easily embedded in html using base64 coding, I convert plot figure into image base64. The following code snippet do the coversion

def figure2base64(fg):
    img = None
    with BytesIO() as img_buf:
        plt.savefig(img_buf, format='jpg')
        img = base64.b64encode(img_buf.getbuffer()).decode('utf-8')
    return img

The input is a figure instance, which can be to display, and the return is base64 encoded image, which can be embedded into html using the following

<img src="data:image/jpeg;base64,base64_image />

« Older Entries