Thursday, December 10, 2015

Install Playonlinux from command line to accept the license by Tab -> Enter

This POST addressed how to accept license when clicking enter doesn't respond the OK display when installing playonlinux from command line.
Hit  key, then hit  to accept the license. 

That is it. So easy, just switching among buttons, to highlight button. Same like in windows.

Ubuntu apt mirror access error.

This post addressed one issue I had tonight.

W: Failed to fetch  Unable to connect to

sudo rm /var/lib/apt/lists/* -vf
sudo apt-get update

Or switch apt mirror from this link

Friday, November 20, 2015

Cron and Anacron to schedule jobs in Linux


$crontab -e   to edit
$crontab -l   to list
$crontab -l -u username   to list cron jobs of username


runs commands periodically. Unlike cron(8), it does not assume that the machine is running continuously. Hence, it can be used on machines that aren't running 24 hours a day, to control daily, weekly, and monthly jobs that are usually controlled by cron.
qyang@lubuntu-laptop:~$ service anacron start
qyang@lubuntu-laptop:~$ service anacron status
● anacron.service - Run anacron jobs
   Loaded: loaded (/lib/systemd/system/anacron.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2015-11-21 09:19:57 AEDT; 4s ago
 Main PID: 10233 (anacron)
   CGroup: /system.slice/anacron.service
           └─10233 /usr/sbin/anacron -dsq

Nov 21 09:19:57 lubuntu-laptop systemd[1]: Started Run anacron jobs.
Nov 21 09:19:57 lubuntu-laptop systemd[1]: Starting Run anacron jobs...
Nov 21 09:19:57 lubuntu-laptop anacron[10233]: Anacron 2.3 started on 2015-11-21
Nov 21 09:19:57 lubuntu-laptop anacron[10233]: Will run job `cron.daily' in 5 min.
Nov 21 09:19:57 lubuntu-laptop anacron[10233]: Will run job `svnsyncPQAFW.daily' in 15 min.
Nov 21 09:19:57 lubuntu-laptop anacron[10233]: Jobs will be executed sequentially


Sample of downloading data regularly using cron Changing crontab
root@trac ~# cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.


# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#25 6 * * * root test -x /usr/sbin/anacron || ( cd /root/AuctionResults && run-parts --report /root/AuctionResults)
00 12  * * 7 root test -x /usr/sbin/anacron || ( cd /root/AuctionResults && run-parts --report /root/AuctionResults)
Run any executable files,eg.runpython under nominated folder AuctionResults
root@trac ~# ls -al ~/AuctionResults
total 852
drwxr-xr-x  2 root root   4096 Nov 15 12:00 .
drwx------ 11 root root   4096 Sep  9 00:41 ..
-rwxr-xr-x  1 root root   1105 Jul 14 13:48
-rwxr-xr-x  1 root root     39 Jun  9 22:43 runpython
qyang@lubuntu-laptop:~/Svn_Local_Personal/A_001_Notes$ locate cron |grep bin

service control in debian/lubuntu/ubuntu - sysv-rc-conf


Install sysv-rc-conf via apt.
$sudo sysv-rc-conf

Aliasing Automatic Gain Control and FFT


A filter chosen in anticipation of a certain sample frequency is called an anti-aliasing filterAliasing on wiki. A real anti-aliasing filter trades off between bandwidth andaliasing
Undersampling, which causes aliasing.
Without an anti-aliasing filter, frequencies higher than the Nyquist frequency will influence the samples in a way that is misinterpreted by the interpolation process. Ref
  • Paper(pdf) from National Instruments on Aliasing and Sampling at Frequencies Above the Nyquist Frequency.
  • Notes:
    R (sampling rate) = 100MS/s
    fs (signal being sampled = 70MHz
    fN (the Nyquist frequency) = 50MHz
    fa (aliased frequency) = 30MHz
    The frequency of the aliased signal can be found from the following simple equation:
    fa = |R*n - fs|
    Although sampling at twice the Nyquist frequency will ensure that you measure the correct frequency of your signal, it will not be sufficient to capture the shape of the waveform. If the shape of the waveform is desired, you should sample at a rate approximately 10 times the Nyquist theory.
If known input frequency range, then sample rate more than 2*InputFreqRange? will remove aliasing. However, real input signal could include signal frequency higher than wanted frequency range, these high frequency signal will cause aliasing at pre-designed smapling rate. (high freq signal and low freq signal end up with same sampling points at lower (than required) sampling rate.) That's the whole reason u need anti-aliasing filter in the front end to filter out unsupported high frequency signals.

Automatic gain control - (AGC)

Finite Impulse Response (FIR) filter


Monday, November 16, 2015

Python: Retrieve files from URL link
#!/usr/bin/env python
import urllib
from datetime import datetime

saveFileName = "Sydney-Auction-Result-""%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("",saveFileName )
saveFileName = "Adelaide-Auction-Result-""%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("",saveFileName )
saveFileName = "Melbourne-Auction-Result-""%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("",saveFileName )
saveFileName = "Brisbane-Auction-Result-""%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("",saveFileName )
#saveFileName = "Sydney-Domain-Auction-Result-""%Y%m%d%H%M%S")+".pdf"
#urllib.urlretrieve ("",saveFileName )

Friday, November 13, 2015

Folders and files synchronisation using rsync in Linux

# Creat source folder and files and blank destination folder
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ mkdir src dst
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ mkdir src/a 
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ echo "hell a" > src/a/file1.txt
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
└── src
    └── a
        └── file1.txt

# rsync to test folder and file synch. Both 'a' and 'file1' appeared under 'dst'.
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rsync --delete --checksum --recursive src/ dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   └── a
│       └── file1.txt
└── src
    └── a
        └── file1.txt

# Test newly added folder 'b' being synched
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ mkdir src/b
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rsync --delete --checksum --recursive src/ dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   ├── a
│   │   └── file1.txt
│   └── b
└── src
    ├── a
    │   └── file1.txt
    └── b

# Test newly added file 'file2.txt' being synched
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ echo "hell b" > src/b/file2.txt
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rsync --delete --checksum --recursive src/ dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   ├── a
│   │   └── file1.txt
│   └── b
│       └── file2.txt
└── src
    ├── a
    │   └── file1.txt
    └── b
        └── file2.txt

# Test newly delete folder 'a' and 'file1.txt' inside being synched.
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rm -rf src/a/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rsync --delete --checksum --recursive src/ dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   └── b
│       └── file2.txt
└── src
    └── b
        └── file2.txt

# Test newly delete file 'file2.txt' being synched.
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rm src/b/file2.txt 
rm: remove regular file ‘src/b/file2.txt’? y
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rsync --delete --checksum --recursive src/ dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   └── b
└── src
    └── b

# Add back 'file2.txt' and check
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ echo "hell b" > src/b/file2.txt
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rsync --delete --checksum --recursive src/ dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   └── b
│       └── file2.txt
└── src
    └── b
        └── file2.txt

# modify 'file2.txt' and check synch
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ cat dst/b/file2.txt
hell b
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ vi src/b/file2.txt
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ cat src/b/file2.txt
Modified ...hello b
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ rsync --delete --checksum --recursive src/ dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ cat dst/b/file2.txt
Modified ...hello b
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   └── b
│       └── file2.txt
└── src
    └── b
        └── file2.txt

Using cp command line for multiple files copy
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   └── b
│       └── file2.txt
└── src
    ├── a
    │   └── file1.txt
    └── b
        ├── file2.txt
        └── file3.txt

5 directories, 4 files
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ cp {src/a/file1.txt,src/b/file{2..3}.txt} dst/
qyang@lubuntu-laptop:~/Trash/Sandbox-Trial$ tree
├── dst
│   ├── b
│   │   └── file2.txt
│   ├── file1.txt
│   ├── file2.txt
│   └── file3.txt
└── src
    ├── a
    │   └── file1.txt
    └── b
        ├── file2.txt
        └── file3.txt

Wednesday, November 11, 2015

Bash to synch one particular folder from one SVN repository to another SVN repository


pushd ~/Svn_Local_Proj/Cascade/Firmware/ 

svn up
# Synch two local SVN copies,but ingore .svn etc.
rsync --delete --cvs-exclude --checksum --recursive ~/Svn_Local_Proj/Cascade/Firmware/ ~/Svn_Local_Proj_HomeTrac/Proj_FW/ 

pushd ~/Svn_Local_Proj_HomeTrac/Proj_FW/ 
svn up
#Add new files to repo if there are new files
svn add --force * --auto-props --parents --depth infinity
svn ci -m"Auto Synch SVN copy to Trac from Lubuntu"


Bash to copy files from AWS to local drive


# Copy from AWS
# Password based ssh access, but downside is disclose plain text password. Better use ssh key pair based access
# sshpass -p "Password" scp -pv*.pdf ./
rsync --checksum qqec2:~/AuctionResults/*.pdf ./
echo "Done synch with AWS"
ssh qqec2 "if [ ! -d 'AuctionResults-Bkup' ]; then mkdir -v AuctionResults-Bkup; echo 'Created folders that doesnot exist';fi;
#ssh qqec2 "if [ ! -d "AuctionResults-Bkup" ]; "
#"then mkdir -v AuctionResults-Bkup; "
#"echo "Created folders that doesnot exist";"
#"cp -vp AuctionResults/*.pdf AuctionResults-Bkup/""
echo "Done moving all download pdf files to bkup folder on AWS"

Open a file browser from your current command prompt terminal directory


explorer .        # For windows command line
nautilus .        # Linux command line
open .            # MAC OS X
dolphin .         # Linux KDE 4

Saturday, November 7, 2015

Friday, November 6, 2015

DDD Front-End Debugger

Summary of DDD

The purpose of a debugger such as ddd is to allow you to see what is going on “inside” another
program while it executes—or what another program was doing at the moment it crashed.
ddd can do four main kinds of things (plus other things in support of these) to help you catch
bugs in the act:
• Start your program, specifying anything that might affect its behavior.
• Make your program stop on specified conditions.
• Examine what has happened, when your program has stopped.
• Change things in your program, so you can experiment with correcting the effects of one bug
and go on to learn about another.

Technically speaking, ddd is a front-end to a command-line debugger (called inferior debugger,
because it lies at the layer beneath ddd). ddd supports the following inferior debuggers:
• To debug executable binaries, you can use ddd with gdb, dbx, Ladebug, or xdb.
− gdb, the gnu debugger, is the recommended inferior debugger for ddd. gdb supports
native executables binaries originally written in C, C++, Java, Modula-2, Modula-3, Pascal, Chill, Ada, and FORTRAN. (see section “Using gdb with Different Languages” in
Debugging with gdb, for information on language support in gdb.)
− As an alternative to gdb, you can use ddd with the dbx debugger, as found on several
unix systems. Most dbx incarnations offer fewer features than gdb, and some of the
more advanced dbx features may not be supported by ddd. However, using dbx may be
useful if gdb does not understand or fully support the debugging information as generated
by your compiler.
− As an alternative to gdb and dbx, you can use ddd with Ladebug, as found on Compaq and DEC systems. Ladebug offers fewer features than gdb, and some of the more
advanced Ladebug features may not be supported by ddd. However, using Ladebug may
be useful if gdb or dbx do not understand or fully support the debugging information as
generated by your compiler.
− As another alternative to gdb, you can use ddd with the xdb debugger, as found on
hp-ux systems.
• To debug Java byte code programs, you can use ddd with jdb, the Java debugger, as of jdk
1.1 and later. (ddd has been tested with jdk 1.1 and jdk 1.2.)
• To debug Python programs, you can use ddd with pydb, a Python debugger.
• To debug Perl programs, you can use ddd with the Perl debugger, as of Perl 5.003 and later.
• To debug Bash programs, you need a version Bash that supports extended debugging support.
To get this enhanced version see You will need
version 2.05b-debugger-0.32 or later to work with ddd.

Man Page in Linux

How to view same thing in different man page?????
How to read entire man page without knowing names of a particular command????

There are POSIX Programmer's Manual and Linux Programmer's Manual and Library Functions Manual

To find help on any commands based on what manpage packages have been installed.
qyang@lubuntu-laptop:~$ dpkg --list |grep manpage
ii  manpages                                                    3.74-1ubuntu1                              all          Manual pages about using a GNU/Linux system
ii  manpages-dev                                                3.74-1ubuntu1                              all          Manual pages about using GNU/Linux for development
ii  manpages-posix                                              2.16-1                                     all          Manual pages about using POSIX system
ii  manpages-posix-dev                                          2.16-1                                     all          Manual pages about using a POSIX system for development
#apt-get install manpages-posix manpages-posix-dev
#yum install man-pages
#yum install libstdc++-docs          to see man page of C++ library
$man pthreads
$man ldd
$man pthread_mutex_lock

$man std::iostream
$man std::vector
$man malloc

Shared Libraries Demo *.so file.

Ref 1 cmd line to generate *.so on stackoverflow
Ref 2 stackflow post ld --verbose -llibxxx

testsomain is smaller when not compiled with testso.c 
[q.yang@fedora20 Trash]$ gcc testsomain.c -o testsomain -L./ -ltestso
It's bigger when compiled with testso.c. It's one of the benefit of using dynamic library.
[q.yang@fedora20 Trash]$ gcc testsomain.c testso.c -o testsomain
#include "testso.h"

int main(void)
  printf("Testing calling function in *.so \n");

void Ext_PrintHello(void)
  printf("%s Invoked from external module.\n",__func__);
//#error "this file has been included here"

void Ext_PrintHello(void);
Compile to generate dynamic library:
Note: MUST use -fPIC option PositionIndependantCode(PIC)
*.so file name must be, cannot be
[q.yang@fedora20 Trash]$ gcc -shared -fPIC -o testso.c
Compile main program to load dynamic library *.so
[q.yang@fedora20 Trash]$ gcc testsomain.c -o testsomain -L./ -ltestso
Set load library search path
[q.yang@fedora20 Trash]$ LD_LIBRARY_PATH=./
[q.yang@fedora20 Trash]$ export LD_LIBRARY_PATH
Run program
[q.yang@fedora20 Trash]$ ./testsomain 
Testing calling function in *.so 
Ext_PrintHello Invoked from external module.
Checking so file dependencies $ldd and file info $file. (Running for i686 or ARM)
duser@$ file ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0xf54c8aad49c8dfd0220885eab40fe703c0e5495b, not stripped

duser@$ ldd => /lib/i386-linux-gnu/ (0xb754b000)
 /lib/ (0xb770f000)

We can also use linker $ld to check where system default search path for *.so shared library files. Given [Ref 2]
duser@$ld -L./ -ltestso --verbose

attempt to open /usr/i686-linux-gnu/lib32/ failed
attempt to open /usr/i686-linux-gnu/lib32/libtestso.a failed
attempt to open /usr/local/lib32/ failed
attempt to open /usr/local/lib32/libtestso.a failed
attempt to open /lib32/ failed
attempt to open /lib32/libtestso.a failed
attempt to open /usr/lib32/ failed
attempt to open /usr/lib32/libtestso.a failed
attempt to open /usr/local/lib/i386-linux-gnu/ failed
attempt to open /usr/local/lib/i386-linux-gnu/libtestso.a failed
attempt to open /usr/local/lib/ failed
attempt to open /usr/local/lib/libtestso.a failed
attempt to open /lib/i386-linux-gnu/ failed
attempt to open /lib/i386-linux-gnu/libtestso.a failed
attempt to open /lib/ failed
attempt to open /lib/libtestso.a failed
attempt to open /usr/lib/i386-linux-gnu/ failed
attempt to open /usr/lib/i386-linux-gnu/libtestso.a failed
attempt to open /usr/lib/ failed
attempt to open /usr/lib/libtestso.a failed
/usr/bin/ld.bfd.real: cannot find -ltestso
If we tell the load library path via -L option. Linker will find it.
duser@$ ld -L./ -ltestso --verbose
attempt to open .// succeeded
-ltestso (.// needed by .//
found at /lib/i386-linux-gnu/ needed by /lib/i386-linux-gnu/
found at /lib/i386-linux-gnu/
/usr/bin/ld.bfd.real: warning: cannot find entry symbol _start; not setting start address

Wednesday, November 4, 2015

Sample code of recursive function in C/C++ (ToDo.....)


What needs to pay attention when creating safe recursive function?

Sample Codes of Thread Safe functions and variables (ToDo....)

The simplest method is to make your variables private (but you do that already, right?) and to use synchronized accessor methods. Accessor methods allow access to private member variables, but in a controlled manner. Take the following accessor methods, which provide a safe way to change the value of a counter.

 Here is how to make variable thread safe in java. Make it private and accessible via synchronized public function call.
public class MyCounter
private int count = 0; // count starts at zero

public synchronized void setCount(int amount)
count = amount;

public synchronized int getCount()
return count;

In C/C++, mutex, would be necessary.

Function Pointers in C/C++

#include <iostream>
#include <cstring>
#include <vector>

using namespace std;
namespace DemoFunPt {
typedef void (*CallBackFunc)(int i_input);
// Register callback function
vector<CallBackFunc> Callbackfuncs;

void Func_A(int i_input)
  cout<< "Hello from Func_A " << i_input << endl;

void Func_B(int i_input)
  cout<< "Hello from Func_B " << i_input << endl;

void RegisterCallbackFunc(CallBackFunc i_FuncPt)


int  main()

   for(int i=0; i< DemoFunPt::Callbackfuncs.size(); i++){
   cout<<"Done demo" << endl;
   return 0;

root@trac ~# g++ funcpointer.cpp -o test
root@trac ~# ./test
Hello from Func_A 0
Hello from Func_B 1
Done demo

Sunday, November 1, 2015

exercises in python

In [4]: a
Out[4]: ['1', '2', '3', '4']

In [6]: ',tail'.join(a)
Out[6]: '1,tail2,tail3,tail4'

In [20]: dict
Out[20]: {'H1': 'H1 UL1 [%]', 'H2': 'H2 UL1 [%]'}

In [21]: for i in dict: print dict[i]
H2 UL1 [%]
H1 UL1 [%]

>> type([]) is list
>>> type({}) is dict
>>> type('') is str
>>> type(0) is int
>>> type({})

>>> type([])

>> type([]) is list
>>> type({}) is dict
>>> type('') is str
>>> type(0) is int
>>> type({})

>>> type([])

In [3]: print int("0x3cf",0)  python hex to int

Auto start wanted application on Lubuntu log in.

Putting launcher into ~/.config/autostart. Ref '' ''
./ vncserverstart /home/qyang/
./ startxcompmgr /home/qyang/
vncserver &
xcompmgr -n &
#!/usr/bin/env python3
import os
import sys
home = os.environ["HOME"]

name = sys.argv[1]; command = sys.argv[2]

launcher = ["[Desktop Entry]", "Name=", "Exec=", "Type=Application", "X-GNOME-Autostart-enabled=true"]
dr = home+"/.config/autostart/"
if not os.path.exists(dr):
file = dr+name.lower()+".desktop"

if not os.path.exists(file):
    with open(file, "wt") as out:
        for l in launcher:
            l = l+name if l == "Name=" else l
            l = l+command if l == "Exec=" else l
    print("file exists, choose another name")

Thursday, October 29, 2015

Sample Python Codes plot value with date time axis in matplotlib

[1] plotting-time-in-python-with-matplotlib

#!/usr/bin/env python

import matplotlib.pyplot as plt
import datetime

ax = tuple([datetime.datetime(2015, 10, 27, 17, 17, sec) for sec in range(1,10)])
print ax

ay = tuple(range(1,10))

# Beautify the display format

When doing enough zoom in, it will display in macro seconds resolution. When zooming out enough,it will display dates.

Python Notes

[1] date_demo1.html
[2] date_demo2.html
[3] plotting-time-in-python-with-matplotlib

Docky in Lubuntu

[2] GUI for Xcompmgr
[3] Adding application to docky
[4] docky usage wiki

Open /usr/share/applications/ in 'File Manager PcManFM', then drag those applications to docky. Basically, it's like copying those xxxx.desktop to docky launch list. [3]

Wednesday, October 28, 2015

Static Variable Inside C Function.

#include <stdio.h>

#define TEST_3

void FuncA ()
#ifdef TEST_0
  // 0 value initialization only happen once if defined 'static'.
  static int StaticVar=0;
#ifdef TEST_1
  // 0 value initialization happen every time when FuncA is called.
  int StaticVar=0;
#ifdef TEST_2
  // When not give inital value, system set StaticVar to '0'
  // Changed value will stay next time when FuncA is called as StaticVar
  // is defined with keyward 'static'.
  static int StaticVar;
  printf("StaticVar is : %d\n",StaticVar);
  StaticVar = 2;
#ifdef TEST_3
  // When no 'static', system set StaticVar to a random value.
  // (I think it depends on what value in stack.)
  // But in test it seems, StaticVar keep same value as it's retrieving 
  // value from same postion in stack.
  int StaticVar;
  printf("StaticVar is : %d\n",StaticVar);
  StaticVar = 3;

  printf("StaticVar is : %d\n",StaticVar);


void main()
  printf ("====Done====\n"); 

The results after defining different test cases:

qyang@lubuntu-laptop:~$ ./Learn_static 
StaticVar is : 0
StaticVar is : 1
StaticVar is : 2
StaticVar is : 3
StaticVar is : 4
StaticVar is : 5
qyang@lubuntu-laptop:~$ ./Learn_static 
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
qyang@lubuntu-laptop:~$ ./Learn_static 
StaticVar is : 0
StaticVar is : 2
StaticVar is : 3
StaticVar is : 2
StaticVar is : 3
StaticVar is : 2
StaticVar is : 3
StaticVar is : 2
StaticVar is : 3
StaticVar is : 2
StaticVar is : 3
StaticVar is : 2
qyang@lubuntu-laptop:~$ ./Learn_static 
StaticVar is : 134513947
StaticVar is : 3
StaticVar is : 4
StaticVar is : 3
StaticVar is : 4
StaticVar is : 3
StaticVar is : 4
StaticVar is : 3
StaticVar is : 4
StaticVar is : 3
StaticVar is : 4
StaticVar is : 3

Tuesday, October 27, 2015

C++ Notes



Pure Virtual Function

When you have a pointer to an object, the object may actually be of a class that is derived from the class of the pointer (e.g., a Vehicle* that is actually pointing to a Car object; this is called “polymorphism”多态性).

Dynamic binding is a result of virtual functions.

setw ( )


Pattern matching and regular expressions in Linux Command Line


Regular expressions (regex):
PATTERN=re.compile(r'''((?:[^\t "']|"[^"]*"|'[^']*')+)''')

From [1]

[ ] (square brackets)
specifies a range. If you did m[a,o,u]m it can become: mam, mum, mom if you did: m[a-d]m it can become anything that starts and ends with m and has any character a to d inbetween. For example, these would work: mam, mbm, mcm, mdm. This kind of wildcard specifies an “or” relationship (you only need one to match).
{ } (curly brackets)
terms are separated by commas and each term must be the name of something or a wildcard. This wildcard will copy anything that matches either wildcard(s), or exact name(s) (an “or” relationship, one or the other).
For example, this would be valid:
cp {*.doc,*.pdf} ~
This will copy anything ending with .doc or .pdf to the users home directory. Note that spaces are not allowed after the commas (or anywhere else).

From [2]

find -regex ".*\.\(xls\|csv\)"

find -name "*.xls" -o -name "*.csv"

Sunday, October 25, 2015

Saturday, October 24, 2015

Classless Inter-Domain Routing (CIDR)

[1] wiki

Classless Inter-Domain Routing is a method for allocating IP addesses and routing Internet Protocol packets. The Internet Engineering Task Force introduced CIDR in 1993 to replace the previous addressing architecture of classful network design in the Internet. Its goal was to slow the growth of routing tables on routers across the Internet, and to help slow the rapid exhaustion of IPv4 addresses.
Classless Inter-Domain Routing allocates address space to Internet service providers and end users on any address bit boundary, instead of on 8-bit segments. In IPv6, however, the interface identifier has a fixed size of 64 bits by convention, and smaller subnets are never allocated to end users.

Wednesday, October 21, 2015

DB meaning and definition.

[1] on DB

-3dB half, 3dB twice

In [33]: 10*math.log(10,10)
Out[33]: 10.0

In [34]: 10*math.log(2,10)           2 times
Out[34]: 3.0102999566398116          how 3 dB derived

Monday, October 19, 2015

Sunday, October 11, 2015

Top linux kernel contributors from linux foundation report.

[1] linux-foundation-releases-annual-linux-development-report

The top 10 organizations sponsoring Linux kernel development since the last report (or Linux kernel 2.6.36) are Red Hat, Intel, Novell, IBM, Texas Instruments, Broadcom, Nokia, Samsung, Oracle and Google.[1] Mobile and embedded companies have been increasing their participation in recent years, not only adding more hardware support to the kernel but also taking responsibility for the advancement of core kernel areas.

§  For the first time, Microsoft appears on list of companies that are contributing to the Linux kernel. Ranking at number 17, the company that once called Linux a “cancer,” today is working within the collaborative development model to support its virtualization efforts and its customers. Because Linux has reached a state of ubiquity, in which both the enterprise and mobile computing markets are relying on the operating system, Microsoft is clearly working to adapt.

A blog post about linux driver

[1] notes of driver example

Got [1] from LinkedIn discussion.

Kernelnewies web link


KGDB for Kernel Module Debugging

[1] kgdb

Secure Programming

[1] secure programming

Code Testing and Assessment

[1] sloccount (code count and efforts estimation - found through 'lshw' creator.
[2] gcover - Code coverage
[3] valgrind  - Memory leaking

Tuesday, October 6, 2015

HTML Notes

[1] html_links from w3schools
[2] html tag (anchor point within a page) from w3schools
[3] Syntax Highlighter in Blog 
[4] pre tag from w3schools 
[4] div
[5] tt
[6] css_selectors via id(unique style), class(common style)

Ref [1] [3]
  • Create anchor via 'id' attribute in html tag
  • Add Link to anchor within web page '#tips'
  • Add Link to anchor from other page externally 'xxxx.htm#tips'

Useful Tips Section

Visit the Useful Tips Section Visit the Useful Tips Section

Ref [2]

The tag defines a hyperlink, which is used to link from one page to another.
In HTML 4.01, the tag could be either a hyperlink or an anchor. In HTML5, the tag is always a hyperlink, but if it has no href attribute, it is only a placeholder for a hyperlink.
HTML5 has some new attributes, and some HTML 4.01 attributes are no longer supported.

Show text in box
xrdb $HOME/.Xresources
xsetroot -solid grey -cursor_name left_ptr
autocutsel -fork
lxsession -s Lubuntu -e LXDE

Saturday, October 3, 2015

Open Source Hardware -- BeagleBone


PRU in BeagleBone
Example of blinking LED via PWM through GPIO pin. It's using PRU to achieve this. [2] -> [3]

[4] mentioned in pru/README.

Key bindings


Keybindings in Lubuntu   [1]
Modify keybindings in Lubuntu by changing its ~/.config/openbox/lubuntu-rc.xml [2]

What's key ring for?

[3] how-to-recover-reset-forgotten-gnome-keyring-password/65294#65294

Installed seahorse and reset/change keyring password. [3]

The big idea here is that if someone else were to access your PC and did not know the master password to your keyring, they could not access your stored login information. The same principle is put to use by's addon for your browser. (only it's distributed, meaning I can use it on several instances of browsers across PC's)
In summary, I offer this snippet from the gnome-keyring page located here

GNOME Keyring is a collection of components in GNOME that store secrets, passwords, keys, certificates and make them available to applications.
GNOME Keyring is integrated with the user's login, so that their secret storage can be unlocked when the user logins into their session.
GNOME Keyring is based around a standard called PKCS#11, which is a standard way for applications to manage certificates and keys on smart cards or secure storage.

System log in Linux


After fedora20, /var/log/messages no longer available.

$journalctl -n 100      show latest 100 lines of system log message

In debian/ubuntu it's in /var/log/syslog.

Wednesday, September 30, 2015

Filesystem Hierarchy Standard in Linux


Linux File System version is 2.3, announced on January 29, 2004. [1]


Since the publication of early documentation, the directory name has been re-explained in various ways. Recent interpretations include backronyms such as "Editable Text Configuration" or "Extended Tool Chest". [2] 

Sunday, September 27, 2015

SVN Check out failure on Dbian - SSL error: Key usage violation in certificate has been detected


sudo apt-get install libneon27
cd /usr/lib
sudo rm
sudo ln -s /usr/lib/ (double check that symbolic link is created)

Another way  is to upgrade SVN client to latest SVN 1.8.xx which already handles http/https access.

Reasons behind this [2]
GnuTLS library is an alternative to OpenSSL. Most Subversion clients for Windows are built against OpenSSL and are not affected by this issue. While some Subversion packages (available mostly on Linux-based operating systems such as Ubuntu and Debian) are built against GnuTLS and are affected.

Install gcc / g++ man page manually on Debian.


 Install gcc / g++ man page manually on Debian.

Edit /etc/apt/sources.list to include non-free repositories.

#apt-get update

#apt-get install gcc-doc

Wednesday, September 23, 2015

Linux package collection


#apt-get autoremove                    clean up unused packages
#apt-get -f install                         fixing broken dependencies
#apt-get update                            update apt-get repository
#apt-get upgrade                          upgrade all apt packages
#apt-cache search keywordofpackage    search for an apt package in Ubuntu
#apt update
#add-apt-repository ppa:teatime/ppa
#apt install teatime-unity
#dpkg --list                                             list all installed package in Ubuntu
#dpkg -i xxxx.deb                       Install from downloaded package.

#yum search keywordofyumpackage     search for an yum package in Fedora

$systemctl daemon-reload

#apt-get install gcc-4.9
#apt-get install g++-4.9
#apt-get install gcc
#apt-get install g++
#yum install libstdc++-docs            libstdc++-docs.x86_64 0:4.8.3-7.fc20  man page for C++ lib
#apt-get install manpages-posix manpages-posix-dev
#yum install man-pages             man-pages.noarch 0:3.53-6.fc20  showing $man ldd $man pthread_mutex_lock after installation

#apt-get install libasio-dev           modern c++ library for network programming
#apt-get install libasio-doc
#apt-get install make

#apt-get install cmake
#apt-get install cmake-qt-gui         replacement for cmake -i wizard option

#apt-get install ipython
     Suggested packages:
     ipython-doc ipython-notebook ipython-qtconsole python-matplotlib
     python-numpy python-zmq python-pexpect-doc
     The following NEW packages will be installed:
     ipython python-decorator python-pexpect python-simplegeneric
#apt-get install python-matplotlib

sudo apt-get install qt4-designer --fix-missing

#apt-get install  vim-gnome
#sudo apt-get install ctags            then install tagsbar plug in
#sudo apt-get install exuberant-ctags    exuberant-ctags better than ctags which covers only c
#apt-get install cscope              

#apt-get install meld                  visual file comparison tool
#apt-get install subversion
#apt-get install git

#apt-get install kompare      similar like meld....visual file comparison

#apt-get install gawk                    to change from mawk to gawk to use --field-separater option in awk command line
#apt-get install ack-grep
#apt-get install screen                 screen/terminal logging tool
#apt-get install trace-route       to avoid modern firewall, u can use trace-route xxxx -T via tcp socket
#apt-get install dos2unix             convert dos format text file to unix format
#apt-get install nfs-common nfs-kernel-server            Then modify /etc/export and firewall settings to set up NFS server.

#apt-get install arp-scan           ip-scan for LAN

#dpkg -i ~/Downloads/pac-      PAC Manager, Perl/Gtk approach to sssh/telnet/rdp/... connections managing.

#apt-get install openssh-server

#apt-get install freerdp-x11            to remote desktop From Linux to Windows
       qyang@lubuntu-laptop:~$ xfreerdp /u:UserName /p:Password /v: /f

#apt-get install tightvncserver       to remote desktop from Windows to Linux (faster than xrdp and x11vnc)
#apt-get install xtightvncviewer
#apt-get install autocutsel

$vino-preferences will bring ubuntu14.04.3 default installed desktop sharing options.

#apt-get install pptp-linux network-manager-pptp network-manager-pptp-gnome  for VPN connection to Microsoft VPN server

#apt-get install network-manager-vpnc                       for VPN connection using Cisco Compatible VPN (vpnc)
#apt-get install network-manager-vpnc-gnome           for VPN GUI integration with Gnome

#apt-get install lib32z1 lib32ncurses5                         required package for Cisco AnyConnect client installation
#apt-get install network-manager-openconnect-gnome    openconnect client
#./                                                             for VPN connection using Cisco AnyConnect
                                                                                    Scripts downloaded when browsing to install Cisco AnyConnect Client in Linux

run $systemctl daemon-reload if seeing error "Failed to start vpnagentd.service: Unit vpnagentd.service not found." [2]

#apt-get install ufw                                       ufw - program for managing a netfilter firewall

#apt-get install sysv-rc-con          debian service config package installed on lubuntu-laptop
( #apt-get install rcconf                    service control)
( #apt-get install sysvconfig              chkconfig like service config on debian  [1] )
#yum install chkconfig                   fedora service control

MISC - MustHave
#apt-get install xpad                              sticky notes counterpart in Linux (others similar have knote,tomboy etc)
#apt-get install tree                                list folder structure
#apt-get install libreoffice
#apt-get install shutter                           screen shot tool, similar like snipping tool in win7. build-in pic annotation.
#apt-get install gnome-screenshot         gnome build-in screen shot tool shift+prtscn
                                                               $gnome-screenshot –file=[FILENAME]    
                                                               $gnome-screenshot -i  
                                                               $gnome-screenshot -a  
                                                               $gnome-screenshot -w
#sudo apt-get install file-roller              a tool to open and view *.tar *.tar.gz
#clock or teatimer                               a good tool for timer remind
#apt-get install imagemagick                a good tool to convert multiple images into one pdf file using 'convert' command line as part of imagemagick.

#apt-get install docky
#apt-get install xcompmgr                      enable 3D effect for docky applicataion
#apt-get install seahorse             front-end to reset/change key ring password
#apt-get install gconf-editor            alt+f2 bring cmd prompt, type 'gconf-editor' config docky position
sudo apt-get install gtypist
sudo apt-get install dvorak7min
sudo apt-get install typespeed
sudo apt-get install transmission     default official BitTorrent client in ubuntu, transmission-gtk, transmission-common

#sudo apt-get install ubuntu-restricted-extras
#sudo apt-get install libdvd-pkg  (> 15.04)
#sudo dpkg-reconfigure libdvd-pkg

Linux App Collection

Ref [1]
Ref [2]
Ref [3]
Ref [4]
Ref [5]
Ref [6]
Ref [7]

Music Player:                                                                      Banshee  [1]
Notes:                                                                                 Tomboy Note [2]
Win7 Snipping Tool Counter Part on Linux:                         Shutter [3]
Dock:                                                               Cario-Dock,Docky [5]   Plank [4]
Pdf Editor                                            pdfedit not usable,inkspace do one page only at one time.
                              Using liboffice draw to import all pages and edit by adding text on top of doc.[6]
                         Fill up once, not edit later then using Chrome build-in pdf viewer to edit and print.[7]
TerminalLogging                                                                  screen

$screen -L    start logging
Ctrl+a d to detach screen
$screen -r   to resume screen

Run windows app on Linux using Wine.

[1] how-to-install-and-use-wine-to-run-windows-applications-on-linux

[2] 910-i-have-just-switched-from-win7-to-zorin-ubuntu-i-have-been-working-with-an-ai-program-called-verbot-for-awhile-and-my-question-is-how-do-i-run-it-and-net-framework-on-zorin-please-help

[3] difference-between-wine-and-mono

If your Linux PC has limited RAM and you don't want to sacrifice large chunk of RAM to run VM just to be able to run one or two windows app. Wine is your answer. You save buying one window license to run window app.

[1] Shows you how.

PlayOnlinux is also mentioned as a wonderful tool to make it possible to handle different versions of wine and wine configs because if you use it for more then one app it's sometimes necessary to install different wine versions.

You can use Wine for that purpose. but it only works on .net 2.0 / 3.0, Most probably, .net 4 is beyond the capacity right now. Ur best bet is for .net support on Linux is MONO. [2]

Monday, September 21, 2015

Remote desktop from Windows to Linux


Through VNC as most people traditionally did.
Through RDP. [1]

 yum install xrdp -y
# chkconfig --levels 35 xrdp on
# service xrdp start

# rpm -Uvh

Under debian using xrdp + vino [2] [3]
 vi /etc/xrdp/xrdp.ini

# set empty username because VNC auth 
# doesn't actually use username, so no
# point in asking the user for one.

name=Active Local Login

name=Clean Session
$sudo vino-preferences