Sep
22
2007
You can easily find enough readings on moon eclipse from the web. Even though full lunar eclipses are not very common, nowadays, not many people bother to get up at night to see the fantastic show.
I still remember when I was a little kid. Life was just not as crowd as it is now. One night, or early morning, I wandered on the street waiting for the moon to be covered by shadow of the earth. I was about to see what I read from a very thick book on solar system and the universe. And, guess what, it happened!
I don't understand why people are all so focused on a very limited view of the world. When you look into the sky, especially at night, you know there is much much more to explore out there!

Sep
22
2007
I am not going to explain this idea as if I am a physician or mathematician. This is only some random thoughts when I was hiking on the mountains.
Imagine moving on the earth from point A to point B. Mathematicians have figured out the shortest path on the surface of the earth, which roughly is a sphere, is the arc of the great circle connecting A and B. However, if we keep on moving along that direction, eventually, we will come back to A!
As human beings, we are confined by gravity to the surface of the earth. When we seemingly move towards one direction aiming at some target, along the shortest path, the path is actually pointing to our back ;-)
Now imagine you are moving in the universe, towards somewhere far far away. You might believe that if you keep on moving, you are heading to the "outside" of the universe. Well, think again, you might be heading to where you are right now! The space can be bent so that you will never hit the edge of it even if it is finite!
Now I want to ask this question: how large is the universe? Let's start a light beam pointing towards one direction, if we can somehow figure out when it will come back and hit our butt, we know the total length of the great circle of the universe. This is under the assumption that the universe has its mass distributed uniformly on all directions, hence, it is somehow a "sphere." In reality, this assumption may not hold.
Another point is the time dimension, does it also have a great circle? Why not?
See also Möbius strip - Wikipedia
Sep
22
2007
| To find size under a dir |
|
du -sk * |
| To find # of files in a dir |
|
find . -type f | wc |
|
find . | cut -f 2 -d | uniq -c | sort n |
|
find . | cut -f 2-3 -d | uniq -c | sort n |
| To find and do sth to the results |
|
find dir_name -name filename* | xargs cat | sort | uniq > filename_new |
| To find all symbolic links |
|
ls -lR | grep '\->' |
| o use tar, gzip, unzip, bzip2 |
|
tar cvf - . | gzip > filename.tar.gz |
|
gzip -dc filename.tar.gz | tar xvf - |
|
bzip2 -d filename.bz2 |
| To sort file |
|
sort +0 -nr input_file > output_file -- sort with first column(+0), using number order(-n), reversed order(-r) |
| To remove duplicated lines |
|
uniq input_file > output_file |
| To get first/last k lines of a file |
|
head -n 10 input_file > output_file |
|
tail -n 10 input_file > output_file |
| To get certain lines in a file |
|
sed -n -e 20,30p filename -- only print lines 20~30 |
| To replace all blanks after 1,2,3 with just 1,2,3 |
|
cat filename | sed -e 's/\([1-3]\)\([ ]*\)/\1/' |
| awk |
|
Line level handling |
|
|
awk ' {split ($0, a, "\t"); printf("%s\t%s\n", a[2], a[3])} ' input_file > output_file |
|
|
awk '{if ( ($2=="xxxxxxx") && ($1>150)) print $0}' input_file > output_file -- given condition |
|
To right justify 1st column |
|
|
cat filename | awk '{printf "%10d %s\n",$1,$2}' |
|
To sum numbers in a column |
|
|
cat filename | awk 'BEGIN { tot=0 } { tot+=$1 } END { print tot }' |
|
Generate batch processing scripts |
|
|
Move ls -1 * | awk '{ print "mv " $1 " " $1}' | sed -e 's/EXT_A\(.*\)EXT_A/EXT_A\1EXT_B/' |
|
|
Copy ls -1 * | awk '{ printf "scp host:/path/%s %s\n", $1, " ."}' |
|
To compare two sorted files |
|
|
diff old_file new_file | grep ">" | awk '{print $2}' > diff.added |
|
|
diff old_file new_file | grep "<" | awk '{print $2}' > diff.deleted |
| vi |
|
To change to UPPER and lower cases |
|
|
:%s/.*/\U&/ |
|
|
:$s/.*/\L&/ |
|
To delete ^M |
|
|
:1,$ s/Ctl-VCtl-M//g |
|
To view HEX value and recover |
|
|
:%!xxd |
|
|
:%!xxd -r |
Sep
21
2007
For Firefox
obj.addEventListener(’mousemove’, function(event){window.myEventHandler(event)}, false);
For IE
obj.attachEvent(’onmousemove’, function(event){window.myEventHandler(event)});
and you have myEventHandler like the following:
window.myEventHandler= function(e) {
e = (e) ? e : window.event;
mouseX = e.clientX;
mouseY = e.clientY;
……
}
Sep
21
2007
You have a table, say Tbl_Facts (Id INT, Grade INT)
What you want to do is to put number of rows for different values of Grade side by side.
You can use IF function to do so if you know all the possible values of Grade
SELECT
SUM(IF(Grade = 1, 1, 0)) AS CntGrade1,
SUM(IF(Grade = 2, 1, 0)) AS CntGrade2,
SUM(IF(Grade = 3, 1, 0)) AS CntGrade3,
SUM(IF(Grade NOT IN (1, 2, 3), 1, 0)) AS CntOthers
FROM Tbl_Facts
If you have a formula to calculate a score of your facts, say when Grade is 1, you get 10 points; when Grade is 2, you get 5, when Grade is 3 you get 0, otherwise you get -5. What is the total score of the rows in your table?
SELECT
SUM((CASE Grade WHEN 1 THEN 10 WHEN 2 THEN 5 WHEN 3 THEN 0 ELSE -5 END)) AS Score,
FROM Tbl_Facts
Sep
21
2007
Although this is not very elegant, it works.
SELECT @no:=@no+1 rownum, t.*
FROM (SELECT @no:=0) r, table_name t
Sep
19
2007
When you hike, sometimes you can get a cramp down in your calves, or even on your thighs. A cramp is a sudden, involuntary and painful muscle spasm. These hurt like the blazes, can almost cripple you.
2 things that cause cramp are (1) heavy exercise (2) loss of salt through excessive sweating such as in heat exhaustion.
To relieve cramps in your calves and thighs, straighten out your leg so that your knee is not bent. If the cramp is in the front of your muscle then bend your knee. Essentially this is to make the muscle as long as it can possibly get. If you get the cramp back in your calf not only should you straighten your knee but you should also point your toes up.
In all cases, massage the affected area so that you can get the muscle to relax. Also, it’s a good idea to get some fluids into you — sports drinks are great.
When the situation becomes not manageable, you should call for help and sometimes call 911 before it is too late. Sometimes, rangers will be the best resource to help. Remember, you need to give yourself a break, do not try to make your body work hard for you any more!
I have found a very nice set of Videos for Exercise & Fitness Advice on http://www.videojug.com/. Among which this title How To Deal With A Cramp In The Calf is very helpful.
Sep
06
2007
When you start your VPN client, sometimes you will get this error message.

The reason is as it states: "VPN Service has not been started." So you need to start the Windows service. To do so on an XP system, you can go to Start(M) -> All Programs -> Administrative Tools -> Services

You will see a window like this

Find the Cisco VPN Service, start it, and you shall be able to start your VPN client application now.