Archive for July, 2011

Change windows xp’s time synchronization frequency how-to

July 28, 2011 Leave a comment

Found the solution here:

Default is set to 604800 (7 days, bloodily stupid value chosen by M$?)

Change to a smaller amount, for example, 86400 (1day) or even 3600 (1 hour) if the OS is running some time-sensitive stuff.

A system restart is required for the new setting to be in effect.

Using (and booting from) SATA III drive in Mac OSX Lion

July 25, 2011 5 comments

I wondered if I could switch the SATA port from the blue (SATA 3.0Gb/s) to white(SATA 6.0Gb/s) port since my hackintosh has been upgraded to LION so today I did just that and bang I’m on SATA III without any issue. But the weird part is I don’t feel any speed difference. With SATA III

time dd if=/dev/zero bs=1024k of=tstfile count=1024
1024+0 records in
1024+0 records out
1073741824 bytes transferred in 8.016426 secs (133942713 bytes/sec)

real	0m8.030s
user	0m0.004s
sys	0m1.381s

Divide 1024MB by 8 seconds and I got a write speed to 128MB/s on SATA III.

To satisfy my own curiosity, I plugged the hd (a 2TB Hitachi SATA III) back to the SATA II port and ran another write test. And the result turned out to be

time dd if=/dev/zero bs=1024k of=tstfile1 count=1024
1024+0 records in
1024+0 records out
1073741824 bytes transferred in 8.283360 secs (129626362 bytes/sec)

real	0m8.290s
user	0m0.004s
sys	0m1.179s

Which yields a 123MB/s, it’s slower than SATA III but not by much.

Using either port the outcome is pretty close to the results from:

Categories: benchmarking

Mac OS X Lion terminal color (remote access) problem fix

July 23, 2011 18 comments

After upgrading to Lion I noticed that the Homebrew theme that I’ve been using since Snow Leopard doesn’t display colors correctly(using different colors for directories, different types of files etc.) any more when working on remote hosts via ssh (local dir colors still work though) and switching to other themes doesn’t help. After messing around with the Terminal settings I finally found the cause and a solution. It seems Lion changed the terminal type to xterm-color256 during the upgrade (don’t remember what the setting was in SL though). The solution is simple enough, just change the emulation type for terminal from xterm-color256 to xterm-color (see screenshot below).

[ Update 1/2/2012 ]
Actually found a better solution here:
1. Keep the current xterm-256color in your Mac Terminal
2. Add the following lines to your ~/.profile on your remote host

[ "$TERM" = "xterm" ] && TERM="xterm-256color"
alias ls='ls --color'


. ~/.profile
Categories: dircolor, howto, mac osx

“This version of Mac OS X 10.7 cannot be installed on this computer” fix

July 21, 2011 10 comments

Had a hardtime to get Lion download started following the guide at, I kept getting “This version of Mac OS X 10.7 cannot be installed on this computer” error while try to install Lion via App Store. Tried changing the system definition to MacPro3,1 without success. Found the solution from the comments below the guide (actually just found out it was mentioned very obviously in the guide as well, not sure it’s added after many people reported the same problem):

1) Get the newest version of multibeast (currently 3.8)
2) Select “System Utilities”, “Chimera” (this is the key), “MacPro3,1” and install
3) Restart

Categories: lion, mac osx, tony mac osx

Debugging with gdb: a couple of notes

July 14, 2011 Leave a comment

While debugging with gdb, one can use the following gdb command to instruct gdb to continue when a SIGPIPE signal is sent to the program being debugged.

(gdb) handle SIGPIPE nostop

Every time when a SIGPIPE command is fired, one will see the following on the gdb console

Program received signal SIGPIPE, Broken pipe.

The nostop gdb command should take care of most of the situations where user interaction is not required. However if the information to be printed by gdb exceeds one screen, the following prompt will appear

---Type <return> to continue, or q <return> to quit---

due to the fact that gdb has pagination on by default, meaning if the erroneous output from gdb exceeds a screen, gdb will ask user for actions.

The reason behind that, I guess, is that gdb doesn’t want the important information to be missed since the top most lines will be scrolled out of the screen (default number lines per screen is 68 in gdb). This is useful when debugging in interactive mode, however it’ll also pause the program. If this is not desired, simply use the following gdb command to turn off pagination:

(gdb) set pagination off

Or alternatively,

(gdb) set height 0


Categories: debugging, gdb

Mysql count with case statement

July 1, 2011 Leave a comment

In one of my recent perl scripts, I need to get a row count of total records from a mysql table, as well as the row count of some rows with some criteria. By combining the technique from and the atomic row fetch trick I mentioned a while back, I came up with the following script (for illustration only hence this is not the actual script that I wrote)

#!/usr/bin/perl -w
use strict;
use DBI;

# make db connection and stuff ...
my $dbh=DBI->connect( 'DBI:mysql:db:localhost:3306', 'username', 'password' ) or die( $DBI::errstr );

my $sql=qq{ select 
    count(feedback_id) as total_count, 
    count( case when feedback_type in ('suggestion', 'bug_report') then 1 else null end ) as special_count
from customer_feedbacks};

my ($total_count, $special_count)=$dbh->selectrow_array( $sql );
# do something with $total_count and $special_count

$dbh->disconnect() if $dbh;

The benefit of crafting the mysql statement this way is that I only need to do one mysql query instead of two, combined with atomic fetch, the resulting code becomes very clean.

Categories: mysql, perl, Programming