Monday, February 15, 2010

CSS Notes

CSS Notes


With opacity you can control the brightness of an element. For e.g.:

button.disabled {

The above code would make the button to be 70% opaque if it has class "disabled"

However, the above wont work in IE. IE uses a different style attribute "filter". So, the above code should be:

button.disabled {
    filter: alpha(opacity = 70);


Hover is a nice css attribute which can be implemented for any HTML element (in FF). Here is how to use it:

div.titlebar:hover {

In IE hover works only for "a" (anchors). To make it work for all other tags we need to include the following in the css, and also make sure to download the htc (

body { behavior: url("css/"); }

Friday, October 16, 2009

Linux essential commands

Linux essential commands

Kernal / OS related commands

1. To know the version/flavor of Linux:
cat /proc/version
cat /etc/issue

2. system information
uname (  --kernel-release, --kernel-version, --all )

Storage and memory related

Hard disk

1. To know the amount of space (hard disk) utilized:
df -h
Similarly by using the du command, we can see the amount of disk space used for a set of files or directories
du -sh /home
This gives total disk space used by the /home directory

2. Clear duplicate files and broken symlinks
FSlint is a utility to find and clean various forms of lint on a filesystem, especially duplicate files and broken symlinks.

sudo apt-get install fslint

3. Display amount of free and used memory in the system

free (Default displays in KB)

free -m (to display in MB) free -g (to display in GB)

4. Find Out Hard Disk Specs:
# sudo hdparm -I /dev/sda


1. View the most CPU intensive processes currently running


Package Management

1. Cleaning up of partial package, apt cache, unused dependencies

sudo apt-get autoclean

sudo apt-get clean

sudo apt-get autoremove

2. Remove Orphaned Package

sudo apt-get install gtkorphan

3. To Search packages
sudo apt-cache search dos2unix

4. The following command creates a list of all the installed packages at the present time
sudo dpkg --get-selections > /etc/package.selections


When you are working on a large program, it can be difficult to determine which modules need to be recompiled because of their dependency relationships. The make utility automates this process. make looks at dependency lines in a file named Makefile in the working directory and constructs the target. A simple makefile has the following syntax:

target: prerequisite-list
TAB construction-commands

Note: TAB is keyboard tab

The first ine is dependency line, where the targest is the name of the file that depends on the files listed in the prerequisite-list. construction-commands are regular shell commands that construct target file.


form: size.o length.o
     gcc -o form size.o length.o
size.o: sice.c form.h
     gcc -c size.c
length.o: length.c form.h
     gcc -c length.c

Macros in Make

Syntax of a macro definition is


$ cat Makefile
# Make example

form: size.o length.o

     $(CC) form size.o length.o
size.o size.c form.h
     $(CC) -c size.c

This way if you want to change the compiler, you just have to change the line CC=gcc.

Manual or help related commands

1. Get help on general or system commands, tools, libraries etc.

2. Quick reference commands

3. Quick shell reference

4. Related to programming languages
    perldoc, javadoc etc.

and .. no Google is not a linux command!

4. type -a svn (It will dispaly all the execution files ...) like

5. lsb_release -a
which will print distribution specific information

Users and group management

1. Create new group
   addgroup group1
   After creating a group the system allocates a new group id to the group.

2. Create new user
adduser --home /home/test --shell /bin/bash --ingroup testgroup testuser
adduser -h /home/test -s /bin/bash testuser testgroup
After creating the new user, the system allocates a new user id to the user

3. id
prints  the current user's id

4. See all the users or groups
   cat /etc/passwd
   cat /etc/group

5. Change user's attributes
    usermod -a -G admin testuser
        (this command adds the testuser to the admin group)
        (-a stands for append. If it is not given, the existing groups of testuser will be completely ignored, and testuser will just become a member of only admin group)

6. Change password

Session or terminal specific

1. See the users logged in


2. Find what is the current terminal


3. Clear current terminal setting

  tput reset

4. Empties the current screen



Shutdown Command

shutdown -h now


Find and list

1. To Find the Folders is a Folder

 ls -l  | grep ^d

2. To find older files, and perform some action:

find . -name "*.bz2" -mtime +10 -exec rm -f {} \;

The above command finds all the bz2 files which are older than 10 days, and delete them.

Shell Script

To access arguments individually use $1, $2 etc. To access all the arguments in one shot use $@.
There is one more way of accessing the arguments  - $* - the difference between $* and $@ is that one allows quoted arguments whereas the other
does not.

Another command from the same family is shift .. this can be used to access the arguments using $1, $2 etc.

Internet or Web

WVDial (Setting up mobile gprs with computer)

1. Do "wvdialconf /etc/wvdial.conf" which will create a default configuration
2. Update "Phone" according to your mobile provider value
3. Just run "wvdial"


If you want to download all the files in a specific directory of a url, use wget with the options "-r" and "-np".
"-r" stands for recurseive download.
"-np" stand for no-parrent. If you dont use this option, and just use "-r", then wget downloads all the diretories and files from the base url irrespective of the exact directory you mention.
E.g.: wget -r -np

Thursday, November 15, 2007

Apache - Multi-Processing Modules (MPMs)

MPMs are Responsible for binding to network ports on the machine, accepting requests, and dispatching children to handle the requests. For Linux, two types: worker (threaded MPM) and prefork (non-threaded MPM)

worker MPM
prefork MPM

How it works

Uses multiple child processes. It's multi-threaded within each child, and each thread handles a single connection.

Uses multiple child processes, each child handles one connection at a time.


fast and highly scalable

speed is comparable to that of worker


Memory footprint is comparatively low

Memory usage is high, and more traffic leads to greater memory usage


less tolerant of faulty modules, and a faulty thread can affect all the threads in a child process.

highly tolerant of faulty modules and crashing children

Suited for

multiple processors

single or double CPU systems

Tuesday, July 03, 2007

Better Code Through Destruction

Perl's garbage collector counts references. When the count reaches zero (which means that no one has a reference), Perl reclaims the entity. The approach is simple and effective. However, circular references (when object A has a reference to object B, and object B has a reference to object A) present a problem.

A common example is a tree-like data structure. To navigate both directions--from root to leaves and vice versa--a parent node has a list of children and a child node has a reference to its parent. Many CPAN modules implement their data models this way, including HTML::Tree, XML::DOM, and Text::PDF::File. All these modules provide a method to release the memory. The client application must call the method when it no longer needs an object. However, the requirement of an explicit call is not very appealing and can result in unsafe code.


Instead of explicitly calling the method to delete the object, create a special guard object (of another class) whose sole responsibility is to release the resource. When the guard object gets destroyed, its destructor deletes the tree.
    use HTML::TreeBuilder;

foreach my $filename (@ARGV) {
my $tree = HTML::TreeBuilder->new;

my $sentry = Sentry->new($tree);

next unless $tree->look_down('_tag', 'img');
## next, last or return are safe here.
## Tree will be deleted automatically.

package Sentry;
sub new {
my $class = shift;
my $tree = shift;
return bless {tree => $tree}, $class;
my $self = shift;

Note that now there is no need to call $tree->delete explicitly at the end of the loop. The magic is simple. The code of DESTROY method of the Sentry package calls, in turn, the method delete of the $tree object.

Finally, there is no need to code your own Sentry class. Use Object::Destroyer, originally written by Adam Kennedy.


Thursday, June 21, 2007

Switching between HTTP and HTTPS


Following statements are there in my Apache2 virtual hosts section

Redirect /host/directory/folder/login.php https://servername/host/directory/folder/login.php
Redirect /host/directory/folder/register.php https://servername/host/directory/folder/register.php

How to return to http (not https) when the above 2 pages are not involved?


RewriteRule /.../login.php https://.../login.php [R]
RewriteRule /.../register.php https://.../register.php [R]

RewriteRule /.../login.php - [S=2]
RewriteRule /.../register.php - [S=1]
RewriteRule ^/(.*) http://servername/$1 [R]

In the HTTPS VH, if you get login.php or register.php you don't rewrite it (the "-"), then you skip the next 2 or 1 RewriteRules ( [S=2], [S=1]) - that is, you skip over the general purpose rewrite back to HTTP. So login.php or register.php get served from HTTPS and everything else goes back to HTTP.

Thursday, June 07, 2007

Perl Code Profiling - Apache::DProf

  1. In
       # The Apache::DProf requires this
    use Apache::Registry;

  2. In conf:
       PerlModule Apache::DProf

  3. Make sure the logs directory has write rights

  4. Restart Apache & do whatever you want in the browser page

  5. Stop Apache (only then the tmon.out will get complete output)

  6. Go to the directory where tmon is (logs/dprof//) and run dprofpp

Refer: Code Profiling Techniques

Monday, June 04, 2007

Apache and strace

To display a trace of system calls. Useful for debugging.

root@sri# apachectl stop (First stop Apache and then restart Apache with strace)
root@sri# strace -f -o trace.txt /etc/rc.d/init.d/httpd start

-f: Traces child processes as they are created by currently traced processes.

-o: Outputs to a text file