Monday, June 2, 2014

Understanding C++ memory and variables


#include <iostream>
using namespace std;
void f1 (int *j)
{
cout << "in f1() beginning-------------\n";
    cout << "       j addr is: " << &j << " is pointed to addr " << j << " value is: " << *j <<"\n";
    int l = 20;
    int *k = &l;
    j = k;
    //k = 0;
    cout << "in f1():======================\n";
    cout << "       l addr is: " << &l << " value is: " << l << "\n";
    cout << "       k addr is: " << &k << " is pointed to addr: " << k << " value is: " << *k << "\n";
    cout << "       j addr is: " << &j << " is pointed to addr " << j << " value is: " << *j <<"\n\n\n";
}

void f2(int **j)
{
    cout << "in f2() beginning-------------\n";
    cout << "       j addr is: " << &j << " is pointed to addr " << j << " value is: " << *j <<"\n";
    cout << "       the value is an address and the exact data is: " << **j << "\n";

    int l = 20;
    int *k = &l;
    *j = k;
    //k = 0;
    cout << "in f2():======================\n";
    cout << "       l addr is: " << &l << " value is: " << l << "\n";
    cout << "       k addr is: " << &k << " is pointed to addr: " << k << " value is: " << *k << "\n";
    cout << "       j addr is: " << &j << " is pointed to addr " << j << " value is: " << *j <<"\n";
    cout << "       the value is an address and the exact data is: " << **j << "\n\n\n";
}

int main()
{
    int i=10;
    int *j = &i;

    cout << "before f1() in main:\n";
    cout << "       j addr is: " << &j << " is pointed to addr " << j << " value is: " << *j << "\n\n";

    f1(j);
    cout << "after f1() in main: \n";
    cout << "       j addr is: " << &j << " is pointed to addr " << j << " value is: " << *j << "\n\n";

    f2(&j);
    cout << "after f2() in main: \n";
    cout << "       j addr is: " << &j << " is pointed to addr " << j << " value is: " << *j << "\n\n";

    return 0;
}
results:
before f1() in main:
      j addr is: 0x28fea8 is pointed to addr 0x28feac value is: 10
in f1() beginning-------------
      j addr is: 0x28fe90 is pointed to addr 0x28feac value is: 10
in f1():======================
      l addr is: 0x28fe7c value is: 20
      k addr is: 0x28fe78 is pointed to addr: 0x28fe7c value is: 20
      j addr is: 0x28fe90 is pointed to addr 0x28fe7c value is: 20
after f1() in main:
      j addr is: 0x28fea8 is pointed to addr 0x28feac value is: 10
in f2() beginning-------------
      j addr is: 0x28fe90 is pointed to addr 0x28fea8 value is: 0x28feac
      the value is an address and the exact data is: 10
in f2():======================
      l addr is: 0x28fe7c value is: 20
      k addr is: 0x28fe78 is pointed to addr: 0x28fe7c value is: 20
      j addr is: 0x28fe90 is pointed to addr 0x28fea8 value is: 0x28fe7c
      the value is an address and the exact data is: 20
after f2() in main:
      j addr is: 0x28fea8 is pointed to addr 0x28fe7c value is: 20

Wednesday, May 14, 2014

How to install python packages on Windows 7

Brief steps:
1. Download a package
2. Extract the package to a folder_pkg
3. Open Windows Command Prompt
4. Go to the folder_pkg
5. > python setup.py install
Then done. Check PythonHomeDir/Lib/site-packages

Useful packages:
1. simplejson: https://pypi.python.org/pypi/simplejson
2. XlsxWriter: https://pypi.python.org/pypi/XlsxWriter

An Detailed Example for installing XlsxWriter Package (TODO)

Saturday, January 11, 2014

高峰体验

[摘] 一个徒步登山者,费尽千辛万苦,克服许多的艰难险阻,每一步都挣扎在生死边缘。开始的时候,还有很好的现实感,知道山知道水,攀登中还会有幽默和笑语。慢 慢的,躯体的痛苦,情绪的沉抑,心身的耗竭让你忘却了行为的意义,甚至怀疑攀登的价值和现实性,你的内心挤满了渴望与逃避,冒险与胆怯、放弃与坚持的双向 冲突,知觉变得凝重而迟缓,现实感消隐,意识逐步的缩窄。再后来,你的思想似乎停滞,感觉麻木,忘了自己是谁,在做什么和为什么要做,只是机械地向上走。 你的意识界沉静而虚无,只有心灵那一丝光亮,仍在坚持和闪耀着。        终于,你到达了那高耸卓绝的山顶,按理说积压太长的期待会给你带来像爆炸一般的狂喜,但却没有发生。你似乎忘却了自我,忘却了存在,时间和空间消融在一 起,没有边界,四周只有一片纯净的虚空,深邃而神秘。你甚至会有一瞬的迷茫,不知道你接下来要做什么?这时,一种像海潮般的愉悦和满足感从遥远的心灵深处 释放、溢出、扩展,伴随着高峰上的洁净、安详,和谐席卷了你,你似乎听见了心灵的笑声,品尝到生命融入那种永恒与无限的感觉。慢慢的海潮过去,你的内心仍 充满着充沛的活力和美妙无比的欣喜,灵感激荡,思想饱满而充实。在以后很长的日子里,你对自我的态度和对世界的感觉已经完全的不同。每当遇到困难的时候, 回忆那不平凡的一刻,你的内心依然会荡漾出坚毅、活力和创造力,成为你自由、自信、自强不息的精神源泉。

[摘马斯诺高峰体验]

Friday, January 3, 2014

Sed Command Basics


Description: the most command parameter of sed command is 's', which stands for substitute.
Format: sed 'PARAM/REGEXP/REPLACEMENT/FLAG' filename
        It searches for matched patterns (by REGEXP) and replaces it with REPLACEMENT.  PARAM and FLAG decides which match is replaced.

Examples:
  1. Replace every first match in a line 
  $ cat sed_cmd_study.txt
  This is to study sed command in Linux system.
  Actually, this is in a cygwin terminal.
  Here are some list of stuff that I am interested:
  Linux Hacking
  C programming and C++ programming
  Python programming and Perl programming
  Photoshop applications and design
  And all the other related stuffs


  $ sed 's/programming/coding/' sed_cmd_study.txt
  This is to study sed command in Linux system.
  Actually, this is in a cygwin terminal.
  Here are some list of stuff that I am interested:
  Linux Hacking
  C coding and C++ programming

  Python coding and Perl programming
  Photoshop applications and design
  And all the other related stuffs

    [NOTE]: in this case, the original file is not modified


    2.  Replace every matches in file
  $ sed 's/programming/coding/g' sed_cmd_study.txt
  This is to study sed command in Linux system.
  Actually, this is in a cygwin terminal.
  Here are some list of stuff that I am interested:
  Linux Hacking
  C coding and C++ coding
  Python coding and Perl coding
  Photoshop applications and design
  And all the other related stuffs

     
    [NOTE]: in this case, the original file is not modified


     3. Only replace the 2nd occurrence of a line in file
  $ sed 's/programming/coding/2' sed_cmd_study.txt
  This is to study sed command in Linux system.
  Actually, this is in a cygwin terminal.
  Here are some list of stuff that I am interested:
  Linux Hacking
  C programming and C++ coding
  Python programming and Perl coding
  Photoshop applications and design
  And all the other related stuffs

     
    [NOTE]: in this case, the original file is not modified

     4.  Replace all the matches and write the modified lines in a file
  $ sed 's/programming/coding/gw output.txt' sed_cmd_study.txt
  This is to study sed command in Linux system.
  Actually, this is in a cygwin terminal.
  Here are some list of stuff that I am interested:
  Linux Hacking
  C coding and C++ coding
  Python coding and Perl coding
  Photoshop applications and design
  And all the other related stuffs


  $ cat output.txt
  C coding and C++ coding
  Python coding and Perl coding



     5. Delete last X number of characters from each line
  $ sed 's/...$//g' sed_cmd_study.txt
  This is to study sed command in Linux syst
  Actually, this is in a cygwin termin
  Here are some list of stuff that I am interest
  Linux Hack
  C programming and C++ programm
  Python programming and Perl programm
  Photoshop applications and des
  And all the other related stu