Monday, June 30, 2008

I solved the Rubik Cube!!

I finally am able to solve a scrambled Rubik Cube! I started playing with the cube when I was a kid in 1980s. I declared it as impossible to solve back then, and remain impossible after I have all grown up.

What makes it so difficult is that it is hard to build on your previous success. It is already hard to solve 1 side. If you can solve one side, you MUST mess it up to attempt to solve further. This frustrating cube seemed to have lost its popularity for a couple decades and now making a comeback. I knew there are solutions, I actually saw a booklet when I was a kid (which didn't come with my cube in 1980s), but the instructions were too hard for me.

It is decades later and now I am ready to tackle it again! Being able to solve it seems to be a fun skill to have. My new Rubik Cube comes with a 7-step solution sheet! But just following the instructions isn't so easy! Some sequence are hard to remember, and it is already the easiest layer-by-layer solution.

Terminology: each face of the cube is named: Up, Down, Left, Right, Front, Back, much like x-y-z axes. "U" means turn the upper face clockwise, "Ui" means turn it counterclockwise. Ok, so far so good.

My heart sank as I read the first step: you must solve the green cross on your own.

Fortunately after actually playing with the cube, it isn't so difficult to get the green cross. Then we can use a sequence to insert the green corners! Wow, without this it is hard to solve even 1 side.

Now, we can turn the solved green side to the bottom, the next step is the middle layer. If you see an inverted "T", you can move the tip of the inverted T left or right using a (fairly long) sequence.

Solving two layers are not too difficult.

Then it remains to solve the (blue) top. Now it gets harder.

You need to first get a blue cross. Look around for a specific pattern then apply another sequence to make the blue cross. It is not so hard yet.

The next step is to put the blue cross correctly. Apply a sequence to move the edges, repeat if necessary. (this is a little tricky, when you apply the sequence one block stay and 3 blocks move)

The only remaining cubes are the 4 corners. They can be all scrambled up!

Next we apply a sequence so that all four top corners are at the right position, color doesn't matter now (repeat sequence if necessary).

Now the last step, with red facing front, apply a sequence to fix each corner! Fix one and you mess up the rest of cube! Worry not, keep going! Fix all four corners (keep red facing you) and we are done!

How satisfying to be able to solve it!!

The sequences are difficult to remember, and it IS a lot of moves. How did those people solve it in little more than 20 seconds? How did they do it blindfold?! Ah, the method in the booklet is just the beginner's method.

On my own, I am never even able to solve just 1 side without the solution. I have NO clue how did they come up with the solutions.

Nowadays it is not just solution booklets, there are websites that you can literally put color of each face and a solution will crank out for you! There are even detailed demos on youtube!

The cube is no longer impossible to solve!

However, it will take me a while to practice and remember the patterns it takes to solve one.

Last thought: when you buy a Rubik cube,it is perfect condition, all sides are arranged properly. Why did you mess it up in the first place and want to put it back the way it was?

AJAX was here

I was able to create simple AJAX code for the most frequently used example to spice up your information website: stock quote and weather information. Where do you get stock quote and weather information? There are PLENTY of sites. Yahoo!Finance is a popular place for stock, and the national weather service give you the info.

Old school HTML will simply provide links to information on those service providing sites. Nowadays people demand more! How about those info right on your site? This is nothing new. People have been doing that for YEARS. Now I am asked to put this in the company's intranet site.

Just how do you get information from another site into your site? One way is AJAX. Basically we quietly make a call to service providers and they will send us information, in XML, or comma-delimited, or whatever, and the event handler will quietly handle the response back from the service provider. (That's the first A, which stands for Asynchronous, in AJAX). The J is simply Javascript, and the next A is merely the conjunction "And". The X is everybody's favorite XML.

The task now becomes: just what is the URL to the service provider? What type of format am I getting back? How do I parse the results?

Hopefully you will find what you need from your provider.

This link gave me some great examples to get to weather service.

This link provides the nuts and bolts I needed to get stock information! Hmm, how come I can't find field description from the CSV in yahoo!finance? I pulled all that JSF stuff out and just do simple HTML.

Thursday, June 26, 2008

Philosophy and Confucius

Few has ever achieved the status of Confucius, the ancient Chinese thinker who shaped much of Eastern thoughts. His words are still frequently quoted, although some may not realize.

Do we ever quote anything from western philosophers such as Aristotle or Plato?

I am poorly educated, I can't quote any statement from any western philosopher, other than the now laughable 4 (or 5) element theory and the tale of Galileo's ball dropping experiment that marked the dawn of modern science. Math and computer graphics students may have heard of the Platonic solids.

It seems like the influence of ancient philosophers has diminished in Western culture, or that we are already practicing the society put forth by ancient philosophers without realizing? Democracy is probably rooted in ancient thoughts of some Greek philosophers but I am sure only a few elites can tell you the details.

Some of Confucius's idea are still interesting to read about. Confucius did not attempt to explain natural phenomenon like Aristotle, rather, he focus on building character, interpersonal communication, and how to run a country!

See this wiki article, the Chinese edition of course gives much more details.

Some famous quotes, with my rough translation:

"(Confucius's Student) Mr. Chung remind himself with questions 3 times a day: Am I loyal (to my king) or am I always planning to take advantage? Do I communicate with my friends but not trust them? Do I preach but not exercise what I preach?"曾子曰: 吾日三省吾身:為人謀而不忠乎?與朋友交而不信乎?傳不習乎?

This are such great questions! Mr. Chung strive so hard to be a great man.

"If there are 3 people, there must be a teacher for me within, choose his good stuff to learn, change the bad stuff of him" 三人行,必有我師焉。擇其善者而從之,其不善者而改之。

It is good to learn from friends and help friends grow isn't it?

"If you want to be quick, then you won't reach there" 欲速則不達。

This is so frequently quoted! How many times are you on a rush project without resources you need?

"If you want your work sharpened, you must first sharpen your tool" 工欲善其事,必先利其器。

This is quoted often too. Are you given a lowly computer to run that memory hog software development tool? Invest in good equipments.

"Be patient or you may ruin big plans" 小不忍則亂大謀

"See no evil, hear no evil, say no evil" 子曰:「非禮勿視,非禮勿聽,非禮勿言」

This is a very small sampler of wisdom statements as Confucius revealed in the Analects in his discussion with his students (that I copied off from that Wiki article). Although some of these may sound "common sense". Confucius collect them all.

Confucius is focusing on being the kind gentleman (Ok, it is very hard to exactly translate "仁") that practices rituals 禮.

Confucius became the role model that eventually got promoted to a "saint" level. Chinese history does not have religious saints like St. Paul or St. John. In fact, Confucius stay away from religious talk though he does have many worshippers! 子不語怪,力,亂,神.

Confucius is required reading for generations of students until modern times. Language has evolved so much that Confucius become hard to access for today's students. It needs a modern translation! (ok, there are probably a lot, but the original text is such classics).

Confucius text are not HUGE like Aristotle or Plato. It would be a great 1-semester college or even high school course.

Chinese students are trained to read and follow those in authority, and not encouraged to question authority.

Today's students should read philosophy with an open mind. Know what the ancient greats say, be able to agree or disagree with their views. It trains thinking and writing! Just what is preventing YOU to become the next great philosopher?

Tuesday, June 24, 2008

A new CAR

When I watch the Price is Right, there is such EXCITEMENT when the contestant has a chance to win a new car. The contestants jump up and down as the host explain how to win the car by playing a certain game. Ok, I used to watch Price is Right,haven't watched in many years. Why are some game shows so long running? ok, that's another topic.

Cars are exciting gifts for TV game shows, or awarding your children as they proudly graduate from high school.

How about a new car for perfect attendance for an elementary student? Check this news item.

http://www.nbc5.com/education/16686208/detail.html?rss=chi&psp=news

This is too big a gift, even for a straight A elementary student with perfect attendance. A couple bookmarks are just fine for encouraging the kids.

It is time to demand MORE for students! Attending school is their BASIC responsibility! If a school age child is not sick on a school day, the child SHOULD be in school. It is non sense to award them with such big gifts. Waita minute, the kid is not even allowed to drive until many years later. What's that for?

Waita minute is it a promotion trick for the auto maker?

Monday, June 23, 2008

USB toys

USB ports are great. Thumbdrives killed off the flaky floppy disks. Plug in external hard drive for extra storage. Plug in a card reader to read files from your camera, or your music device to download songs. Standardization is good sometimes.

USB can draw power from your machine to charge your device or even power a toy. A long time ago I saw a magazine featuring the USB Missile Launcher. Saw the real thing in a store. Fun stress relief if you have friendly neighbors in your cube at work.





I also saw USB Chess which I almost want to buy:




For decades most people play with computer with 2D chess pieces on screen. It feels different to play on a real set.

If it is prettier, not straight dull black and white (perhaps wooden pieces) I would have bought it.

Additional toys that looks interesting on Amazon are:
Screenmasher



Tengu





This is classic example of fun innovation. So USB can delivery electricity? Put it in use!

Am I getting these toys? No. Toy collecting is luxury for the rich. I window/web browse shop. I buy ONLY must-have items.

Friday, June 20, 2008

Street Fighter IV

I spent a decade playing the fighting series Street Fighters.
SF1 is hard to execute moves, it was less fun then Yie Ar Kung Fu. SF2 is major hit when I was freshman in college, followed by a long series of versions and updates: Champion Edition, Turbo. More characters! More supers!
Then there was a time when Capcom refuses to do a sequel, instead, they do a prequel with the kid version Street Fighter Alpha series.... Then there was the rough polygon 3D series known as EX. And there was the vs. Marvel series... That super fireball is a big laser beam! (They had to upgrade Ryu to fight the powerful XMen)

I spent countless quarters. I am still not a REAL good player, but fairly decent.
I spent lots of $ on the GREAT Street Fighter comics made in HK... That is such great artwork and story.

Then SF3 was there. Eew, it wasn't so impressive! Only ONE super moves? I actually didn't play a lot with it, but it wasn't so revolutionary. SF1 to SF2 was revolutionary. SF3 OUGHT to be revolutionary, ought to be real fun. But nope, it was a big letdown.

Finally, after a LONG time, Street Fighters are back from the dead, there is wow amazing looking Street Fighter IV! Watch this impressive video here. Now THAT'S revolutionary. That's what SF3 should be.

http://www.amazon.com/Capcom-34009-Street-Fighter-IV/dp/B0012N5MIO/ref=pd_bbs_sr_1?ie=UTF8&s=videogames&qid=1213994929&sr=8-1

Computer graphics have evolved SO MUCH! Gaming has evolved so much. NO ONE is going to the arcades now. It is a sunset industry.

But am I going to buy a PS3 to play this? Not really. There are other priority of life now. Life also revolved much.

Java Server Faces: a first look

In the beginning there was Java Servlets: Server-side Java code to handle HTML posts. That was a breakthrough. Then the world gets sick of cranking HTML outputs with out.println("<table><tr><td>Your result is..."); Then there was the ingenious idea of embedding Java code right inside HTML, and there was Java Server Pages JSP. Waita minute, does this ingenious idea come from copying Microsoft's ASP? JSP is out for a decade now.

Since then, people has always wanted to organize their JSP pages with their java classes. For years people try to use XML to associate their JSP and java files and handle the submit button actions. The Model-View-Controller is exactly what people want to do. Many such frameworks exist, most notable is Struts and Spring (terminology came from supporting elements of your car under the hood).

The idea of these frameworks is to first hack the WEB.xml in java project to handle files with .do or .whatever extension to be processed in their servlet hidden in their jars. That servlet will figure out how to direct to the corresponding java "controller" object to handle initializing or any submits by looking at some XML configuration files.

Frameworks may make use of custom tag library (a feature of JSP) to make you relearn all the HTML tags that you know and love to make it play well with the framework.

Sun came up with its own: Java Server Faces (JSF). It is worth noting because it comes from Sun.

The idea is this: every page is associated with a bean. Beans are nothing more than some private variables and get/set methods. The association is in the faces-config.xml file. Then each JSP has a list of navigation rules. Submit button hit? make it call your method, or go to another "view", which is the JSP.

Every HTML element is re-implemented by the html taglib. instead of <INPUT type=text...> you do <h:inputText...>
The upside: JSF provides validation rule, such as make that a required field. (Ok, I can implement my own flexible rules too, the way *I* want it)

JSF adds additional syntax with the # and the {} in accessing your bean, like <h:inputText value="#{myclass.firstName}">

You can define a HTML data table and use the taglib so that you don't have to write a loop to loop through your results.

Doing View Source on the generated page reveals each javascript is generated for you to do all sorts of stuff. We are one more level of abstraction: we don't handcode those javascript. One way to look at it is that it is better because of less code, another way is that it reduces your flexibility.

I am still learning what JSF can do, it looks like you can do a lot, including working with AJAX. The cost of is new taglib syntax and use one bean per page, and be careful with that faces-config.xml. Note: The JSF file itself gives no clue about where the bean it is using is located, no import statement is there. I like this simple tutorial: http://exadel.com/tutorial/jsf/jsftutorial-kickstart.html

It is worth noting because it is part of Java, and seems to be endorsed by a lot of web applications.

Monday, June 16, 2008

Why does a piece of cloth pick up spilled water?

I watched a HK-made science TV show for kids featuring this question...

If you spilled water on your floor, you put a piece of cloth or paper towel on it, why does the water gets absorbed?

This is the same concept explaining how sponge able to hold water, just how does it work?

Yikes I am stumped. I am a college graduate and I can't explain this.

The phenomenon is called capillary action.
I don't remember seeing that formula in my college physics class. Of course, the formula is not shown to the elementary school audience watching the show.

This also explains how plants draw water from the earth.
Watching science education shows can be a humbling experience. There are many many scientific phenomenons that I can't explain!

Thursday, June 12, 2008

Outrageous convservatives

In google news, I saw this shocking headline: GOP likely to attack Michelle Obama in election fight.

Ok, so GOP is not physically attacking her. What a relief.

But they are going to attack her like this:

Michelle Obama was widely criticized on conservative blogs when she said "For the first time in my adult lifetime, I am really proud of my country" at an appearance on behalf of her husband in Milwaukee, Wisconsin, in February.

The Obama campaign said Michelle Obama's comment reflected her excitement about the grassroots support her husband is receiving, but conservatives said the statement raised questions about her patriotism.



These "conservatives" are outrageous and NAIVE.

Listen to the strategist


"Considering there are so many issues -- legitimate issues -- that you can use on Barack Obama, to attack his wife to me is sheer utter stupidy of the highest level," Stephen Marks, a Republican strategist, said. "Mr. Obama is going to come to his wife's defense and it's going to humanize both of them."


Focus on issues, focus on the candidates, not on their spouse.

McCain needs to show himself better than what Bush can do.
Obama needs to show the changes are actually going to work

Tuesday, June 10, 2008

D

Long long time ago there was a programming language known as BCPL. Then there was B, then there was C! Unix is written in C and that become de facto standard of programming. Structured programming was much much better than hacking assembly.

Object oriented programming came in and shook the software world. C needed an update. Should it be called P, the next letter in sequence? or should it be called D, the next letter in the alphabet? I've heard that the marketing guys avoided "D".

The OO successor of C was ingenuously called C++! The C operation ++ was attached to the name of the language!

Then there was java, completely different name without any attachment to BCPL name or the alphabet, created out of frustration of the ugliness of C++ (but slowly it is gaining the ugly stuff such as templates!)

Microsoft's relationship with Sun got sour... It needs its own C++ based modern language... what should it be called? Oh my, smart name, C# as in the next music note!

Today I discovered a rather little known, rather obscure new C-derived language, called D.
http://www.digitalmars.com/d/2.0/index.html.

Do we need another language?
The trend nowadays is everyone create their own new languages. Enter Perl, Ruby, (someone will soon do Emerald?), Phyton etc... As if their goal of their lives is to tell their mom: "look mom! I've got a new language!" The world seems to fall in love with templates and closures.

This D language has many rather obscure stuff. My prediction is that it will not fly.
Java and C# are here to stay. We only need a new language if it is revolutionary.

Anyone ever thought of naming the next C like language something C+=? so you start with C+=2, then C+=3, ....

Chinese chess positions

If I am pursuing a PhD in computer science, I think I will pursue chess algorithm as my thesis!
It will be more fun than other boring academic stuff such as P vs NP isn't it? Chinese Chess and western chess are both easy to learn but very difficult to master. (Think you are good in Chinese chess? Try xiexie, or play with an elderly street player in some streets of Hongkong). In strategy games, experience count!

Ok ok, I know it is difficult to become a PhD, and the best part is: I don't have to be one to earn a fairly decent living, No one will pay for this work unless I am real good that can create Deep Red to beat the top Chinese player in the world (who is most likely, um, Chinese). Ok, I am just a so-so student, probably can't get into graduate school in the first place.

So I went to Wiki to see what's there about Chinese chess, good basic information there. I came across with this as external link.

http://www.csie.ndhu.edu.tw/~sjyen/Papers/2004CCC.pdf.

This is most interesting in the PDF: the value position of each piece (page 10).


14 14 12 18 16 18 12 14 14 4 8 16 12 4 12 16 8 4
16 20 18 24 26 24 18 20 16 4 10 28 16 8 16 28 10 4
12 12 12 18 18 18 12 12 12 12 14 16 20 18 20 16 14 12
12 18 16 22 22 22 16 18 12 8 24 18 24 20 24 18 24 8
12 14 12 18 18 18 12 14 12 6 16 14 18 16 18 14 16 6
12 16 14 20 20 20 14 16 12 4 12 16 14 12 14 16 12 4
6 10 8 14 14 14 8 10 6 2 6 8 6 10 6 8 6 2
4 8 6 14 12 14 6 8 4 4 2 8 8 4 8 8 2 4
8 4 8 16 8 16 8 4 8 0 2 4 4 -2 4 4 2 0
-2 10 6 14 12 14 6 10 -2 0 -4 0 0 0 0 0 -4 0
Position values of a Rook Position values of a Horse


6 4 0 -10 -12 -10 0 4 6 0 3 6 9 12 9 6 3 0
2 2 0 -4 -14 -4 0 2 2 18 36 56 80 120 80 56 36 18
2 2 0 -10 -8 -10 0 2 2 14 26 42 60 80 60 42 26 14
0 0 -2 4 10 4 -2 0 0 10 20 30 34 40 34 30 20 10
0 0 0 2 8 2 0 0 0 6 12 18 18 20 18 18 12 6
-2 0 4 2 6 2 4 0 -2 2 0 8 0 8 0 8 0 2
0 0 0 2 4 2 0 0 0 0 0 -2 0 4 0 -2 0 0
4 0 8 6 10 6 8 0 4 0 0 0 0 0 0 0 0 0
0 2 4 6 6 6 4 2 0 0 0 0 0 0 0 0 0 0
0 0 2 6 6 6 2 0 0 0 0 0 0 0 0 0 0 0
Position values of a Cannon Position values of a Pawn.


It is well known that a horse in the middle of your palace is a bad position, as a cannon can easily pin you down and your Advisors (Guards) are disconnected. You get -2 points. But according to this chart, there are worse positions! Cannons at your opponent's palace are big negative positions.
Look at the most valuable position. a huge 120 point when your pawn is at the middle of your opponent's palace! Waita minute, how come the rook at the same place is not worth nearly as much? Um, I think the values for Pawns should tone down a bit. I have another opinion: the Cannon at the bottom line is very valuable! One cannon in the middle line and one in the bottom is a formidable situation!

Friday, June 6, 2008

Java Twix

No, this is not a new programming tool, rather, a new tweak to a favorite chocolate bar.



As a java programmer, I cannot resist this. Hmm, this is good choclate with taste of coffee. Hmm, it is REAL good.

I'll worry about the hundreds of calories later. It is so difficult to lose just 100 calories, but so easy to take in hundreds.

Wednesday, June 4, 2008

Monochrome Nostagia

Today's monitors and LCD screens have vibrant colors. That is so unimaginable in the old days when there was just monochrome monitors that was either green or amber. I would not have imagined being able to watch a full color movie on a computer today back in the 1980s.

I played with the Commodore PET, Commodore 64, the IBM PC, Tandy 1000, and the Sperry. Thanks toChicago Public Schools for providing those toys!

Ok, the Tandy had color monitors (though only a CGA with 16 colors). But some older 8088s, 286s or Sperry didn't.

A while ago I discovered this fun DOS command. COLOR.

Try "color 0a" at the DOS prompt to simulate a monochrome monitor. The parameters of COLOR are 2 hex digits, meaning 16 colors, like those for a very old CGA monitor. Have fun.

Found a great Euler page (in Chinese)

Recently I encountered some fancy phone: the blackberry. It's got a colorful screen! Hmm let's see what apps it comes with. Ah, I found the calculator.

Each time I have my hand on a calculator, I TEST it!

-9, square root, will I get a generic E or "Error" spelled out?

5 / 0 =. Will I get a generic E or "Division by Zero!" error?

1 - 5 =. Will I get a negative sign in front, in the back, or the word "Minus"?

Ok, it gives me -Error-. Hmm, why does the square root called a "root"?

See, I understand why the unix superuser is called the root, as users decdend from it like a inverted tree... I understand why my ancestors can be referred to as my root... Why is the "radical" operation called "root"?

I decided to google around. I haven't found the answer yet. Ah, I found that the square root of 2 and 3 has a relationship with arctan and π! I have yet to understand the equations... (to be continued...)

I also found the following great discussion of the great mathematician Euler:
http://elearning.emath.pu.edu.tw/mkuo2003/2003mh/VII/18thold2/1894Leonhard%20Euler/eular.detail.htm

I left the google perference to Chinese page only.

If you survey people who are the greatest mathematicians, many will say "don't know" or "don't care". For those who do know, you may get people like Euclid, Newton, Archimedes. Euler should be among the list of the all-time greatest! (So do Gauss, Galois,... and more)

Obama makes history

Obama has won! Made history! In fact, either Clinton and Obama would have made history as first woman or first black to become Democratic nominee. That moment came as soon as John Edwards drops out.

The next question for Obama is: who would be your running mate?

Is Clinton going to be the VP candidate? Waita minute, Clinton offered Obama to be HER VP candidate not too long ago.

Obama should now think: why am I not able to capture some big states that Clinton can?

McCain should think: can I deliver the CHANGES that people Obama promise? Please, try to function without that teleprompter

Tuesday, June 3, 2008

Scumbag and gridbag

Even Bill Clinton can't control his language by calling a reporter a "scumbag". See this link for details.
Some reporters are slimy and sleezy. Yes, some are scumbags. It is interesting that some words are classified as appropriate and some are not.

In Java programming there is a difficult-to-use thing known as the GridBagLayout that one needs to know a few things about to pass the Sun Certififed Java Programmer test.

In Java UI, you add controls to a form in one of the defined Layouts. Unfortunately there is simply no way to put them on your specified coordinates! You can't even specify the exact width and height of a button either in most layouts. The gridbaglayout is the most cusomizable layout but it is just very hard to use. Java HAD the opportunity to be a great platform for rich client programming. They blew it. Java UI are not nearly as cool as what Flash can do. Java is retreated just to server side programming.

I call it the ScumBagLayout.

Monday, June 2, 2008

Talk and repent cycle

Obama's pastors say sensitive political comments, stirring up controversy, apologize after realizing trouble.
Sharon Stone also says something inappropriate about the China earthquake, soon apologize after knowing that irritated 1/4 of the earth's entire population.

Think before you talk. Adults should be able to do that. It is wasting everybody's time to say something outrageous then repent.

Here is some ancient wisdom.
"Sickness comes from things going IN your mouth. Trouble comes OUT of your mouth. "

Translation: what you take in (food) can make you sick. What you say can get you into trouble.

Is church a good place for sensitive political comments? NO!

The pastors should stick to their Bible, isn't it?

Let me remind those supposed-to-be-well-respected pastors:
"When words are many, sin is not absent, but he who holds his tongue is wise." (Proverbs 10:19)

"but no man can tame the tongue. It is a restless evil, full of deadly poison" (James 3:8)