Thursday, July 24, 2008

PERL - How to use %INC & @INC on command line

perl -e 'use XML::Simple;use XML::Parser; foreach my $tuni (keys %INC){print $tuni . "\t" . $INC{$tuni} . "\n"}'

perl -e 'print "@INC\n"'

Multiple -e can be used, just like shell's sed program.

Wednesday, July 9, 2008

Unix - Large file aware utilities

A large file is a regular file whose size is greater than or
equal to 2 Gbyte ( 2**31 bytes). A small file is a regular
file whose size is less than 2 Gbyte.

Large file aware utilities
A utility is called large file aware if it can process large
files in the same manner as it does small files. A utility
that is large file aware is able to handle large files as
input and generate as output large files that are being pro-
cessed. The exception is where additional files are used as
system configuration files or support files that can augment
the processing.

For example, the file utility supports the
-m option for an alternative "magic" file and the -f option
for a support file that can contain a list of file names. It
is unspecified whether a utility that is large file aware
will accept configuration or support files that are large
files. If a large file aware utility does not accept confi-
guration or support files that are large files, it will
cause no data loss or corruption upon encountering such
files and will return an appropriate error.



The following /usr/bin utilities are large file aware:

adb awk bdiff cat chgrp
chmod chown cksum cmp compress
cp csh csplit cut dd
dircmp du egrep fgrep file
find ftp getconf grep gzip
head join jsh ksh ln
ls mdb mkdir mkfifo more
mv nawk page paste pathchck
pg rcp remsh rksh rm
rmdir rsh sed sh sort
split sum tail tar tee
test touch tr uncompress uudecode
uuencode wc zcat



The following /usr/xpg4/bin utilities are large file aware:

awk cp chgrp chown du
egrep fgrep file grep ln
ls more mv rm sed
sh sort tail tr


The following /usr/sbin utilities are large file aware:

install mkfile mknod mvdir swap

Wednesday, July 2, 2008

Knowledge about pixel, resolution and how to convert pixel into inches

Folks,
Recently I got to work with GD library using PHP 5.xx and was little confused about pixels, resolution and how to convert them into physical dimensional measurement units like centimeters or inches.

I think, lots of people are still very confused about it but still work as developers in GUI or web development.

Here is some information......

Say, there is an image of a flower 400x300 pixels. It means that height of this image is 400 pixel and width is 300 pixels. With it, there must be one more attribute of screen called 'resolution' (Remember, your color TV resolution).
Say that is 72 ppi (pixel per inch).

Simple mathematics: 72 ppi means
72 pixels in 1 inch
Therefore, 400 pixels in = 400/72 = 5.55 inches tall
Therefore, 300 pixels in = 300/72 = 4.16 inches wide

Hope it clears the cloud.

Tuesday, July 1, 2008

How to convert seconds into HH:MM:SS (24 hour format)

// $startstamp, $endstamp are both UNIX timestamp
// from Jan 1, 1970 mid night

function elapsed_time($startstamp, $endstamp)
{
$sec=$endstamp - $startstamp;

$hours = ($sec/3600);
list($hours, $x) = split('\.', $hours);
if ($hours < 10)
{
$hours = "0" . $hours;
}

$min = ($sec%3600);
$min = ($min/60);
list($min, $x) = split('\.', $min);
if ($min < 10)
{
$min = "0" . $min;
}

$sec = ($sec%60);
if ($sec < 10)
{
$sec = "0" . $sec;
}

return "$hours:$min:$sec";

}