Roy Tang

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

Blog Notes Photos Links Archives About

All entries tagged questions.

You can subscribe to an RSS feed of this list.

Jul 2012

  • Currently we have an Amazon EC2 instance and Oracle RDS in Europe. For performance reasons we also want to set up a server in Asia, but we need to be able to keep the contents of the database in sync across two sites. Apparently Amazon RDS doesnt support RAC, so I was wondering if there are other solutions to keep the two databases in sync in real-time?

    Thanks!

  • I’m trying to write a servlet Filter that under certain conditions will read the HTML response returned by the JSP file and process it (using an XHTML parser) and make some modifications to it before finally returning it to the browser (basically I’m trying to implement a global change to avoid having to modify hundreds of JSPs individually)

    I’m using Tomcat. I started out by providing a wrapper for the HttpServletResponse and the ServletOutputStream before passing them back to the filter chain. However, I’m getting an “IllegalStateException: getOutputStream() has already been called for this response.” It seems to happen whenever one of our taglibs tries to write using the writer returned by “this.pageContext.getOut()”, so I guess the response/writer/outputstream being used by Tomcat isn’t using the wrapper classes I passed via the filter.

    Any suggestions? Or is there a better way to accomplish what I’m trying to do?

Jan 2012

  • Given a JSF/EJB stack, how do I filter the contents of a dataTable listing automatically using the values of a field in a pojo/entity bean?

    i.e. I have an entity bean Employee with name field having a value of “John” I would like to use this bean to filter the data table to show only records with name John, and not having to construct the where clause manually?

  • I’m trying to get a sense of what are the most commonly-used Java web frameworks, with a focus on large, enterprisey projects. I’m interested in which one is most favored by companies/enterprises (which may not be the same as the one most favored by developers or the open source community I guess). I’d also like to be able to cite specific projects used by each framework, preferably big-ticket or well-known ones.

    Anyone have any idea about this stuff or can point me in the right direction?

    Thanks!

Dec 2011

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.

May 2011

  • We have a wifi router set up at home connected to our DSL router. And a lot of computers using it…there’s a desktop (connected to the router via a wired connection), 6 laptops, an ipad and a few internet-capable cellphones (yeah, there are a lot of us at home)

    Sometimes our internet will “act up”, meaning some of the wireless devices will register as being connected to the access point but unable to access any sites. In such a case the other devices seem to be access the internet just fine.

    I’m wondering if there’s some sort of limit or anything to the number of wireless devices we should be allowing to access the router that causes this problem? What things do I need to check?

Mar 2011

Jan 2011

  • So I came home and stumbled upon a bit of a mystery. When I got home my brother was using my desktop PC that was running Windows 7 (I have accounts for my 2 brothers and my mom on the machine, but mine is the only admin account). After he finished his game he logged out and I logged in to my account, but found only strangeness.

    My windows account seems to have been somewhat “reset”, meaning:

    • my quick launch shortcuts were gone
    • my dropbox account did not automatically login
    • my pidgin accounts were no longer there
    • I had to relogin Steam
    • iTunes could not launch (I had hooked up my iDevice before logging in)
    • The Documents/Pictures/Music shortcuts in the start menu no longer work

    However, despite that:

    • my desktop wallpaper was still correct
    • my documents folder was still there in c:\Users\my account name\My Documents as expected
    • Google Chrome settings seem to have been retained
    • other accounts on the same machine seem to be fine

    I asked my brother if he had installed anything strange during the day, he only installed Yahoo Messenger. I last used the machine around 24 hours ago and it was fine then.

    I’m not sure what else has been affected. I’m inclined to just create a new admin user for me to use, but I’d like to have some idea of what actually happened.

  • 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

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

  • I have an Acer Aspire 4920G that I’ve had for a couple of years, running Windows/Ubuntu.

    I have temperature monitors set up so i can see that with time my CPU temps go as high as 85C, sometimes even spiking to 90C. On startup, the temps are around 65C-75C.

    How bad is this, and anything I can do to avoid it/reduce the temp? I’ve already tried to open up the laptop to clean away any dust, but unfortunately some of the screws are really hard to remove. I don’t want to take it to a shop before trying stuff out myself as I’m no longer under warranty.

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

Apr 2010

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

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