Thursday, October 29, 2015

Sample Python Codes plot value with date time axis in matplotlib



[1] stackoverflow.com/ 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))

plt.plot(ax,ay)
# Beautify the display format
plt.gcf().autofmt_xdate()
plt.show()


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

Python Notes





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

Docky in Lubuntu

[1] ubuntuforums.org
[2] ubuntuforums.org 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;
#endif
#ifdef TEST_1
  // 0 value initialization happen every time when FuncA is called.
  int StaticVar=0;
#endif
#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;
#endif
#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;
#endif

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

}


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

}
The results after defining different test cases:

Test_0
qyang@lubuntu-laptop:~$ ./Learn_static 
StaticVar is : 0
StaticVar is : 1
StaticVar is : 2
StaticVar is : 3
StaticVar is : 4
StaticVar is : 5
====Done====
Test_1
qyang@lubuntu-laptop:~$ ./Learn_static 
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
StaticVar is : 0
====Done====
Test_2
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
====Done====
Test_3
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
====Done====

Tuesday, October 27, 2015

C++ Notes

[1] http://www.cplusplus.com/reference/sstream/stringstream
[2] www.parashift.com/c++-faq/


CONCEPT
--------------

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.



LIBRARY
------------
setw ( )
stringstream

iostream-vs-stdio

Pattern matching and regular expressions in Linux Command Line


[1] tldp.org/LDP/GNU-Linux-Tools-Summary
[2] unix.stackexchange.com/questions/28155/find-files-with-certain-extensions

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