Roy Tang

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

Blog Notes Photos Links Archives About

All entries tagged stackoverflow.

You can subscribe to an RSS feed of this list.

Oct 2011

  • I’m trying to build a CSS-based menu. I want it to be able to adjust when the browser resizes so I’m using floats to wrap the menu items to the next line as needed. However, I want to have an extra buffer cell at the end to round out the menu appearance, see the sample image below (this an image the designer made from photoshop).

    Example here

    I can set the background image of the containing div to fake it (using the clearing floats trick I found at http://quirksmode.org/css/clearing.html), but then I have the additional problem of having extra space on the right side because I the cited trick says I should set the width to 100% on the container. (see image below)

    enter image description here

    I also don’t have any borders on that extra area after the last item. So, what’s the proper way to go about this? Can anyone suggest any good online implementations I can check?

    Thanks!

Jul 2011

  • Some background: We’re working on projects that involve projects across 2 different countries, and we’ve been using CVS. Developers in the country not hosting the CVS server will take forever to connect to the remote server, so we’ve set up this system to have 2 separate CVS servers in each country and have a sync job that keeps them in sync every hour or so.

    Given this, we’re looking at migrating to a distributed version control system, mostly because we’ve been having problems with the sync job failing and the limitation that for a given set of files only one side can have the writelock for it at a time.

    We’re currently looking at Mercurial for this purpose, so can anyone help tell us if:

    a. Will Mercurial be a good fit for our use case above? How easy will it be for devs to make the transition, i.e. will they still be able to work the same way? etc

    b. Can Mercurial support branching a specific folder only?

    c. We also hold a lot of binary docs in version control, will they be suitable for Mercurial?

    d. Is there support for getting the “writelock” of particular files? i.e. I want no other people to update these particular files while I’m working on them

    Thanks!

  • We’re developing a BPM application to be run on Weblogic, and all the tutorials point to using Oracle ADF for rendering the task forms. My question is: is it feasible to use some other framework other than Oracle ADF for this? We’re not really that familiar with either Oracle BPM or Oracle ADF, but we can’t avoid using Oracle BPM (contract reqt), so we would like to see if we can avoid Oracle ADF instead to minimize the learning effort.

Mar 2011

Jan 2011

  • I have some legacy powerbuilder programs I need to take a look at (view the source, layouts, etc), they are from PowerBuilder 6.5. All I have available is PowerBuilder 11 (demo/eval version), and it seems to be unable to open the PBL files (selecting them in the file open dialog does nothing).

    I guess that it is because the version is very old. ANyone have any idea how I can view those old source files?

    Thanks!

Dec 2010

Oct 2010

  • Anyone know of any guides for this? I’m a complete newbie to weblogic and to container-managed security. What I’ve done already is:

    1. setup an LDAP authenticator in Weblogic
    2. created a simple webapp in Eclipse
    3. Configure web.xml: Added security-constraint, security-role and login-config elements. The realm name used is “myrealm” which already exists in Weblogic. The role name I used is “Admin” which is a global role in Weblogic
    4. Create a simple jsp page “login.jsp”. It doesn’t actually do any logging in but just a Hello World type of thing. I set this page as form-login-page and form-error-page in login-config in web.xml
    5. Export this webapp to a war file and deploy it in Weblogic
    6. I test it by accessing http://weblogic-server/test/login.jsp, and I expect that I’ll be asked to login using an LDAP user first. This doesn’t happen, it just shows the Hello World jsp.

    I’ve also tried adding a weblogic.xml to map the “Admin” role to a specific LDAP user (didn’t work).

    Any advice? It seems there’s a lack of online references for this sort of thing (or I don’t really know what I should be searching for)

    Edit: I’ve also tried using BASIC auth instead of FORM (no luck)

    My web.xml settings are below:

    <security-constraint>
    <display-name>Test SC</display-name>
    <web-resource-collection>
        <web-resource-name>Test WR</web-resource-name>
        <url-pattern>/hello.jsp</url-pattern>
        <http-method>*</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>Admin</role-name>
    </auth-constraint>
    </security-constraint>
    
    <security-role>
    <role-name>Admin</role-name>
    </security-role>
    
      <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>myrealm</realm-name>
    </login-config>

Sep 2010

Jul 2010

  • Back story: I’m planning to implement a casual game to be deployed in a webapp, but I don’t want to use Flash, instead just plain Javascript. One benefit of Flash that I would want though is that it distributes a binary and not the source code so it’s easier to protect your code from being reused/stolen by somebody else, or to prevent the client from modifying the code to “cheat” in the game?

    So my question is: what are the ways to similarly protect a Javascript application? Am I limited to the usual methods of using a code obfuscator? Will that be enough?

  • Say I have the following HTML:

    <head>
        <style>
            #container {
                border: 1px red solid;
            }
            .floaty {
                width: 200px;
                float: left;
                border: 1px green solid;
            }
        </style>
    </head>
    <body>
    <div id='container'>
        Text inside the container
        <div class='floaty'>
        Floaty block 1<br/>
        Floaty block 1<br/>
        Floaty block 1<br/>
        </div>
        <div class='floaty'>
        Floaty block 2<br/>
        Floaty block 2<br/>
        Floaty block 2<br/>
        </div>
        <div class='floaty'>
        Floaty block 3<br/>
        Floaty block 3<br/>
        Floaty block 3<br/>
        </div>
    </div>
    </body>
    

    This renders as: floaty divs

    What’s the proper CSS way to have the container (red-bordered box) completely surround the floaty green-bordered boxes?

Jun 2010

  • Is there any Python library that allows me to parse an HTML document similar to what jQuery does?

    i.e. I’d like to be able to use CSS selector syntax to grab an arbitrary set of nodes from the document, read their content/attributes, etc.

    The only Python HTML parsing lib I’ve used before was BeautifulSoup, and even though it’s fine I keep thinking it would be faster to do my parsing if I had jQuery syntax available. :D

Jan 2010

Dec 2009

  • 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: http://pastebin.com/m527e05dd

    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 {
      app.Quit(0);
    }
    WScript.Quit(err);
    

    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

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

  • 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

  • I’m writing a C# program that acts as a PowerPoint 2007 plugin. On some machines, some calls to the PowerPoint object model throw a COMException with the message RPC_E_SYS_CALL_FAILED. I couldn’t find any specific advice on what to do regarding this error, or how to avoid it. From Googling it looks like something to do with the message queue or Single-Threaded Apartments. Or am I way off?

    Example of the error message is:

    System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED))
    at Microsoft.Office.Interop.PowerPoint._Presentation.get_FullName()

    Unfortunately, the problem is occurring on a client’s machine, so I have no easy way to debug it! Should I just retry the calls whenever I get this error?

    Any advice to help me resolve this problem would be greatly appreciated!