$ = solve problem * boss's happiness
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.
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.
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
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!
References
https://git-scm.com/book/en/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Bash
http://misc.flogisoft.com/bash/tip_colors_and_formatting
http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/nonprintingchars.html
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.
- Download git-completion.bash from git source code. This file auto complete(using <tab> key) your branch name in your bash prompt:
$ wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash - Download git-prompt.sh . This script shows your current branch name:
$ wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh - $ source git-completion.bash
$ source git-prompt.sh
$ 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:
gideon@gideon-i5:~/catkin_ws/src/turtlebot(indigo)$
To include the above scripts everytime you start your bash, change your .bashrc. I put the following lines to my .bashrc
source ~/.git-completion.bashAs a note, in Bash, the <Esc> character can be expressed with the following syntaxes:
source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
# 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\]\$ '
- \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!
References
https://git-scm.com/book/en/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Bash
http://misc.flogisoft.com/bash/tip_colors_and_formatting
http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/nonprintingchars.html
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.
$ xhost +
Enable X11 forwarding
$ ssh username@hostname -X
Wednesday, December 14, 2016
Gazebo in web browser
http://gazebosim.org/gzweb
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
http://www.karlrunge.com/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 Windows (TightVNC client)
- same as other VNC connection.
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 vncOther alternatives of VNC clients are:
$ vncserver -kill :1
- TigerVNC -http://tigervnc.org/
- UltraVNC - http://www.uvnc.com/
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. (https://en.wikipedia.org/wiki/Digital_signature)
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)
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. (https://en.wikipedia.org/wiki/Digital_signature)
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)
Saturday, November 12, 2016
Build your own ARM cross toolchain from source
I used to have a mac and I want to use it for software development. I need to build Linux kernel but I couldn't find the ARM cross compiler toolchain for OSX. If you're in the same situation, you can follow below links to build you own toolchain:
- https://istarc.wordpress.com/2014/07/21/stm32f4-build-your-toolchain-from-scratch/
- http://jeremyherbert.net/get/stm32f4_getting_started
Wednesday, October 26, 2016
adding arm-none-eabi-gcc using Ubuntu ppa
If you're using Ubuntu apt, you can use the following command to install the
arm-none-eabi-gcc ARM cross compiler from ppa repository:
arm-none-eabi-gcc ARM cross compiler from ppa repository:
$ su
# apt-add-repository -y ppa:terry.guo/gcc-arm-embedded
# aptitude update
# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A3421AFB
# aptitude update
# apt-get install gcc-arm-none-eabi
and then when you type arm-none and tab, you should see the arm cross-compiler.
gideon@gideon-i5:~$ arm-none-eabi-
arm-none-eabi-addr2line arm-none-eabi-gcc-4.9.3 arm-none-eabi-nm
arm-none-eabi-ar arm-none-eabi-gcc-ar arm-none-eabi-objcopy
arm-none-eabi-as arm-none-eabi-gcc-nm arm-none-eabi-objdump
arm-none-eabi-c++ arm-none-eabi-gcc-ranlib arm-none-eabi-ranlib
arm-none-eabi-c++filt arm-none-eabi-gcov arm-none-eabi-readelf
arm-none-eabi-cpp arm-none-eabi-gdb arm-none-eabi-size
arm-none-eabi-elfedit arm-none-eabi-gprof arm-none-eabi-strings
arm-none-eabi-g++ arm-none-eabi-ld arm-none-eabi-strip
arm-none-eabi-gcc arm-none-eabi-ld.bfd
Sunday, March 29, 2015
Using ant to build Android sample code
It used to be so easy to build Android's code, now with Android Studio and gradle it become so complicated.
Let me put it down how to use ant to build before Google swipe everything away. and this is the only way to build their sample code now since many sample codes are not migrated to Android Studio and gradle/gradlew yet.
Let me put it down how to use ant to build before Google swipe everything away. and this is the only way to build their sample code now since many sample codes are not migrated to Android Studio and gradle/gradlew yet.
- go to sample code root directory. android-21 is the target API, the command will generate build.xml for build process
$ android update project --target android-21 --path . - build the debug apk
$ ant debug - use find . -name *.apk to locate the apk file. use adb to install apk to your phone
$ adb install ./bin/NewsReaderActivity-debug.apk
Summary:
- $ android update project --target android-21 --path .
- $ ant debug
- $ adb install ./bin/NewsReaderActivity-debug.apk
Simple as that!
Subscribe to:
Posts (Atom)