General

Two Letters in One Day

Monday, March 1st, 2010 -- By ET

First letter was from our university president, explaining that in light of the recent financial crisis, we have to follow the new budget plan and reduce the salary by 5.4%.

Second letter was from my daughter’s school, explaining that in light of the recent financial crisis, they have to follow the new budget plan and increase the tuition by 5%.

What an ironic world.

Converting ISBN13 to ISBN10

Thursday, January 28th, 2010 -- By ET

I need to convert a bunch of isbn numbers from the 13-digit format to the 10-digit format.

Figured out the algorithm, and implemented the following subroutine in PERL.  It should be fairly simple to port it to other languages.

sub isbn1310{

my $isbn13=shift;
my @isbn13=split(//,$isbn13);

my $sum = ($isbn13[3] * 10) + (9 * $isbn13[4]) + (8 * $isbn13[5]) + (7 * $isbn13[6]) + (6 * $isbn13[7]) + (5   *   $isbn13[8]) +
(4 * $isbn13[9]) + (3 * $isbn13[10]) + (2 * $isbn13[11]);

my $mode = int(($sum / 11) + 1);
my $last = (11 * $mode) - $sum;
if ($last == 10) {
$last = “X”;
} elsif ($last == 11) {
$last = 0;
}

my   $isbn10=”$isbn13[3]“.”$isbn13[4]“.”$isbn13[5]“.”$isbn13[6]“.”$isbn13[7]“.”$isbn13[8]“.”$isbn13[9]“.”$isbn13[10]“.”$isbn13[11]“.”$last”;
return $isbn10;
}

Computing Power Skirmish

Wednesday, January 6th, 2010 -- By ET
I have to make some heavy computations these days.  It gives me a chance to compare the computing power of my two computers.
On both machines, I have the same version of MySQL.  The program, written in Perl, conducts some complex calculations based on MySQL data.
skirmish
Dell-Mac Skirmish
It is interesting to observe that my Macbook Pro actually performs better than my Dell Server.  The above figure shows 5 random sampling points, at which I count how many data records have been processed since last sampling.  Macbook constantly beats Dell.
Here are the specs:
Dell:
Dual Quad-Core Xeon CPU 2.33GHz, 32GB Memory, 1T HDD, Windows 7 64 Bit
Macbook Pro:
Core 2 Duo Intel CPU 2.8GHz, 8GB Memory, 500G HDD, Snow Leopard 64 Bit
Due to the nature of the program, only 1 CPU-Core can be used, this may explain the disadvantage of Dell. (Although it has 8 cores, 4 times that of the Macbook Pro.)
UPDATE:
A few more hours of data keep supporting the advantage of Macbook:

dellmac

Fully Utilizing My Computing Power

Tuesday, January 5th, 2010 -- By ET

Before tweaking MySQL: it used 5% of the CPU and 250MB of the memory.

After tweaking, it uses 94.3% of the CPU and 2.33GB of the memory.

I could increase the memory use even more if I needed it. :-D

screen-capture9

Join Multiple PDF files to a Single One on Mac

Monday, December 28th, 2009 -- By ET

I downloaded an ebook, it contains hundreds of one-page pdf files.  I certainly don’t want to upload all of these one-pagers to my Kindle. To concatenate these files, there is no simply and easy way.  Commercial software packages are available from $14.00 to 20Euro.

A simply perl hack does the job:

  1. Install the perl module:
    perl -MCPAN -e 'install("PDF::Reuse")'
  2. Create a perl program, call it “catpdf.pl”:

    use strict;
    use PDF::Reuse;

    prFile(”output.pdf”);

    for(@ARGV) {
    prDoc($_);
    }

    prEnd();

  3. To concatenate, call it in two possible ways:
  • perl catpdf.pl a.pdf b.pdf, or
  • perl catpdf.pl *.pdf

————–

As a side note, it is really easy to concatenate mp3 files on mac, just do:
cat *.mp3>output.mp3

Avatar

Thursday, December 24th, 2009 -- By ET

The most memorable sentence, by the Colonel: “We will fight terror with terror.” It sounds so familiar. LOL.

If you have watched “Brave Heart”+”The Last of the Mohicans”+”Minority Report”, you pretty much miss nothing.

Overall, it is still a good movie.

Time is the Coin of Your Life

Monday, December 7th, 2009 -- By ET

time_is_the_coin_of_your_life_you_spend_it_do_not_allow_others_to_spend_it_for_you-carl_sandburg-480x360-20091207

RIP: Dr. Tsien Hsue-shen (Qian Xuesen)

Sunday, November 1st, 2009 -- By ET

Dr. Tsien Hsue-shen (also spelled as Qian Xuesen) passed away yesterday.

To me, he is as legendary as John Nash. A movie based on his life would also be highly appropriate named “A Beautiful Mind”.

qian

Interestingly, both Nash and Tsien were affiliated with MIT.  It was 2008 when I last visited Hang Zhou, the hometown of Tsien, I visited the memorial museum (called Qian King Temple) dedicated to Tsien’s ancestor Qian Liu.  I found Tsien’s Certificate of Master of Science, conferred in December, 1936.  The design hasn’t changed a bit for so many years.  It looks exactly the same as my certificate which I got in 2006, almost 70 years after Tsien got his. I cannot express how proud I was while looking at that certificate.

Tsien is a very typical Chinese scientist, smart, hard-working and humble. He kept a very low profile despite his great achievements.   Great achievements comes with great social responsibility, he sets a great example for anyone who cares to call himself/herself a scientist.

BibTeX Title Capitalization (Uppercase) Tool

Wednesday, August 26th, 2009 -- By ET

I type my BiBTeX entries carefully, but different journals may have different requirements for capitalizing paper titles.

Some would like a plain format, like
Some, Author, 2009, “Capitalizing BibTeX titles: A simple tool,” Science, 110(1), 1-20.

Some Bibtex class files may automatically lowercase all words after the first, so the title looks like:
“Capitalizing bibtex titles: a simple tool,”

To make the title correct, we can add curly brackets, and change the title as:
“Capitalizing {B}ib{T}e{X} titles: {A} simple tool,”

This helps to address the issue, but what if a journal requires all first Characters to be capitalized? like this:
“Capitalizing BibTeX Titles: A Simple Tool,”

It is not hard to write a program to capitalize all words, but then there are complications, like the following case:
“Capitalizing BibTeX titles for Some Journals: A Simple and Intuitive Tool,”

In the above example, “for”, and “and” should not be capitalized.

In another example,
“Capitalizing BibTeX titles for Some Journals: Vote For a Solution,”

The second “For” should be capitalized, but “a” should not be capitalized.

So some intelligence is needed to convert the titles. That’s why I wrote this tool that correctly capitalize the titles.

The location of the tool is: http://blog.mikezhang.com/dcolumn/bibcapital.cgi.

There are some example entries in the box, just click “submit”, see how it works.

To process your file, simply copy and paste into and from this text box.

Again, this tool is offered as is. If you find it useful, that’s great. If you have problems with it, please talk to my friend Feng Zhu, he helped me to debug this tool, I’m going to hold him responsible for additional bugs.

A Complicated SQL Query

Monday, August 17th, 2009 -- By ET

Just wrote the most complicated SQL query I’ve ever encountered.  Since the table “clicks” has more than 5 million records, I’m going to wait till tomorrow to get the result.

The reason I have to write this is that I was trying to use a PERL program to do the same, and so far, after two days, it is still running with very slow progress.


create table sqlhistory as
SELECT a.inc, a.clicktime, (SELECT MAX(clicktime) FROM clicks b
where a.keyid=b.keyid and a.adid=b.adid and b.clicktime<a.clicktime
) as bctime, a.keyid, a.adid, a.bid, a.price, a.rank, a.reserve_price, a.reserve_price_new
FROM clicks a
where a.bid<>(select c.bid from clicks c
where a.keyid=c.keyid and a.adid=c.adid and c.clicktime=(SELECT MAX(clicktime) FROM clicks b
where a.keyid=b.keyid and a.adid=b.adid and b.clicktime<a.clicktime

)
limit 1
)

======Update====

Sun Wei suggested a new way to do it, and the productivity increased almost 1000 fold

1.

create table clickorder as
select * from clicks
order by keyid, adid, clicktime

2.

create an auto_increment field called ‘inc’, and a new field called lastbid

3.

update clickorder a, clickorder b
set a.lastbid=b.bid
where b.inc=a.inc-1 and a.keyid=b.keyid and a.adid=b.adid


BlogTimer
You are visitor number several since September 1, 2001

Copyright Xiaoquan (Michael) Zhang, 2004-2010. All rights reserved.
All trademarks property of their owners.