Sunday, February 1, 2015

How to Show Hibernate SQL Statements in Grails

Problem
You want to see all Hibernate SQL statements when using grails.

Solution
You must have these line of codes inside your conf/Config.groovy configuration file.

log4j = { debug 'org.hibernate.SQL' trace 'org.hibernate.type' }
The SQL statements will appear on the standard output console.

Monday, January 19, 2015

Update MySQL User Password

SET PASSWORD FOR 'root'@'localhost' = '';

The SQL script above sets the password for the user root to blank.
The script will run successfully if the current user has UPDATE privilege on the MySQL database.

Friday, October 31, 2014

How to Import Existing GIT Project to BitBucket

Here are the steps to import your existing GIT project to BitBucket. This tutorial focuses on local GIT project. If you plan to import project from your hosting site, checkout this Atlassian article instead.

1. Login to to your BitBucket account.

2. Create a new repo.
Click Create button.
Click Create repository button to save the new repo.

3. Open your Terminal application to the project's path.
cd /path/to/my/repo

3.1. Remove any existing remote (in this case the remote name is origin). Skip this if your project has no remote yet.
git remote rm origin

4. Point your project to the new BitBucket repo.
git remote add origin https://mybitbucketusername@bitbucket.org/mybitbucketusername/myexistingproject.git

5. Push the project and all its refs.
git push -u origin --all

6. Push tags in the project.
git push -u origin --tags

Done. :)

Tuesday, September 3, 2013

Maximize an ImageView on Android

Problem
How to maximize an ImageView on Android while keeping the aspect ratio? There's a lot of combinations available on the Internet but the following code alone was able to solve my problem.

Solution
<ImageView android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:scaleType="fitCenter" />

Important Note
Make sure the ImageView is inside a LinearLayout for the android:layout_weight to work.

Source
Comment of Mohsen Afshin on stackoverflow.com

Wednesday, August 7, 2013

phpMyAdmin Installation on Ubuntu using Terminal

Had to install phpmyadmin on Ubuntu 12.04

Just used the following command:
sudo apt-get install libapache2-mod-auth-mysql phpmyadmin


When asked to choose a Web server, I chose
[*] apache2


Clicked Enter when asked to create the database called dbconfig-common

Entered password for MySQL root, phpMyAdmin.

The installation completed but I was not able to open the link:
http://127.0.0.1/phpmyadmin/

Had to edit /etc/apache2/apache2.conf and added the following to the end of the file:
Include /etc/phpmyadmin/apache.conf


Restarted apache using
sudo /etc/init.d/apache2 restart


Finally, opened http://127.0.0.1/phpmyadmin/ again and it worked at last.

Friday, May 24, 2013

How to Display a JavaScript-like Alert in Java

Just put the following in your Java code:

javax.swing.JOptionPane.showMessageDialog(null, "Your message here");

Note:
Similar to JavaScript, your code will pause executing until you close the message dialog. So be careful when deploying your code for the client.

Thursday, May 2, 2013

OCJP Exam Tips I didn't find online


Just want to share my experience when I took the SCJP Exam years ago. Yep, OCJP was called that way back when Sun Microsystems was not yet acquired by Oracle.

After months of reviewing, thanks to God He allowed me to pass the exam with a score of 91%.

The duration of the exam is not a problem.
From my experience, the time allotted to take the exam is more than what is needed. You can actually double the number of questions on the exam so it will fit more to the exam duration. Here's why: During the exam, I actually used the time answering the questions and checking all the items all over again as if it was my first time. That is to include the time it took me to go to the restroom and also taking a glass of water outside the exam room. After I ended my exam, I still have fifteen minutes left unused.

Don't underestimate the ability of fresh eyes.
Do other things before rechecking your answers. I discovered many wrong answers when I rechecked my answers. That was, when I went to the restroom and had a drink of a glass of water. I'm sure I won't realize what's wrong with my answers if I continuously stared at my answers to each questions at that time.

Put your review book beside your bed
No superstition involved here. In this way you will cover more topics since you'll be reading it more often most likely before sleeping. Reviewing is also effective in making you sleepy. Your sleep will help you review and reviewing will help you sleep. And to you, both are beneficial :)

Reading an SCJP reviewer once is not enough
The reason is quite obvious here. Even with a year of experience in Java programming, it is not a reason that you already know all the topics covered in the exam. Take mock exams that measure your ability for each topic. After reading the book and taking exams, review topics you think you are not really familiar with yet. Then, code as necessary.


More tips when taking the exam:


Eat your meal two hours before the exam
When you eat your meal, your blood supply focuses on your stomach for about two hours during digestion. Your brain needs a lot of oxygen especially when taking the exam. Prevent your stomach from competing with the oxygen your brain needs.

Make an effective habit on your exam time
For sure you know the time of the day you will take the exam right? Why not answer mock exams on the days prior to your exam at the same time of the day of your exam. This will condition your body. The time you take the exam, your body already knows that you will be answering questions again.

Don't schedule your exam on an unholy hour
Perhaps you don't want to take your exam very early. Also, will not schedule it on a time of the day you usually feel sleepy.

Ask permission to God
Things happen if only God allowed it. Why not ask His permission. His decision determines if you'll pass or fail. But wait, just make sure you did your part - reviewed enough for the exam. Ask His protection on the day of your exam. Who knows you'll be sick by day you take it, or you'll be late because of the traffic, etc. It is good to rely to someone who controls everything. Make sure you ask it in Jesus' name. It's the only way you can connect with God.

Initially posted this entry on my multiply.com but multiply has closed my account already.