Apache Authentication and Mongrel Cluster

Currently I'm running a mongrel cluster for my rails application. This works much nicer then the FastCGI version.
There was only one problem, I had an .htaccess file to restrict access to the public directory.


AuthName "Somewhere"
AuthType Basic
AuthUserFile /home/nobody/.htpasswd
Require valid-user

The problem was I needed to enter this login data 2 times.
Well after doing some google research I found out the problem was the location of the authorizationcode. I think the .htaccess file is used by every Process of the ProxyBalancer... But I'm not sure...

The solution for this problem was to place the authorization code in the proxy balancer:



BalancerMember http://rails_site:5532
BalancerMember http://rails_site:5533
AuthName "Somewhere"
AuthType Basic
AuthUserFile /home/nobody/.htpasswd
Require valid-user

That's all ;-)

Closing an IE popup two times while busy with Ajax request hangs IE

Closing an IE popup (twice) while a XmlHttpRequest is running, uses up all available connections.

To reproduce this:
- create a slow XmlHttpRequest (xhr). (Running about a minute or so)
- Open a popup window which executes this xhr. Close it while it's still running
- Open this same popup again. (Second request). Directly close it while the xhr is running.
- Open another popup... et voila... IE Hangs..

This problem is what I was experiencing. After hours of frustrations we found a workaround:
In the onunload of the body tag you must call the "open" method on the same XmlHttpRequest object.
The call of "open" disconnects and stops the old request. Appearently abort doesn't do this

Working code:










WARNING: This solution has only be tested with IE7!

Update 23-01-2008:

Solution for this problem with prototype is. Just put this code in an seperate javascript file. Include this file after prototype.js call iefix_runGarbageControl() in the onunload and the bug is fixed ;-)


// IE TCP/IP Connection Leak FIX, with prototype
if( Prototype.Browser.IE )
{
var iefix_xhrs = new Array();
function iefix_runGarbageControl() {
for(var i=0; i

Update 24-04-2008:
Added: place 'iefix_runGarbageControl()' in the onunload

I would like a limit per join in sql!

Currently I'm busy optimizing a query.

I've got the following query:

SELECT a.*, c.*
FROM a
LEFT JOIN b ON a.id = b.a_id
LEFT JOIN c ON b.c_id = c.id
WHERE x

I'm only interested in 1 row of the table c. I don't care for others..
I can only reach table c via table b.
There are many b tables with an a_id.

For performance reasons I would like to implement this like this.

SELECT a.*, c.*
FROM a
LEFT JOIN b ON a.id = b.a_id LIMIT 1
LEFT JOIN c ON b.c_id = c.id
WHERE x

Why isn't (a form of this contruct) not an sql standard. And hasn't any database implemented this contruct. Or am I missing something?

When you have many indirect joins this can be a huge time saver.

Btw. Alternative syntax for sql server:

SELECT a.*, c.*
FROM a
LEFT JOIN TOP 1 b ON a.id = b.a_id
LEFT JOIN c ON b.c_id = c.id
WHERE x

** btw The database I need this construct for, has got many redundant records.

Text Measurements with Flash Actionscript 2

Today I found a great class to help me calculating text metrics in Flash. It's really nice, you can use it to locate every single word / line etc. in a (for instance) wrapping textField. Actionscript 3 has got nice built in methods for this, but unfortunately, for the current project I need to develop with Actionscript 2. Jack Doyle created a very nice actionscript 2 class for this:

http://blog.greensock.com/textmetrics/