Tuesday, 11 June 2013

Showing logs on MyBatis with eclipse

MyBatis is a framework mainly done for Java which allow the use of dynamic SQLs. By default it does not print logs of the SQL generated. If you wish it to print the SQLs, you can do the follow:

1. Downlod the log4j jar from here:

2. Include it in your project
2.1 Creates a folder called "lib" in your project directory.
2.2 Copy and paste the jar file on it.
2.3 Go to eclipse and refresh the project
2.4 On the library folder, right click on the new jar and select "Build with" -> "Add to build path"

3. Create the configuration file
3.1 Create a new text file called log4j.properties and paste the follow content on it:

log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.SQL Map.engine.impl.SQL MapClientDelegate=DEBUG
   
log4j.logger.com.ibatis=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG


3.2 Save it on the class bin folder of your project.

Source:
StackOverFlow: http://stackoverflow.com/questions/2635058/ibatis-get-executed-sql

Monday, 18 February 2013

Drupal 7 - Enable and use the contact form

By default, the contact form of Drupal 7 has been disabled. To enable and use it, do the follow:

1. Enable the module
1.1 On the dashboard, click on Modules
1.2 Check the Contact checkbox
1.3 On the buttom, click on Save Configuration

2. Set the contact information
2.1 On the dashboard, click on Structure
2.2 Click on the Contact form
2.3 By default, there is only one contact form: Website feedback. Click on Edit to modify the data
2.4 You could change the follow fields:
- Category: The name of the contact form
- Recipients: The person/s who/m is going to receive the contact info via mail. If there are several receivers, there must be a coma (,) between them.
- AutoReplay: The message that the person who filled the contact form will receive automatically
- Weight: It is a way to organize several contact forms. The larger number means that it is heavier, and the smaller number or negative number means that it is floating on the top.
- Selected: If the contact form will be selected by default. Note that there just can be one contact form to be selected as default.
2.5 Once all the data has been filled, click on Save.

3. Show the contact form as part of main menu
3.1 On the dashboard, click on Structure
3.2 Click on Menus
3.3 On the row of Main menu, click on Add links
3.4 Fill the data
- Menu Link title: Contact
- Path: contact
- Description: Contact form
3.5 Click on Save

4. Enable the contact form for anonymous users
4.1 On the dashboard, click on People
4.2 On the tab of the right top, click on Permissions
4.3 Check Side-wide contact form for anonymous user and authenticated user.
4.4 Click on Save permissions

Drupal 7 - Restoring the password via database

On Drupal 7, the password of any user is stored in the database as hash of it. It is in the column Pass of the table users. If it is needed to reset and there is not any other admin in the system, (and the mail service does not works), it could be set manually in the database.

1. Creates a new password hash
1.1 Open the folder of Drupal 7. Usually it is under htdocs/drupal7
1.2 Open the file index.php from any text editor
1.3 Add the follow code at the buttom of the php file

require_once 'includes/password.inc';
echo user_hash_password('a');
die();

1.4 Open the Drupal main web page. Usually it is


and the password's hash will appears on the buttom of the web page. For example, for the password a, it is:

$S$D8rBxmbI63KswZzFpWVMETfnoUoluLi7r.An3Yxp66dA/fxqMzO8

2. Set the password on the database
2.1 Open the phpMyAdmin. Usually it is


2.2 On the left panel, select the database of Drupal. Usually it is called Drupal7
2.3 On the left panel, select the table users
2.4 On the main screen, chose the row with the right user name. Click on the Column Pass and paste the hash of the new password
2.5 Click on Enter to save. You will see the message "One file has been updated"

Note: Don't forget to remove the added code on the step 1.3 to load correctly the main page of Drupal.

Friday, 1 February 2013

Have XBMC in chinese

Having XBMC in chinese is not just change the settings to chinese, there is few more steps to do:

1. Change the fonts
1.1 Go to System and click on Settings
1.2 Click on Appereance
1.3 On the Skin's submenu, change the fonts to "Arial based"

2. Change the character set
2.1 Go to System and click on Settings
2.2 Click on Appereance
2.3 On the International's submenu, change the character-set to "Chinese Simplified (GBK)"

3. Change the language
3.1 Go to System and click on Settings
3.2 Click on Appereance
3.3 On the International's submenu, change the Language to "Chinese Simplified"

4. Change the preferred audio language (optional)
4.1 Go to System and click on Settings
4.2 Click on appereance
4.3 On the International's submenu, change the Preferred audio language to "Chinese simplified"


5. Change the preferred subtitle language (optional)
5.1 Go to System and click on Settings
5.2 Click on appereance
5.3 On the International's submenu, change the Preferred subtitle language to "Chinese simplified"

Thursday, 31 January 2013

Convert the browser into a notebook

If you want to convert your browser into a notebook or a text editor, just copy and paste the follow code in the navigation bar:

data:text/html, <html contenteditable>

It works on Google chrome, Mozilla Firefox but not Intenet Explorer.

Source: Microsiervos

Sunday, 18 November 2012

Generating SSH Public-Private Key

The pair ssh public-private key is a very common way to identify a specific computer, rather using the MAC address, which could be changed by software.

As the their name figure, the public key is a key which anyone could have and use, and the private key is a key that only the owner should have. They are related such way, that a  message cipher by the public key only could be decipher by the private key, and vice versa. Check the wiki page for more information.

One of the possible use of the public-private key is in the git repository: Each repository contains a set of public keys. When anyone tries to commit (push) code to the repository, the repository will ask the computer to decipher a message ciphered by public keys. Only if the computer could decipher correctly anyone of the ciphered messages, which means it has its public key in the set of allowed public keys, the code will be committed (pushed).


Check if they already exist

By default, the generated keys will be stored in the .ssh folder in your home directory. There will be two files: id_rsa and id_rsa.pub. The first one is private, which you SHOULD NEVER SHARE IT, and the second one is public, which means it should be given when anyone request you the ssh key.

Because the ssh keys are quite important, it is good to check if it already exists.
1. Go to your home directory
cd (Linux & Mac os)
cd C:/usr/USERNAME (Windows)
2. Go to the default ssh directory
cd .ssh
If you see some error telling that the directory does not exists, then the keys could be generated safely. Skip this part. Other wise, continue
3. Back up the existence keys.
mkdir MyOldKeys
mv id_rsa* MyOldKeys (Linux & Mac os)
move id_rsa* MyOldKeys (Windows)

1. Unix based systems (Linux and Mac OS)
On Unix based systems, you just need one simple command in the terminal or console to generate the ssh keys.
ssh-keygen -t rsa -C "YourMailAccount@gmail.com"
where -t is used to specify the type of keys to be generated and -C, some comment.

During the process, it could ask you about the passphrase. It is quite important that you remember the passphrase, because it could be used every time when the private key is used.

2. Windows
On windows, there are several ways to generate the ssh keys. The most simple one is download the msysgit client for windows, which through the git bash, the process is the same as any Unix based systems.

The another way is using the puttyGen, another good utility from Putty.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html 

Once downloaded, you just have to click on the "Generate" button and move the mouse on the white space to introduce some random data.

When the process finishes, you can click on "Save public key" and "Save private key" to save both keys.

Souce:
GitHub - Generating SSH Keys