Monday, March 29, 2010

This is pretty cool


This is pretty awesome. Try it now: "Trương Thúy Ngân", "Truong Thuy Ngan" and Trương Thúy Ngân. The links will be opened via anonymouse.org to prevent customized search results from Google. You may want to use Google Vietnam version: "Trương Thúy Ngân", "Truong Thuy Ngan" and Trương Thúy Ngân.

You invaded my life, didn't you?

Friday, March 26, 2010

UML Diagram - Very first steps

Well, this is our second assignment of Java: writing an application which allows user to create a UML diagram and generate the code (with empty methods, of course) in Java. Actually the assignment suggested another reversed approach: reading Java source code files and generate the UML diagram but our team decided to choose it.

After some discussion, yesterday, mr Tran Viet Son has done the data structure for the application which is pretty interesting and I'm showing you now. The source code can be grab here. All the core classes are under a package called com.tranvietson.uml. The test code is something like this

Wednesday, March 24, 2010

vBulletin users list in AdminCP Options

I intended to write about this for a while but I haven't had time. This is pretty cool stuff. When ever you want to have a users list for your plugin? Let's say you want to give some members a special permission to use the plugin. What's the best way to do that? Well, adding a field into `users` table is not really good. Setting up a new bitfield permission is interesting but if some other coder use the same bitfield value, disaster! Hmm, the most secure thing will be a separate table to store authorized userid, really good but slow and costly (and stupid somehow), nobody implements a new table just to store those userids! Many coders will use vBulletin Core Options system, create a free type input box, ask the Administrator to input userids, seperated by comma, etc... That's a good approach I think since it's quick and easy, most Administrators have enough knowledge to get the correct userids. But well, if we can make it better, why not? That's why I came up with this idea: use vBulletin Options system to store and load that piece of data but I will display usernames along with userids. That's really useful but then I think why don't I improve it even more? Store user basic information in an array, serialize it to store in database, unserialize when needed. Administrator can now input usernames to add to the list and remove a user from the list if they want. Piece of cake!

Ok. That's enough of talking. I'm going to the main points now.

First you will need to have the option



Use the hook location named "admin_options_print". This will print out our interface



Ok. Now is the part where we parse thing and store information


Huray! See if it work or not


You may want to grab the plugin here. It does nothing except this beautiful users list. Have a nice day.

Saturday, March 20, 2010

Expression Handling (2nd approach)

After the first implementation, I have made a few more improvements and now, after submitting my assignment I think it's safe to post the final version of the classes here. Source code is available here (MediaFire). You may want to read the documentation here (Google Docs, in Vietnamese). The script is now accept natural expression input from console. The most interesting feature is each variable can also be enter as an expression (and it will ask for it's variables also). What does this mean?

For example, you input an expression: 5+x+y*z. Obviously, it will be calculated at 5 + x + ( y * z)
But because you used 3 variables, it will ask your for x, y, z. I will assign x with value of 20, y with 10.
Now is the fun stuff: I input "a-b" for z. Uhhhh. What do you think the script will do now?
Ah ha, it will ask for z.a (which means the 'a' variable of 'z' expression), 100 to go
And then z.b: 1000 to go
The result is -17985 (I'm not really sure with this result but you can check yourself)

That example is from the documentation. Feel free to leave comment

Tuesday, March 16, 2010

Expression Handling

I intended to post the whole Java source code but unfortunately, there are 8 files in total so I think it will be better if you get them from MediaFire. Don't worry, there are only ~500 lines of code and I wrote comment for every single method.

Actually, the main class (Expression) design isn't done by me 100% because I have to follow the assignment requirement (also in the uploaded file). I don't really understand why we have to have 2 constructors and then another append() method. Really, I can't get it. Tell me if you have an idea.

Anyway, using the Expression class is very simple. Here is how I tested it:



Please note that it will run but an Exception will be thrown about variable b hasn't been initialized yet. You can either remove b from the append() method or use setValue() method to assign an value for the variable.

Also note that: currently the class support adding, subtracting, multiplying and dividing. Functions can be supported easily by writing a new class (ExpressionFunction?) and change the RPNize() static method (using Shunting-yard algorithm) a little bit. All comments are welcome. Thank you for reading

Monday, March 15, 2010

Dining Philosophers

Heck, this is my assignment at college. Took me 1 hour looking around to figure out how to use wait() and notify() methods of Java Object. It's kinda cool. Let's rock and roll.

Full source code is available here.