Chrome CSS Drop Down Menu Offsets with Centered Pages

I decided to try Chrome CSS Menu on a project I'm working on. While I'd love a pure CSS solution, I don't have time to roll my own, and everything I saw relies on fixed width parent elements. The Chrome menu is very easy to drop into your existing CSS html.

The one problem I had was using this menu with a fixed-width, centered page. For example, a 900 pixel wide page, centered:

<style>
div#ie_fix {
text-align:center;
}

div#container {
   margin: 0 auto 0 auto;
   text-align: left;
   width:900px;
   position:relative;
   }
</style>

<div id="ie_fix">
<div id="container">
***MAIN PAGE GOES HERE***
</div>
</div>

I really needed that container div to be positioned relative, and that was making the drop down menu offsets off by whatever the left page margin happened to be.

My solution was to change (hack) the chrome.js file to stop spidering up the parent elements when it hit that container div.

Make this:

while (parentEl!=null)

Into this:

while (parentEl!=null && parentEl.id!='container')

fckeditor and AJAX

fckeditor is cool, and so is AJAX. I've never used them together until today, and it's quite simple.

One gotcha that was killing me - if/when you use Javascript to send the contents of the fckeditor window, keep these few things in mind (for use with ColdFusion, BTW):

  • Assuming you have a submit button that sends the contents to a JS function, use this to grab that content:
    FCKeditorAPI.GetInstance('myInstance').GetXHTML());
  • And if/when you send your data from JS to CF, be sure to use the javascript encode function:
    var foo = encode(FCKeditorAPI.GetInstance('myInstance').GetXHTML()));
  • And if/when you use CF to work with that data, decode it with urldecode:
    <cfset fixedContent = urldecode(incomingData)>

Nested CASE in SQL

There's nothing especially difficult about nesting CASE statements in SQL, but I guess it could be confusing sometimes.

Here's an example:

case [group]
   when 'C' then
      case control
         when 1 then
               case phase
                  when 1 then 'Initial Diary'
                  when 2 then '8 week pause'
                  when 3 then 'Ending Diary'
                  else 'unknown'
               end
         else
               case phase
                  when 1 then 'Initial Diary'
                  when 2 then 'Learing Modules'
                  when 3 then 'Ending Diary'
                  else 'unknown'
               end
      end
   when 'P' then 'Parent Modules'
end as phaseText

Editing single files with cfEclipse

One thing that kind of bugged me with Eclipse is that I thought I could only edit code contained in a project.

What if you want to edit some standalone file somewhere? I thought I was out of luck. Then I stumbled upon the File Explorer tab (window -> show view -> file explorer view).

You can navigate to any file and edit it, without that file being included in an Eclipse project.

It's probably common knowledge, but I didn't know...

SQL Server triggers not firing with replication

Ran into a problem today. Two SQL DBs, using transactional replication. I had some triggers created on the subscriber end that worked off insert, delete, and update operations.

The triggers worked great when inserting/updating/deleting data locally on the subscriber DB. But when a table was modified via replication, no triggers fired.

I thought replication just treated updates as a series of deletes and inserts, but the delete and insert triggers weren't firing, either.

If you're having a similar problem, first make sure your triggers don't have a "not for replication" setting. Sadly, mine don't. That's sad because a solution took a very long time to find.

The solution was a rather cryptic setting that tells replication to send updates *as* updates, rather than a delete/insert.

DBCC TRACEON (8207, -1)

Read about the details and caveats here. I don't think this is the best solution, but nothing seemed to work, and nobody seems to know why this would occur.

Apache Monitor on Vista

This should be my last Apache/Vista x64 post.

From what I've seen, Apache Monitor won't run correctly out of the box. You'll get some lame error code like "the program completed successfully" or something like that.

What you need to do is go to your start menu, right click on the Apache Monitor, and select Properties. Go to the compatibility tab, and choose the windows XP compatibility mode. That should do it.

Coldfusion / Apache 2.2 on Vista x64

More headaches from installing Apache 2.2 on Vista x64 today.

The Apache connector is bad. First, see Adobe's fairly pathetic technote here.

Install the new wsconfig.jar as they describe. If the remainder of the technote works for you, I hate you. If not, I'll save you a few hours of swearing.

Go to your cfusionmx7\runtime\lib folder and copy the .bat file that's attached to this message (download link below). Of course, you will have to update your paths such that they're correct (you can do that in notepad).

You can also enter commands directly in the command prompt if you are looking for extra stress today.

When all's said and done, apache should hopefully restart and serve up .CFM files correctly.

Installing Apache 2.2 on Vista

I ran into a couple problems today installing Apache HTTP Server v2.2 on Vista x64. Here's the problems, and the workarounds:

  1. Install
    You can't simply click on the Apache install msi and have everything work as it should. You'll get permission errors like service not installed or service not found.

    The solution that I found (via google) is to right click on command prompt in the start menu and select Run as administrator. Once there, navigate to the folder holding your Apache install msi and run it manually. Ish. I'm sure there's a better way, but I wasn't patient enough to find it.

  2. Editing httpd.conf
    This was frustrating. I edited the http.conf file, and when I went to save it, I got an error message saying the file could not be created or something like that.

    The solution is to either modify the security properties of http.conf (giving your user modify access), or run notepad as the administrator (as we did above for command prompt). I'd modify the security settings if I were you.

Removing trailing zeros from decimal numbers in SQL

Say you've got a numeric field (SQL Server DB) which returns numbers to three decimal places, e.g. 1.000, 2.125, 3.250, etc.

How do you return those numbers minus the trailing zeros? I can't believe this is so difficult. Surely there's an easy way to do it. Here's the hack I used:

SELECT replace(rtrim(replace(replace(rtrim(replace(myCol,'0',' ')),' ','0'),'.',' ')),' ','.') as myColDisplay
FROM myTable

Ick.

Quickly Shrink a SQL Server Transaction log

Okay, say you encounter a SQL Server Database that's got a HUGE transaction log, and you need to shrink it quickly. MS has several KB articles such as this one.

But if you really want to shrink the log file fast, and you don't need to keep the transaction log, here's a short cut:

Obviously, you'll need to stop using the database for a few minutes. All SQL processes that access the Database need to be closed.

The first step is to detach the Database. Do not skip this step; it's rather important for the health of your DB:

--detach the database:
EXEC sp_detach_db dbName

The next step is to delete the transaction log file (the .ldf file, NOT the .mdf). Note you are DELETING the transaction log. Obviously, it will no longer be available.

Finally, reattach the Database:

--attach the database:
EXEC sp_attach_single_file_db dbName, 'c\mssql\data\dbName.mdf'

appending an ntext field

Say you want to do something like this:

update table set ntextThing = ntextThing + '!' where id = 1

That's not going to work. This does, though:

DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(ntextThing)
FROM item
WHERE id =1
UPDATETEXT table.ntextthing @ptrval NULL 0 '!'
GO

Nested Query Loops - Worst code ever

I had no idea how bad nested query loops are. But oh man, they are BAD.

I came across this "technique" this week when a very busy site started resonding extremely slowly - like 30 seconds per request, sometimes more. I didn't write the code, but I "got" to fix it.

Check this out, if you have a strong stomach:

[More]

Keep it scalable, kids

We had a lot of trouble today with some really bad code that looked to be written about 10 years ago.

It was simply horrible. Nested loops, tons of CFIFs, you name it. Opening and editing this one CF file felt kinda like fixing a leaky pipe in my crawlspace. Dusty air, spiders all over the place, dark, no room to move...yuck.

Anyway this one page suddenly became very popular, and was definately NOT scalable. I rewrote it so the server would stop crashing (!) and it is now seriously about 100 times faster than before.

If, by chance, you are a person looking for web development services, be sure to get someone who knows what they're doing.

If, by chance, you are a developer, make your code scalable. Most of you know this, but I'll say it anyway -- Just because your code runs well on your dev box, it doesn't mean it will perform the same way when it's hit by 50 concurrent users. And if you have to write nasty slow code, at least cache it.

Thanks, I'm going to bed now.

International Characters in DB from CF 4.5

Every now and then you get a little job that seems simple and straight forward, but is anything but. I just encountered one of those.

I recently inherited an old CF application, written in CF 4.5 or 5.0.

The cfml templates have Japanese characters simply pasted in the file, with a meta tag in the HEAD section of the HTML that sets the character set to x-sjis (shift japanese).

[More]

SES can cause trouble if you're not careful

So I recently deployed some SES URL code to a big site we did. One thing I forgot to do was adjust a layout file that is used by sort of sister site - same content, different layouts.

Anyway, I did not add the BASE HREF tag to this layout file. The layout file uses about 50 images or so, all called via a virtual directory.

<img src="myDir/whatever.gif">

Since I forgot to add a BASE HREF, each image call was preceded with the entire SES url:

So each image request actually called a page of the site! Worse yet, the code took MYDIR as a url parameter, which caused the code to throw an error (an unexpected value).

So each page request was throwing about 50 or so errors, each of which resulted in a robust error report sent to my inbox. I'm still getting email messages 30 minutes later. Ugh.

SES lives on

I've done a lot of work with SES, (Search Engine Safe) URLS in the past. I new project has recently required I use them again.

This client knows a lot about Google placement so it's quite interesting. We'll see how they work.

Changes will probably be made to the red viper systems and green viper systems websites based on the lessons learned here.

See here for our sesConverter stuff, or see it in action.

base href breaks javascript form submit

I placed a BASE HREF tag in my application the other day. To my dismay, it somehow screwed up all of my links that submit a form. For example:

<a href="#" onclick="document.theForm.submit();">

I still am not sure what the issue is. I worked around it fairly easily so I guess I'll put off investigation for when I have the time.

But it's a very irritating little problem that took a while to diagnose.

<TBODY> is handy

TBODY? I never used it before. I thought it was just something Dreamweaver put in HTML for some reason.

But the other day, TBODY came in handy. I used it to make a quick and dirty blowout user interface like this:

[+] Thing 1

The code is very simple - and I got to finally use TBODY:

[More]

RegEx Backreferences

Backreferences are cool, but I've never needed to use them before.

I just ran into something where they were quite handy.

I had to manipulate a string like the following:

TNF S/S VENT POLY SHIRT W

The end goal was to see if the string had either a S/S or L/S in it, along with SHIRT. If both substrings were found, remove SHIRT and move the S/S or L/S to the end of the string.

It's not hard, but a one liner kind of is. Backreferences really helped out here.

[More]

CF Loop Bug

I've seen this numerous times throughout the years but I've never actually written it down.

When you do a CFLOOP within a query loop, odd things occasionally happen.

For example:

<cfoutput query="getWidgets">
<select name="whatever">
<cfloop query="getThings">
      <option value="#getThings.ID#" <cfif getThingsID EQ getWidgets.ThingID>selected </cfif>>#getThings.Name#</option>
</cfloop>
</select>
</cfoutput>

The value for getWidgets.ThingID will be lost!

So you have to patch it up like so:

<cfoutput query="getWidgets">
<select name="whatever">

<!--- This line will fix the problem --->
<cfset foo = getWidgets.thingID>

<cfloop query="getThings">
      <option value="#getThings.ID#" <cfif getThingsID EQ foo>selected </cfif>>#getThings.Name#</option>
</cfloop>
</select>
</cfoutput>

This happens in pretty much all versions of CF I've tested on, including v7.

I don't think this happens EVERY time, just in certain situations. Irritating? Hell yeah.

Adding Line Breaks for Printed Media

CSS gives us a nice way to insert line breaks into HTML with page-break-before and page-break-after.

Here's a pretty self explanitory example below. Looks normal in the browser, but when you print the HTML, line breaks are there.

<html>
<head></head>
<body>
This is the first page
<br style="page-break-before:always;">
This is the second page
<br style="page-break-after:always;">
This is the last page
</body>
</html>

More Entries


Psykel blog uses BlogCFC (by Raymond Camden). Layout design inspired by arcsin