• missing xbfish.com image

Category Archives: Programming

Redirect URLs using .htaccess

Suppose you want to redirect http://example.com/folder to http://anotherfolder.example.com, you can add the following line in your .htaccess file:

Redirect permanent /folder http://anotherfolder.example.com

Reference :: http://www.besthostratings.com/articles/htaccess-redirects.html

[CakePHP 2.0] Authenticating user with email

By default in CakePHP 2.0, the authentication component make use of 2 fields to authenticate a user: username & password

If your web application requires user to login using email instead of a username, you can add in the following code snippet in the respective controller:

1
2
3
4
5
6
7
8
public $components = array(
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'email')
            )
        )
    )
);

Take note that $components is a variable instead of a function under a controller.

Explanation: In the above code snippet, the email posted by the form will be taken as the username for the authentication component. The authentication component will then authenticate the user using email when $this->Auth->login() is called.

For more info, please refer to CakePHP 2.0 authentication component.

Checking JDK / JRE bit version on Windows

To check Java Development Kit (JDK) or Java Runtime Environment (JRE) bit version on Windows, open up command prompt and enter the following command:

java -version

If it is 32-bit, you should see something embedded in the version info: Java HotSpot(TM) Client VM

If it is 64-bit, you should see something embedded in the version info: Java HotSpot(TM) 64-bit Server VM

This information is gathered from Java 6. I am not sure this is applicable to Java 7. If anyone knows, please comment. :)

Create new Rails application with MySQL as default db driver

To create a new Ruby on Rails application with MySQL as the default db driver in database.yaml:

rails new app -d mysql

Add -d mysql at the end of the command.

[WordPress] Version 3.3 Admin Toolbar

After updating to WordPress Version 3.3, the admin toolbar is now different from version 3.2.x

Left side of the admin toolbar:

xbfish.com

Right side of the admin toolbar:

xbfish.com

The admin toolbar is now neater and nicer looking.

Installing Rails Node.js in Ubuntu

I faced with the following error when bundling install a Ruby on Rails application:

missing xbfish.com image

I already had mysql2 installed and the error turned out that my development environment is lacking of Node.js

To install Node.js in Ubuntu, open up your Terminal and enter the following command:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

For other Linux distro installation, refer to Node.js @ GitHub.

[Linux] Check Ruby and Rubygems version

To check Ruby version installed on a Linux, enter the following command in Terminal:

ruby -v

To check for Rubygems version, the command is:

gem -v

Install Ruby 1.9.2 in Ubuntu

To keep this post sweet and concise, the first thing you need to do is to open up Terminal.

Gain root access by entering the following:

sudo -s

You will be prompted for your root password.

Next, enter the followings:

apt-get install build-essential zlib1g zlib1g-dev libruby1.9.1 libxml2 libxml2-dev libxslt1-dev
apt-get build-dep ruby1.9.1
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.bz2
tar xvjf ruby-1.9.2-p0.tar.bz2

After extracting, open up ruby-1.9.2-p0/ext/Setup and uncomment zlib line (remove the #).

Then, configure, compile and install:

./configure
make
make install

Viola!~ You are done installing Ruby 1.9.2

HTML5 doctype tag

With the introduction of HTML5, the doctype is made simpler. The doctype for HTML5 is as follows:

<!DOCTYPE html>

Example of a html structure for HTML5:

1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
 
<body>
The content of the document......
</body>
 
</html>

[WordPress] Remove Twenty-Eleven Theme mobile formatting

Twenty-Eleven theme is WordPress version 3.x default theme and it supports mobile format. This means whenever a user browses a WordPress powered site using his/her mobile phone, the site will be displayed in a mobile friendly way.

If you want to remove this mobile formatting, open up header.php in Twenty-Eleven Theme folder. Remove/comment the following line:

<meta name="viewport" content="width=device-width" />

Hope this helps. :)