Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Sep 142010
 

Calculate PHP script's execution time

Answer:

If you want to estimate the PHP script's execution time, you can try something like the following:

<?php

$time_start = microtime(true);

// some long running codes...

$time_end = microtime(true);

echo "Time (msec) passed: " , $time_end - $time_start;
Sep 132010
 

How to set the filetype in Vim

Answer:

When you created a new file by using the command vi, vim does not know the file type unless you save the file with a specific extension, e.g. test.c, or sometimes when the extension cannot be recognized by vim, you need to set the file type manually in command mode - pressing Esc + :

:set filetype=c

That is it.

Sep 122010
 

mount: unknown filesystem type 'nfs'

Answer:

If you attempt to mount a NFS share, using the mount command, e.g.

# sudo mount -t nfs 192.168.1.2:/data/share /mnt/share

And it gives:

mount: unknown filesystem type 'nfs'

You would need to install the nfs clients to solve it:

# sudo apt-get install nfs-common

Sep 112010
 

Multi-line strings in Bash

Answer:

Bash support multiple line string, e.g.

#!/bin/bash
sort  <<EOT
apple
orange
banna
EOT

When you execute the script,

# bash test.sh

It gives:

apple
banna
orange
Sep 102010
 

Generate new list using map in Perl

Answer:

The Perl's map function is superb cool for generating new list based on an existing list.

1. Generate new array based on an existing array

my @new = map {$_ * 2} (1, 2, 3);

# @new contains 2, 4, 6

2. Generate new hash based on an existing array

my %new = map {$_ => 1} (1,2,3);

# %new contains a hash...
#      {
#           '1' => 1,
#           '3' => 1,
#           '2' => 1
#       };