Sunday, December 15, 2013

How to enable your web application in your home laptop/pc to be assessible from public network?

To enable my web application that installed on my home laptop/pc to be accessible from public network, below are the steps of what I have gone through to get it working.

Assume that you have created an account at http://freedns.afraid.org/
- Create subdomains
- Install FreeDNS Update client at your laptop/pc

Assume that you are using SingTel service provider as what I am.
Note: SingTel is blocking port 80, your Apache Web Server should listening to other port, I configured my Apache Web Server to listen to port 81.

Assume that you have configured static IP address in your laptop/pc

Below are the steps to configure the port forwarding at your router
1.  Type in http://192.168.1.254 in your browser access the router configuration interface.
2. Click on "Security" -> "NAT and Port Forwarding"
3. Click on "Add a Port Forwarding Rule"
4. Edit the "Application" name
5. Edit the "Source Port" as 81, since port 80 is being blocked
6. "Destination IP" as the laptop/PC fixed IP address.
7. "Destination Port" as 81
8. Click on "Ok" button

Access from public network with your subdomain configured at FreeDNS, you should be able to access your web server.

Friday, December 13, 2013

How to import MySql dump with big blob field?

Error message "Error Code: 2006 - MySQL server has gone away" is prompted when trying to import MySql database dump consists of big blob field value into MySql database.

Below are the steps to resolve this issue
1. Edit max_allowed_packet parameter in my.ini
max_allowed_packet = 524288000
2. Restart MySql database server
Assume the parameters below represent 
Database user id, for example, 'root' : [DB_USER_LOGIN] 
Database dump file : [DB_DUMP_FILE] 
Database name : [DATABASE_NAME]

3. Connect to database
mysql -u[DB_USER_LOGIN]
4. Use the new database that created for importing
use [DATABASE_NAME]
5. Import the data from database dump into newly created database.
\. [DB_DUMP_FILE]

Saturday, November 30, 2013

How to configure db_link on Postgres database to pull data from other database?

I have 2 databases that running on the same database server, but, I have requirement to create a query to join data from the 2 databases. To achieve that, I have to configure db_link in my database server.

Assume the 2 databases are being named as dbA and dbB and the connection are from dbA
dbB User ID: [USER_ID]
dbB Password: [PASSWORD]


To enable db_link, run the command below to enable db_link function
psql -U postgres
postgres=# CREATE EXTENSION dblink
To list the installed extension, type in the command as described below
postgres=# \dx
Below are the sample command that to select data from dbB
SELECT events.* FROM dblink('dbname=dbB user=[USER_ID] password=[PASSWORD]','SELECT title FROM events') AS events(title character varying(255));


Friday, November 8, 2013

How to get your phing to print out timestamp within your timezone?

Try to get the phing scripts below to echo the right timestamp but always unable to do so. The printed timestamp always based on the UTC timestamp.

    <tstamp>
        <format pattern="%Y%m%d_%H%M%S" property="build.time">  
    </format></tstamp>

 <target name="tstamp"> 
  <tstamp>
  <echo>build time = ${build.time}</echo> 
 </tstamp></target>
Initially, I thought this was phing issue, put the locale attributes insides 'format pattern="%Y%m%d_%H%M%S" property="build.time" locale="Asia/Singapore"', but it doesn't solve the issue.
Spent quite a long time to find the root cause, finally, got the clue on what was happening.

Open the php.ini that your PHP is referring to, edit the locale as your current timezone. For other timezone, please refer to http://us1.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Singapore
Rerun your phing with the same piece of code. Voila! it just work like a charm!

Wednesday, November 6, 2013

How to resolve "Could not open configuration file /etc/httpd/conf/httpd.conf: Permission denied" when start httpd service on RHEL 6?

I encounter this when I transfer (scp) httpd.conf file from my local machine to my new RHEL 6 server. I overwrote the httpd.conf file at /etc/httpd/conf directory and restart httpd service through "service httpd restart". Error message  "Could not open configuration file /etc/httpd/conf/httpd.conf: Permission denied" is prompted.

Type in the command below,
ls -Z
Output as described below is displayed
-rw-rw-r--. user1     user1      unconfined_u:object_r:user_home_t:s0 httpd.conf
-rw-r--r--. root       root       system_u:object_r:httpd_config_t:s0 magic
Steps to resolve this

1. Run the command below to change "unconfined_u:object_r:user_home_t:s0" to "system_u:object_r:httpd_config_t:s0".
chcon system_u:object_r:httpd_config_t:s0 httpd.conf
Once restart httpd service, it should be able to restart the apache service now.

2. For the sake of change the ownership correctly, you can run command below to change the owner
chown root:root httpd.conf
chmod 644 httpd.conf



Sunday, October 27, 2013

not working in PHP 5.3.3

Redeploy my app on WAMP that aare running on PHP version 5.3.3, out of sudden, discover my old code that use is not working. All my pages suddenly display "?>" or ">" characters everywhere in my web page.

Search through the web and finally got the solution:-

Open php.ini, set "short_open_tag" to "On" value as described below

short_open_tag = On
Restart your webserver, everything will be working fine now.

Saturday, October 19, 2013

How to resolve "You don't have administrator rights! freeSSHd will close!" error message while launch freeSSHd?

Setup SSH server using freeSSHd 1.2.6 on my machine running on Window 7. Error message "You don't have administrator rights! freeSSHd will close!" keep prompting when the app is launched.


Below are the steps to resolve this issue
1. Download OllyDbg from http://ollydbg.de/. Launch the app


2. Open "FreeSSHDService.exe" as displayed in the screenshot below.
Note: The file located at the FreeSSHd installation folder


3. Press Ctrl+G and search for address "0041312A"



4. Right click on the selected "0041312A" address, select "Binary" -> "Edit" menu.


5. Change "HEX +00" field value from "74 49" to "90 90". Click on Ok button.


6. Right click on the modified address, select "Copy to executable" -> "Selection" menu.


7. A new exe will be generated. Right click on any boundaries of the window,select "Save File" menu.



8. Overwrite the existing "FreeSSHDService.exe", launch the app, you can find FreeSSHD icon in the system tray..


Tuesday, October 15, 2013

How to migrate MySql data files to other folder/drive?

Let's say you have installed an application that make used of the mysql database and you have completed the installation in a particular folder/drive. Now, you wish to migrate the data storing location to other folder/drive. In order to migrate MySql data files location, below are the details steps :-

Environment
OS: Window 7 Enterprise
MySQL: MySQL version 5.6.12

Assumption
MySQL home directory : [MYSQL_HOME]
MySQL new data files directory : [NEW_DATA_FOLDER]

1. Shutdown MySQL database
2. Copy the "data" folder that normally located at [MYSQL_HOME]\data to new data files directory, [MY_NEW_DATA], for example, "d:\data".
3. Open my.ini that located at [MYSQL_HOME]\my.ini
4. Edit the my.ini by changing the parameter as describe below:
datadir=[NEW_DATA_FOLDER]
5. Restart the MySql database server, that's it!

Thursday, October 3, 2013

How to send email through telnet command to SMTP server?

Assumption
SMTP Server : [SMTP_SERVER]
Client Machine Name : [CLIENT_MACHINE_NAME]
Email From: [EMAIL_FROM]
Email Recipient: [RCPT_TO]

Steps to use telnet command to send email through SMTP server

1. Type in telnet command as described below to connect to the SMTP server.
telnet [SMTP_SERVER] 25
2. Type in the command below to introduce yourself to the SMTP server. For example, "hello localhost"
helo [CLIENT_MACHINE_NAME]
3. Type in the command as described below to set the email address that used to send email.
MAIL FROM:[EMAIL_FROM]
4. Type in the command below to set the recipient gmail id
RCPT TO:[RCPT_TO]
5. Enter the command "DATA" to proceed with composing the email body.
DATA
6. Enter the email body and follow by '.' to trigger email sending
Hello Testing!
.

Tuesday, October 1, 2013

Issue encounter and simple note on PostgreSQL exploration

How to export and import sqldump file into PostgreSQL database?

Note: 2 format types of sqldump that PostgreSql can produce :-
- copy format
- sql format

In case to avoid problems that I encountered by using "copy" format, I advice to use "sql" format.

For my scenario, I use phpPgAdmin to export sqldump. Below are the steps to export sqldump from the source of the database server and import to the target of the database server:
1. Login through phpPgAdmin to access the source database server.
2. Tap on database name in the left menu
3. Tap on "Export" tab in the right hand screen
4. Select "Structure & Data" option with "SQL" format as displayed in the screen below


5. Click on "Export" button, sqldump file in sql extension will be downloaded.
6. Use pgAdminIII tool, create the database in your new target database server.
7. Open the query editor, open the sqldump script and execute the script.
8. Tables structure will be created and all the data will be imported to the target database server.

How to export database schema with command line?

Assume the parameters below represent
Database User ID: [USER_ID]
Database Name: [DATABASE_NAME]
SQL output file: [SQL_FILE]
pg_dump --schema-only -U [USER_ID] [DATABASE_NAME] > [SQL_FILE]
Note: Applicable on Linux

How to export database dump and import into newly created database?

Assume the parameters below represent
Database user id, for example, 'postgres' : [DB_USER_LOGIN]
Database name, for example, 'mydatabase' : [DATABASE_NAME]
Database dump file, for example, 'dump.sql' : [DATABASE_DUMP_FILE]

1. Export database dump from source database using the command as described below (Without copy owner and privileges)
pg_dump --no-owner --no-privileges -U [DB_USER_LOGIN] [DATABASE_NAME] > [DATABASE_DUMP_FILE]
2. Create [DATABASE_NAME] database in your POSTGRES database server

3. Import database dump to the target database using the command as described below
psql -U [DB_USER_LOGIN] [DATABASE_NAME] < [DATABASE_DUMP_FILE]
How to create users and new PostgreSQL database through command line?

Assume the parameters below represent
New user id, for example, 'george' : [NEW_DB_USER_LOGIN]
New user password, for example, '12345678' : [NEW_DB_USER_PASSWORD]
New Database name, for example, 'mydatabase' : [NEW_DATABASE_NAME]

1. In the Linux terminal, type in the command below to add new user
adduser [NEW_DB_USER_LOGIN]
Note: If command not found error message is prompted when 'adduser' is used, type in '/usr/sbin/adduser' to create user.

 2. Use the command below to reset the new user's password
passwd [NEW_DB_USER_LOGIN]
3. Create a new database based on the database template1
psql -d template1 -U postgres
4. Create new user
template1=#CREATE USER [NEW_DB_USER_LOGIN] WITH PASSWORD '[NEW_DB_USER_PASSWORD]';
5. Create new database
template1=#CREATE DATABASE [NEW_DATABASE_NAME];
6. Grant new user access right to the new database
template1=#GRANT ALL PRIVILEGES ON DATABASE [NEW_DATABASE_NAME] to [NEW_DB_USER_LOGIN];
7. Type in '\q' to quit the template1.

How to get your PHPMailer sample code to work properly with your SMTP Server?

Download PHPMailer recently to test on email sending through SMTP server, out of no luck, it just can't send email through the SMTP server  (Microsoft ESMTP MAIL Service, Version: 5.0.2195.738).

Assume the parameters below represent

SMTP Server: [SMTP_SERVER]
Client Server Name: [CLIENT_SERVER_NAME]

Configure all the necessary parameter in SMTP.php class provided by PHPMailer in examples folder, out of no luck, it just can't send email. Turn on the SMTP debug parameters in SMTP.php

// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug  = 2;
The debug messages are displayed as described below:
SMTP -> FROM SERVER:220 [SMTP_SERVER] Microsoft ESMTP MAIL Service, Version: 5.0.2195.7381 ready at Mon, 23 Sep 2013 14:38:12 +0800 
CLIENT -> SMTP: EHLO [[CLIENT_SERVER_NAME]]
SMTP -> FROM SERVER: 501 5.5.4 Invalid Address
SMTP -> ERROR: EHLO not accepted from server: 501 5.5.4 Invalid Address
CLIENT -> SMTP: HELO [[CLIENT_SERVER_NAME]]
SMTP -> FROM SERVER: 501 5.5.4 Invalid Address
SMTP -> ERROR: HELO not accepted from server: 501 5.5.4 Invalid Address
CLIENT -> SMTP: AUTH LOGIN
SMTP -> ERROR: AUTH not accepted from server: 503 5.5.2 Send hello first
CLIENT -> SMTP: quit
SMTP -> FROM SERVER:221 2.0.0 [SMTP_SERVER] Service closing transmission channel
SMTP Connect() failed.
Mailer Error: SMTP Connect() failed.
Refer to the debug messages, message "Invalid Address" is keep prompting.

Troubleshoot the debug message and discovered that special character '[' and ']' is appended to the [SMTP_SERVER_NAME] value.

Comment out 5 lines of source code at line 720  in "class.smtp.php" as described below and replace with a new 5 lines of source code as described below that removed '[' and ']' characters:
    //if(!$this->SendHello('EHLO', "[" . $host . "]")) {
    //  if(!$this->SendHello('HELO', "[" . $host . "]")) {
    //    return false;
    //  }
    //}
 
    if(!$this->SendHello('EHLO', $host)) {
      if(!$this->SendHello('HELO',$host)) {
        return false;
      }
    }
Try to resend email, it just work like a charm!

Thursday, September 12, 2013

How to configure PHPUnit and Aptana Studio 3?

Try to get PHPUnit integrated with Aptana Studio 3 for my unit testing, discover that it is not straight forward. Aptana Studio 3 is not ready for that kind of tight integration. I have to make use of "External Tools" on Aptana Studio to launch PHPUnit through DOS command.

Assumption
- PEAR has been installed
- Running on Window 7
- Download PHPUnit 3.7.25 from https://github.com/sebastianbergmann/phpunit/ ("phpunit.phar" will be downloaded)
- Follow the Zend 2 sample tutorial to prepare the unit testing script http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html

Steps to configure

1. Install phpunit on your machine by running the command as described below in "Command Prompt" window with phpunit.phar in the same directory.
  
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
2. Once phpunit has been installed, phpunit.bat file will be created in [PEAR_INSTALL_PATH]. Launch the "Command Prompt" window and type in the command as described below to check the version of PHPUnit.
phpunit --version
PHPUnit 3.7.25 by Sebastian Bergmann.
Note: "phpunit" command is working provided you right click "Command Prompt" icon and select "Run as administrator" to launch the "Command Prompt" window.

3. In Aptana Studio 3.0, "External Tools" menu will not be available in the "Run" menu. Steps as described below are required to turn on the "External Tools" option.
- Right click the "Web Perspective" and select "Customize" menu, "Customize Perspective" screen will be displayed.


- Select "Command Groups Availability" tab and check the "External Tools" check box as shown in the screenshots below.

- Click on "Ok" button to dismiss the "Customize Perspective" screen. Click on "Run" menu, "External Tools" will be displayed.

4. Select "Run" ->  "External Tools" -> "External Tools Configuration", the configuration screen will be displayed.


5. Fill in the details as described below
Name: PHPUnit

Location: [PEAR_INSTALL_PATH]\phpunit.bat
Note: Normally phpunit.bat is located at the PEAR installation path if PEAR is used to install PHPUnit.

Working Directory: ${project_loc}/module/Application/test
Note: Based on the tutorial provided by Zend2, http://framework.zend.com/manual/2.0/en/user-guide/unit-testing.html, this should be the folder that consists of "phpunit.xml.dist" file.

6. Select unit testing class, for example, "IndexControllerText.php", click on "Run" -> "External Tools" -> "PHPUnit", the unit testing script will be executed and test result will be output to "Console" screen.

Friday, September 6, 2013

Issue encounter and simple note on Mantis exploration

System Environment
Mantis Version: 1.2.15
WAMP version 2.4

How to configure email notification on Mantis using Gmail SMTP Server?

Note: Assume Gmail account has been created

Steps to resolve
1. Open config_defaults_inc.php, edit the parameters as described below:
/**
  * Allow email notification.
  * Set to ON to enable email notifications, OFF to disable them. Note that
  * disabling email notifications has no effect on emails generated as part
  * of the user signup process. When set to OFF, the password reset feature
  * is disabled. Additionally, notifications of administrators updating
  * accounts are not sent to users.
  * @global int $g_enable_email_notification
*/
$g_enable_email_notification = ON;

/**
  * select the method to mail by:
  * PHPMAILER_METHOD_MAIL - mail()
  * PHPMAILER_METHOD_SENDMAIL - sendmail
  * PHPMAILER_METHOD_SMTP - SMTP
  * @global int $g_phpMailer_method
*/
$g_phpMailer_method = PHPMAILER_METHOD_SMTP;

/**
  * This option allows you to use a remote SMTP host.  Must use the phpMailer script
  * One or more hosts, separated by a semicolon, can be listed.
  * You can also specify a different port for each host by using this
  * format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com").
  * Hosts will be tried in order.
  * @global string $g_smtp_host
*/
$g_smtp_host = 'smtp.gmail.com';

/**
  * These options allow you to use SMTP Authentication when you use a remote
  * SMTP host with phpMailer.  If smtp_username is not '' then the username
  * and password will be used when logging in to the SMTP server.
  * @global string $g_smtp_username
*/
$g_smtp_username = '[GMAIL_ACCT_ID]';

/**
  * SMTP Server Authentication password
  * @global string $g_smtp_password
*/
$g_smtp_password = '[GMAIL_ACCT_PASSWD]';

/**
  * This control the connection mode to SMTP server. Can be 'ssl' or 'tls'
  * @global string $g_smtp_connection_mode
*/
$g_smtp_connection_mode = 'ssl';

/**
  * The smtp port to use.  The typical SMTP ports are 25 and 587.  The port to use
  * will depend on the SMTP server configuration and hence others may be used.
  * @global int $g_smtp_port
*/
$g_smtp_port = 465;

How to send email using simple SMTP command through Gmail SMTP Server?

Note: 
- Assume Perl is installed on your machine to encode both user id and password in base64.
- Assume OpenSSL is available on your machine

Steps to resolve

1. Using openssl to direct connect to the Gmail SMTP server, a SSL handshaking will be executed.
openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof

2. Type in the command below to introduce yourself to the mail server.
ehlo [MY_DOMAIN] //Note: ehlo localhost

3. Before hand, please use Perl on another command prompt to encode both your [GMAIL_USER_ID] and [GMAIL_USER_PASSWORD] into base64. Below are the command helping you to generate encoded user id and password for authentication purpose.
perl -MMIME::Base64 -e "print encode_base64(qq(\000[GMAIL_USER_ID]\@gmail.com\000[GMAIL_USER_PASSWORD]))"
Once the command has been executed, you will get an encoded output, let's assume it as [BASE64_USERID_PASSWORD]

4. Back to your SMTP command prompt, type in the command as shown below to pass the authentication
AUTH PLAIN [BASE64_USERID_PASSWORD]
Response "2.7.0 Accepted" will be prompted

5. Type in the command below to set the sender gmail id
MAIL FROM: <[SENDER_GMAIL_ID]@gmail.com>

6. Type in the command below to set the recipient gmail id
RCPT TO: <[RECIPIENT_GMAIL_ID]@gmail.com>

7. Enter the command "DATA" to proceed with composing the email subject and body.
DATA

8. Enter the email body and subject based on the description and shown below
Subject: Hello Testing

Hello Testing!
.
Note: The '.' is represented the email composing has been completed and trigger sent command

How to resolve Mantis email problem when WAMP 2.4 is used?

Configure email notification on Mantis that run on WAMP 2.4 through Gmail SMTP server, always unable to send email. Have a further investigation, discovered that I need to turn on php_openssl in my WAMP PHP extensions. When turn on the php_openssl extension, encounter the error as shown in the log file.
[Mon Sep 09 14:57:33.670249 2013] [mpm_winnt:notice] [pid 1544:tid 352] AH00418: Parent: Created child process 2280
[Mon Sep 09 14:57:34.174249 2013] [ssl:warn] [pid 2280:tid 244] AH01882: Init: this version of mod_ssl was compiled against a newer library (OpenSSL 1.0.1e 11 Feb 2013, version currently loaded is OpenSSL 1.0.1d 5 Feb 2013) - may result in undefined or erroneous behavior
[Mon Sep 09 14:57:34.909049 2013] [ssl:warn] [pid 2280:tid 244] AH01882: Init: this version of mod_ssl was compiled against a newer library (OpenSSL 1.0.1e 11 Feb 2013, version currently loaded is OpenSSL 1.0.1d 5 Feb 2013) - may result in undefined or erroneous behavior
[Mon Sep 09 14:57:35.824849 2013] [ssl:warn] [pid 2280:tid 244] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
From the error log, seems like OpenSSL version is not correct and I found out the hyperlink as described below to explain steps to upgrade the OpenSSL version.

http://stackoverflow.com/questions/17354788/enabling-openssl-in-wamp

Once the OpenSSL version is upgraded to version OpenSSL 1.0.1e, I am able to turn on php_openssl in my WAMP PHP extensions and finally email notification is working in my Mantis installation.

How to turn on LDAP authentication on Mantis?

To turn on the LDAP authentication on Mantis that normally required by corporate users, below are some tips on how to achieve it.

Steps to resolve

1. Open config_defaults_inc.php, edit the parameters as described below:
/**
* login method
* MD5, LDAP, BASIC_AUTH or HTTP_AUTH.
* Note: you may not be able to easily switch encryption methods, so this
* should be carefully chosen at install time. However, MantisBT will attempt
* to "fall back" to older methods if possible.
* @global int $g_login_method
*/
$g_login_method = LDAP;

//Examples, ldap://ldap.example.com:389
$g_ldap_server = 'ldap://[LDAP_SERVER]:389';


//Examples, dc=employee,dc=it,dc=departmentname,dc=companyname
//Note: Please use the most exact DN instead of global DN. Otherwise,
//Mantis will keep throwing empty response and the application will always 
//show empty page
$g_ldap_root_dn = '[LDAP_DN_PARAMETER]';

//Use sAMAccountName for Active Directory
$g_ldap_uid_field = 'sAMAccountName';

/**
* The distinguished of the user account to use for binding to the LDAP server.
* For example, 'CN=ldap,OU=Administrators,DC=example,DC=com'.
*
* @global string $g_ldap_bind_dn
*/
$g_ldap_bind_dn = '[DOMAIN_NAME]\[USERNAME]';

/**
* The password for the service account to be used for connecting to the LDAP server.
*
* @global string $g_ldap_bind_passwd
*/
$g_ldap_bind_passwd = '[PASSWORD]';

/**
* Should we send to the LDAP email address or what MySql tells us
* @global int $g_use_ldap_email
*/
$g_use_ldap_email = ON;

/**
* The LDAP Protocol Version, if 0, then the protocol version is not set.  For Active Directory use version 3.
*
* @global int $g_ldap_protocol_version
*/
$g_ldap_protocol_version = 3;

How to turn on debug message in Mantis for LDAP troubleshooting?

To turn on the debug message for LDAP troubleshooting, below are the steps and configuration that are required

Steps to resolve
1. Open php.ini which is located at "[WAMP_INSTALL_PATH]\bin\apache\Apache2.4.4\bin".
2. Uncomment 'error_log = "[WAMP_INSTALL_PATH]/logs/php_error.log"'
3. Open config_defaults_inc.php in Mantis, change the value of g_log_level to LOG_LDAP
$g_log_level = LOG_LDAP;
Restart your WAMP server, LDAP log will be available at [WAMP_INSTALL_PATH]\logs\php_error.log.

How to reset your mysql user account password through command line?

Open your mysql browser, type in the command as displayed below

UPDATE mysql.user SET Password=PASSWORD('[MyNewPass]') WHERE User='root';
FLUSH PRIVILEGES;
Relogin again.

Wednesday, September 4, 2013

How to use cocospods in managing library dependencies in your iOS project?

In the process of exploring MMDrawerController library, discover cocoapods that are quite useful in managing library dependencies in my iOS project.

In general, CocoaPods is equivalent to MAVEN in J2EE project. Lets walk through all the necessary steps to get the concept on how it works.

Assumption
- Ruby MRI 2.0.0 or 1.8.7 (ships with Mac OS X)

Install CocoaPods
- Open Mac terminal
- Enter "sudo gem install cocoapods" and enter administrator password
- Type in command "pod setup" to install CocoaPods.
- Navigate to the project folder, enter "touch Podfile" command to create Podfile
- Enter command "open -e Podfile" to launch the text editor
- Edit the Podfile file with the configuration as shown below
platform :ios, '5.0' 
pod 'MMDrawerController', '~> 0.4.0'
- Navigate to the project folder that you wish to import the library through cocoa pods.
- Enter "pod install", MMDrawerController will be imported, a project file with ".xcworkspace" extension will be created.
- Open project file with the extension ".xcworkspace", a "Pods" project will be included. All the imported library will be included in the "Pods" project.

Tuesday, September 3, 2013

How to integrate VisualSVN, TortoiseSVN and Aptana to create a PHP development environment?

In setting up my PHP development environment, I have made use of the software listed below :-  
- Aptana Studio 3 (IDE)
- VisualSVN Server Manager version 2.6.4 (Source control application)
- TortoiseSVN 1.8.1 (SVN client)

Note: Assume both Aptana and VisualSVN, TortoiseSVN have been installed on the same or different machine.

Below are the details to get the environment up:-
1. Open VisualSVN Server Manager, right click "Repositories" and select "Create New Repository..." menu.


2. Enter "Repository Name", for example "efront", click on "Next" button.
3. Select "Single-project repository (with the top-level 'trunk', branches' and 'tags' folders)" radio button, click on "Next" button.
4. Select "All Subversion users have Read/Write access" radio button, click on "Create" button.
5. "Repository Name" and "Repository URL" will be displayed, click on "Finish" button.

Note: SVN administrator will be responsible to create the repository for the team lead/developer. [REPOSITORY_URL] will be provided by administrator to team leader/developer.

6. Assume you are team leader/developer now, you have a new project, you are going to check in your source code into the new repository. Create a new folder and check out the source code using the repository url ([REPOSITORY_URL]\trunk) using TortoiseSVN client.

7. Copy the source code into the checkout folder, right click on the "efront" folder, select TortoiseSVN -> Add. Click on "Ok" button.

8. Right click on the "efront" folder, select "SVN Commit" menu, a dialogue box will be popup. Enter some comment and click on "Ok" button. The source code will be committed to the SVN server.

Note: Team leader will provide the [REPOSITORY_URL]  to developer. Developer will launch Aptana Studio to check out the source code. Assume developer account creation has been completed by SVN administrator.

9. Developer launch Aptana Studio, click on File -> Import to import project from SVN.


10. Enter the repository url and authentication details. Click "Next" button.

Note: If you wish to checkout those source code in trunk for development, please enter URL as "[REPOSITORY_URL]\[PROJECT_NAME]\trunk". When the message "Do you wish to normalize URL by cutting its last segment off?" just select "No" because you are intended to checkout source code from trunk folder.


11. In "Select Resource" screen, just click "Finish" button.
12. In "Check Out As" screen, click on "Finish" button.
13. In "Select a wizard" screen, select "PHP Project" and click on "Next" button.
14. In "New PHP Project" screen, enter your "Project name" and the location of the source code. Click on "Finish" button.

Up till now, developer should be able to get their environment up in Aptana Studio for development.

15. When source code committing is required, right click on the "Project name" in Aptana Studio and select "Team" menu. All the SVN features will be displayed.


Why "Syntax error" message is prompted on Aptana Studio 3.0 when "trait" is using on the php class?

Discover that Aptana Studio 3.0 don't support new syntax from PHP version 5.4, it supports only up to  PHP version 5.3. This is really inconvenient to see a red "X" mark or "Syntax error" messages that appear everywhere in all the classes in my project. I just turn off the PHP Project Natures from the project to clean up those unnecessarily errors prompt.

Steps to turn off PHP as the "Project Natures"
1. Right click project name, select "Properties" menu
2. Select "Project Natures" and unckeck "PHP" checkbox, click on "Ok" button.
3. Close on reopen project dialogue box will be prompted, just follow the instruction.
4. Select "Project" -> "Clean..." menu to refresh the project, all the red "X" marks and "Syntax error" messages will be cleared.

Just a workaround for me who easily getting confused by the error prompt in the IDE. Still waiting for Aptana to support PHP version 5.4.

Thursday, August 29, 2013

Issue encounter and simple note on CakePHP 2.3.9 & WAMP 2.4 exploration

How to disable debug mode on cakephp? (Please refer to the selected red rectangle)



Steps to resolve
1. Open core.php located at "[WAMP_INSTALL_PATH]\app\config".
2. Edit debug value to "0" and deploy to the server
<?php
    Configure::write('debug', 0);
?>
3. Deploy to the server, the debug mode will be disabled.

How to resolve "Forbidden You don't have permission to access / on this server." error message when access the new installed WAMP server version 2.4?

Description
Install a new WAMP server and when access the web server using the assigned IP address through browser, "Forbidden You don't have permission to access / on this server." error message is displayed.

When using localhost/127.0.0.1 in the local machine to access the WAMP server, the default WAMP page is displayed.

Steps to resolve
1. Edit https.conf which located at "[WAMP_INSTALL_PATH]\bin\apache\Apache2.4.4\conf", edit the configuration as shown below
<Directory "[WAMP_INSTALL_PATH]/www">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order Deny,Allow
    Allow from all
</Directory>

2. Make sure port 80 in Window 2008 firewall  is opened.
- Launch "Windows Firewall with Advanced Security" screen
- Right click "Inbound Rules" and select "New Rule..." menu
- Select "Port - Rule that controls connections for a TCP or UDP port", click "Next" button
- Select "TCP" type and enter "80" for "Specific local ports", click "Next" button
- Select "Allow the connection" and click"Next" button
- Check "Domain", "Private" and "Public" checkbox and click on "Next" button
- Enter "Name" and "Description" value and click on "Finish" button.

3. Restart WAMP server, WAMP index page will be displayed.

How to redirect all the visitor's request to a particular subdirectory?

Description
When came to a requirement to redirect all visitor request to a particular subdirectory, for example /myapp/ in your PHP web application, normally I will use Apache rewrite feature to redirect all the request.

Steps to resolve
1. Edit httpd.conf and uncomment "LoadModule rewrite_module modules/mod_rewrite.so"
2. I have enable the virtual host configuration, add in the rewrite engine as described below

<VirtualHost *:80>
 ServerName [SERVER_NAME]
 DocumentRoot "C:/wamp/www"
        ErrorLog "c:/wamp/logs/apache_error.log"
        CustomLog "c:/wamp/logs/access.log" common
 RewriteEngine on
 RewriteRule ^/$ /[MY_APP_DEFAULT_FOLDER]/ [R]
</VirtualHost>
3. Rewrite your Apache web server.

Monday, August 26, 2013

How to get your first Zend framework work on WAMP?

This is not a new thing and you can find this anywhere, I just note it down for my personal reference just in case I'm too old to remember all this.

OS: Window 7 Enterprise
WAMP version 2.4

1. Download Zend project skeleton from https://github.com/zendframework/ZendSkeletonApplication

2. Unzip the Zend framework and rename it as "ZendProject".

3. Open DOS prompt and change to the "ZendProject folder"

4. Type in the command as shown below to download Zend framework
php composer.phar self-update

5. Type in the command as shown below to install Zend framework.
php composer.phar install
During executing this command line, you might encounter the error as shown below.
You must enable the openssl extension to download files via https
To resolve this error, please enable openssl at WAMP server. Open php.ini located at [WAMP_HOME_FOLDER]\bin\php\php5.4.12 uncomment extension=php_openssl.dll

6. Once the installation has been completed, the output as described below will be displayed
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing zendframework/zendframework (2.2.3)
    Downloading: 100%

zendframework/zendframework suggests installing ext-intl (ext/intl for i18n feat
ures (included in default builds of PHP))
zendframework/zendframework suggests installing doctrine/annotations (Doctrine A
nnotations >=1.0 for annotation features)
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback r
andom byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavail
able)
zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyMan
ager to handle lazy initialization of services)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf f
or creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recapt
cha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\
Form)
Writing lock file
Generating autoload files

7. In WAMP server, I enabled vhost file by uncomment "Include conf/extra/httpd-vhosts.conf" in [WAMP_HOME_FOLDER]\bin\apache\Apache2.4.4\conf folder.

8. Add the configuration as displayed below in httpd-vhosts.conf file located at [WAMP_HOME_FOLDER]\bin\apache\Apache2.4.4\conf\extra folder.
<VirtualHost *:80>
    ServerName zend2
    DocumentRoot D:/work/research/Zend/ZendProject/public
    SetEnv APPLICATION_ENV "development"
    <Directory D:/work/research/Zend/ZendProject/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

9. Edit "hosts" file located at C:\Windows\System32\drivers\etc folder.
127.0.0.1       zend2 localhost

10. Open the browser, type in URL "http://zend2/", the Zend2 framework page as displayed below will be displayed

Sunday, August 11, 2013

Issue encounter and simple note on Google AppEngine exploration

Issue 1

During the deployment of the sample app "Guestbook" to AppEngine through Eclipse, error message "Unable to update app: Cannot get the System Java Compiler. Please use a JDK, not a JRE." is prompted. Please refer to the screenshot as shown below:


Steps to resolve
1. Open the eclipse.ini, normally located at "ECLIPSE home path".
2. Add configuration as shown below in the first line of eclipse.ini.
-vm
[JAVA_HOME_PATH]/bin/javaw.exe
3. Restart Eclipse and redeploy the app to AppEngine, you will be able to get this through.

Issue 2

Try to use Jersey (version 1.7) to create JAX-RS service on Google App Engine, please refer to http://tugdualgrall.blogspot.sg/2010/02/create-and-deploy-jax-rs-rest-service.html.
Encounter the error in AppEngine log as described below when use browser to call the service.

Uncaught exception from servlet
java.lang.IncompatibleClassChangeError: Implementing class
 at com.google.appengine.runtime.Request.process-638cb79974cf6c0a(Request.java)
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
 at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:359)
 at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
 at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
 at com.sun.jersey.api.core.PackagesResourceConfig.(PackagesResourceConfig.java:78)
 at com.sun.jersey.api.core.PackagesResourceConfig.(PackagesResourceConfig.java:89)
 at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
 at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
 at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
 at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
 at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
 at javax.servlet.GenericServlet.init(GenericServlet.java:212)
 at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
 at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
 at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
 at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
 at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
 at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
 at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
 at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:435)
 at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:442)
 at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
 at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
 at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
 at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:439)
 at java.lang.Thread.run(Thread.java:722)

Steps to resolve
1. Right click project in Eclipse and select "Properties".
2. Change "Datanuclues JDO/JPA version to "v1". Please refer to screenshot as described below.


3. Redeploy the app to AppEngine. You should be able to call the service.

Reason: The used of asm-4.0.jar by AppEngine crash with the Jersey 1.7.

Friday, August 9, 2013

How to get your first CakePHP tutorial work on WAMP?

In getting first CakePHP example works on WAMP, steps below illustrated how I get through.

1. Download CakePHP framework from GitHub: https://github.com/cakephp/cakephp/tags
2. Unzip CakePHP source code and place it in
"[WAMP_INSTALL_PATH]\wamp\www\cakephp" directory.
3. Create Post.php in "/app/Model" directory.
<?php
    class Post extends AppModel {
  
    }
?>
4. Create PostsController.php in "/app/Controller" directory.
<?php
class PostsController extends AppController {
    public $helpers = array('Html', 'Form');
 
  public function index() {
        $this->set('posts', $this->Post->find('all'));
    }
}
?>
5. Create index.ctp in "/app/View" directory.
<h1>Blog posts</h1>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Created</th>
    </tr>

    <!-- Here is where we loop through our $posts array, printing out post info -->

    <?php foreach ($posts as $post): ?>
    <tr>
        <td><?php echo $post['Post']['id']; ?></td>
        <td>
            <?php echo $this->Html->link($post['Post']['title'],
array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
        </td>
        <td><?php echo $post['Post']['created']; ?></td>
    </tr>
    <?php endforeach; ?>
    <?php unset($post); ?>
</table>

Note: To get this example to work on WAMP, uncomment "LoadModule rewrite_module modules/mod_rewrite.so" in httpd.conf file. Restart Apache Web Server.

6. Type in "http://localhost/cakephp/posts/index" in your browser to access this example.

Once able to get the first example to work, please follow with the example provided in CakePHP website to continue with the further exploration.

Saturday, August 3, 2013

Issue encounter and simple note on Android Studio exploration

Issue 1

Change the IDE for my current project that used to develop on "Eclipse" to "Android Studio", encounter the error and issue as described below

1. Prompted the error message "unmappable character for encoding UTF-8" when build my current project on Android Studio.

- Click on "File" -> "Setting"
- Select File Encodings in the left menu
- Change IDE Encoding from "UTF-8" to "ISO-88590-1"

Rebuild the project.


Tuesday, April 2, 2013

How to resolve Eclipse long loading time?

Recently, I discover my Eclipse take a long time to launch its workspace. It is frustrating especially if you are rushing an urgent project.

Basically I take 2 steps to resolve this

Step 1
1. Go to \.metadata\.history, remove all the subfolders inside .history folder.

Step 2 - Once after the Eclipse is launched
1. Select Window -> Preferences
2. Select General -> Workspace -> Local History
3. Change Days to keep files to "1"
4. Click "Apply" follow by "Ok" button
4. Restart your Eclipse, this time the loading time should be much faster.

Sunday, March 31, 2013

How to enable MAT (Eclipse Memory Analyzer) in your Eclipse?

When talk about out of memory crashing issue in my Java app, I really felt helpless in finding the root cause. Even though MAT can be an alternative in helping me getting closer to the issue, but in the end of the day, all still depending on the code review and the best practice during the development.

Below are steps to setup the MAT.

1. To install MAT, open Eclipse, click on Help -> Install New Software ->
2. Enter "Add" button and enter "Name" and "Location" into the dialog box
Name: MAT
Location: http://download.eclipse.org/mat/1.2/update-site/
3. Check the "Memory Analyzer for Eclipse IDE" and "Standalone Memory Analyzer" and click on "Next" button. Follow the step as shown in the wizard, the MAT will be installed into the Eclipse once the Eclipse is restarted.


4. To allow the application to generate hprof file, right click on the project, Run As -> Run Configurations, select "Arguments" tab and enter "-XX:+HeapDumpOnOutOfMemoryError" into "VM arguments" text box.

5. When the Java/Android app crashes, hrof will be generated.

6. Double click on the hprof file, MAT will be launched and select "Leak Suspect Report" option and click on "Finish" button.

7. Leaks Suspect report will be generated.

If you encounter "Parsing heap dump" while opening the hprof file, open the eclipse.ini file which is located at Eclipse home folder. Increase the -Xms and -Xmx size (until the message disappear), refer to the highlighted paragraph as shown below:-


-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120522-1813
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
1024m
--launcher.defaultAction
openFile
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
1024M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-Xms8192m
-Xmx10240m


To produce Android hprof file for MAT analysis, launch the DDMS, select device follow by running application. Click on dump HPROF file, the MAT analyzer will be launched.





Sunday, March 17, 2013

How to use Android fragment (1)?

To cut short and make this tutorial simple and practical, I have made use of the component from https://github.com/chrisbanes/Android-BitmapCache/ to demo-ing fragment in my usage.

Note: This component does help in solving the jerkyness of the app while loading the image through network.

Below are the steps to include Android-BitmapCache component

1. Edit previous project with the below configuration
Application Name: TechTips
Project Name: TechTips
Package Name: com.example.techtips

2. Import the library from Android-BitmapCache component. Please refer to the screen as shown below:


3. Add 3 classes into the TechTips project as shown in the screen below
- NetworkedCacheableImageView.java
- SampleApplication.java
- SDK11.java

4. activity_tech_tips.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TechTipsActivity" >

   <fragment
        android:id="@+id/techtipsfragment"
        android:name="com.example.techtips.TechTipsFragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />

</RelativeLayout>
5. fragment_tech_tips.xml.
Refer to the fragment_tech_tips.xml, add in the ImageView with network access

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <uk.co.senab.bitmapcache.samples.NetworkedCacheableImageView
        android:id="@+id/nciv_pug"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/app_name"
    />
</LinearLayout>


6. TechTipsActivity.java
package com.example.techtips;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class TechTipsActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_tech_tips);
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_tech_tips, menu);
  return true;
 }
}


7. TechTipsFragment.java
package com.example.techtips;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import uk.co.senab.bitmapcache.samples.*;

public class TechTipsFragment extends Fragment{
 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_tech_tips, null); 
        NetworkedCacheableImageView currentImageView = (NetworkedCacheableImageView)v.findViewById(R.id.nciv_pug);
        final boolean fromCache = currentImageView.loadImage("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSjsDTbniCrwOUKFiOF4i06fpMplrqjFMPi3s7bhm5K-jWGqK-p", false);

        if (fromCache) {
         Toast.makeText(getActivity().getApplicationContext(), "From Memory Cache", Toast.LENGTH_LONG).show();
        } else {
         Toast.makeText(getActivity().getApplicationContext(), "From Disk/Network", Toast.LENGTH_LONG).show();
        }
        return v;
    }
}