December 18, 2009

Bypass Friendly Internet Explorer 404 Messages

Filed under: ColdFusion, PHP — joel.cass @ 9:22 am

I had to build a custom 404 page today and was bashing my head against a wall regarding Internet Explorer’s friendly “The webpage cannot be found” error message page.

Well, according to this link, the solution is simple – the page has to be at least 512 bytes. Too easy.

Of course, you can simply just add 512 bytes of whitespace and/or reduce the amount of whitespace to 512 minus the original size of the page. If your page is greater than 512 bytes you have nothing to worry about.

The ColdFusion repeatString and PHP str_repeat methods would be useful for this.

December 11, 2009

Automatic image resizing in PHP

Filed under: PHP, StructureCMS — joel.cass @ 9:54 am

One big issue in content management systems is that images are usually handled poorly. Even with the best file management capabilities, you can’t help users from uploading their 12 megapixel 15 megabyte images from their recent Christmas party and then chucking them into the content and resizing them down to fit the screen. The problem is that even though the image appears ’small’ in the browser, the full size image is downloaded and displayed, wasting bandwidth and slowing down the user experience.

A concept I really admired in Sitecore and have copied to StructureCMS is that resized images could automatically be created on the server-side and returned to the client simply by adding the parameters ‘w’ or ‘h’ to the URL, e.g. take these images for example:×120.gif

The attributes “w” and “h” can be added to the url to resize the image:×120.gif?w=60
test120x120, h=200

(if both parameters are defined, image is resized to ‘fit’ within the dimensions)

If you look at the images on their own, you will notice that they are resized by the server, and you can change the dimensions. The crunched down, resized version is sent back to the user, saving bandwidth and improving the user experience. Images are then cached so that future requests do not require any server resources.

How did I do this?

  1. I created image.php in the website root – this gets URL params and creates a new resized image (I’m not going to explain the code – it’s pretty simple)
  2. I installed the apache mod_rewrite module – this is as simple as opening your httpd.conf file and unhashing the line ‘LoadModule rewrite_module modules/’ (and then restarting apache)
  3. I created an .htaccess file that rewrites URL’s
  4. I then modified the tinyMCE image.js file to add the size attributes to the URL

The beauty of this modification is that it won’t break anything if apache nor mod_rewrite are installed. And, with some modification this code could be used on any website.

December 7, 2009

Magpie Evasion Strategy Part 3: It works!

Filed under: Cycling — joel.cass @ 8:35 am

Some of you may remember my earlier post from over a year ago regarding the cable tie helmet:

Magpie evasion strategy part 1: The cable tie helmet

Well, I can gladly say that I went for a whole season without being hit by a bird, with much help (I believe) from the cable tie helmet. I have been followed and squawked at, but unlike last year before I discovered the cable tie helmet, I have not been hit, once!

Furthermore, I see more and more people adopting the cable tie helmet – so I suspect it works for them too?

I also suspect part of my strategy was about being more aware of nesting birds and how they might come to attack. I have kept my distance from known sites and have not tried to “wave off” or look back at swoopers – simply keep the ears open and look to the shadows!

I found an interesting site on swooping birds today: Interestingly enough, the Indian Minor does not get a mention. I find these birds to be the most aggressive of all – however I have never been hit by one, they did set off a rather aggressive magpie I passed last year.

December 4, 2009

Windows XP stalls on “Applying computer settings”

Filed under: Technology — joel.cass @ 9:32 am

It seems that since about 6 months ago, there has been this annoying bug in windows XP that causes it to stall on “Applying computer settings” every 2nd time my machine is booted. Strangely enough, this has happened to me in two completely different environmments at two different workplaces.

Searching google didn’t come up with much, except this one thread:

I thought I would describe how to change these settings:

  1. Open the control panel, open networking
    Control Panel

    Control Panel

  2. Open the network adapter that you use to connect (double-click the icon or click on link highlighted below)
    Control Panel, Networking

    Control Panel, Networking

  3. Scroll down to Internet Protocol (TCP/IP), click it, then click the “Properties” button.
    Networking Properties

    Networking Properties

  4. In the TCP/IP Properties dialog, click “Advanced” button
    TCP/IP Properties

    TCP/IP Properties

  5. In the Advanced TCP/IP Settings dialog, click the WINS tab
    Advanced TCP Settings

    Advanced TCP Settings

  6. Under the “NetBIOS setting” area, change to “Enable NetBIOS over TCP/IP”
    Selecting NetBIOS over TCP/IP = Enabled

    Selecting NetBIOS over TCP/IP = Enabled

  7. Click OK/Close to all dialogs
  8. Reboot your computer to test – yay! fast logon!

Why this happens, I am not so sure. All I could suggest is that if NetBIOS is disabled on the Active directory server (most likely for security reasons) it will also be disabled on your computer.

The delay in logon probably occurs because a service is attempting to collect information using NetBIOS when it is not available. Making NetBIOS available effectively fixes the problem.

December 2, 2009

Measuring disk space in Coldfusion

Filed under: ColdFusion — joel.cass @ 2:15 pm

If you’re supporting any legacy applications, then it’s probably only a matter of time until you will get that call early in the morning… “Hi, this is technical support, your server’s down. It seems to have run out of space on drive X…”.

This could have easily been avoided if you had set up some sort of alert. The should be easy right, as easy as using a cfdirectory tag… Oh wait, hold on, other than a recursive listing and summary being extremely inefficient, cfdirectory doesn’t tell you how much space is left on your drive.

Well, we’re all lucky that ColdFusion is built on top of Java. As it turns out, since JDK 6.0 Java has exposed drive information via the library.

For example, if you wanted to get a list of all drives on the server, you could use the method File.listRoots():

<cfset objFile = createObject("java","")>
<cfset aryRoots = objFile.listRoots()>

<cfset lstDrives = "">

<cfloop from="1" to="#arrayLen(aryRoots)#" index="i">
    <cfset lstDrives = listAppend(lstDrives, aryRoots[i].getPath())>

Dumping out #lstDrives# would return something like “A:\,C:\,D:\” etc.

From that, you can then get the amount of space available:

<cfset objFile = createObject("java","").init("C:\")>

<cfset stcReturn = structNew()>
<cfset stcReturn.freeSpace = objFile.getFreeSpace()>
<cfset stcReturn.totalSpace = objFile.getTotalSpace()>
<cfset stcReturn.readAccess = objFile.canRead()>
<cfset stcReturn.writeAccess = objFile.canWrite()>

If you wanted to set up an alert, you could use the readAccess / writeAccess flags to determine whether the drive should be checked. Chances are that if a drive cannot be read or written it is most probably a CD drive or an external media drive that is empty.