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

Saturday, October 24, 2015

Classless Inter-Domain Routing (CIDR)



[1] wiki
[2] www.iplocation.net/subnet-mask

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] animations.physics.unsw.edu.au 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] www.linuxfoundation.org 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] elinuxdev.blogspot.com.tr notes of driver example


Got [1] from LinkedIn discussion.

Kernelnewies web link

[1] kernelnewbies.org

KGDB for Kernel Module Debugging

[1] www.kernel.org 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
#!/bin/sh
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


[1] https://github.com/millerap/AM335x_PRU_BeagleBone
[2] http://elinux.org/ECE497_BeagleBone_PRU
[3] http://boxysean.com/blog/2012/08/12/first-steps-with-the-beaglebone-pru/
[4] http://mythopoeic.org/bbb-pru-minimal/


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

[1] https://help.ubuntu.com/community/Lubuntu/Keyboard
[2] http://cipricuslinux.blogspot.com.au/2012/11/edit-shortcuts-keybindings-in-lubuntu.html


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

What's key ring for?

[1] http://askubuntu.com/questions/32164/what-does-a-keyring-do
[2] http://askubuntu.com/questions/184266/what-is-unlock-keyring-and-how-do-i-get-rid-of-it
[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 lastpass.com'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

[1] https://ask.fedoraproject.org/en/question/9299/sticky-how-do-i-view-logs-on-fedora/




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.