CFDUMP equivalent in Flex?

I’ve made the leap into the world of Flex in the last day or so, and so am going through the process of “Flexing” concepts I know from other languages.  I’m going to make a note of all of them because I think they’re handy to know.

Tonight while trying to workout some functionality related to web services I found I needed to delve into the data being retrieved,  the need for the ever handy CFDUMP came to mind.  A look around showed that there doesn’t appear to be anything as user friendly as CFdump in Flex, but I cam across this article on ObjectUtil.

Basically you can use the ObjectUtil class to dump trace data (including complex objects) to the debug window thus:

<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.managers.PopUpManager;
import mx.utils.ObjectUtil;
private function remotingCFCHandler(e:ResultEvent):void
{
//Dump the result of a call to a webservice
trace( ObjectUtil.toString( e.result ) );
}
]]>
</mx:Script>

<mx:Script>

<![CDATA[

import mx.rpc.events.ResultEvent;

import mx.managers.PopUpManager;

import mx.utils.ObjectUtil;

private function remotingCFCHandler(e:ResultEvent):void

{

//Dump the result of a call to a webservice

trace( ObjectUtil.toString( e.result ) );

}

]]>

</mx:Script>

Which will while not quite CFDUMP will provide you (hopefully) with enough data to move past your problem.

How to use SnagIt to post direct to Evernote

Found a great tutorial today that demonstrates clipping direct from SnagIt 8+ to Evernote, two of my favourite tools the latter of which I’ve only really just discovered.  The tutorial on Posting from SnagIt to Evernote is simple to implement and while the demo is for SnagIt 9 I still use a version 8 of the product and it works in exactly the same way.  Great solution for two brilliant tools…

Conditional formatting in excel – Highlight a column if it is longer than X

I’ve been using Excel a lot more recently to crunch numbers, and something that I’ve found particularly handy has been the conditional formatting function, which will surprise surprise, format a cell or cells based on a condition. For me I was using the spreadsheet to highlight cells based on the length of their contents, I was using the spreadsheet for managing Google Adwords and needed to be sure that the titles, and descriptions didn’t exceed their maximum length like this:

excel-conditional-formatting-highight

I found it surprisingly confusing initially, mainly I think because I was thinking the conditional formatting was going to be managed inline like a traditional formula, it isn’t, it has it’s own management interface where you specify to what the formatting is supposed to be applied and for what reasons.

Ok, so I won’t go gthrough the whole process, I’ll assume you have seen (in Outlook 2007) the “Conditional formatting” button under the “home” tab:

excel-conditional-formatting-select

And have also seen the “Highlight Cells rules” link underneath, here is the place where you can specify the conditions you want to highlight, and have set it up so that at least one cell does what you want (this was pretty straight forward I think, if you’re not sure what to do please leave a comment/question).

From here though I was stuck, I didn’t get how to update the range to which it was applied, and have it rolled out across multiple cells.  In step the  ”Manage rules” link that is in the image above.  This is a separate screen where you get a summary of all the conditional formatting rules on your spreadsheet. Open it up and you will see something like this:

excel-conditional-formatting-manage

As you can see I have used a formula based on a relative cell value (i.e. one that updates relative to the cell you’re working with rather than referring to a single static location), this is what those $ symbols mean, the rule I have is that any cell that exceeds 25 characters in length should be coloured red.  The mistake I had originally made was to firstly not use a relative cell value (my original formula was len($S$1) > 25    ) and then to not have specified the range correctly in the “applies to” box.

Experimenting with the “Rules Manager” for conditional formatting reveals this to be just as powerful as you were probably expecting when you started.  Good luck!

.htaccess redirecting a Wordpress site to a new domain

.htaccess problems and can be a real pain, especially if like me you only do things with the .htaccess file every now and then so aren’t completely comfortable with the syntax.  Last night when helping a friend and author of the excellent ExchangeWire (about tracking the nascent ad exchange and ad trading networks) switch a domain, I configured the .htaccess file using a standard format:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www. oldomain.com$
RewriteRule ^(.*)$ “http\:\/\/www\.newdomain\.com\/$1″ [R=301,L]

I say “a” standard format because as anyone who has used .htaccess before knows, there are a few variations on this syntax that do the same thing.  Not thinking about it much I put this in the root .htaccess of the Wordpress install, I tested the top domain, worked fine, but the pages themselves just kept redirecting to the the root, not the actual page.  My complete .htaccess file that was not redirecting properly:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www. oldomain.com$
RewriteRule ^(.*)$ “http\:\/\/www\.newdomain\.com\/$1″ [R=301,L]

Ok so the clued up amongst you will realise the problem was caused because of the ordering of the commands I had put in the file, this is important. In terms of importance, the domain redirection had to happen first, so I needed to put it above the Wordpress command otherwise the Wordpress command hijacked the process and confused the primary redirect.  So, the lesson is be careful of the order you put things in and the potential conflicts that can occur as a result.  Keep the major redirects/rules at the top of the page (e.g. when you want to change domains) and the more detailed one(s) below for more consistency (such as Wordpress redirects).

Time to tweet!

I’ve finally integrated this little blog of tips and tricks with a twitter account.  If you’d like to keep up to date on the latest posts,  please follow me!

fb.connect.logout doesn’t work (doesn’t log user out of facebook)

I’ve been doing a Facebook Connect implementation using CakePHP and was having no luck using the fb.connect.logout function.  I’m not sure whether this qualifies as a bug (dodgy code) or just a case of RTFM (or look at the examples closely) but I simply couldn’t get the fb.connect.logout function to log me out of Facebook and consequently my own application.

Testing a few combinations the on

<a href=”/users/logout” onclick=”FB.Connect.logout(logoutCallback())”>Logout</a>

(who’s logic I found here http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.logout)

simply didn’t work.  The function was called as was the callback but it simply didn’t log out of Facebook.

The only way I could get it to work was using the logoutAndRedirect function instead, using the following:

<a href=”#” onclick=”FB.Connect.logoutAndRedirect(‘/users/logout’)”>Logout</a>

NOTE: Originally I had put a value in the href attribute (“/users/logout” thinking it would degrade nicely) but this stopped the main function from working, so as far as I can tell you must have a # symbol in the href.

Variable is “undefined” even with cfparam Coldfusion 9

Going through some testing as part of our upgrade to Coldfusion 9 I encountered a compatibility issue that is worth knowing about. In Coldfusion 9 there is now a variable status “undefined”, that is the variable can exist (and appear in cfdump for example) but is not usable, it is explicitly undefined. This is a problem because if you try and use cfparam later for example it doesn’t override the “undefined” variable. So far the only place I’ve seen this is when using components, and then to be fair the condition arose because of some inconsistent defaulting so it’s not completely the fault of the new process but it’s worth being aware of if you are getting unexplained “undefined” errors when moving up to Coldfusion 9.

Ok so consider the following:

<CFFUNCTION name=”getByCriteria” access=”public” returntype=”query” output=”false” displayname=”" hint=”">
<CFARGUMENT name=”child_ocl_id” required=”false” >

This will result in an explicitly set variable that is set to “undefined” – the cfdump is thus:

cfdump_with_undefined_variable

Note the explicitly “undefined” status as well as (what my code was expecting) the “[empty string]” status

This stays the same whether you add a cfparam later or not, thus:

<CFFUNCTION name=”getByCriteria” access=”public” returntype=”query” output=”false” displayname=”" hint=”">
<CFARGUMENT name=”child_ocl_id” required=”false” >
<CFPARAM name=”arguments.child_ocl_id” default=”my new default” >

Note the above example isn’t what was in my code! It’s just a simple explanation of the behaviour I noticed. So just something to be aware of if you get unexplained “undefined” errors in your migration to Coldfusion 9.

How to retrieve the Facebook session key using php client api

Working through an implementation of the Facebook Connect I got caught up in the tangle of documentation that surrounds it and couldn’t work out how to get the session key information so here it is a note to self about how to retrieve the Facebook session key using php client api:

$fbsessionid = $this->facebook->api_client->session_key;

PHP new line not showing in text

Note to self whenever you are experiencing problems with rendering new lines in php e.g. using \n you must wrap these in double quotes not single e.g.

This will NOT work

echo ='My line with a line feed \n';

This WILL work

echo ="My line with a line feed \n";

Free coldfusion Diff comparison of HTML – CFX_CompareHTML

The Coldfusion open source community just keeps getting stronger. Whenever I talk to other cf programmers who are thinking of moving to another platform (there still seems to be a deep seated belief that CF is not a “real” programming language) I point them to great projects like RIAForge or a host of open source tags and components that I have used recently to remind them that the community is alive and well.

The latest of these that I have implemented successfully is an excellent implementation of DaisyDiff by Daniel Mackey.  Though he has put together a direct Java jar implementation I have opted for his CFX_CompareHTML implementation because of it’s support for UTF-8 characters, he sent it on to me directly the last time I checked it wasn’t available on line (thanks Dan).

The free CFX_compareHTML does a DIFF analyses on formatted html, and then displays it as a combined diff output, this is useful for comparing before and after content for example and is comparable to tools such as (the very expensive) diffdoc.  Diffdoc costs about $4000 for a server license, and while it has more applications (i.e. as a desktop tool) for web based html comparison CFX_CompareHTML is more than adequate.

Once installed (the one downside of CFX tags is of course the need to install them and set their path in CF admin) it’s as simple as:

<cfx_CompareHTML left=“Some HTML content” right=“Some more HTML Content”>

Produces the following (nicked from CFDan.com – hope that’s ok Dan?!)

compareHTML

As I mentioned there are a couple of great tags/components in the CF open source world that I’ve used lately, and inspired by this excellent work I’ll be documenting them over the coming days.