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.