Monday, June 30, 2008

Handle Chinese in Python while using Pydev and Pygame

I never really try to program anything that has to deal with the Chinese before, even though I'm a 100% Chinese. However, I recently came accross a problem of renaming some of my files, which have Chinese in them. I decided to write a little script to do the task in order to practice my Python skill. Very soon I encountered the unicode problem. After some searching and hacking, I was able to solve the problem. To avoid forgetting the solution, I put down this sample program as my note for future reference.

To display the string correctly in the eclipse console, set the encoding to UTF-8 under "Run Dialog => Common". Also in the project properties, set the "Text file encoding" to UTF-8.

# -*- coding: UTF-8 -*-

import sys
import pygame
from pygame.locals import QUIT

pygame
.init()

# This string contains both simplified Chinese and traditional Chinese.
unicode_string
= u'Hello Unicode String!简体!繁體!'
# Test the string in Eclipse console.
print unicode_string

# Must use a font that is capable of displaying Chinese.
string_font
= pygame.font.SysFont('simsun&nsimsun', 16, True, False);
string_surface
= string_font.render(unicode_string, True, (0, 255, 0))

# Display the string to the pygame screen.
screen
= pygame.display.set_mode((300, 40), 0, 32)

while True:
# Missing this event handle loop will cause the pygame window freezes somehow.
for event in pygame.event.get():
if event.type == QUIT:
exit()

screen
.fill((0, 0, 0))
screen
.blit(string_surface, (10, 10))
pygame
.display.update()


Sunday, June 29, 2008

Ready . . . Get Set . . . Go!

It's been a while after my last post. I was trying to keep up the posting as the summer starts, but didn't expect the blogger was blocked by the GFW of China. -_- Fortunately it's finally unlocked now, and I can access my blog again.

It seems like the Blogger has upgraded the system and added a bunch of cool new features. Therefore I figured I might as well give a new look to my blog, and I even changed the title and URL of the blog.

Since I don't really start looking for jobs until August, I have quite a long summer to spend. I think it will be helpful for me to learn something and probably do a project during this time. Currently I'm learning the Flex 3 and python, even thought they don't really go together. Also, an old article about making a game in a week came across me accidentally, and it really inspired me. I think I will try to do something similar in this summer.

After all, 1/3 of the summer has been gone, and I think I am getting ready. It's time to run.

Wednesday, April 2, 2008

Code Review: Informative Workspace Project

Since I am one of the developers for this project, I would like to dive right into what the weakness are for our system, because those are what really matter to me.

First of all, the current system, in short, is just a tiny bit more than useless. The reason I said it's almost useless is because the current system is very limited in terms of functionality, and it's totally a failure in terms of usability.

For the functionality, it only has a date picker that doesn't really do anything rather than allowing the user to pick a date (hell, so what!), and a tree that displays the structure of the system with some hackystat sensor data for the related members. (yeah, but in a totally ugly and sloppy way) And both of these don't even work for every project. The projects are all set, the user cannot create or delete any project. Heck, the user can't even have much interaction with the current system. We spent quite a lot of time getting the directories tree up, but it turns out that it's not even that useful for indicating the logical "whereabout" of the developers. The structure of the tree gives more information in terms of how the project is set up, and how the files are laid out. But this kind of information is easily obtainable from the project repository, and it's not something that you need to see 24/7. In other words, having that kind of information 24/7 in the telemetry wall is a little bit waste of resource.

For the usability, I didn't realize it's such a great trouble to modify the code until someone aims me about the problems he encountered while tackling the code. I have to agree, it's simply lame. Things that seem to go without saying for me could be quite meaningless to people who didn't write the code. Even with the comment, there is not much help. Not to mention that the comment for the system right now is not sufficient at all. The idea to push back the implementation of a GUI for the user to customize the account information and such is proven to be wrong. It is almost a necessity from the view point of the users.

Finally, when it comes down to the point that is the system actually useful or not, my own opinion is that given the vision of the system - to give an overview of the project - this system should be very useful. However, the current system certainly doesn't fulfill this vision. The poor representation of the member status and the over-usage of the screen estate are major problems right now, and it is obviously not the correct way to go. Professor Johnson recommended the usage of JTreeMap. Although the idea of it seems very amusing, the implementation of it doesn't really fit into the current system. I can almost feel the the big change of the system is coming along. Well, hopefully it is a good one.

Wednesday, March 19, 2008

Code Review: iHacky Project

I did my review by following the installation guide from the iHacky project site. The process is so easy because I already have a facbook account and hackystat account. The actual usage of the application is pretty much the same as what the team demonstrated during the class time, and there's really nothing much I found useful at the moment. So far, the only useful bit of functionality of the application seems to be the searching for the peopl who use the same tools as me. (On a side note, when I tried the search, the auto-complete feature didn't work for me. Is there any special steps required to trigger it?)

In terms of the source code, since I have literally no knowledge of PHP, I can't give too much comment on it. However, I do see the lack of QA tools used for the project. The team should at least provide a way of building the system, so that the project can be actually applied in the telemetry hudson.

In terms of documentation, the installation guide should probably specify that the user must be login into facebook before they actually click the link to the add the application. Also, I don't understand why the application cannot be found within the facebook application search, because that was the initial way I tried to find the application, and I believe that's how most people will look for an application in facebook.

In terms of usability, there are quite a lot of problems exist in the current system. First of all, in the profile, the user is required to enter their hackystat account info. However, there's no way to change this info after it's been set. Also, I tried with another account with false hackystat info, the system didn't detect that. I suggest the team to add some sort of authentication mechnism on this. Second, the tools tab, as the Hong said, should be integrated into the profile page. Then in the profile page, the tools should have link on them or near them that the user can simply click on the link and find the people who are using the same tool. Third, the team tag seems to belong the projects tag. I don't really see the reason of separating them. Also, in the projects page, I personally don't really need the "default project". Maybe a link to create new project in hackystat can be included here. Lastly, I don't know what the invite tag is for.

Honestly, the system right now has very very limited actual usage. Instead of trying all sorts of different ideas, I think the team should be focusing on one particular feature and keep working on it to make that feature become actually useful. The tools is one of the good features to work on for now. By enabling the user to edit the tools they use, and finding other people who use the same tools, are something good to know. Also, besides what tools are used, I would also like to know the information on how frequent the tools are used, when was the tool used last time, etc. The hackystat sensor could provide all these information easily. Right now, only the projects information comes from hackystat, and it's not something that useful for me. Also, the whole class is suppose to have this system installed by now, so the team could use us as their initial users base. After all, facebook is all about community connection, but the system is only been used internally by the 3 developers right now.

Overall, the iHacky team is on a good start for the project. From the developer guide, I can see how hard it is for them to get their project up on facebook and running, and they are using PHP, which is something that they are not familiar with. Right now things are set, I'm expecting them to provide something more insignful and useful in practice in the next milestone.

Monday, March 17, 2008

Hudson - My first impression of continuous integration

Things I learned about continuous integration that I did not know before
The Hudson is running on the CSDL telemetry wall since the semester began, and I kind of grab the idea of what it is doing by looking it so often since my project requires me to look on that wall every now and then. What I didn’t notice, however, is that it not only does compile and build the project, but also runs various QA tools, such as checkstyles, PMD, findbugs, JUnit, etc. Also I didn’t know that Hudson is so automated that once you set it up, you can almost forget about it. The features that Hudson offers are far more than I expected.

Problems I had to resolve in order to get the informative workspace system to build under Hudson
I have encountered various problems while I was trying to getting my informative workspace system to work under Hudson, but the real problem that took me quite a while to figure out was to make the system deploy in tomcat by Hudson. First of all, since the system is deployed in tomcat, it requires the tomcat to be running first. And since tomcat is using the default 8080 port, I have to somehow change the port for Hudson. (Well, actually now I think about it, maybe deploying Hudson in tomcat would also solve the problem.) Anyways, what I did was putting the "--httpPort=8081" parameter. However, changing the port didn't solve my problem. I still got the error of deploying the war file into tomcat, and it is a http response 505 error. After some googling, I guessed the problem was caused by the "C:\Documents and Settings" folder, which was the default home directory for Hudson to store a local copy of the SVN files. Since the way I deploy my war file is using ant script, and ant doesn't like the spaces, it simply refused to work. After I set up a variable HUDSON_HOME and points it to a folder without space, things went very smooth. (I still haven't set the emma up, but I was thinking to exclude it from my normal build routine anyways, so I will just leave it as it is for now.)

Update: Later I tried to create a new job with space in the name and the deployment also failed. This could be the original reason for the failure in the deployment. But since ant doesn't like space anyways, I would rather to keep things simple by eliminating both the spaces in HUDSON_HOME and in the job name.

Steps Philip has to carry out in order to get the informative workspace system running using the CSDL Hudson server
Other than setting HUDSON_HOME to a folder without space (which I assume is already been done), I don't see there are any extra steps needed for getting the informative workspace system running in the CSDL Hudson server.