Pages - Menu

標籤

AWS (1) bash (1) Boost (2) C (2) CMake (2) Concurrency_Programming (3) CPP (37) Database (2) DNS (1) Docker (4) Docker-Compose (1) ELK (1) emacs (4) gcp (1) gdrive (1) git (1) gitbash (2) gitlab (1) kvm (4) Linux (5) MT4 (4) MT5 (4) Multicast (2) MySQL (2) Nijatrader8 (1) OpenCV (1) Python (4) QT5 (1) R (1) rdp (3) screenshot (1) ssh (3) Tabnine (1) TCP (1) TensorFlow (1) Tools (12) Ubuntu_1904 (11) Ubuntu_20_04 (5) UDP (1) VS2010 (1) VS2015 (1) VS2019 (1) WebServer (1) Win10 (1) winmerge (1) WSL (1) xrdp (1)

搜尋此網誌

2018年6月25日星期一

Start up application in Windows 10

How to add start up application

  • Insert the application short cut to the following path.
  • C:\Users\<YOURUSERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
    

2018年6月16日星期六

Prepare Ubuntu environment


Installation command line

$ sudo apt-get install build-essential
$ sudo apt-get install git git-core gitk git-gui
$ sudo apt-get install vim vim-gtk
$ sudo apt-get install cmake
$ sudo apt-get install ffmpeg
$ sudo apt-get install python-pip python-dev
$ sudo pip install --upgrade pip 
$ sudo pip install --upgrade virtualenv
$ sudo pip install translate # this is used to translate text
$ sudo pip install autosub # this is used to get subtitle from video

2018年6月13日星期三

Use iconv library for character set conversation


An example from stack overflow



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iconv.h>
#include <stdio.h>

int main (void) {
    iconv_t cd = iconv_open("ISO_8859-1", "UTF-8");
    if (cd == (iconv_t) -1) {
        perror("iconv_open failed!");
        return 1;
    }

    char input[] = "Test äöü";
    char *in_buf = &input[0];
    size_t in_left = sizeof(input) - 1;

    char output[32];
    char *out_buf = &output[0];
    size_t out_left = sizeof(output) - 1;

    do {
        if (iconv(cd, &in_buf, &in_left, &out_buf, &out_left) == (size_t) -1) {
            perror("iconv failed!");
            return 1;
        }
    } while (in_left > 0 && out_left > 0);
    *out_buf = 0;

    iconv_close(cd);

    printf("%s -> %s\n", input, output);
    return 0;
}

Command line

$ echo -n -e \\xAD\\xA9 > source.bin # output binary data to file
$ incov -f ISO-8859-9 -t UTF-8 source.bin # convert from ISO-8859-9 to UTF-8
$ iconv -f $(file -bi filename.ext | sed -e 's/.*[ ]charset=//') -t utf8 filename.ext > filename.ext # convert any encoding to utf-8
$ iconv -c -f utf-8 -t ascii file.txt # clear all non-ascii chars of file.txt

2018年6月8日星期五

Prepare third party library

Boost

    $ sudo apt-get install build-essential
    $ wget -O boost_1_55_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download
    $ tar xzvf boost_1_55_0.tar.gz
    $ ./bootstrap.sh --prefix=/usr/local/boost/1.55.0
    $ ./b2 -j 4
    $ sudo ./b2 install
    

OpenCV

  • Prepare
    • Compiler and essential
      • $ sudo apt-get install build-essential
        $ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
        
    • Optional
      • $ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
        
  • Get the source
    • From http
    • From github
      • $ git clone https://github.com/opencv/opencv.git
        
    • From official website
      • https://opencv.org/
  • Build and install
    • $ mkdir release
      $ cd release
      $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv/xx.xx ..
      $ make -j 4
      $ sudo make install
      

Spacemacs as c++ IDE

Aim

  • This post talk about how to set up Spacemacs on ubuntu as a c++ IDE

Prerequisite

Steps

  • Install emacs from source
  • $ sudo apt install build-essential checkinstall
    $ sudo apt-get build-dep emacs24
    # Download the source code, extract it
    $ tar zxvf emacs-25.1.tar.xz
    $ cd emacs-25.1
    $ ./configure --prefix=/usr/local/emacs/25.1
    $ make -j 4
    $ sudo mkdir -p /usr/local/emacs/25.1
    $ sudo make install
    
  • Add emacs to PATH
  • $ vim ~/.bashrc
    # insert the following line
    $ export PATH=/usr/local/emacs/25.1/bin:$PATH
    
  • Install spacemacs
  • $ cd ~
    $ mv .emacs.d .emacs.d.bak
    $ git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
    $ emacs --insecure
    
  • Install GNU Global from source
  • $ tar zxvf globalxxx.tar.xz
    $ cd global
    $ ./configure --prefix=/usr/local/global/xx.xx
    $ make -j 4
    $ sudo mkdir -p /usr/local/global/xx.xx
    $ sudo make install
    
  • Add Global to PATH
  • $ vim ~/.bashrc
    # insert the following line
    $ export PATH=/usr/local/global/xx.xx/bin:$PATH
    
  • Install cscope from source
  • $ tar zxvf cscopexxx.tar.xz
    $ cd cscope
    $ ./configure --prefix=/usr/local/cscope/xx.xx
    $ make -j 4
    $ sudo mkdir -p /usr/local/cscope/xx.xx
    $ sudo make install
    
  • Add cscope to PATH
  • $ vim ~/.bashrc
    # insert the following line
    $ export PATH=/usr/local/cscope/xx.xx/bin:$PATH
    
  • Install YCMD
  • $ cd ~/Downloads/SoftwareInstall
    $ git clone https://github.com/Valloric/ycmd.git
    $ sudo apt-get install build-essential cmake python-dev
    $ cd ycmd
    $ git submodule update --init --recursive
    $ ./build.py --clang-completer
    
  • Fix a bug for spacemacs
  • $ vim ~/.emacs.d/layers/+tags/cscope/packages.el
    # change the command prefix from g to c
    
  • Update .spacemacs
    • Download file spacemacs from here
    • compare the downloaded file with ~/.spacemacs, you will found that you have to upgrade some layers, ycmd location and c++ indent information.
  • DONE

How to use

  • View gtags layer for information about how to use gtags
  • View cscope layer for information about how to use cscope
  • Download from here:
    • prepareClang.sh
    • prepareEmacsTag.sh
  • Put them to /usr/bin
  • Go to your c++ project root
  • ./prepareEmacsTag.sh
  • use spacemacs to view source code under the project root
  • DONE

What you have now

  • You can do code navigation by gtags and cscope
  • You can have auto-complete and syntax checking accomplished by ycmd backend for c++

2018年6月7日星期四

Windows Subsystem for Linux, Linux GUI application

Aim

  • This article talks about 
    • How to activate Window Subsystem for Linux(WSL).
    • How to use linux gui application

Activate WSL

  • Control panel > Programs and Features > Turn Windows features on or off > Windows Subsystem for Linux
  • Restart
  • Install linux distribution from Windows store
  • Launch and wait for installation finished
  • After that you can use it as a normal linux as soon as you find any problem XD
  • Reference

Use Linux gui applicaion - WSL2

  • You need X server for those linux gui application
  • If the font size is too small, you can add flag --dpi 108 -ac
    • -ac : disable the access control


  • Install application that have gui for demo
  • sudo apt-get install git gitk git-core vim-gtk
    
  • Point to X server
  • export DISPLAY=<IP to your windows host, example:192.168.1.10>:0
    
  • Run demo application
    • gvim

Use Linux gui applicaion - WSL

  • You need X server for those linux gui application
  • If the font size is too small, you can add flag --dpi 88


  • Install application that have gui for demo
  • sudo apt-get install git gitk git-core vim-gtk
    
  • Point to X server
  • export DISPLAY=:0
    
  • Run demo application
    • gvim

  • Reference

Mount drive on WSL

  • Mount usb drive
  • mkdir /mnt/d
    sudo mount -t drvfs d: /mnt/d
    
  • Mount network drive
  • mkdir /mnt/share
    sudo mount -t drvfs '\\192.168.0.101' /mnt/share
    
  • Reference

Speed up WSL


2018年6月5日星期二

Setup SSL web server

Aim

  • This post is talking about how to set up a SSL web server by using self signed certification, on ubuntu and using apache

Server info

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

Prerequisite

  • sudo apt-get install apache2

Steps - Prepare server

  • Get script from here
  • Generate private keys and certification files
    • bash genKeys.sh
      • You will get
        • root.key ---- Private key of certification authority(CA)
        • root.pem ---- Public key(certificate) of CA
        • server.crt ---- Server certification signed by CA
        • server.csr ---- Server certificate signing request
        • server.key ---- Private key of server
  • Install server private key and certification
    • sudo mkdir /etc/apache2/ssl
    • sudo cp server.crt server.key /etc/apache2/ssl
  • Update apache configuration file
    • meld default.-ssl.conf default.-ssl.conf.bak
      • default.-ssl.conf ---- updated file
      • default.-ssl.conf.bak ---- original file
    • You can now see the difference, update /etc/apache2/sites-available/default.-ssl.conf depends on your needs
  • Enable apache on ssl
    • sudo a2enmod ssl
  • Enable virtual server
    • sudo a2ensite default-ssl.conf
  • Restart apache server
    • sudo service apache2 restart
  • Now, server is ready

Steps - Prepare client

  • Since the steps are varied by different browser and vision, I will only provide a generic description.
  • Include the file root.pem into browser as a trusted authority.
  • If you success, you can visit the web site through:
    • https://sulfred-PC.test.sulfred.com
      • sulfred-PC ---- host name of your server, get it by command `hostname` on your server
    • And you should see
    • A green Secure

 Principle about certificating a web server providing SSL service

  1. There is a third party Certification Authority(CA), and everyone trusts her.
  2. CA has her own private key(root.key) and public key(root.pem)
  3. There is a web server who want to provide SSL service.
  4. She needed to generate her own private key(server.key) and certification request(server.csr).
  5. Web server provider will send the request file(server.csr) to CA.
  6. CA will use her private key and public key to generate a certification file(server.crt) to web server provider.
  7. Web server provider will use private key(server.key) and certification file(server.crt) to set up the server.
  8. Finally, customer needed to insert the CA's public key(root.pem) into their browser so that they can visit the web server in a secure way.

Explanation about Scripts

  • genKeys.sh
    • All the commands are included inside this file. Those four steps covered almost from point 1 to 7 of the above section.
    • There are comments inside this file which reveal the meaning of those configuration files.
  • ./config/v3.ext
    • This file included v3 extension information
    • This is used to solve error:
      • missing_subjectAltName
    • Important information is the alternative dns name, which is needed for latest chromium browser, especially the version later than 58, reference
  • ./config/root.csr.cnf
    • This is used to create root.pem file
  • ./config/server.csr.cnf
    • This is used to create server.csr file