Thursday, 27 December 2012

How to generate a Tag Cloud using PHP Script?

How to generate a Tag Cloud using PHP Script?

Using PHP Source code, we can generate tag cloud easily. You will find Tag Cloud in almost each and every website and blog. Most of the websites you browse are coded in PHP including facebook and tag cloud is very common in these websites. So, I will use PHP script to generate tag cloud here in this post.

PHP Tag Cloud Generator Script:

I have created a PHP function "getCloud" to generate tag cloud using PHP script. This function accepts array of tags, maximum and minimum size of the tags which will be the part of cloud.

function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 )
{
 $minimumCount = min($data);
 $maximumCount = max($data);
 $spread       = $maximumCount - $minimumCount;
 $cloudHTML    = '';
 $cloudTags    = array();
 $spread == 0 && $spread = 1;
 foreach( $data as $tag => $count )
 {
  $size = $minFontSize + ( $count - $minimumCount )
   * ( $maxFontSize - $minFontSize ) / $spread;
  $cloudTags[] = '<a style="font-size: ' . floor( $size ) . 'px'
  . '" class="tag_cloud" href="#" title="\'' . $tag  .
  '\' returned a count of ' . $count . '">'
  . htmlspecialchars( stripslashes( $tag ) ) . '</a>';
 }

 return join( "\n", $cloudTags ) . "\n";
}

/**************************
****   Sample usage    ***/

$arr = Array('Actionscript' => 35, 'Adobe' => 22, 'Array' => 44, 'Background' => 43,
 'Blur' => 18, 'Canvas' => 33, 'Class' => 15, 'Color Palette' => 11, 'Crop' => 42,
 'Delimiter' => 13, 'Depth' => 34, 'Design' => 8, 'Encode' => 12, 'Encryption' => 30,
 'Extract' => 28, 'Filters' => 42);

echo getCloud($arr, 12, 36);

Real IP Address Location Lookup and Trace using PHP Script

Real IP Address Location Lookup and Trace using PHP Script

Sometimes we have to lookup or trace IP Address and Location of a user for some purpose like for validation, security, spam prevention etc. Locating and Tracing Real IP Address of a user is very easy using PHP Script.

Server Variables in PHP to get Real IP Address of Client

Normally I have seen that $_SERVER['REMOTE_ADDR'] is used to find out the IP Address of the client. But this server variable does not work well if your client is connected to the Internet through Proxy Server. Proxies can be used to cache content, speeding up the request, to block offensive content, reformat pages for certain devices such as PDAs and cell phones or protect against computer viruses. All of these things can be done with providing any anonymity to the user. Anonymous proxies do get a lot of attention though and if a visitor to your site is using an anonymous proxy you won't be able to get their real ip address.

In that case $_SERVER['REMOTE_ADDR'] in PHP just returns the the IP address of the proxy server not of the client’s machine.

So there are other server variables available in PHP which will give you the real IP Address of the client even if your client is using the proxy server. You can use $_SERVER['HTTP_CLIENT_IP'] and $_SERVER['HTTP_X_FORWARDED_FOR'] server variables to get the real IP Address of the client.

Following is the function written in PHP which will fetch the real IP address of the user even if he is behind a proxy server.

function GetRealIPAddress()
{
 if (!empty($_SERVER['HTTP_CLIENT_IP']))
 {
  $ip=$_SERVER['HTTP_CLIENT_IP'];
 }
 elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
 //to check ip is pass from proxy
 {
  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
 }
 else
 {
  $ip=$_SERVER['REMOTE_ADDR'];
 }
 return $ip;
}

Explanation of above PHP code to get real IP Address of Client:

In the above PHP function to get real IP Address of client, first attempt is to get the direct IP address of client’s machine, if not available then try for forwarded for IP address using HTTP_X_FORWARDED_FOR. And if this is also not available, then finally get the IP address using REMOTE_ADDR.

You can make your above PHP function to get Real IP Address of Client more robust by referring the following PHP code:

function GetRealIPAddress()
{
    if (isset($_SERVER["HTTP_CLIENT_IP"]))
    {
        return $_SERVER["HTTP_CLIENT_IP"];
    }
    elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
    {
        return $_SERVER["HTTP_X_FORWARDED_FOR"];
    }
    elseif (isset($_SERVER["HTTP_X_FORWARDED"]))
    {
        return $_SERVER["HTTP_X_FORWARDED"];
    }
    elseif (isset($_SERVER["HTTP_FORWARDED_FOR"]))
    {
        return $_SERVER["HTTP_FORWARDED_FOR"];
    }
    elseif (isset($_SERVER["HTTP_FORWARDED"]))
    {
        return $_SERVER["HTTP_FORWARDED"];
    }
    else
    {
        return $_SERVER["REMOTE_ADDR"];
    }
}

Five ways to deal with a hypercritical boss

Five ways to deal with a hypercritical boss

You love your job , your colleagues are fun, and the pay’s nothing to crib about either. But perfect as that sounds, it comes with a major fly in the ointment: an overly-critical boss. He’s the one who always manages to find something negative about that project you slaved over, keeps hounding you with instructions and advice, and micromanages at every step. It can make work a pain, but not if you know how to handle it.

1. Take a good look at yourself

That’s the starting point when you have an overly critical boss. Look at it from a learning point of view. Examine your own performance. Try and gauge if there’s something lacking at your end and whether there is some justification to your boss’ criticism. Being receptive is a part of learning and growth.

2. Always address the issue

It never pays to suffer in silence. The issue needs to be worked out. Don’t be accusatory. Approach your boss politely, directly and diplomatically and try and find out why he is being so critical. In nine out of 10 cases, your boss will come around and give you feedback. If there is someone who doesn’t and has a personal problem with you, then maybe it’s time to move on.

3. Keep the communication going

Keep your boss in the loop about whatever project you may be working on with frequent updates. Get feedback and ask directly so you know what the boss wants.

4. Do not lose your composure

One of the best ways to deal with such bosses is to be patient and professional as far as possible. If the boss is being overly critical, do not let yourself cry or lose your temper. Listen to what your boss says, speak calmly in return, and try not to take any harsh words personally.

5. Maintain a good relationship

Doing this will hold you in good stead. It is very important to have a robust working relationship with your colleagues. They are more likely to be there for you if you are a team player and offer support in return. In fact, your ability to promote, communicate your value with colleagues and superiors is equally important.

Wednesday, 26 December 2012

21 Most Frequently Asked Basic Unix Interview Questions and Answers

21 Most Frequently Asked Basic Unix Interview Questions and Answers

Here is the list of most frequently asked basic unix interview questions and answers. There unix interview questions are very basic and based upon unix shell scripting and common unix commands which are frequently used by any unix user.

1. What is UNIX?

It is a portable operating system that is designed for both efficient multi-tasking and mult-user functions. Its portability allows it to run on different hardware platforms. It was written is C and lets user do processing and control under a shell.

2. What is Shell?

A shell acts as an interface between the user and the system. As a command interpreter, the shell takes commands and sets them up for execution.

3. What are the key features of the Korn Shell?

- history mechanism with built-in editor that simulates emacs or vi
- built-in integer arithmetic
- string manipulation capabilities
- command aliasing
- arrays
- job control

4. What are some common shells and what are their indicators?

sh – Bourne shell
csh – C SHell
bash – Bourne Again Shell
tcsh – enhanced C Shell
zsh – Z SHell
ksh – Korn SHell

5. What is shell scripting in UNIX?

Shell scripting is used to program command line of an operating system. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to program operating systems of windows, UNIX,  Apple etc. Also this script is used by companies to develop their own operating system with their own features.

6. What is a typical syntax being followed when issuing commands in shell?

Typical command syntax under the UNIX shell follows the format:
Command [-argument] [-argument] [--argument] [file]

7. What is command substitution?

Command substitution is one of the steps being performed every time commands are processed by the shell. Commands that are enclosed in backquotes are executed by the shell. This will then replace the standard output of the command and displayed on the command line.

8. What is a directory?

Every file is assigned to a directory. A directory is a specialized form of file that maintains a list of all files in it.

9. What is history command in UNIX?

We use history command along with grep command in unix to find any relevant command you have already executed.

10. How do you copy file from one host to other?

By using "scp" command. You can also use rsync command to answer this UNIX interview question or even sftp would be ok.

11. How do you find which process is taking how much CPU?

By using "top" command in UNIX.

12. How do you check how much space left in current drive?

By using "df" command in UNIX. For example "df -h ." will list how full your current drive is.

13. How do you know if a remote host is alive or not?

You can check these by using either ping or telnet command in UNIX.

14. How will you run a process in background? How will you bring that into foreground and how will you kill that process?

For running a process in background use "&" in command line. For bringing it back in foreground use command "fg jobid" and for getting job id you use command "jobs", for killing that process find PID and use kill -9 PID command.

15. How will you find which operating system your system is running on in UNIX?

By using command "uname -a" in UNIX

16. What is the command to list all the links from a directory?

You can answer command like: ls -lrt | grep "^l"

17. How will you create a read-only file in your home directory?

You need to create a file and change its parameter to read-only by using chmod command you can also change your umask to create read only file.
touch file
chmod 400 file

18. What is the difference between Swapping and Paging?

Swapping:Whole process is moved from the swap device to the main memory for execution. Process size must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more flexibly as compared to the paging systems.
Paging:Only the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory. It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.

19. What are filters?

The term Filter is often used to refer to any program that can take input from standard input, perform some operation on that input, and write the results to standard output. A Filter is also any program that can be used between two other programs in a pipeline.

20. Differentiate multiuser from multitask.

Multiuser means that more than one person can use the computer at the same time. Multitask means that even a single user can have the computer work on more than one task or program at the same time.

21. What is inode?

An inode is an entry created on a section of the disk set aside for a file system. The inode contains nearly all there is to know about a file, which includes the location on the disk where the file starts, the size of the file, when the file was last used, when the file was last changed, what the various read, write and execute permissions are, who owns the file, and other information

Advantages and Disadvantages of SaaS (Software as a Service) Business Model in Cloud Computing

Advantages and Disadvantages of SaaS (Software as a Service) Business Model in Cloud Computing

Defination of Software as a Service (SaaS)

Software as a Service (SaaS) is a type of Cloud Computing. SaaS is a software distribution model in which applications are hosted by a vendor or service provider and made available to customers over a network, typically the Internet. SaaS is also known as "on-demand software". In SaaS, software and associated data are centrally hosted on the cloud. SaaS is typically accessed by users using a thin client via a web browser.

Advantages of Software as a Service (SaaS)  

1. SaaS (Software as a Service) is Cheap

Software as a Service allows organizations to access business functionality at a cost typically less than paying for licensed applications since SaaS pricing is based on a monthly fee. Unlike traditional software which is conventionally sold as a perpetual license with an up-front cost (and an optional ongoing support fee), SaaS providers generally price applications using a subscription fee, most commonly a monthly fee or an annual fee.

2. Less Hardware Required with SaaS (Software as a Service)

Software is hosted remotely, so business organizations don't need to invest in additional hardware. To support scalability, the application is installed on multiple machines (called horizontal scaling).

3. Little Maintenance Required with SaaS (Software as a Service) 

Software as a Service removes the need for organizations to handle the installation, set-up and often daily upkeep and maintenance. Initial setup cost for SaaS is typically lower than the equivalent enterprise software. SaaS vendors typically price their applications based on some usage parameters, such as the number of users using the application. So SaaS provides easier administration. SaaS does automatic updates and patch management. No compatability issues will arise by using Saas as all users will have the same version of software. SaaS reduces IT support costs by outsourcing hardware and software maintenance and support to the SaaS provider.

Diadvantages of SaaS (Software as a Service) 

1. Security Issue: As data is stored on cloud, security becomes a major issue.

2. Latency Issue: Again as data is stored in cloud far away from end user, it may take more transactional time as compared to traditional approach. So, SaaS model is not suitable for applications that demand response times in the milliseconds.

3. Total Dependency on Internet: Relying on an Internet connection means that data is transferred to and from a SaaS firm at Internet speeds, rather than the potentially higher speeds of a firm’s internal network.

4. Switching between SaaS vendors is difficult: Switching SaaS vendors may involve the slow and difficult task of transferring very large data files over the Internet.
 
Applications of SaaS (Software as a Service)

SaaS has become a common delivery model for many business applications, including accounting, collaboration, customer relationship management (CRM), management information systems (MIS), enterprise resource planning (ERP), invoicing, human resource management (HRM), content management (CM) and service desk management.

Future of SaaS (Software as a Service)

SaaS is becoming an increasingly prevalent delivery model as underlying technologies that support Web services and service-oriented architecture (SOA) mature and new developmental approaches, such as AJAX, become popular. Meanwhile, broadband service has become increasingly available to support user access from more areas around the world.

How to love the job you hate?

How to love the job you hate?

We all are aware about the feeling of getting out of bed every Monday morning. We spend our highest-energy hours working, and families get what’s left. The problem of being stuck in a job you hate is that it makes your- self worth take a hit. Money is the not the only employee motivator and job satisfaction plays a very important role. The following tips can be used to make things better in a job that doesn’t rouse your interest.

1. Communicate: Let your boss know your achievements and problems. Don’t boast and don’t grumble. Define the problem at hand and offer ways to solve it.

2. Do Something for Yourself: Take on a project that’s dear to your heart or set aside time for what you do best.

3. Seek Feedback: Ask your boss and co-workers, “How am I doing?” Make it clear that you seek feedback to improve your performance and not because you crave praise.

4. Tackle Tough Assignments First: Get the difficult or unpleasant work out of the way first, because it doesn’t improve with time and will look truly hideous after lunch. This also allows you to finish the day with something you find challenging and enjoyable.

5. Have A Little Fun: Work isn’t play, but it doesn’t have to be mind-numbingly serious all the time. A few jokes will boost everyone’s morale.

6. Encourage Teamwork: Teamwork is a good way to increase productivity. Working in teams is a learned skill. If you don’t know the basics, learn them and share your insights with others.

7. Maintain your health: Pay attention to your physical and mental health. Stick to the basics: Eat right, exercise and get enough sleep. If you feel tired, your job performance will suffer.

8. Get a Life: People who have interests outside work make better employees. Take the time to do whatever you are passionate about. No one has ever said on his deathbed, “I wish I’d spent more time at the office.”

Professional Suicide: How people ruin their career?

Professional Suicide: How people ruin their career?

Professional suicide can be defined as a series of acts and actions of arrogance or any other activity that one regrets doing, which ruins the career of an individual. Even the most successful executives and leaders can suddenly “go off the track”and ruin their careers.

The following factors cause successful executives and professionals to fail:

1. Poor Interpersonal skills: Although technical competence may initially pay off, but as one moves up in an organization, interpersonal skills become more important. Having an arrogant style, being insensitive to those around you, or coming off cold and aloof can lead to being dejected by managers and supervisors.

2. Over-Controlling and Inability to Delegate: In today’s team-centered corporate world, it is important to be able to work successfully with others to get the job done. Managers who try to do it all by themselves, or who are unable to build a team, are likely to fail.

3. Big Mouth and non-performers: This breed of people talk a lot but their talks do not hold any substance. Through their words they can build beautiful castles and do the impossible but when it comes to execution or performance, they don’t even get any closer to their words. They find excuses for their non-performance.

4. Inability to Adapt: Change is the only constant thing in organizations. Employees who fail to adapt to changes become obsolete. This results in failing further on projects and producing inferior results.

5. Lack of commitment and accountability: These people are never willing to make any commitment. They prefer not to have deadlines for any targets and when asked to finalize a date, they make an excuse that their work is influenced by external factors.

6. Inability to think strategically: Quite often, we get bogged down in the day-to-day work and focus too much on short-term goals. However, career success requires constantly looking at the big picture, and thinking strategically about it. Strategic thinking helps in anticipating problems, recognizing new opportunities, and building a track record of accomplishments.