Htam::Diary.Theme(cs)

Posting theme: computer science.

Themes: { PHOTO, SURF, TT, VB, TACIT, CS, SCIENCE, SPORT, BIBLE, IM, HTAG, MATH, COMP, FAITH, SYSOP, TEST } =
htam@192.168.0.*
2007-06-16 23:59:59
[CS] Mcabber0 comments
This Saturday, I decided to try out some text-based jabber clients.  Since Thursday, I've tried Kopete, Psi, Pidgin, and Finch.  The first three are not text-based, and I decided I prefer text-based clients.  (My AIM client is pork, which is written in C, and I have modified it.)  I tried Finch, but the interface was unsatisfactory.  The code was also hard to read.  I found a bug but was unable to identity the correct place to change in five minutes.  (When I first used pork, I was able to find the place to make a feature addition in five minutes.)  Apparently Centericq also supports Jabber, but since I turned it down as my AIM client (in favour of pork), I find no reason to try it this time.  I tried Mcabber.  To my pleasant surprise, it was very good.  After a few minutes, I was able to identify where I would like to change the code (the client is also written in C, one of my most comfortable languages).  I changed its timestamp format (a must for me), changed the command character from a slash (/) to a backslash (\).  This has to do with my familiarity with (La)TeX; hence I performed the same change on pork when I started using it.  I also utilized its event handler to use the on screen display engine that I have been using for AIM/pork.  Now both AIM and Jabber communications will be displayed on screen.  All this work for what?  To use Google Talk, of course.  There are two very good friends of mine who seldom use AIM, but frequently use Google Talk.  In one sense, I spent all of today trying to establish proper communication channels with them.

My next work for Mcabber is of course to implement a text replacement system.  I also plan to port features of pork and Mcabber to each other.  Besides porting my text replacement plugin for pork over to Mcabber, there are other features that can be ported.  For instance, the window number system of pork is preferable over the alternate functionality of Mcabber switching between two (but not more) windows.  On the other hand, Mcabber supports aspell (which I also installed today) quite nicely; I have always wanted spell checking for pork; this could be a good opportunity to do so.  More ambitiously, perhaps I will either port AIM capabilities of pork over to Mcabber, or port Jabber capabilities of Mcabber to pork.  Then I will have one client to rule them all.
htam@134.208.47.*
2005-09-05 23:59:59
[CS] Cube Solver System0 comments
This Monday, de, the previously mentioned friend of mine, decided to write a cube solver system using PHP and an available java applete from, I believe, http://lar5.com/cube/.  I decided to provide the development environment in hopes of sparking collaboration between us and saving the time that both of us write a similar system (like the previously mentioned cube record system).  The server can now be reached at phd.htam.org.  Feel free to take a look.  If you are interested in joining development, contact me.

We spent the night prototyping and implementing the bare essentials of a Cube class.  It is currently functional, with the ability to solve a randomly generated cube (by reversing the steps, no less).  With the two of us joining force, whenever there's a project going, the phd development team should crank out code in a very efficient manner.
htam@134.208.47.*
2005-09-04 23:59:59
[CS] Cube Record System0 comments
This Sunday, I started writing a new cubing record system, sparked by the system developed by a friend of mine (`de') who started cubing, indirectly or directly I am uncertain, due to my influence.  I do not exactly like his system, so when he announced that he is working on multi-user support, I decided to join the market.
htam@127.0.0.1
2005-08-30 23:59:59
[CS] Site-Wide Security Revamped0 comments
This Tuesday, I worked on my website authentication.  Yesterday I made the calendar.  One little problem: Once I move back to the States, my parents will no longer be on my private network.  Setting up VPN for this little purpose is not worth it.  So I decided to move it to public domain.  This is not good either: I wouldn't want my schedule to be posted for the world to see, what if I have a `meet girlfriend' entry in there?  So I added accounts to my security system with username/password login and bitflag-type priviledge granting system.  Yay.
htam@127.0.0.1
2005-08-29 23:59:59
[CS] Calendar0 comments
This Monday, I programmed an objected oriented calendar system in PHP without using database as storage.  Why?  I wanted the solution to be lightweight and without the entanglement of another server.  The result?  Functional, colour coded, little calendar that makes my plan easy to recall.  I am placing this on the intranet.
htam@127.0.0.1
2005-08-07 23:59:59
[CS] Sudoku Analyzer0 comments
This Sunday, I spent several hours improving my previous Sudoku solver frontend.  Now it is capable of stepping through the entire deduction process and finally present the full solution (of puzzles that does not require trial-and-error).  Currently the analyzer uses the original frontend for entering a grid setup, and supports the following modes of reasoning: positional and numeric elimnations, intersectional analysis, and set eliminations; all with visual feedback.  Explicitly ruled out numbers for each grid is saved and displayed in the status line when the mouse hovers over the link in the grid.  Take a look in the puzzles section.
htam@127.0.0.1
2005-08-03 23:59:59
[CS] Perl Package0 comments
This Wednesday, I found a bug in my ham/htr scripts which was very mysterious.  Why mysterious?  Because I cannot seem to comprehand its different behaviour when it gets automatically loaded and when I manually load the perl scripts into pork.  It turns out that I had a faulty understanding of the way the perl scripts are run.  (Yes, I also make this kind of mistakes.)  Looking back, this problem only occured after I changed the variable names so both scripts look similar, or shall I say, identical, in the skeleton.  That is where the problem came in.  I should have known that the cause of the bug is the only thing I changed before the bug appeared.  Doh.  In any case, I decided that namespace collisions should not be worked around by adding prefixes to all my variables.  I, therefore, out of options, experimented with packages.  As it turns out, it is very easy and straight forward.  Inject one line and alter a few PORK::event_add's and PORK::alias'es.
htam@127.0.0.1
2005-08-02 22:15:22
[CS] htr 0.20 comments
This Tuesday, after doing another five (5) ACM problems, I decided to stop for a now.  As previously mentioned, my new favourite program is pork and I wish to enhance its features by writing perl scripts for it.  Today, I wrote htr-0.2htr stands for Htam's Text Replacement mechanism.  A stole a lot of code from ham.  In fact, I copied ham to htr and then starting s/// like mad.  In any case, the basic structure, the data-saving structure, the help structure, and commands add, del, and edit, are basically the same.  The way the script is invoked is also through an alias for commands and catching an event for easy execution.  htr, as the name suggests, replace text.  Many have wondered why I would type long words such as `affirmative' and `negative' in place of short words like `yes' and `no,' respectively.  I used a rudimentary text replacement functionality via a gaim plugin.  If gaim could have a plugin, so can pork, and better!  My script allows regular expression matching, fine tuning contexts matched, and also direct command of the entire repetoire including searching and listing with regex matching.  In any case, I am going to use it myself for a few days until I am pretty sure there are no stupid bugs; and also until I have the strength to finish the random functionality where it chooses one replacement randomly.  Afterwards it will be up in my pork section.
htam@127.0.0.1
2005-08-01 22:38:15
[CS] More ACM0 comments
This Monday, I did even more ACM problems.  Apparently, I am hooked again.  I did ten (10) today.  The summer after ninth grade, I moved to America (before then, I did not do much C/C++ programming, as can be seen in a few posts back); so I was quite busy that summer.  I attended to MO(S)P the summer after tenth grade; and I spent most of my time studying for placement tests and getting ready for college last summer (after twelfth grade).  However, it would appear that I was pretty free the summer after eleventh grade.  Correct, I also did some ACM problems back then.  It took up too much time so I decided to quit.  However, now my urge to do some more came back.  Let us see how long it will last.
htam@127.0.0.1
2005-07-31 23:59:59
[CS] POJ0 comments
This Sunday afternoon, I decided to try some ACM problems while they are hot: during a competition.  I participated (somewhat) in PKU's POJ Monthly of July.  It is clear now how untrained I am in solving ACM problems.  All in all, I solved five (5) problems today.

This evening, my family (including my mother!) went out and ate dinner with my uncle, aunt, cousin, her husband, and my (only) nephew.  The food was quite good.  My cousin's husband is Polish, so I demonstrated my immense knowledge of the Polish language as taught by Michael Woods: ``how are you.''  It was an interesting evening.
htam@127.0.0.1
2005-07-30 23:59:59
[CS] ham 0.30 comments
This Saturday, I worked on ham some more.  It is now version 0.3 with regex matching, highlighting, AND editing enabled.  Now when typing /ham edit it no longer says something shamefully as `this is currently NOT operational.'  If you are interested, go to my cs section.  Note that I am a C programmer, not a Perl hacker.  Let me know if something I do is very (or even slightly) un-perl-ish.  I would like to write my perl programs like perl programs and my C programs like C programs.  (I sort of stopped favouring C++ once I realized that my C++ programs look too much like C programs.)
htam@127.0.0.1
2005-07-29 23:59:59
[CS] ACM at PKU0 comments
This Friday, for some unknown reason, I suddenly decided to do osme more ACM problems.  I've submitted a few problems back in 2003 to the Online Judge at UVa.  Then I entirely stopped coding for this kind of context.  Today I ventured into the PKU Online Judge repository and solved a few problems, ten (10) to be exact.  Perhaps I'll do more in the future when I am bored, but perhaps not: I have way too many projects on my hand right now, I should consolidate and finish some of them.  Most notably, I should quickly bring ham to maturity and perhaps submit it to the author of pork; and at the slight chance that it is incorporated into the main distribution as an `example' perl script, I would then have finally stepped my feet into the unknown world of open source user contributions.  Furthremore, I would like to finish it so I can completely switch over to pork from gaim.
htam@127.0.0.1
2005-07-28 23:59:59
[CS] ham0 comments
This Thursday, I created ham.  What is that?  It's something to do with pork, of course, ;-).  ham stands for Htam's Away Messages.  It is an away message handler for pork.  (Remember pork is an awesome text-based AIM client from Tuesday.)  After `learning' perl (I've done perl scripts before, but not as extensive as this one), or shall I say, while learning perl, I wrote ham today.  It has basic functionalities such as adding away messages (with an associated keyword), removing, using (by typing the keyword, the message assigned is used as away message), listing, searching, and randomizing.  I intend on including regex support.  The current version is 0.2.  As it is less than 1.0, it is of course still in beta.
htam@127.0.0.1
2005-07-27 23:59:59
[CS] XOSD0 comments
This Wednesday, I decided to learn to use the xosd library. I installed xosd-2.2.14 when I wanted tbp. When I played with pork yesterday, I mentioned I hacked audio notification upon reception of messages. However, whenever I am playing music, /dev/dsp cannot be used. So I experiemented with using rxvt.mapAlert: 1 and other means. I also considered using screen -Dr, but that would involve disappering windows. I also tried xterm and mrxvt, none proved to be helpful in visual notification. Therefore I decided to use xosd. I installed xosd-devel-2.2.14 and read some documentation. It is so simple to use.

So I wrote xosd_logd in C. It has to be daemonized because we would not like to create a new on screen display every time we have a message to display; besides the overhead, it would be hard to prevent overwriting and inreadability. Therefore I decided to use the newly-discovered fifo mechanism. I mainly used portions of code from xosd_cat. You ask me why I do not simply use xosd_cat? It does not suit me well.  Even though it hides output instead of scrolling away when there are no more inputs, it merely hides it.  When we have input next time, it redisplays original text!  This behaviour is far from acceptible for my taste.  Of course I overcame it easily in my own code.  I also (sort of) reversed the effect of scroll_age.  Now it prevents output from scrolling too quickly, instead of going too slowly.

Now all is well with my new xosd_logd until my pork hangs; why? If xosd_logd is not running (for whatever reasons), writing to the fifo will block.  This is not an acceptible behaviour either.  To overcome this, I wrote a safer frontend in shell script xosd_log.  This shell script is called every time and is responsible to do superficial checking of the status of xosd_logd.  I definitely can add more checking.  It checks if the fifo is there, writes to the fifo in a subshell (forked, so as to never block) with (primitive) locking.  If the lock file was not removed, this indicates (possibly) that the operation was blocking, probably because xosd_logd failed to read.  It will then kill xosd_logd; rm fifo and retry.  After a while, all this has been established.  But I noticed this setup is prone to isn;rt'ion attacks.  I successfully attacked my own computer!  It is not xosd_logd nor xosd_log that is unsafe.  It is actually that the way I was calling xosd_log with message on the command line.  Everyone knows we should never trust user input, especially random people IM'ing me.  So I modified xosd_log with the ability to read from a file and send it off to a the real fifo.  The reason for using this double architecture is that a normal file will not lock on writing.  Furthermore, using the fifo on the C daemon's end means it does not need to constantly open a normal file, remove contents, and close the file stream; which will probably incite race conditions given the rate my peers type message ;-).  In any case, I am done. xosd_logd.c is, obviously, a C source file, while xosd_log is a shell script front end, and .pork/xosd_im.pl is the Perl plugin (that I also wrote) to be loaded into pork and handles IM events.  The following is wc output.
  63  167 1783 c++/xosd/xosd_logd.c
  34  139  752 bin/xosd_log
  24  84  548 .pork/xosd_im.pl
121  390 3083 total


I discovered that I am now more and more favouring shell scripts (over writing everything in C/C++). Summary of languages:
Proficient languages: C++, PHP, C
Used to be proficient: QBasic (third grade), JavaScript (fifth grade), Visual Basic (junior high), Visual C++ (high school), Scheme (college freshman)
Starting to become proficient: SQL, Shell scripting (/bin/sh), Perl, (regex)
Not proficient but want to be: sed, Mathematica scripting
htam@127.0.0.1
2005-07-26 23:59:59
[CS] Pork0 comments
This Tuesday, I found pork, a ncurses-based (text-based) AIM and IRC client. (I saw a link in Jimmy Jia's AIM profile.) In any case, I find this to be an well-written client in C. After using it a bit, I discovered that it did not come with support for playing sound. It did provide Perl scripting (which I used to create a dynamic profile successfully.) However, the event of receiving a message does not distinguish between whether an on-going coversation (as noted by an open window) and a new conversation. In my humble oppinion, audio notification of ONLY new conversations is one of the best mode for my use (and probably many other users'.) Therefore I decided to look into the source code. After less than ten (10) minutes, I had modified the source code, and recompiled. Now it plays a sound only when a NEW convesation is initiated. I am very pleased by the well organization of the source code and the ease of hacking. The entire project excluding the protocols consists of 24344 lines of code (wc: 24344  62200 525184 total). I usually cannot absorb the gist and program flow of such a big program as efficiently. (Of course thanks to ctags.) But in any case, I am VERY pleased by my own performance AND the well-written source code. An author said he did not really want to write documentation, but his source code is enough! Very well indeed. I plan on working on modifying this project to my specification.
htam@127.0.0.1
2005-07-21 21:57:04
[CS] Bible Library0 comments
This Thursday, I decided to revisit my PHP Bible library (if you are not geeky, then you probably don't know what I am talking about.) In any case, I rewrote parts of it: notably the access layer (I know, bad idea). The main work is to make BibleParse() return an array, which contains much more information than the previous string version. This also removes the need for passing in control codes. I wrote a BibleString to wrap around it for the original functions, but I still need to change the codes. The motivation is to move the online datasource to a centralized server, i.e. biblegateway.com. I have been searching for a more reliable source of Chinese Bible. (The previous one I use often produce error codes.) Furthermore, I have been linking to crosswalk.com for English versions. I suddenly realized the pages are a bit resource-consuming. Using a source with multi-language support makes coding on my part easier. Now I simply need to change the version identifier instead of the whole URL; not to mention the semantic differences of the query string of different sites. All in all, it was a success today. I might expand this library some more and eventually integrate it back into my diary mechanism. Currently I am the only one authorized to use my Bible library.
htam@127.0.0.1
2004-11-12 16:59:59
[CS] Alarm0 comments
This Saturday afternoon, I coded an alarm for my roommate.

David's alarm clock stops itself after x seconds, where x is a positive integer less than or equal to sixty (60). David claims x is thirty (30), but I am not positive. In any case, it is not sufficient to wake him up in the morning. Since I have class at 0900 on odd days of the week and his classes are not until 1000, he really does not want me to wake him up when I leave on a regular basis. Therefore, he occasionally miss classes when he does not want to. (I am not considering the planned skipping, that is another issue and I am not interested in dealing with that.)

So today we discussed the different ways of rectifying this problem. The easiest but costly way is to buy a new alarm clock. We can also take apart the alarm clock and see if we can hack it. Sadly, neither of us is proficient at that sport. So the third, and the most cost-efficient way (read: free) is for me to code a program for him. Actually I am pretty sure there are alarm programs all over the place, but I just felt like coding.

So his specifications were that the program would play a sound file. Hopefully it will be easy to change the sound file. Hopefully the program will just play random files from a specified directory, then he could simply change the content of the folder. This I set out to fulfil, knowing that I cannot hard code any filenames, I digged up my built-in source code viewer (which I wrote a year or two ago) to my multi-user text-based adventure game. I also digged up my little program which lived in the tray area which played sound and annoying popups every once in a while to tell me to take a break from using the computer. I managed to craft up a small program which will randomly select a WAV file from the sound sub-folder to play. Upon completion, it will randomly choose another audio file to play, continue until awakened human intereact to indicate his recovery of consciousness.
htam@127.0.0.1
2004-08-27 15:03:09
[CS] Telnet0 comments
As no one knows, I have been coding my own telnet software. Today I semi-intergrated it with htcs so it can upload color files. It will attempt to replace color codes typed with ` to denote esc-esc with the correct key strokes. It should be working properly. Yay.
htam@127.0.0.1
2004-08-21 17:56:28
[CS] Htam's Text Coloring Suite0 comments
It's been a while since I wrote some short-but-sweet tiny helper applications. I am quite happy about my program today.

I just wrote the Htam's Text Coloring Suite (htcs) this Saturday afternoon.
Have a glance at htcs.
This suite provides easy way to colorize plain text.
(I am not sure of the standard in the Windows world, so this is potentially geared only toward the *nix world.)

Valid HTML 4.01
htam 7687