C++; Singleton Design Pattern

Singleton is a creational design pattern.
Provide one and only instance of an object.

#include using namespace std; 
class MySingleton 
      public: static MySingleton* iInstance; 
      public: static MySingleton* GetInstance(); 
      private: MySingleton(); 
}; 
MySingleton* MySingleton::iInstance = NULL; 
MySingleton::MySingleton() 
      cout << "Inside construtor ..." << endl; 
MySingleton* MySingleton::GetInstance() 
{
      if ( iInstance == NULL ) 
      {  
           iInstance = new MySingleton(); 
      } 
     return iInstance; 


void main() 
     MySingleton* obj; 
     obj = MySingleton::GetInstance(); 
}

Useful linux commands


Vi Editor:

    x          Delete character at cursor
    X          Delete character before cursor
    Y or yy  Yank (copy) current line into "unnamed" storage buffer.
    p          Paste unnamed storage buffer after current line.
    P          Paste unnamed storage buffer before current line.
    r           Replace character
    R          Overwrite characters from cursor onward
    s          Substitute one character under cursor continue to insert
    S          Substitute entire line and begin to insert at beginning of line
    J           Join current and following line into one line



  • Use command: ":e filename"
       Start new edit session on specified file name without closing current vi /        vim editor process.
  • Find/Replace:Example:
       :%s/fff/rrrrr/  -   For all lines in a file, find string "fff" and replace with                                   string "rrrrr" for the first instance on a line.
       :%s/fff/rrrrr/g -  For all lines in a file, find string "fff" and replace with                                   string "rrrrr" for each instance on a line.
       :%s/fff/rrrrr/gc - For all lines in a file, find string "fff" and replace with                                   string "rrrrr" for each instance on a line. Ask for                                           confirmation
       :%s/fff/rrrrr/gi - For all lines in a file, find string "fff" and replace with                                   string "rrrrr" for each instance on a line. Case                                               insensitive.

Extract or Unpack a tar File:


  • To extract tar file of type:
       tar -xvf <filename>.tar
  • To extract .tar.gz (gzip) file

    tar -xzvf <file name>.tar.gz
  • To extract .tar.bz2 (bzip2) file
       tar -xjvf file.tar.bz2

  • To extarct single file from tar file
        tar -xvf file.tar foo.txt 
        tar -xzvf file.tar.gz foo.txt 
        tar -xjvf file.tar.bz2 foo.txt

Where,
-x : Extract a tar ball.
-v : Verbose output or show progress while extracting files.
-f : Specify an archive or a tarball filename.
-j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
-z : Decompress and extract the contents of the compressed archive created by gzip program (tar.gz extension).