Change apache server's default listening port

Tested on VPS hosting using ubuntu server 10.04.

Change the port number in the following files:
/etc/apache2/sites-enabled/example.com
/etc/apache2/ports.conf
/etc/apache2/sites-available/default
Finally, remember to restart apache server:
/etc/init.d/apache2 restart

Question Paper Downloader for Thaparians

Latest Software here
Latest Code here
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.net.URL;

public class FileDownloader
{
 public static void main(String args[])
 {
  if(args.length != 2 && !(args[0].equals(""))){
   System.out.println("Usage: <web-link> <new-filename>");
  }else{try{
   if((args[0].substring(7,10)).equals("172"))
    args[0] = "http://cl.thapar.edu/" + args[0].substring(20);
   System.out.println("FileDownloader: "+args[0]+" "+args[1]);
   URL url = new URL(args[0]);
   java.io.BufferedInputStream in = new BufferedInputStream(url.openStream());
   java.io.FileOutputStream fos = new FileOutputStream(args[1]+".pdf");
   java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
   byte[] data = new byte[1024];
   int x=0;
   while((x=in.read(data,0,1024))>=0)
   {
    bout.write(data,0,x);
   }
   bout.close();
   in.close();
  }catch(IOException e){
   System.out.println(e.toString());
  }}
 }
}

Steps for Java Web Start

  1. Make jar file of your class files and resources like icons, images etc. using following command:
    jar cf JarFileToCreate.jar abc.class def.class ...
    For More details on creating Jar files, see create-jar-file-for-java-app
  2. Make jnlp extension text file with following information:
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="http://localhost/jnlp" href="MyApp.jnlp">
        <information>
            <title>My App Title</title>
            <vendor>MonishVendor</vendor>
        </information>
        <resources>
            <!-- Application Resources -->
            <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
            <jar href="TestApp.jar" main="true" />
    
        </resources>
        <application-desc
             name="DemoName"
             main-class="GUI_QPDownloader"
             width="300"
             height="300">
         </application-desc>
         <update check="background"/>
    </jnlp> 
  3. That's all. Now run jnlp file from any web-browser to test

    How to create jar file for the java app you make.

    Modifying a Manifest File

    You use the m command-line option to add custom information to the manifest during creation of a JAR file. This section describes the m option. The Jar tool automatically puts a default manifest with the pathname META-INF/MANIFEST.MF into any JAR file you create. You can enable special JAR file functionality, such as package sealing, by modifying the default manifest. Typically, modifying the default manifest involves adding special-purpose headers to the manifest that allow the JAR file to perform a particular desired function.
    To modify the manifest, you must first prepare a text file containing the information you wish to add to the manifest. You then use the Jar tool's m option to add the information in your file to the manifest.

    Warning:  The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.

    The basic command has this format:
    jar cfm jar-file manifest-addition input-file(s)

    Effective C++ Ed. 3rd: Item 43: Know how to access names in templatized base classes

    In derived class templates, refer to names in base class templates via
    1. a "this->" prefix
    2. using declarations or
    3. an explicit base class qualification like:
      Base::func()
    The 3rd option should not be used in case of virtual functions.
    prev | next

    Effective C++ Ed. 3rd: Item 42. Understand the two meanings of typename

    What's the difference between the following two declarations:
    template<class T> class Widget;                 // uses "class"
    
    template<typename T> class Widget;              // uses "typename"
    
    
    When declaring template parameters, class and typename are interchangeable.
    But use typename to identify nested dependent type names, except in base class lists or as a base class identifier in a member initialization list.
    prev | next

    Effective C++ Ed. 3rd: Item 41. Understand implicit interfaces and compile-time polymorphism

    • Object-oriented programming revolves around explicit interfaces and runtime polymorphism.
    • In template and generic programming, these are less important. Instead, implicit interfaces and compile-time polymorphism move to the fore.

    Effective C++ Ed. 3rd: Item 40. Use multiple inheritance juriciously

    With multiple inheritance (MI), you may have a class hierarchy with more than one path between a base class and a derived class. For example:
    class basic_ios { ... };
    
    class basic_istream: public basic_ios { ... };
    
    class basic_ostream: public basic_ios { ... };
    
    class basic_iostream: public basic_istream, public basic_ostream
    { ... };
    To restrict inclusion of members of class basic_istream twice into class basic_iostream, use virtual inheritance. Declare the above classes as:
    class basic_ios { ... };
    
    class basic_istream: virtual public basic_ios { ... };
    
    class basic_ostream: virtual public basic_ios { ... };
    
    class basic_iostream: public basic_istream, public basic_ostream
    { ... };
    But try to avoid virtual inheritance because:
    1. objects created using virtual inheritance are generally larger.
    2. Access to data members in virtual base classes is also slower than those in non-virtual base classes.
    Cheers

    Effective C++ Ed. 3rd: Item 39. Use private inheritance judiciously

    A class "is-implemented-in-terms-of" might be achieved by:
    • composition (see prev. item for detail)
    • private inheritance. 
    Now, which to use when? Former should be used whenever possible. Private inheritance would be handy when you need to redefine a virtual member function or need to access to protected base class members.
    Beside the 2 alternatives mentioned above,
    • we may have a design something like:
    class Widget {
    private:
      class WidgetTimer: public Timer {
      public:
        virtual void onTick() const;
        ...
    
      };
       WidgetTimer timer;
      ...
    
    };
    
    In the third alternative's example, we need to redefine onTick() of class Timer.This design is appreciated over private inheritance because 1.the derived classes would not be able to refine onTick(). 2. In case of private inheritance, Widget get compilation dependencies on the definition of class Timer which would force us to #include timer.h Whereas in alternative 3, By defining WidgetTimer class out of the Widget class and placing a pointer to WidgetTimer would require just declaration of WidgetTimer class at the minimum.
    prev | next
    cheers

    Effective C++ Ed. 3rd: Item 38. Model "has-a" or "is-implemented-in-terms-of" through composition

    Composition is the relationship between types that arises when objects of one type contain objects of another type. Composition means either "has-a"(things related to application domain) or "is-implemented-in-terms-of."(things related to your software's implementation domain like mutexes, buffer, search trees etc.)

    prev | next
    Cheers

    Effective C++ Ed. 3rd: Item 37. Never redefine a function's inherited default parameter value

    Never redefine an inherited default parameter value, because these are statically bound unlike the virtual functions ( the only functions which should be overridding).
    The following NVI technique is one of the alternatives if you want to redefine an inherited default parameter value:
    class Shape {
    public:
      enum ShapeColor { Red, Green, Blue };
    
      void draw(ShapeColor color = Red) const           // now non-virtual
      {
        doDraw(color);                                  // calls a virtual
      }
    
      ...
    
    private:
      virtual void doDraw(ShapeColor color) const = 0;  // the actual work is
    };                                                  // done in this func
    
    class Rectangle: public Shape {
    public:
    
      ...
    
    private:
      virtual void doDraw(ShapeColor color) const;       // note lack of a
      ...                                                // default param val.
    };
    
    
    prev | next
    Cheers

    Effective C++ Ed. 3rd: Item 36. Never redefine an inherited non-virtual function

    When base class pointer points to a derived class pointer and an inherited non-virtual function which is refined in derived class, the definition present in base class would execute. This happens because non-virtual functions are statically bind. So
    1. Either declare only those functions non-virtual which will remain invariant in derived classes
    2. Or use virtual functions or it's alternatives at defines here.
    prev | next

    Cheers

    BSD sockets: Server Client Chat Program using TCP

    Check latest version here.

    Header File 1 for Server Program: SChat_register.h
    #ifndef SCHAT_REGISTER_H
    #define SCHAT_REGISTER_H
    //SChat_register.h
    #include "SChat_connect.h"
    
    typedef short bool;
    int* ar;//= (int*) malloc(sizeof(int));
    int maxIndex;// = 0;
    int top;// = -5;
    bool reg_lock;// = false;
    
    void getRegisteredList(){
     int i;
     for(i=0; i<=top; i++)
      printf("%d\t", ar[i]);
     printf("\n");
    }
    //call this before using any other function of this library
    void init(){
     ar = (int*) calloc(1, sizeof(int));
     if(ar == NULL)
      Error("malloc error in init");
     top = -1;
     con_init();
     maxIndex = 0;
     reg_lock = false;
    }
    

    Effective C++ Ed. 3rd: Item 35. Consider alternatives to virtual functions

    • Non-virtual Interface Idiom (NVI): Provides an alternative to public virtual functions by making these public and accesible via a public non-virtual member function. It does NOT elimination the use of virtuals.
    • Function Pointers: To eliminate using virtual member functions, pointer to function can be kept as a member. It is good when all needed information for the function is available from public interface.
    • tr1::function: It is like function pointers but more generic and can even point to function objects or member functoins. So clients can use any compatible calling entity.
    • The "classic" Strategy Pattern: To move virtual functions from 1 inheritance hierarchy to other.
    prev | next

    Cheers

    Ubuntu Server 10.04: What ports are open?

    Run the following command:

    netstat -anltp
    


    Cheers.

    Effective C++ Ed. 3rd: Item 34. Differenciate between inheritance of interface and inheritance of implementation

     Under public inheritance, use:
    • Pure virtual functions to specify inheritance of interface only.
    • Simple virtual functions to specify inheritance of interface plus inheritance of a default implemetation.
    • Non-virtual functions to specify inheritance of interface plus inheritance of a mandatory implementation.
    Note: Instead of using simple virtual functions, we can also use pure virtual function along with their definition as shown:
    class Airplane {
    public:
      virtual void fly(const Airport& destination) = 0;
    
      ...
    
    };
    
    void Airplane::fly(const Airport& destination)     // an implementation of
    {                                                  // a pure virtual function
      default code for flying an airplane to
      the given destination
    }
    
    class ModelA: public Airplane {
    public:
      virtual void fly(const Airport& destination)
      { Airplane::fly(destination); }
    
      ...
    
    };
    
    class ModelB: public Airplane {
    public:
      virtual void fly(const Airport& destination)
      { Airplane::fly(destination); }
    
      ...
    
    };
    
    class ModelC: public Airplane {
    public:
      virtual void fly(const Airport& destination);
    
      ...
    
    };
    
    void ModelC::fly(const Airport& destination)
    {
      ... //code for flying a ModelC airplane to the given destination
    }
    

    prev | next
    Cheers and try hosting at Linode.

    Effective C++ Ed. 3rd: Item 33. Avoid hiding inherited names

    • Names of functions, typedefs etc. in base class get "shadow"ed if anything with those names is present in derived class.
    • The function names get "shadow"ed irrespective of the arguments of the functions regardless of whether the functions are virtual or non-virtual.
    • Sometimes it's desirable to inherit the overloads. Use Base::functionName(); to make these visible in derived class.
    •  Say If we have Base::mf1(); and Base::mf1(int); But we only want former to be visible in derived class, the above trick won't work. Use forwarding functions as: derived::mf1(){ base::mf1() }
    Note: For template classes, see item 43.
    prev | next
    Cheers and try hosting at Linode.

    Effective C++ Ed. 3rd: Item 32. Make sure public inheritance models "is-a"

    • Where-ever object of base class can be used, derived class object can also be used but vice-versa is not true.
    • Public inheritance asserts that everything that applies to base class objects- everything! - also applies to derived class objects.
    prev | next

    Cheers

      Network Programming: Echo Client Server program (Iterative)

      Echo server client: The way a server program and client(program ) interacts is what their protocol (set of rules they have for interation) is!! This server client program is echo program. Once successfully connected, Client writes anything. Server reads that and send back the same text. This goes on till client disconnects or writes text beginning with "exit". This is echo protocol.

      All programs are tested in SUSE Linux Enterprise Server 10 (i586) VERSION = 10 PATCHLEVEL = 2. For how to check the distribution of linux you are running, read this.

      The server serves the client one after the other in iterative fashion.
      Echo Server program:
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <unistd.h>
      #include <sys/types.h> 
      #include <sys/socket.h>
      #include <netinet/in.h>
      
      void error(const char *msg)
      {
          perror(msg);
          exit(1);
      }
      
      int main(int argc, char *argv[])
      {
           int sockfd, newsockfd, portno;
           socklen_t clilen;
           char buffer[256];
           struct sockaddr_in serv_addr, cli_addr;
           int n;
           if (argc < 2) {
               fprintf(stderr,"ERROR, no port provided\n");
               exit(1);
           }
        
      //STEP1 socket function
           sockfd = socket(AF_INET, SOCK_STREAM, 0);
           if (sockfd < 0) 
              error("ERROR opening socket");
        
      //STEP2 address structure
           bzero((char *) &serv_addr, sizeof(serv_addr));
           portno = atoi(argv[1]);
           serv_addr.sin_family = AF_INET;
           serv_addr.sin_addr.s_addr = INADDR_ANY;
           serv_addr.sin_port = htons(portno);
      
      //STEP3 bind function
           if (bind(sockfd, (struct sockaddr *) &serv_addr,
                    sizeof(serv_addr)) < 0) 
                    error("ERROR on binding"); 
      
      //STEP4 listen function
          listen(sockfd,10);
       
      //STEP5 accept and serve clients one by one in iterative fashion
       while(1){
        clilen = sizeof(cli_addr);
        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
         if (newsockfd < 0) error("ERROR on accept");
         bzero(buffer,256);
         while(  (n=read(newsockfd,buffer,255)) > 0  ){
         if (n < 0) error("ERROR reading from socket");
         n = write(newsockfd,buffer,n);
         if (n < 0) error("ERROR writing to socket");
         bzero(buffer,256);
         }
         close(newsockfd);
       }
           close(sockfd);
           return 0; 
      }
      
      
      
      Echo Client program:
      #include <stdio.h>
      #include <stdlib.h>
      #include <unistd.h>
      #include <string.h>
      #include <sys/types.h>
      #include <sys/socket.h>
      #include <netinet/in.h>
      #include <netdb.h> 
      
      void error(const char *msg)
      {
          perror(msg);
          exit(0);
      }
      
      int main(int argc, char *argv[])
      {
          int sockfd, n;
          struct sockaddr_in serv_addr;
          struct hostent *server;
      
          char buffer[256];
          if (argc < 3) {
             fprintf(stderr,"usage %s hostname port\n", argv[0]);
             exit(0);
          }
      
      //STEP1 socket function
          sockfd = socket(AF_INET, SOCK_STREAM, 0);
          if (sockfd < 0) 
              error("ERROR opening socket");
          server = gethostbyname(argv[1]);
          if (server == NULL) {
              fprintf(stderr,"ERROR, no such host\n");
              exit(0);
          }
       
      //STEP2 prepare address structure
          bzero((char *) &serv_addr, sizeof(serv_addr));
          serv_addr.sin_family = AF_INET;
          bcopy((char *)server->h_addr, 
               (char *)&serv_addr.sin_addr.s_addr,
               server->h_length);
          serv_addr.sin_port = htons(atoi(argv[2]));
      
      //STEP3 connect function: request to server for connection
          if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
              error("ERROR connecting");
        
      //STEP4 read and write to server.
          while(1){
        bzero(buffer,256);
        fgets(buffer,255,stdin);//read from client stdin
        if((n=bcmp("exit",buffer,strlen(buffer))==0)){ close(sockfd); return 0; }    
        n = write(sockfd,buffer,strlen(buffer));//write to server
        if (n < 0) error("ERROR writing to socket");
        bzero(buffer,256);
        n = read(sockfd,buffer,255);//read from server and save it in array buffer
        if (n < 0) error("ERROR reading from socket");
        printf("%s\n",buffer);//write to stdout the buffer's contents
          }
          close(sockfd);
          return 0;
      }
      
      Cheers and try hosting at Linode.

      Network Programming: Day-Time Client Server program (Concurrent)

      All programs are tested in SUSE Linux Enterprise Server 10 (i586) VERSION = 10 PATCHLEVEL = 2. For how to check the distribution of linux you are running, read this.

      The server serves the client one after the other in concurrent fashion using fork().
      Server program:

      Network Programming: Date-Time Client Server program (Iterative)

      This is the first post in network programming program series.
      All programs are tested in SUSE Linux Enterprise Server 10 (i586) VERSION = 10 PATCHLEVEL = 2. For how to check the distribution of linux you are running, read this.

      The server serves the client one after the other in iterative fashion.
      Server program:

      Which distro of linux are you using?

      This is how you can check:
      Simply run the following command
      cat /etc/*-release

      This will not only tell you the linux distro you are using, but also the version number. Plus some other optional details.

      Tested on RedHat, OpenSuSe and Ubuntu server.


      Cheers and try hosting at Linode.

      Effective C++ Ed. 3rd: Item 31. Minimize compilation dependencies between files

      It is beneficial if the implementation changes in a library does not forces the clients to re-compile their code. But how would you minimize compilation dependencies? The key to this is replacement of dependencies on definitions with dependencies on declarations. There are following 2 ways:
      • Handle classes: By employing pimple idiom in classes.
      • Interface classes: By declaring abstract base class
      Besides this, libraries should be implemented as declarations and definitions in separate header files. So that clients only include header files containing declarations only.

      prev | next
      Cheers and try hosting at Linode.

      Effective C++ Ed. 3rd: Item 30. Understand the ins and outs of inlining

      • Inline functions prevent the cost of function call. However, excessive overzealous inlining leads to code bloat, resulting in addition paging, reduced cache hit rate etc.
      • Implicit inline request: when defining a function inside a class.
      • Explicit inline request: when preceding function's definition with inline keyword.

      Effective C++ Ed. 3rd: Item 29. Strive for exception-safe code

      When an exception is thrown, a exception-safe fuction:
      • Leak no resources
      • do not make data structures corrupt.
      Exception-safe functions should offer one of three guarantees:
      • the basic guarantee
      • the strong guarantee
      • the nothrow guarantee

      Effective C++ Ed. 3rd: Item 28. Avoid returning "handles" to object internals.

      While returning internal handles from a member function, consider
      • returning const object. This results in read-only access of the returned parameter.
      The problem with dangling references will still remains. So it's better to avoid returning reference, pointer or iterators from a function. This would minimize dangling handles and also might provide better encapsulation in case of member functions.

      prev | next
      Cheers and try hosting at Linode.

      How to check free space in Ubuntu?

      The sizes of files and directories can be listed using:
      ls -l

      To see the free space left in partitions, use:
      df -h

      Other filters for df are given below:

      Apache access.log format And Status Codes

      Operating System: Windows XP SP2 
      Server: localhost
      Sample String from access.log: 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
      Each part of this log entry is described below.
      127.0.0.1 (%h)
      This is the IP address of the client (remote host) which made the request to the server. If HostnameLookups is set to On, then the server will try to determine the hostname and log it in place of the IP address. However, this configuration is not recommended since it can significantly slow the server. Instead, it is best to use a log post-processor such as logresolve to determine the hostnames. The IP address reported here is not necessarily the address of the machine at which the user is sitting. If a proxy server exists between the user and the server, this address will be the address of the proxy, rather than the originating machine.

      Effective C++ Ed. 3rd: Item 27. Minimise casting

      Instead of "old" C style casts:



      (T) expression             // cast expression to be of type T 
      T(expression)           // cast expression to be of type T
      



      Prefer C++ style-casts:

      Effective C++ Ed. 3rd: Item 26. Postpone variable definitions as long as possible

      1. Postpone a variable's definition until right before you have to use the variable
      2. Try to postpone the definition until you have initialization arguments for it. 
      3. By doing so, you avoid constructing and destructing unneeded objects, and you avoid unnecessary default constructions. 
      4. This help document the purpose of variables by initializing them in contexts in which their meaning is clear.
      prev | next

        Effective C++ Ed. 3rd: Item 25 Consider support for non-throwing swap.

        Contents:
        •     Default Swap
        •     Member Swaps
        •     Non-member swaps
        •     Specializations of std::swaps
        •     calls to swap

        Swap has become a mainstay. Swap is a very useful function. It's important to implement it properly. Among many uses, it is a common mechanism for coping with the possibility of assignment to self. A typical implementation in std is:
        namespace std {
        template  <>        // typical implementation of std::swap;
        void swap(T& a, T& b)         // swaps a's and b's values  
        {
            T temp(a);
            a = b;
            b = temp;
          }
        }
        

        To override swap function:

        Effective C++ Ed. 3rd: Item 24. Declare non-member functions when type conversions should apply to all parameters

        Way 1:
        class Rational {
        public:
            Rational(int numerator = 0,        // ctor is deliberately not explicit;
                int denominator = 1);     // allows implicit int-to-Rational conversions
                int numerator() const;             // accessors for numerator and
                int denominator() const;           // denominator
        
                const Rational operator*(const Rational& rhs) const;
            private:
            ...
        };
        
        Rational oneEighth(1, 8);
        Rational oneHalf(1, 2);
        result = oneHalf * 2;                             // fine - oneHalf.operator*(2);
        result = 2 * oneHalf;                             // error! - 2.operator*(oneHalf);
        
        Way2:
        class Rational {
          ...                                             // contains no operator*
        };
        
        const Rational operator*(const Rational& lhs,     // now a non-member
                                 const Rational& rhs)     // function
        {
          return Rational(lhs.numerator() * rhs.numerator(),
                          lhs.denominator() * rhs.denominator());
        }
        
        Rational oneFourth(1, 4);
        Rational result;
        result = oneFourth * 2;                           // fine
        result = 2 * oneFourth;                           // hooray, it works!
        
        Result: As multiplication should be commutative, Way2 should be used when type conversions should apply to all parameters.

        prev | next
        Cheers and try hosting at Linode.

        Effective C++ Ed. 3rd: Item 23. Prefer non-member non-friend functions to member functions

        Reasons to prefer non-member non-friend functions to member functions: 
        1. Encapsulation: More functions present in a class, lesser is the encapsulation.
        2. Modularity: Functionality of a class in terms of non-member functions or convenience functions can be defined in different header files in the same namespace. This will enable us to include only required functionality along with the class. For example: Functionality of standard library in namespace std is partitioned into many header files viz. vector, iostream, list etc. 
        3. Extensibility: Writing convenience function as mentioned in above point lets other users extend the functionality. This can be done by defining more code in a new header file with the same namespace.
          prev | next
          Cheers and try hosting at Linode.

          Effective C++ Ed. 3rd: Item 22. Declare data members private


          Declare members private for :
          1. Syntactic Consistency: Every call-able member would be a function.
          2. Granular Accessibility: Using "setter" and "get" functions
          3. Encapsulation:
            • Implement functions the way it suits best. For example: On embedded devices: it must use less memory whereas on other machines, it may be allowed to take more memory to speed it up more.
            • Private data members put more restriction on their interaction with the users as compared to protected and public data members. So removing private data member (to change some implementation) leads to less broken code relatively.
          prev | next
          Cheers and try hosting at Linode.

          Ubuntu Server: How to list all the groups and users

          Linux is a multi-user operating system.  This means that the administrator will have to be careful in how users are managed. List of users is maintained in /etc/passwd along with more information like the group the belong to etc. To view its contents, run: cat /etc/passwd
          The each line of output is like:
          www-data:x:33:33:www-data:/var/www:/bin/sh
          Here there are 7 items mentioned below in order from left to right:

          Effective C++ Ed. 3rd: Item 21. Don't try to return a reference when you must return an object

          1. Remember not to return reference to a local object/variable in any function. As local variable/objects dies as soon as function ends.
          2. Remember not to return a dynamically allocated object (using new operator). User of the function may forget corresponding delete call.
          3. Remember not to return reference to a local static object/variable in any function say f().
            In this case f(obj1, ...) = = f(obj2, ...) will always comes true.
          4. Instead return the object by value.
          prev | next
          Cheers and try hosting at Linode.

          Effective C++ Ed. 3rd: Item 20. Prefer pass-by-reference-to-const to pass-by-value

          • For User-defined types(yes, for even small ones) Instead of
            Way 1:
            returnType FunctionName(ArgType1 arg1, ...);

            use
            Way 2:
            returnType FunctionName(const ArgType1& arg1, ...);

            This would reduce the cost of calling copy constructor and destructor for each argument passed as shown above.
          • If a derived object of class ArgType1 is passed by Way1, the copy the called function will get will contain only information defined in Base Class ie. ArgType1 here due to Object Slicing. It can be prevented using Way2.

          Note: Iterators and function objects of STL and build-in types are better off passed by value due to their design.
          prev | next
          I hope this helps
          Cheers and try hosting at Linode.
          Monish

          Effective C++ Ed. 3rd: Item 19. Treat Class Design As Type Design

          What all you must consider to provide in a class you write? Check the following:
          1. Constructors and Destructor as well as memory allocation and deallocation fuctions.
          2. Object Initialization vs. Object Assignment.
          3. Copy constructor to pass objects by value.
          4. Error checking for object values outside legal range allowed, specially in constructors, assignment operators and "setter" functions.
          5. Declare virtual functions and virtual destructor depending upon: if you want to allow others to inherit this class.
          6. Type Conversion functions and constructors.
          7. Provide required functionality by defining functions and Overloaded operators.
          8. Disallow suitable standard funtions. (COPY CTOR etc.)
          9. Use access specifiers depending upon who will be allowed to access particular members.
          10. What kind of guarantee does the class provide in terms of exception safety, resource usage?
          11. Make your class generic using class template if  required.
          12. Is this class is what you need? Can't this be achieved through a function?
          prev | next
          Hope this helps
          Cheers and try hosting at Linode.
          Monish

          Strong Passwords

          A strong password is defined as any password which meets the following criteria:
          • At least fifteen (15) characters in length.
          • Does not contain your user name, real name, organization name, family member's names or names of your pets.
          • Does not contain your birth date.
          • Does not contain a complete dictionary word.
          • Is significantly different from your previous password.
          • Should contain three (3) of the following character types.
            • Lowercase Alphabetical (a, b, c, etc.)
            • Uppercase Alphabetical (A, B, C, etc.)
            • Numerics (0, 1, 2, etc.)
            • Special Characters (@, %, !, etc.) 

          Examples

          Google: Ranking System

          Google maintains much more information about web documents than typical search engines. Every hitlist includes position, font, and capitalization information. Additionally, they factor in hits from anchor text and the PageRank of the document. Combining all of this information into a rank is difficult. They designed the ranking function so that no particular factor can have too much influence. First, consider the simplest case -- a single word query. In order to rank a document with a single word query, Google looks at that document's hit list for that word. Google considers each hit to be one of several different types (title, anchor, URL, plain text large font, plain text small font, ...), each of which has its own type-weight. The type-weights make up a vector indexed by type. Google counts the number of hits of each type in the hit list. Then every count is converted into a count-weight. Count-weights increase linearly with counts at first but quickly taper off so that more than a certain count will not help. We take the dot product of the vector of count-weights with the vector of type-weights to compute an IR score for the document. Finally, the IR score is combined with PageRank to give a final rank to the document.

          Secure hosted files

          Operating System: Ubuntu Server 10.04
          Web Server: apache2
          As apache2 accesses file as user: www-data and group: www-data, First change the owner using following command:
          chown www-data: path/file
          and then to making a particular file only readable only to user:www-data
          chmod 500 path/file
          For scripts and images or logo use 500 (r _ x   _ _ _   _ _ _)
          For images which you only want to save but don't want them to accessible to users/www-data, use
          300 (_ w x   _ _ _   _ _ _)

          Remember to give necessary access to the user which updates the hosted files. Another alternative to secure files is Apache Directives and Containers in http.conf of apache server.

          Hope this helps
          Cheers and try hosting at Linode.
          Monish


          Hope this helps
          Cheers and try hosting at Linode.