No public Twitter messages.

Archive for the ‘Tips of’ Category

WordPress auto upgrade in Mac local environment

Saturday, April 17th, 2010

When I test WordPress in local Mac OS X, the auto upgrade function is not available. It shows up like below:

Connection info needed

Here describes reasons and solution. But it doesn't work in my situation: Using XAMPP to set up the testing environment. Another solution were provided in comment 44 by Johan L. It works alright!

Do as follows:

 

To set up file ownership correctly:
In WP root directory
chown -R yourusername:apachegroupname *
In my case...
chown -R johan:apache *

find . -type d -exec chmod 770 {} ';'
find . -type f -exec chmod 660 {} ';'

WP 2.8: add
define('FS_METHOD', 'direct');
define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');
in wp-config.php
The function in file.php reads FS_METHOD and the tmp file creation test is never executed.
Make sure the wp-content/tmp directory exists and is writable by the apache user

Pre WP 2.8: well... you may need to patch the function in file.php by removing the if statement before $method='direct';
see comment #38 above
Only do this if you're sure you've setup file ownership correctly.

BTW the three numbers in chmod describe rights for "user", "group" and "others". read==4, write==2, execute==1. Sum of rights make up the number. Hence 777 means read, write and execute for user, group and others. 660 means read and write for user and group, no rights for others.

NEVER do a chmod 777 on any file or directory. NEVER recommend anyone to do it either!

Note that it's better to upgrade to 2.8 and above first.

The key is the two lines in wp-config.php.

Thanks Johan L.

Shortcut of locking Mac's screen

Wednesday, January 13th, 2010

CTRL+SHIFT+EJECT
Works in Snow Leopard.
Note: Before that, check the General tab on the Security System Preferences panel to ensure that the "Require password [some period] after sleep or screen saver begins" box is checked.
Lock screen

Snagit the screen capture tool

Friday, January 8th, 2010

I introduced Paparazzi! to capture the whole webpage until Ray recommended Layers by Wuonm. Now I just got Snagit from TechSmith, another screen capture too. From the video introduction, it looks good. Will try it out later.

Solving PHP has encountered an Access Violation

Monday, August 31st, 2009

In short: it's caused by compatibility of different version of MySQL.
I have installed php + MySQL on two similar servers. The first one was running without any problem while the second one gave me "PHP has encountered an Access Violation". Here is the version of each component:

  • PHP: 5.2.8
  • MySQL: 5.1.34
  • Zend Optimizer: 3.3.3 (The key point)

On the 2nd server, I installed MySQL before PHP. When deploying the web application, "Access Violation" appeared. I reinstalled MySQL, problem solved. I remembered the difference in phpinfo() between 1st server and 2nd server: MySQL Client API version - 5.0.51a vs 5.1.34. Strange that I installed 5.1.34 on both servers, why the 1st one got older version of API? I did not pay more attention on this question for the problem was solved at that time. But after no more than 24 hrs, same problem happened again. This time, I remembered that I forgot to install Zend Optimizer on 2nd server. Then I install it and found that the API version changed to 5.0.51a... Now I know why the 1st server is running well: Zend Optimizer replaced the MySQL API for php.
My experience is proven here, exact same problem.
It teaches me the lesson again, which, though, I already knew but often forgot to apply:
The latest version may not be the best

Mac OS X: Repair "Open With" list in right-click menu

Thursday, July 9th, 2009

In Terminal, paste command below and press enter:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user

Done,

Use Automator to quick edit "hosts" in Mac OS X

Sunday, May 24th, 2009

A web developer often edit hosts file for developing use. In windows, you can create a shortcut to use notepad to open and edit the hosts file. In Mac OS X, I like using Spotlight to quick open the stuffs I want. But the hosts files is hidden by default and can not be found in Spotlight. So I use Automator to triger TextMate to open hosts file for editing.

Here's what I did in Mac OS X 10.5.6:

  1. Open Automator
  2. In Library of Automator, choose "Get Specified Finder Items" in "Files & Folders" category. Drag it to the right panel.
  3. Open Finder, select "Go -> Go to Folder..." from menu (or use shortcut key "CMD+SHIFT+G"), input "/private/etc/". You can find "hosts" file here. Drag it to Automator, the file list area in "Get Specified Finder Items".
  4. In Library of Automator, choose "Open Finder Items" in "Files & Folders" category. Drag it to the right panel. Choose the application you like to open the hosts file. As to me, I chose TextMate.
  5. Click "Run" button on the top right to test it.
  6. Save it as application in "Application" folder.

This works alright in 10.5.6. But I just upgrade to 10.5.7 a few days ago and I found that it does not work. When test run, the automator can find out the file but cannot open it, even after I repairing the disk permissions. Then I changed another way for step 4 here:

4. In Library of Automator, choose "Run AppleScript" in "Utilities" category. Input following lines:

on run {input, parameters}
tell application "TextMate"
open input
end tell
return input
end run

Test run and bingo!

Custom Fields and Category Order in Atahualpa Theme

Tuesday, April 7th, 2009

Atahualpa theme for wordpress
Atahualpa
is a wonderful WordPress theme that can be customized with 200+ options. It can be use to build simple websites with a bunch of settings. I found that custom fields can not be displayed as it described. I'm not sure if it's a bug. I did some modifications and it works now. Here is how (For version 3.3.2):
Open /wp-content/themes/atahualpa332/functions/bfa_postinfo.php
Find line 10

  1. return get_post_meta($post->ID, $matches[1], TRUE);

Replace with the following lines

  1. ob_start(); the_ID(); $post_id = ob_get_contents(); ob_end_clean();
  2. return get_post_meta($post_id, $matches[1], TRUE);

I don't know why $post->ID can not get the post's id. And the way above is not efficient, but it works.
Now you can use the custom files with the tag %meta('fieldname')% in the theme options -> Post/Page Info Items.
I also would like to manually arrange the order of categories. This function is not built in. There are some plugins can make it happen. I'm using Category Order. Some modifications should be done in Atahualpa too.
Open /wp-content/themes/atahualpa332/functions/bfa_hor_cats.php
Find line 3

  1. $list_cat_string = wp_list_categories('orderby=' . $sort_order . '&order=' . $order . '&title_li=&depth=' . $levels . '&exclude=' . trim(str_replace(" ", "", $exclude)) . '&echo=0');

Replace with

  1. $list_cat_string = wp_list_categories('&title_li=&depth=' . $levels . '&exclude=' . trim(str_replace(" ", "", $exclude)) . '&echo=0');

This removes orderby, order parameters to meet the requirement of Category Order plugin.

A few tips for Mac OS X

Sunday, March 15th, 2009
  • Q: When save Automator as a plug-in for Finder, where on the earth is it?
    A: Find it here "~/Library/Workflows/Applications/Finder"
  • Q: How can I get the full path of a file as soon as possible?
    A: Use AppleScript + Automator in this way. Or install the contextual menu plugin below.
  • Q: I want more handy commands in mouse right click menu?
    A: OnMyCommand is exactly what you need. Though it's somewhat complicated, there are already a bunch of ready-to-go commands for beginners.

Mac widget Currency Converter error

Tuesday, March 10th, 2009

We are experiencing the most serious financial crisis since the Great Crash of 1929. So WHOSE fault, when $1 does not worth $1 any more?

Mac widget Currency Converter error

Okay, I'm sorry for bluffing. First, we might meet currency deflation not inflation, second, it's all about a bug of Mac OS X build-in widget.
After upgrading to OS X 10.5.6, this widget does not work right.
To fix this problem, make a copy of /Library/Widgets/Unit Converter.wdgt on your Desktop, Control-click on it and choose Show Package Contents from the pop-up menu, then open the UnitConverter.js file in a text editor. Search for "USD" (with the quotes). There should be only one matching line:

if (a.iso == "USD") return -1;

Delete this line. Then, delete the else at the start of the next line, i.e. change the line from this...

else if (a.name < b.name) return -1;

...to this...

if (a.name < b.name) return -1;

Save the changes and close the document. I suggest keeping the original widget in /Library/Widgets, and installing the corrected version in ~/Library/Widgets, so that the system's version remains untouched.

The solution was found here:

http://www.macosxhints.com/article.php?story=20090225162441861

Easy way to sync iCal with google calendar

Monday, February 16th, 2009

Google Calaboration for iCal

You can add google account in iCal to sync the calendar. Previously you have to do that manually by a few copy and paste steps, really boring. Last night I found google had released a tool named Calaboration on December 9th last year, which is tiny but easy to use. Simply login with your google account, it will show the calendar you have. Check the ones you want to sync with iCal and click "Add to iCal" and it's done.

Note that the calendar with a lock after it, is read-only. For example, the calendar shared to you by your friends. You can change the setting in preference if it can be ADDED into iCal, but you can not modify it in iCal(either in Google Calendar of course).

Download it here.

I decided to add Chinese version of each post from today. Have to remove to avoid unwanted ads.