List all tables in a database

May 20th, 2012

To list all tables in the mysql database, you can use this SQL

show tables;

Easily add related links to your blog post

February 26th, 2012

Use this easy-to-install widget to show more related posts within your blog post

http://www.linkwithin.com

Criteria of great software

February 24th, 2012

While looking at a software, we can follow the following criteria to judge a software.

  1. Impressive and clean design
  2. Intuitive and easy to use (without even need a training)
  3. Error free (or at least with layman message)
  4. Smart on-screen guide (what to or not to key in, where to go next, what to expect)
  5. Fast performance – loading and processing time
  6. Practical and well-designed logic and flow

Barcode generator on Excel

November 17th, 2011

To use excel to generate a bar code is easy.

1. Download free barcode font

2. Copy the font files to c:\windows\fonts

3. Open an excel file with 2 columns. One column for normal character and another column for barcode.

4. On the second column, paste this formula =CONCATENATE(“*”,A1,”*”)

For open office calc use this formula  =CONCATENATE(“*”;A1;”*”)

5. Choose the “Free 3 of 9 Extended” font

6. Adjust the font size accordingly to get a bigger barcode size

iPhone CSS

November 7th, 2011

This CSS to be used to display website nicely on iPhone. Not tested on Android and other smart phones.

Add this code on top of what ever css style you have.

1
2
3
4
5
<!-- Start iPhone -->
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<link rel="apple-touch-icon" href="/images/money.png" />
<link media="only screen and (max-device-width: 480px)" href="/iphone.css" type= "text/css" rel="stylesheet" />
<!-- End iPhone -->

In iphone.css file, just write the css code. For example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
body,td,input,textarea,select,label { font-size: 6em;}
mainlink {font-size:3em; }
body {
background-color: #fff;
}
 
.header, .footer {
width: 100%;
}
 
.sidebar {
display: none;
}
 
.mainlink {	color:#FFFFFF; font-size:150%; }
 
.mainlink A:link {text-decoration: none; color:#FFFFFF; }
 
.mainlink A:visited {text-decoration: none; color:#FFFFFF; }
 
.mainlink A:active {text-decoration: none; color:#FFFFFF; }
 
.mainlink A:hover {text-decoration: underline; color:#FFFF66; }

Reset root password for MySQL on windows

September 7th, 2011

If you have problem accessing your MySQL database with this error
ERROR 1045: Access denied for user: ‘root@localhost’ (Using password: NO)

You can try reset your root password with the following steps:

1. Create a txt file with this content

UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
FLUSH PRIVILEGES;

2. Save the file as mysql-init.txt in c:\ (or any directory you want)

3. Stop MySQL service

4. Start MySQL service in command prompt with this command line

>c:\mysql\bin\mysqld --init-file=c:\\mysql-init.txt

5. Remove the txt file in created in step 2

Note: You can/need to specify correct path for the file and mysql directory for step 2 and 4.

MySQL database auto backup on windows

September 5th, 2011

To backup mysql database (all databases) can use this batch file

Then you can compile the .bat file to become .exe file so that the password is hidden.

Download bat to exe converter from CNET download

Lastly, you can include the exe file to run in task scheduler

You can have option to upload the file via FTP to other server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
:: Start FTP files to remote server
:: Create the temporary FTP script file
> script.ftp ECHO ftpusername
>>script.ftp ECHO ftppassword
>>script.ftp ECHO lcd /
>>script.ftp ECHO lcd /MySQLBackups/backupfiles
>>script.ftp ECHO binary
>>script.ftp ECHO prompt n
>>script.ftp ECHO put FullBackup.%backupdate%.zip
>>script.ftp ECHO bye
:: Use the temporary script for unattended FTP
:: Note: depending on your OS version you may have to add a '-n' switch
FTP -v -s:script.ftp ftphostcom.com
:: Overwrite the temporary file before deleting it
TYPE NUL >script.ftp
DEL script.ftp
:: DONE FTP backup file to remote server

Database config for localhost and server

August 29th, 2011

To easily toggle database config for localhost and server, you can simply check whether you are accessing the local or server.

1
2
3
4
5
6
7
8
9
10
11
12
13
if (preg_match("/localhost/i", $_SERVER['SERVER_NAME'])) {
define ('DBHOST','localhost');
define ('DBNAME','localdbname'); 
define ('DBUSER','localuser');
define ('DBPASS','localpass');
define ('DEV',TRUE);
} else {
define ('DBHOST','localhost');
define ('DBNAME','serverdbname'); 
define ('DBUSER','serveruser');
define ('DBPASS','serverpass');
define ('DEV',FALSE);
}

Inserting recaptcha to your form

August 27th, 2011

Captcha is good to reduce spam. One of most popular captcha used is recaptcha.

This is how it looks like. Familiar?

captcha

To implement it is very easy. Will take less than 10 minutes of your time.

1. Get your public and private key

https://www.google.com/recaptcha/admin/create

2. Include class file

Download recaptcha library file for PHP (with some sample files)

3. Insert code in form page

1
2
3
4
5
6
7
8
<form method="post" action="verify.php">
        <?php
          require_once('recaptchalib.php');
          $publickey = "your_public_key"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
        <input type="submit" />
</form>

4. Insert code to validate code in process page

1
2
3
4
5
6
7
8
9
10
11
12
13
14
require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
 
  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }

Resume do’s and don’ts

August 19th, 2011

If you are sending out resume to apply for job, please follow the following rules

  • Prepare and send your resume in PDF format. With this your resume formatting will appear same all the time
  • Please always include your LATEST and most PRESENTABLE photo
  • Don’t name your file as resume.doc. Use resume_yourname.pdf instead. Remember not only you that send resume to apply for the job
  • Use email with your real name, not your cat’s name or whatever crazy name. For example abdul.rahman@gmail.com NOT setan_cute@gmail.com
  • Tell about your experience and what you HAVE DONE. Not about what subjects you took during your study. Describe the task, your role and other related information (e.g. technology used, party involved etc)
  • There is no limit of page for a resume. Don’t buy to idea that you need to limit to 1 page, 2 pages or maximum 4 pages. If you write the right thing, people will read it from beginning to the end