Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Photos Links Archives About

All entries tagged software development.

You can subscribe to an RSS feed of this list.

Jan 2010

screen sharing library

I’m looking into screen sharing functionality - i.e. allowing remote users to view your desktop in real time, possibly control it and write annotations (text/drawings) on the shared screen. Something similar to what webex allows in its conferencing software. Preferably a Java-based api, possibly to run from an applet.

Any recommendations on a library/api to use?

Dec 2009

New Comments System

I got tired of having to maintain my own comment moderation system, and I decided against throwing out the django code and going back to wordpress. Instead, I’m migrating the comment system to DISQUS. I love this little mess of django code that’s running my blog. I wish I had time to clean it up. But for now, at least I can have a more industrial-strength comment system in place.
Posted by under post at / Software Development / 0 / 70 words

We’re working on a project with a number of applets that has to work across a large range of OS (WIndows, Mac, Linux), browsers (IE, FF, Safari, etc) and Java versions (1.5+), and it often happens that a fix we apply will cause some sort of security exception an another platform or some other error.

Is there any way for us to prepare automated tests to immediately catch those problems in different platforms? I think it’s not necessary to check that the gui parts are appearing as intended, but just to detect whether unexpected exceptions are occuring.

We have a web screen with a number of applets that has a problem on Mac OSX 10.5.7, Firefox 3.0.15, java 1.5.0_19.

The problem is encountered on the user site. On initial load of applets (with an empty applet cache), the screen locks up/hangs while loading the applets. After refreshing the page, it loads normally. If the cache is cleared, same problem happens again.

Unfortunately, we’re not encountering this on our local test machine (same OS, java and Firefox versions)

We were able to get a jstack thread dump, see below:

However, we’re not sure how to interpret it. Any suggestions or advice?

Edit: We were able to replicate in our testing machine by creating a new user (clean Firefox profile). If we clear the java cache then visit the problematic pages, the edit controls are disabled (we can’t click them to focus them), the Firefox address bar and search box have the same behavior. The edit box controls only “unfreeze” when we access the “Help” menu entry, which has a Search edit box that is active.

I have the following .js file being run using cscript on Windows Vista with Office 2007:

var err = 0;
var app = WScript.CreateObject("Word.Application");
try {
  var filename = WScript.StdIn.ReadLine();
  var enc = filename.toLowerCase().indexOf(".txt") >= 0 ? 65001 : 1252;
  var objDoc = app.Documents.Open(filename, false, true, false, " ", " ", false, " ", " ", 0, enc, true, false, 0, true);
  objDoc.PrintOut(false, false, 0, " ", " ", " ", 0);
} catch (e) {
  err = 1;
} finally {

The point of the code is that it will accept a filename from stdin and print that document using Word. My problem is that for a particular printer we are testing with, the document doesn’t get printed. I can trace that it executes .PrintOut properly and without any errors, and that the WINWORD process is started and terminated as expected (I can see it in the TaskManager). For our other test printer, the script works correctly.

I’m a bit new to this type of scripting (the guy who wrote it is on vacation…), any advice as to how I can resolve this problem?

Edit: I’ve isolated the PrintOut call, the rest of the script is irrelevant, even calling ActiveDocument.PrintOut from inside a Word document has the same problems with the printer.

Let’s say I have a series of

  • elements designed to render via float:left inside a fixed-width container as follows:

    Item 1 | Item 2 | Item 3 | Item 4
    | Item 5 | Item 6

    This is fine, Item 5 and Item 6 are pushed to the second row because the container has a fixed width.

    Now, is it possible to have something similar to above, except that majority of the items will render in the second row? Something like:

    Item 1 | Item 2 
    | Item 3 | Item 4| Item 5 | Item 6

    Basically, I want to render a list of items horizontally, wrapping to the second row as needed, but with majority of the items on the second row if it exists. The number of items to be generated may vary, but will not exceed 2 rows’ worth of items.

  • Nov 2009

    Applets failing to load

    While testing our setup for user acceptance testing, we got some reports that java applets in our web application would occasionally fail to load. The envt where it was reported was WinXP/IE6, and there were no errors found in the java console.

    Obviously we’d like to avoid it. What sort of things should we be checking for here? On our local servers, everything seems fine. There’s some turnaround time when sending questions to the on-site guy, so I’d look to cover as many possible causes as possible.

    Some more info: We have multiple applets, in the instance that they fail loading, all of them fail loading. The applet jar files vary in size from 2MB to 8MB. I’m told it seems more likely to happen if the applet isn’t cached yet, i.e. if they’ve been able to load the applets once on a given machine, further runs on that machine go smoothly. I’m wondering if there’s some sort of network transfer error when downloading the applets, but I don’t know how to verify that.

    Any advise is welcome!

    We have an Applet that can possibly display Chinese text. We are specifying a font for it (Arial), it works fine under both Windows and Mac OSX.

    But in Firefox on Linux the Chinese characters are rendered as squares. Is there a way to work around this? Note that we can’t assume the existence of a particular font file on the client.

    I have an applet that calls a JDialog that contains a JProgressBar component. I subclass the JDialog to expose a method to update the JProgressBar, something like:

    public class ProgressDialog extends javax.swing.JDialog {
        public void setProgress(double progress) {
            jProgressBar1.setValue(jProgressBar1.getMinimum() + (int) (progress * jProgressBar1.getMaximum()));

    I use this dialog in the following manner:

    public void test() throws Exception {
        progressDialog = new ProgressDialog(null, true);
        try {
            // show the dialog
            EventQueue.invokeLater(new Runnable() {
                public void run() {
            // business logic code that calls progressDialog.setProgress along the way
        } finally {

    It works fine on Windows/any browser. However, when invoking the above function on Firefox 2/3/3.5 on a Mac, the progressDialog is displayed indefinitely, i.e. it doesn’t close.

    I suspected that calling setVisible(true) inside the EventQueue was causing the problem, since it’s a blocking call and might block the queue completely, so I tried changing it to:

            // show the dialog
            new Thread() {
                public void run() {

    With this change, the progressDialog now closes correctly, but a new problem emerged - the contents of the dialog (which included the progressbar, an icon and a JLabel used to show a message string) were no longer shown inside the dialog. It was still a problem only on Mac Firefox.

    Any ideas? I realize it’s probably some AWT threading issue, but I’ve been at this for a couple of days and can’t find a good solution. Wrapping the doStuff() business logic in a separate new Thread seems to work, but it’s not easy to refactor the actual business logic code into a separate thread, so I’m hoping there’s a simpler solution.

    The envt is: Mac OSX 10.5 Java 1.5 Firefox 2/3/3.5

    We have a small .Net program that we sell with individual licenses. The individual licenses are enforced by registering a key file that is generated using information from the machine used to install the program (MAC address, etc.)

    Now, we have a customer request for a site-wide license, such that they can deploy to as many machines on their site as possible. From the technical POV I’m not sure what are the usual approaches for this; our old approach won’t work since we can’t map the license to any machine-specific information.

    Any suggestions?

    A few more details:

    • the program is a client-side program that includes an Office Add-In
    • the machines to be installed on may or may not have internet access
    • we aren’t restricted to .Net-only approaches, I’m just looking for a general idea of how this sort of thing is usually handled

    Oct 2009

    I have a CRUD maintenance screen with a custom rich text editor control (FCKEditor actually) and the program extracts the formatted text as HTML from the control for saving to the database. However, part of our standards is that leading and trailing whitespace needs to be stripped from the content before saving, so I have to remove extraneous &nbsp; and <br> and such from the beginning and end of the HTML string.

    I can opt to either do it on the client side (using Javascript) or on the server side (using Java) Is there an easy way to do this, using regular expressions or something? I’m not sure how complex it needs to be, I need to be able to remove stuff like:

    <p><br /> &nbsp;</p>

    yet retain it if there’s any kind of meaningful text in between. (Above snippet is from actual HTML data saved by the tester)

    Let’s say I attach a javascript “change” event handler to a select element, something that dispatches an ajax request to load some stuff from the server.

    This is fine in Firefox. However, in IE, the change event will fire every time you scroll rapidly through the combo box options using a mouse wheel. This is troublesome because it spams the server with requests, and there’s no guarantee the requests come back in the correct order, hence the client-side state may become inconsistent.

    Now, our previous workaround was that we would introduce a timeout to the change handler, such that it would wait a fraction of a second before actually dispatching the request. If in that short time, another change event comes in, we cancel the previous timeout and start a new one, thus preventing spamming multiple requests.

    Now, while this seems to be working, it’s a bit hackish and I’m wondering if there’s any better approach. Is there a different event we can hook to so that it doesn’t fire repeatedly when scrolling with the mouse? Or should we just disable mouse-wheeling altogether (onmousewheel=“return false;”)? Firefox does not seem to support mouse-wheeling thru combo boxes, but I’m not sure if disabling mouse wheeling is a serious usability no-no or something.

    Can anyone recommend other solutions?

    I’ve been meaning to write a nontrivial app using Google App Engine for a while, and here’s my first weekend project: Decklist Sharing Tool, an tool for MTG players to share decklists online. I had the decklist parsing and autocarding code available for a while (and used on my MTG related posts), so that part was fairly easy, I got it done under 3 hours I think. The rest of the time (around 5-ish hours) was spent on glue logic, fixing minor bugs, working on HTML layout, cleaning up text, etc.

    read more (231 words)

    Posted by under post at / Software Development / 1 / 231 words

    Sep 2009

    HTML/Javascript - I want to load images dynamically, and the images I’m going to load can be of varying aspect ratios.

    I want the images to fit into a specific area of the containing div - an area 40% of the containing div’s width and 80% of its height. Since they have varying aspect ratios, of course they will not always use up this entire area, but I want to resize them such that they don’t exceed the bounds. But I don’t know ahead of time whether I should specify the width or the height (and the partner attribute to auto) since I don’t know what the aspect ratio of the images will be ahead of time.

    Is there a CSS way to do this? Or I need to compute the required widths using javascript?

    PS I only need to do this in Firefox 3.5!

    I’m writing a webapp that would run on a device using Firefox to display a bunch of videos. The videos can be huge, up to HD quality, and would be using a large display.

    I would like to be able to queue videos, i.e. have them run one after another. I’ll also have some ajax checking if there are new videos to be displayed, so I need to be able to dynamically load them. I also have some script that I need to run between videos, so I need to be able to respond to the end of each video.

    Note that I’m in control of the environment, so I can make sure the needed plugin (Flash player or QuickTime, etc) and codecs re installed on the machine.

    The question is: what’s the best video format for me to use? FLV or MP4? What technologies should I look into?

    Aug 2009

    Let’s say I have a Java webapp deployed on some Application Server with clustering across a few nodes.

    In the webapp, we maintain a cache of some values retrieved from the database, stored in-memory as static variables. Whenever a user performs an update in a particular screen, we clear the cache so that the cached values will be retrieved again the next time they are needed.

    Now the problem: Since each node in the cluster is running on a separate JVM, how can I clear the cache across all nodes? Basically I want to call a static function on each cluster node. Is there some standard J2EE way to do this, or it depends on the Application Server software?

    Say I add events to an object using either addEventListener or attachEvent (depending on the browser); is it possible to later invoke those events programmatically?

    The events handlers are added/removed using an object like this:

    var Event = {
        add: function(obj,type,fn) {
            if (obj.attachEvent) {
            } else {
        remove: function(obj,type,fn) {
            if (obj.detachEvent) {
            } else {

    Or do I need to store copies of each handler and just add an Event.invoke(…) function?

    Edit: Also, jQuery is not an option :D

    Jul 2009

    Say I had the following:

    <select disabled="disabled" style="border: 1px red solid; color: black;">

    Firefox renders the above with a red border and black text as I expect; but IE does not, it seems to be using native colors for the border and the disabled text. Is there any way for me to be able to style it?

    For edit boxes my workaround was to use readOnly instead of disabled so that I can style it, but it seems for combo boxes the readOnly attribute has no effect.

    Note: I only need this to work in IE (it’s for an intranet webapp where users must use IE), so IE-specific solutions are fine.

    Any idea for this?

    Problems encountered: Using screen.availHeight and screen.availWidth as the height and width params in causes the browser size to include the taskbar, and positioning at (0, 0) ignores the possibility of the taskbar being up there.

    What I want is to open a new window with the size as if it was “maximized” by the user, i.e. it shouldn’t cover the windows taskbar.

    (Oh, and no need to remind me that users don’t like Javascript interfering with their browser windows, etc. This is for an internal intranet webapp…)

    Jun 2009

    Specifically, say I have a string like ABC-123-NNN. I would like the paragraph to have line breaks, but not to break at the dashes.

    i.e. if my text is “The serial number ABC-123-NNN is not valid”, I would like to keep together the entire serial number if it exceeds the container width.

    So the following is ok:

      The serial number 
      ABC-123-NNN is not 

    But the following (which is the behavior of IE6) is not:

      The serial number ABC-
      123-NNN is not valid

    Currently IE seems to break at dashes. Is there any applicable CSS or whatever I can apply to avoid it?

    Given the code below:

    function test() {
        <input type="button" value="Test" onclick="test()" />
        <input type="radio" name="TEST" value="A">A
        <input type="radio" name="TEST" value="B">B

    In IE6, clicking the button doesn’t focus the control, unless I’ve already tabbed through the radio at least once, in which case it works. =/

    Any idea how I should be focusing the control? The above works perfectly fine in FF of course.

    Edit: I found that the control is being focused, except the highlight box around the radio button is not being rendered. (I can hit space to activate the radio button, and also use arrow keys to change the active button). So the question becomes: how can I force the focus highlighting box to render?

    Apr 2009

    I’m experimenting with wx.aui.AuiNotebook; is there a way I can prevent particular tabs from being closed? i.e. I have an app that allows the user to create multiple tabs in an AuiNotebook, but the first 2 tabs are system managed and I don’t want them to be closed.

    Also, in a close event, can I get the window object attached to the tab being closed? (to extract data from it)

    Feb 2009

    You may have noticed the new color scheme and new “Theme Switcher” widget in the sidebar. I had done some CSS work during the past month in the office and it made me want to tweak the stylesheets on this site a bit. I figured I might as well make it easy to switch stylesheets, so I wrote a small Theme Switcher django app. (Well, it’s more of a stylesheet switcher I guess)

    read more (451 words)

    Zed Shaw -- the ACL is Dead

    Excellent talk given at the Canadian University Software Engineering Conference (CUSEC) last year (2008). The presenter is Zed Shaw who’s a famous Ruby guy or something. The video is around 70 minutes long. The first part of the talk is mostly about a Document Management System he worked on, kinda interesting, but the second part is better where he talks about people who program cool things as a hobby and how to avoid becoming just another corporate code.

    read more (101 words)

    Posted by under post at / Software Development / 0 / 101 words

    Code Quality

    I was doing code reviews on an interface file-processing framework to be used in one of our projects. The code was workable and already being used by several programs, and I didn’t see any major functional flaws. But design-wise I felt that it could stand for some improvements/refactoring to be “better object-oriented code” or “easier to maintain”. The current design required a lot of inheritance – the usual way of doing things in older Java code at work.

    read more (562 words)

    Posted by under post at / Software Development / 3 / 562 words

    Jan 2009

    I need to write some javascript to strip the hostname:port part from a url, meaning I want to extract the path part only.

    i.e. I want to write a function getPath(url) such that getPath(“http://host:8081/path/to/something") returns “/path/to/something”

    Can this be done using regular expressions?

    Using Django Pingback

    I actually had some trouble using django-pingback on my custom blog engine; the django-pingback documentation is mostly fine, but there were some caveats that I had to discover myself through a bit of debugging: The URL specified for the XML-RPC endpoint in the HTML head needs to be a full absolute url including domain, i.e., which gave me trouble when I was trying to test using localhost pinging to an online server.

    read more (393 words)

    For the past few months, I’ve been encountering the COM Surrogate Has Stopped Working Error in Windows Vista, as described here. Unfortunately, most of the recommended fixes on this page didn’t work for me. (I had neither DivX nor Nero installed, etc.) Eventually, I had to download InstalledCodec and use trial and error disabling of all the codecs in my system to trace the problem. I narrowed it down to the Xvid Codec and ended up having to disable it.

    read more (80 words)

    Posted by under post at / Software Development / 0 / 80 words

    Dec 2008

    My current blog app supports syntax highlighting in the blog posts, something I cribbed off Djangosnippet #119 One problem I encountered was that there was no quick visual reference for the styles available with pygments, so I wrote a short demo page here so that I could easily see the appearance of each syntax highlighting class. Of course, I haven’t had a chance to use it in a post yet…
    Posted by under post at / Software Development / 0 / 70 words

    Colophon 2008

    Frontend: All page templates are valid (X)HTML. However, I choose not to claim valid XHTML (and no doc type declaration) since I can’t guarantee that blog posts I write are compliant! The site uses standard CSS and uses the Blueprint CSS Framework for the grid layout of the page. The site design is entirely original (if not simple and bland – I’m not very good with website design yet!). The site has minor usage of JQuery Javascript library in some parts.

    read more (283 words)

    I’m not sure if this a settings problem or an HTML problem, but on a page layout I’m working on, Firefox does not render the stylesheet immediately. Meaning for maybe half a second I can see the unstyled page, then the stylesheet kicks in and it renders as I expect.

    All my stylesheets are in external css files loaded in the head tag. I’m not encountering this on Flock (which is a Firefox variant) nor on Google Chrome/IE.

    Any idea how to avoid it?

    $pee = preg_replace( '|<p>|', "$1<p>", $pee );

    This regular expression is from the Wordpress source code (formatting.php, wpautop function); I’m not sure what it does, can anyone help?

    Actually I’m trying to port this function to Python…if anyone knows of an existing port already, that would be much better as I’m really bad with regex.

    Fixing up the comments

    I played around with the built-in comments app today, trying to clean it up. Some findings: Some of the moderation views, such as flagging a post or deleting a post, accept a next parameter that determines where the view will redirect to after the operation. However, the way the url’s are set up, there’s no easy way to pass this parameter normally, even through query strings. THis lovely bug is documented in http://code.

    read more (435 words)

    Posted by under post at / royondjango Software Development / via royondjango / Syndicated: / 0 / 435 words

    Nov 2008

    I’ve been busy at work so fell a bit behind with Django. Last night I worked on a WordPress importer, so that I could migrate posts from my current blog(s) into the Django-powered blog that I’m coding. I’m using BeautifulSoup to parse the WordPress export file and insert them as Django objects. Since I was running the script repeatedly, I had to figure out how to easily run it from the command line, without having to run it from inside manage.

    read more (232 words)

    Posted by under post at / royondjango wordpress Software Development / Syndicated: / 0 / 232 words

    Oct 2008


    I wanted to add some basic tagging to my blog app so I tried out django-tagging. Unfortunately, the featured downloads on the Google Code site are quite out-of-date and would not work with Django 1.0, so I did a subversion checkout instead. If you’re getting an error like “ImportError: cannot import name parse_lookup”, then you need to get the source code from SVN. Adding the tagging to the blog was pretty easy:

    read more (164 words)

    Posted by under post at / royondjango Software Development / via royondjango / Syndicated: / 0 / 164 words

    In my program, I have been receiving an error when I use a command-line compile command for mxmlc. The error is related to an embedded font name not being correctly identified by flex in the system fonts list.

    However, on a whim, I decided to copy the code to Flex Builder and compile it there. To my surprise, it worked, and it found the proper font using the same system name I had given (PMingLiU).

    I suspected my problem may be a locale one, and that my system cannot correctly identify the font name because of locale considerations.

    I’ve tried setting the locale of the compile code to en_US, to no avail. So I would like to ask if anyone here knows how exactly Flex Builder invokes the MXML compiler and what differences there are compared to running mxmlc directly? We know it’s not using the mxmlc.exe directly, since we tried replacing mxmlc with our own executable to capture the command line parameters.

    If it matters, the OS used is Windows XP.

    C# HTML Font Tag Parsing

    I need to parse a large amount of text that uses HTML font tags for formatting,

    For example:

    <font face="fontname" ...>Some text</font>

    Specifically, I need to determine which characters would be rendered using each font used in the text. I need to be able to handle stuff like font tags inside another font tag.

    I need to use C# for this. Is there some sort of C# parser class to make this easier? Or would I have to write it myself?


    Deployment Problems

    So I got a basic blog app up and running. Posting, paged archives, etc. Comments implemented using the django.contrib.comments. No problems here, the only caveat being most of the current documentation found by Google searches refer to the pre-1.0 version. Need to peruse the official docs for 1.0 stuff. RSS feeds implemented using django.contrib.syndication, this one seems fine. I tested it and it’s running fine on localhost. I also have a free django hosting account at http://bells-n-whistles.

    read more (143 words)

    Posted by under post at / royondjango Software Development / via royondjango / Syndicated: / 0 / 143 words

    Philippine Airlines

    My dad asked me to help book a flight from Manila to Boracay for my uncle who would be a balikbayan this weekend. The rates at PAL were better, so we decided to book using their website. I did the search for the flights, booked the seats, input my uncle’s details, etc. When we got to the screen to input the credit card info, my dad went to call my uncle to confirm and to get his credit card.

    read more (541 words)

    Posted by under post at / Software Development / 1 / 541 words
    “when redirecting, how can I make the redirect URL decoupled from the of the parent app?” -> It turns out that HttpResponseRedirect supports relative paths, so this was fine. return HttpResponseRedirect(“../” + str( + “/”) I got the basic posting structure up. /post/new/ -> To make new posts /post// -> To view a single post /post/all/ -> To view all posts I should probably start thinking of a better url scheme.

    read more (167 words)

    Posted by under post at / royondjango Software Development / via royondjango / Syndicated: / 0 / 167 words

    Anyone have any idea how to get the value of “Language for Non-Unicode Programs” in Control Panel Regional Settings programmatically using c#?

    Already tried CultureInfo, RegionInfo and getting the default encoding using the Encoding object, but I can only get the Standards and Formats value or the main code page.

    Starting out

    The quintessential app to learn from is of course a blog. Started using a simple Post model. Added the new post form and view. Can now successfully insert posts into the DB. Next: – create the detail page that will show the post after saving Figure out: – when redirecting, how can I make the redirect URL decoupled from the of the parent app? i.e. if the parent app has the following mapping:

    read more (127 words)

    Posted by under post at / royondjango Software Development / via royondjango / Syndicated: / 1 / 127 words

    Sep 2008

    I was looking to try out some Flex stuff at home, but of course I didn’t have a personal Flex Builder license I could use. (A coworker of mine wisely advised me not to try using my work license at home.) So I looked around to see if there were any free (as in beer and as in speech) alternatives. The one I found was FlashDevelop. Although the IDE looks Eclipse-like, it’s actually built using .

    read more (247 words)

    Posted by under post at / Software Development / 0 / 247 words

    Roy Tang is a: is a personal site, an E/N site, and kind of a commonplace book; I post about a random assortment of topics that interest me including software development, Magic the Gathering, pop culture, gaming, and tech life. This site is perpetually under renovation.