Roy Tang

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

Blog Notes Photos Links Archives About

Questions and answers from the StackExchange network.

You can subscribe to an RSS feed of this list.

Jan 2010

Dec 2009

Nov 2009

  • I have a 320GB western digital external HDD that was working fine a couple of days ago.

    I plugged it into my Windows XP machine at work, and it detects the USB device (it is listed in the Safely Remove Hardware dialog), but it doesn’t detect the disk, not even under Disk Management in Control Panel. I’ve successfully used this ext HD on this machine before, so I suspect it is busted. I tried it on a couple of other machines none of them could detect the disk.

    The only possible reason I could think of is that the bag I was carrying it in fell to the floor off a table a couple of days ago, it might have been damaged then.

    Obviously I would like to have the device working again, but failing that I would like to be able tor recover all the data on the disk.

    What are my options?

    Edit: In case it’s relevant, the product page for the ext HD is here.

  • 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 {
            progressDialog.setLocationRelativeTo(null);
    
            // show the dialog
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    progressDialog.setVisible(true);
                }
            });
    
            // business logic code that calls progressDialog.setProgress along the way
            doStuff();
            
        } finally {
            progressDialog.setVisible(false);
            progressDialog.dispose();
        }
    }
    

    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() {
                    progressDialog.setVisible(true);
                }
            }.start();
    

    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?

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!

  • Here’s our home setup: we have a wireless router, connected are 2 desktop PCs (let’s call them A and B), plus we also have a laptop that connects to the router via wi-fi. Desktops A and B are connected via LAN wires.

    Given that, the problem is that every time desktop A starts up or shuts down (it seems to be simply on power up or power down, the OS it’s booting into doesn’t matter), the wireless connection is reset, i.e. the laptop literally loses the connection and has to reconnect. No such problem happens when restarting desktop B. It’s a bit of a pain when I’m playing online games or something over the laptop and desktop A reboots.

    I’m not sure what to check for here…would it be a problem with the router, with the way the network is set up, or something else?

  • 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) {
                obj.attachEvent('on'+type,fn);
            } else {
                obj.addEventListener(type,fn,false);
            }
        },
        remove: function(obj,type,fn) {
            if (obj.detachEvent) {
                obj.detachEvent('on'+type,fn);
            } else {
                obj.removeEventListener(type,fn,false);
            }
        }
    }
    

    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;">
    <option>ABC</option>
    </select>
    

    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 window.open 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 
      valid
    

    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() {
        document.forms[0].TEST[0].focus();
    }
    
    <form>
        <input type="button" value="Test" onclick="test()" />
        <input type="radio" name="TEST" value="A">A
        <input type="radio" name="TEST" value="B">B
    </form>
    

    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)

Jan 2009

Dec 2008

  • 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?

Oct 2008

  • 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.

  • 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?

    Thanks!

Sep 2008