Monday, March 28, 2011

Mac: Cool Expose Shortcuts/Features in Snow Leopard

Cool Features of Expose in Mac OSX Snow Leopard
With all windows visible (press Expose key [F3] or swipe 4 fingers down on Mac Books).
  • press Command-1 to arrange the windows by name.
  • press Command-2 to arrange windows by application.
  • Press the Tab key to view all windows belonging to one application. Press Tab again to switch between applications while remaining in Expose. You can also click an icon in the dock.
  • Hover your mouse pointer over a window and press the spacebar to view a larger Quick Look version of that window.
  • if you mouse over a window in Expose view , that window will have a blue border. When it does, press the spacebar. That window will now grow to full size -- while still within the Expose view! Now, if you move your mouse over an other window that one will grow to full size while the previous one reverts.

Friday, March 25, 2011

PHP: exec command not working; sh: command not found

When using PHP exec command, if you find sh: Command not found , error in your web server logs, you have to export the full path of that command.

Assuming, that command in /opt/local/bin, change the command to
 $cmd ='export PATH=$PATH:/opt/local/bin; myCommand 2>&1';  
 echo exec($cmd,$out);  

To debug PHP exec command, Read this

For example:
For the PHP code:
 $cmd = "gmake";  
 echo exec($cmd,$out);  

There will be no output. In your web server error log, your will have :
 sh: gmake: command not found  
To fix this, we need to export the PATH of the gmake.

Go to your terminal, find where your command is located, In this example:
 $ which gmake  

So, modify you PHP code as following:
 $cmd ='export PATH=$PATH:/opt/local/bin; gmake 2>&1';  
 echo exec($cmd,$out) ;

This will output, on your web page
 gmake: *** No targets specified and no makefile found. Stop.  

PHP: exec command not working; debugging exec command

While using PHP exec command, if it is not working , Follow these to debug

1. Check your web server error_log.
Usually in MAC, for APACHE web server, it is located at /var/log/apache2/
1.1 Case1: the web server does not have permission to read/execute a command/file.
Solution to Case1: Simple, change file permissions.

1.2 Case2: The exec command will throw sh: Command Not found
Solution to Case2: Read this

2. Append 2>&1 to your command to get std errors as well. Read this for more info

Thursday, March 24, 2011

PHP: Today, Yesterday, Tomorrow dates

In PHP, we can generate Today, Yesterday, Tomorrow Dates the following way:
 $today = date('Y-m-d');  
 $tomorrow = date('Y-m-d', strtotime('tomorrow'));  
 $yesterday = date('Y-m-d', strtotime('yesterday'));  

Monday, March 21, 2011

MySQL: Make a copy of an existing table in MySQL

We can create a copy of an existing table using the following SQL statements.
 CREATE TABLE booger_copy LIKE testing.booger;  
 INSERT booger_copy SELECT * FROM testing.booger;  
If you want to copy only half of the existing table then, you can use LIMIT keyword in the select Query

Mac: Running 32-bit JVM on Mac OSX using eclipse

I had to use SMILE API on 64-bit Mac OSX machine.
SMILE API provides 32-bit version of their binaries.

I found a way to use 32-bit JVM in Mac OSX 64bit machines using Eclipse.
By default Mac OSX comes with both 32 bit and 64bit JVM installed.
Eclipse uses 64-bit JVM by default.

In order to use the 32-bit JVM, do the following in Eclipse
1. Right Click on your project, goto "Run As", Select "Run Configurations"
2. Select the Arguments tab,
3. Add “-d32″ in VM arguments field.

Saturday, March 19, 2011

Using Filezilla to login into Amazon EC2 instance and transfer files

We can login into Amazon EC2 instance using Filezilla FTP client for simple transfers of local files.
Following are the steps:

1. Download and install Filezilla client.
2. Goto Filezilla settings(Windows) or Filezlla preferences (MAC)
3. Click on SFTP, on right side, click on add key file.

4. Select your .pem file. It will prompt you to convert into PPK file.

5. Click ok to close the settings/preferences window.
6. Open site manager, create a new site as show in the image below.
Host: your AMI address
ServerType: SFTP
Logon Tpe: Normal
User: ec2-user
No password required ! Filezilla will read through the keys and find the right key for the user/server pair that you are connecting to.

Friday, March 18, 2011

Using cURLpp software

To use the curlpp, we need to first install.

Download the package at

The simplest way to compile this package is:

  1. `cd' to the directory containing the package's source code and type

  2. Type `make' to compile the package.

  3. Type `make install' to install, if error occurs do 'sudo make install'

  4. You can remove the program binaries and object files from the
     source code directory by typing `make clean'.

After installing, there are several examples at
cURLpp is a C++ wrapper for libcURL.
libcURL is described as:
a free and easy-to-use client-side URL transfer library, supporting FTPFTPSHTTPHTTPSGOPHERTELNETDICTFILE and LDAP. libcurl supports HTTPScertificates, HTTP POSTHTTP PUTFTP uploading, kerberos, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, http proxy tunneling and more!

PHP: exec command to get std errors

By appending 2>&1 at the end of the command will redirect errors from stderr to stdout.
If you run a simple command like cc at the command prompt, you would get the output as following
 $ cc  
 i686-apple-darwin10-gcc-4.2.1: no input files  
If u run the same command using PHP exec command
 $cmd = "cc";  
The output would be and empty array:
 Array ( )  
So, In order to get the error string as well, we need to append 2>&1
 $cmd = "cc 2>&1";  
The output will print:
 Array ( [0] => i686-apple-darwin10-gcc-4.2.1: no input files )  

Mac: location of Apache web server logs

The following location contains error_log for apache web server in Mac machines