Wednesday, August 16, 2017


It took me a while to understand what is LLVM so I gave it a tried. It turns out... basically in layman's term it's a compiler like gcc

I went to their website and downloaded a lot of stuff.. then figured out that in Ubuntu you can try clang (which is the LLVM compiler in Ubuntu) with a single command:
$ sudo apt-get install llvm
So if you really don't want to use gcc like everyone else... then you should use LLVM..   sounds cool?

Sunday, June 11, 2017

Ubuntu Trusty userspace command to put system to suspend

Below is the Ubuntu Trusty userspace command to put system to suspend.
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
Put the above command into the keyboard shortcut can immediately put your desktop to sleep upon entering the shortcut key.

Friday, March 24, 2017

vi indents consist of 4 space characters instead of tab

put the following line to .vimrc for indents that consist of 4 space characters but are entered with the tab key
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab

The width of a hard tabstop measured in "spaces" -- effectively the (maximum) width of an actual tab character.


The size of an "indent". It's also measured in spaces, so if your code base indents with tab characters then you want shiftwidth to equal the number of tab characters times tabstop. This is also used by things like the =, > and < commands.


Setting this to a non-zero value other than tabstop will make the tab key (in insert mode) insert a combination of spaces (and possibly tabs) to simulate tab stops at this width.


Enabling this will make the tab key (in insert mode) insert spaces instead of tab characters. This also affects the behavior of the retab command.


Enabling this will make the tab key (in insert mode) insert spaces or tabs to go to the next indent of the next tabstop when the cursor is at the beginning of a line (i.e. the only preceding characters are whitespace).

Monday, March 13, 2017

An engineer's value

An engineers's value is not defined by one's education level, but defined as a product of one's ability to solve problems and skills to make one's boss happy.

$ = solve problem * boss's happiness

Tuesday, February 28, 2017

I frequently work on my source trees which is managed by git version control.  For many times I worked on several files then I figured I was working on the incorrect checkout.   Then I found out git provides some bash scripts which helps to auto complete your branch name and show the current branch name in the bash prompt (PS1).

However, in the git appendix A it shows a very ugly PS1 script.  I like my original bash PS1 with the branch name and auto-complete, followed by the brach name in bright color.   I paste my code here to remind myself and hopefully can help other people whom want to do the same.

  1. Download git-completion.bash from git source code.  This file auto complete(using <tab> key) your branch name in your bash prompt:
    $ wget
  2. Download . This script shows your current branch name:
    $ wget
  3. $ source git-completion.bash
    $ source
    $ export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\[\e[96m\]$(__git_ps1 "(%s)")\[\e[0m\]\$ '

Then it should turn PS1 like my prompt below:

To include the above scripts everytime you start your bash, change your .bashrc.   I put the following lines to my .bashrc
source ~/.git-completion.bash
source ~/
# PS1 with git (line wrap issue fixed!!)
export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\[\e[96m\]$(__git_ps1 "(%s)")\[\e[0m\]\$ '
As a note, in Bash, the <Esc> character can be expressed with the following syntaxes:

  • \e
  • \033
  • \x1B

For example, \e[31m shows the following characters in Red color.  The ”\e[0m” sequence removes all attributes which can be used end the bash coloring.  However, these <Esc> and color characters breaks the bash windone line wrap counts.  That is why you need \[ and \] to state to bash that those are non-printing characters.

Yes those are not for human.... and if you understand what I said.... get a life!


Friday, February 24, 2017

xhost+ Fix “Cannot Open Display” Error

The below commands will let you do xforwording with good speed, but very poor security.  Recommended to use this only in a trusted network.

Allow clients to connect from any host
$ xhost +

Enable X11 forwarding
$ ssh username@hostname -X

Wednesday, December 14, 2016

Gazebo in web browser

Gzweb is installed on the server-side. Once the server is set up and running, clients can interact with the simulation simply by accessing the server's URL on a web browser.

It's pretty cool.  Try it!

Ubuntu 14.04 (Trusty) Remote Desktop using x11vnc

Remote desktop between Windows 7 (TightVNC client) and Ubuntu 14.04 (Trusty) -sharing the monitor and mouse (similar to remote desktop but quicker)

In Ubuntu:
$ sudo apt-get install x11vnc
$ x11vnc -display :0

In Windows (TightVNC client)
- same as other VNC connection.

listing TightVNC server and kill them

By default, TightVNC launches a default session listening on port 5901.  You can use the following command to display how many vncserver you've started and kill them by display number:

$ netstat -plant | grep vnc
$ vncserver -kill :1
Other alternatives of VNC clients are:

  • TigerVNC -
  • UltraVNC - 

Tuesday, November 15, 2016

How asymmetric signature works

In our daily life, when we say we sign a document, it means we put a signature on a document, and the signature is a drawing which the signer is the only one in the world who can re-create the same signature.  Same idea is applied in the digital world.  When we generate a digital signature, it means only the signer can generate this signature.  By verifying the singature, one can verify that the document is truly generated by the originator(not modified, not a fake from other source).

I'm trying to put this in simple English.  If you're looking for detail scientific equations, you can easily search elsewhere on the web. (

Let me present a scenario.  I'm a FBI head and I'm sending a message to my FBI agent.  Say the message has nothing to encrypt, since it's already a code like "How's Billy?" and it means take action.  Say everybody can send this message to my FBI agent, but how can he know it's from me?  So we use asymmetric cryptograph(aka public key algorithm) for the digital signature.  Here is how it works:

First, I'll have to generate a pair of keys - public and private key. They're not the same key that's why we call it asymmetric cryptography.  If we're using the same key for encryption/decryption, or signature/verification, then it's called symmetric cryptography.  I will keep my private key private, as the definition of "private key".   If I lost my private key, my FBI agent dies.  So keeping private key private is very very VERY important.   I'll have to share my public key to my FBI agent.  How to share and make sure my FBI agent has my public key is another story.   The public key can be public, there is no secret in it, everybody can has it.  The only concern is that the key is legitimate. We don't want our FBI agent to has a wrong key.

Once the above step is setle, then I calculate a hash from my message; we usually call the hash result  a "digest".  It's called digest because a hash is taking any number of bits but always yields the same length of output, as if it doesn't matter how much we eat we always have a digest of same shxt.  Let's pick sha256 for this hash example, the has of the string "How's Billy?" is: b9f36ce69b818c46b23feea7f0b437c9f45bbf009cab333a4cc129a69fb7854a , then I use my private key to encrypt the above hash digest, and it's called a signature.  I'll send my message along with my signature.  My FBI agent receive the message and my signature.  He'll then first do the same sha256 has of my message "How's Billy?".  It should be b9f36ce69b818c46b23feea7f0b437c9f45bbf009cab333a4cc129a69fb7854a .
Then my FBI agent use his public key to decrypt(verify) the signature.  If the encrypted "signature" is the same as the has that he just calculated, then he verified that the message is truely from me.  Otherwise, the message must be from someone else because someone couldn't generate the signature properly(he couldn't generate the same "signature" without my private key, and guessing or hacking my private key is mathematically impractical/impossible).

Same scheme is used for software download.  Softwares are often mirrored or stored in different repositories.  Some can be corrupted or has virus(malware).   The above signature scheme is widely used in open source world to ensure authenticity of the software and also verify integrity(due to the nature of hash algorithm is integrity checking)