@apple4us typical "wolf's coming" for the gov has done 2 much evil. Hard 2 believe not related 2 them. Haha.

Archive for the ‘Tips of’ Category

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.

Reason of Apple Mail starts automatically

Monday, February 16th, 2009

Previously I met the problem that the Apple Mail application starts automatically. I tracked the history for a few days and now I find out the reason. Here under is my analyze:

  • There was no sign that the Apple Mail run in a fixed frequency.
  • The chance of virus is slim too. Because virus often hides itself when doing anything bad like sending email to all contacts. And in another hand, OS X is much safer than Windows at present and no too much virus is reported so far.
  • It could be triggered by some application that I had to find out.

So I check the system log in Console. I found out an error of iCal occurred at the same time that Mail run. When I look into the details, yes, it was there, iCal called a function to run Mail to send a email out. Since I have never set up an account in Mail, it pops up an notice to let me set one. The log also recorded what kind of mail iCal wanted to send. Then everything is clear: I sync the iCal to my google calendar, my google calendar has a series of email reminders to send to myself. While google has it's own mechanism to send them out, iCal uses Apple Mail.

This is just a specific problem. But the way of wisely using the Console and tracking down the history is the key to find out the reason for most problems.

You see, there is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect.

-- The Matrix Reloaded

Gmail improves interface a little bit

Wednesday, February 4th, 2009

Maybe in a few hours, gmail's interface looks different. When I logged in one second ago, my eyes told me there's something different: the Buttons.

Gmail improved interface

To recall the memory to compare, I have to google the old interface out:

Gmail old interface

The buttons in new interface look more compact, beautiful. Not ugly grey buttons any more  (those in screenshot above are styled by Vista theme, but in Windows classic theme, they are like this: Gmail old button).

They are also separated into 3 groups: simple button, drop down list, more action.
The change improved usability. I like it.

Tips: Note that there is a "Mark as read" button in first screenshot.
It can be enabled by a plug-in in "Setting -> Labs -> Mark as Read Button". Small function, but really handy.

Use BlackBerry as bluetooth modem in Mac OS X in China

Sunday, January 25th, 2009

Use BlackBerry8100 as Bluetooth Modem
After trying over and over again, I finally succeeded to set up BlackBerry bluetooth modem in Mac OS X. In fact, there are already several articles talked about this. I just made it work in China Mobile network.
This article is for those who:

I tested it in MacBook aluminum, OS X 10.5.6, BlackBerry 8100 (ROM version 4.3)
The basic configuration is described clearly here: How do I use my Blackberry Pearl as a bluetooth modem with a Mac?. It should work well when you use T-Mobile or Cingular.
If you are in China and using China Mobile, here are some settings you should change:

  1. Open the file BlackBerry 8100 or BlackBerry 8300 in the /Library/Modem Scripts/ folder with text editor. Find out "ATDT*99***1#" and replace it with "ATDT*99#" then save the file. Or you can simply download the file I made, unzip it and put it into the folder I just mentioned.
  2. In "System Preference => Network" panel, use "cmnet" as the Telephone Number, Account Name, Password.

The step 2 wasted a lot of my time. Because in windows, there's no need to set a user name and password when dialing. Before filling the two blanks in OS X, I thought failure of connecting was caused by some other reasons.