Author Archives: invtr

MAMP MySQL cannot access

Some important notes for root password change for MAMP

To change root password to empty/blank again, open terminal and type
/Applications/MAMP/Library/bin/mysqladmin -u root -p’root’ password ”
(root is the original password for mysql in mamp)

MAMP page
In: /Applications/MAMP/bin/mamp/index.php
Change to: $link = @mysql_connect(‘:/Applications/MAMP/tmp/mysql/mysql.sock’, ‘root’, ‘newpassword’);

PHPMyAdmin
In: /Applications/MAMP/bin/phpMyAdmin/config.inc.php
Change to: $cfg[‘Servers’][$i][‘password’] = root

PHP automatic run without cron job

If you don’t have a cron in your serveer, you can use this script to run a daily cron job.

Prepare a writeable file with a date inside and name it as ‘crondate.php’. The file should contain only date in one line.

2012-09-22

Run this function in a file on your website. It will check whether today’s date and date in file are different.
If yes, then it will call any function you want to run daily

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function cron_daily_check() {
	//read file to get last date
	$filename = 'crondate.php';
	$handle = fopen($filename, 'r');
	$filedate = fgets($handle);
 
	//if date different, run a function and update file date
	if (date('Y-m-d') != $filedate) {	 
		/***** call any function or script to execute here ****/
 
		//write new date
		$fh = fopen($filename, 'w') or die("Failed to open file.");
		$stringData = date('Y-m-d');
		fwrite($fh, $stringData);
		fclose($fh);
	}		
}

Should we store datetime or unix timestamp in MySQL?

Timestamps in MySQL generally used to track changes to records, and are updated every time the record is changed. If you want to store a specific value you should use a datetime field.

If you meant that you want to decide between using a UNIX timestamp or a native MySQL datetime field, go with the native format. You can do calculations within MySQL that way ("SELECT DATE_ADD(my_datetime, INTERVAL 1 DAY)") and it is simple to change the format of the value to a UNIX timestamp ("SELECT UNIX_TIMESTAMP(my_datetime)") when you query the record if you want to operate on it with PHP.

Timestamp (both PHP ones and MySQL’s ones) are stored using 32 bits (i.e. 4 bytes) integers ; which means they are limited to a date range that goes from 1970 to 2038.

DATETIME don’t have that limitation — but are stored using more bytes (8 bytes, if I’m not mistaken)

After, between storing timestamps as seen by PHP, or timestamps as seen by MySQL :

using PHP timestamps means manipulations are easier from PHP — see Date/Time Functions

using MySQL’s timestamps means manipulations are easier from MySQL — see 11.6. Date and Time Functions

And, for more informations between MySQL’s TIMESTAMP and DATETIME datatypes, see 10.3.1. The DATETIME, DATE, and TIMESTAMP Types

source:

http://stackoverflow.com/questions/2533767/mysql-whats-the-best-to-use-unix-timestamp-or-datetime

http://stackoverflow.com/questions/409286/datetime-vs-timestamp

To take a screenshot with Mac

Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop
Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard
Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard
Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard

Criteria of great software

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

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