hierarchyid Data Type Not Supported in ColdFusion 9

Microsoft SQL 2008 introduced the hierarchyid datatype helping with child/parent relationships. However this causes an issue if you try to select its data via ColdFusion’s Microsoft SQL Server driver. This breaks in ColdFusion 9.0.1 and I assume prior versions.

Example Table:

CREATE TABLE Org_T1
(
EmployeeId hierarchyid PRIMARY KEY,
EmployeeName nvarchar(50)
)

Example SQL Call:

SELECT * FROM Org_T1

Now first of all you should try to avoid “SELECT *” when possible anyway to increase efficiency. Otherwise the table columns are looked up before querying for results, adding an extra process step.

The way around this would be to list the columns you actually need in the select statement. If you need the data from the “EmployeeId” column you could append the “.ToString()” function to the column name. Example:

SELECT EmployeeId.ToString(), EmployeeName
FROM Org_T1

This will in effect change what data you receive however. The raw data looks something like “0xf0”. The result of the ToString() method looks something like “\1\” and I believe will be of varchar type.

There is a bug entry with Adobe here: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=83590 . Feel free to go vote on this issue to increase its visibility with the ColdFusion team.

NuVal – My New Grocery Shopping Buddy

In Omaha there a quite a few supermarkets to choose from for groceries including Bag and Save, Bakers, Hy-Vee, No Frills, Super Saver, Walmart and more. But I’ve taken notice of one lately: Hy-Vee. They have started to make a move similar to Walgreens and Walmart; they have begun rebuilding or remodeling their stores from cookie-cutter box stores to a more inviting and unique stores.

This transition includes promoting more healthy and organic foods, kind of a middle-man between store XYZ and Whole Foods (which I’ve never been to). But was has been bringing me back more and more is their prominent displays of the NuVal scores. They are an easily recognizable icon next to each product’s price bar that contains a number from 1-100. The greater the number, the healthier the food choice for that food category.

What has caught my attention are facts such as Kraft Fat Free Italian Dressing is has a worse rating than the original. Another example would be noticing the salted and non-salted canned green beans. I’m going to put the same amount of salt on my green beans after I cook it, so I might as well start with none, thus increasing the product’s NuVal score by quite a few points. Even going after the frozen broccoli, some have a higher score because they are preserved or seasoned differently.

Continue reading

SQL – Delete Orphans

In the 1930’s Miss Hannigan wanted to delete orphan Annie, but now we have child neglect laws that prohibit that. Good thing we now have SQL.

Lets say we have two SQL tables that contains names of team members. One is for softball and one is for baseball. We want to remove all players from softball that do not play baseball. You could do this in a loop or a subquery, but if you have team data from the past 100 years this may become quite costly.

Here’s a quick way to make this happen:

DELETE S
FROM Softball S
LEFT JOIN Baseball B ON (S.Name = B.Name)
WHERE S.Name IS NULL

What this is doing is matching the table Softball with Baseball. Any orphaned Softball players (no match with Baseball) end up getting deleted.

Understanding Hexadecimal Color Values

I’ve known about hexadecimal color values for HTML probably since 1994, back in Netscape Navigator Beta days. I’ve always known that they represent a group of Red-Blue-Green values, that when modified you get a new color, however slight or dramatic. Each position can have a value of 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e or f.

But I never really understood why such a silly system that required me to open Photoshop or use Dreamweaver to find the color I’m looking for; that is until today.

Most of us humans do math with a base of 10 (1, 10, 100…). However computer binary code uses a base of 8 (8, 16, 32, 64, 128… look familiar from your SD memory cards?) Hexadecimal has a base of 16, which is easy for a computer to use since 8 + 8 = 16.

Also remember that most visible colors can be reproduced using a mixture of red, green or blue (primary colors) thus we have the RGB groupings.

So “000000” is black and “FFFFFF” is white. In otherwords “000000” has no color and “FFFFFF” has all the color. So what if you want just a little red? Something like “010000” should do it. But what if you want a lot of red? Try “FF0000”. Yellow? “Try “FFFF00”. But this is the basics most of us know.

But where does the alphabet come into play? Can’t seem to get that one position above 9 can you? So use the alphabet to keep adding on top of that 9. So the value of F basically equals a 15 fit into one placeholder. If you want to go to 16 you’d start back at 0 and add a 1 to the previous place holder thus “0F0000” becomes “100000” for that little bit of red.

If this explanation is boring you or just confusing – watch a great short video about this at Nettuts+ .

After I watched this video I now have a clear understanding of what is going on here instead of just winging it via an IDE.

Global AJAX Loading Spinners

Many sites include what are known as AJAX Spinners. They are little graphics that show up on a web page that show something is happening behind the scenes. This is most commonly used when an AJAX request is being made and the end-user is waiting for a response.

There are many different ways you can make this happen.

One is to show and hide the spinner inside each AJAX method. Another is to show and hide the spinner inside the jQuery $.ajaxSetup configuration.

If you load individual spinners for each call this is a pain and can be cluttering. If you load a common spinner you can end up hiding it before a parallel request is finished unless you look at a queue, which is also a pain.

One easy way around all this confusion is to use jQuery’s global AJAX handlers: .ajaxStart and .ajaxStop (also look at .ajaxError)

First setup a common spinner container and graphic.

<style>
#ajaxSpinnerContainer {height:11px;}
#ajaxSpinnerImage {display:none;}
</style>

<div id="ajaxSpinnerContainer">
<img src="/images/ajax-loader.gif" id="ajaxSpinnerImage" title="working...">
</div>

One great place to generate these spinners is ajaxload.info.

The next step is to show the spinner when any AJAX request has begun and hide it when all AJAX requests have completed.

$(document)
.ajaxStart(function(){
    $("#ajaxSpinnerImage").show();
})
.ajaxStop(function(){
    $("#ajaxSpinnerImage").hide();
});

This quick and easy method avoids all the other headache associated with all the other techniques out there as long as you want the spinner shown in a single container.

#ajax, #jquery, #spinner

jQuery Templates

I decided to dig into the new official jQuery Template Plugin developed from Microsoft yesterday. After I finally got the darn thing to work it makes inserting formatted HTML populated with data way easier.

After doing some searches on Google I kept finding articles that announce that Templates would be built into the version 1.5 core. I continued down the path coding by example and researching the API Docs. However I kept running into “tmpl is not a function”. After some continued research I finally found a tiny little comment made by John Resig that it in fact did not make it into the 1.5 release. So now that error makes sense.

To resolve this issue you must still load the jQuery plugin. It appears the plugin is still in beta stages and is available for download from Github or the Microsoft CDN.

Before I’ve been unable to use Microsoft’s CDN because it did not have SSL. But I went ahead and tested to see if they now have it included, and they do!

Here’s how I use it:

<script src="//ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>

This will automatically call it via http or https depending upon the current browser protocol being used.

See a related blog for jQuery on Google’s CDN here.

#cdn, #google, #jquery, #microsoft, #plugin, #template

Detect Mobile Browsers

I’m still fairly new to the mobile platform programming and I’ve never been able to find a good way to detect if you’re coming via a mobile browser or a full browser – until now. Usually what I do is put this in my normal page headers and redirect them to a mobile directory if mobile is detected.

Thanks to Ray Camden‘s suggestion, check out Detect Mobile Browser.

This site has contains open source mobile phone detection scripts for 15 languages / apps.

List includes: Apache, ASP, ASP.NET, ColdFusion, C#, IIS, JSP, JavaScript, jQuery, nginx, node.js, PHP, Perl, Python, and Rails

The ColdFusion script is pretty straight forward and uses a regular expression to figure it all out.

Continue reading

#mobile

MockBox – Mocking a Super Class – Solution

Yesterday I wrote about mocking a super class method while unit testing with MXUnit. If CFC A extends CFC B, and both have the same method name, how do I mock the super method for its call?

Luis Majano with ColdBox wrote up a Blog Post to address how to accomplish this.

Use my example from my previous post:

<!--- Child Class --->
<cfcomponent name="C" extends="message" output="false">
    <cffunction name="send" access="public" returntype="void" output="false">
        <cfargument name="name" type="string" required="true">
        <cfif name neq "test">
            <cfset super.send(name=arguments.name)>
        </cfif>
    </cffunction>
</cfcomponent>

<!--- Parent Class --->
<cfcomponent name="P" output="false">
    <cffunction name="send" access="public" returntype="void" output="false">
        <cfargument name="name" type="string" required="true">
        <!--- Do something --->
    </cffunction>
</cfcomponent>

The super scope is a reference in the variables scope. You can create a MockBox stub to accomplish mocking the super scope. This example creates an empty stub object that mocks the parent send method. The child’s super variable is then overwritten with this stub object. Stub objects are generally used to start working on a project where you are relying on other teams to build that object but has yet to be built.

function setup(){
    variables.mockBox = new mockbox.MockBox();
    variables.component = variables.mockBox.prepareMock( createObject("component","C") );
}

function testSend() {
    // create a virtual super scope and mock a send method on it
    mockSuper = variables.mockBox.createStub().$("send");

    // inject the mock super into the variables scope
    variables.component.$property("super","variables", mockSuper);

    // run the method call
    variables.component.super.$('send');</pre>
}

Luis also states that you can also create a mock of the parent class to leave the methods intact.

variables.mockBox.createMock("P").$("send");

I am still looking for opinions on if I should actually be doing this? Perhaps I should just consider the parent class as a whole and just let the parent method run. What are your ideas on this? How have you handled this in the past and how was your outcome?

#mockbox, #super-class

MockBox – Mocking a Super Class

I’m getting my hands dirty using MXUnit Testing w/ MockBox recently. The basics where fairly easy to pickup, but I’ve now hit a road block. Lets say I need to test this method:

<cfcomponent extends="message" output="false">
    <cffunction name="send" access="public" returntype="void" output="false">
        <cfargument name="name" type="string" required="true">
        <cfif name neq "test">
            <cfset super.send(name=arguments.name)>
        </cfif>
    </cffunction>
</cfcomponent>

So following unit test ideology, I should just test what’s happening in this method and not attached methods.  If I had instantiated an object or the method was in the some component I could just mock the method being called. However since the method is located in the component’s parent, this does not appear to be working. The test contains:

variables.mockBox = new mockbox.MockBox();
variables.component = CreateObject('component', 'thisComponent');
variables.mockBox.prepareMock(variables.component);
variables.component.super.$('send');

This returns the error: “Expression: Element COMPONENT.SUPER is undefined in a Java object of type class [Ljava.lang.String; referenced as ””.

Now technically I could wrap the super.send call inside another local method and mock that method. However that would be coding for the test and would be worthless code and processor usage outside the test.

I’ve Googled this and searched ColdBox’s site for a solution to this, however I’m not getting anywhere.

Does anyone have any ideas or suggestions?

Impressive WP.com Stats

In Feb 2007 WP.com (WordPress) blogged they where running:

  • 152 Physical Processors
  • 511 GB of RAM
  • 174 Hard Drives
  • Several Tera-bytes of Storage

Now 4 years later they are at:

  • 2,475 Physical Processors w/ 8,291 CPU Cores
  • 8,200 GB of RAM
  • 1.3 TB RAM Drives
  • 1.3 Peta-bytes of Storage
  • 8.9 TB of Solid State Disks
  • Plus Amazon S3 as a Backup

So here’s my two cents to add to the load: That’s pretty impressive numbers for a blogging service.