the singularity of being and nothingness
ColdFusion

ColdFusion Query Parameter Weirdness
Aug 3rd
You can file this one under either “huh, that’s kinda cool” or “that’s terrible…don’t ever do it!”…or maybe both.
As of ColdFusion 9, it’s now possible to execute queries in 100% cfscript. This is awesome for me ‘cuz I just happen to prefer to do as much in cfscript as possible.
Anyway, if you’ve worked with the cfscript version of cfquery, you’ll know that mimicking the behavior of cfqueryparam is pretty straightforward. Something like the following should do the trick:
// create new query services qs = new query(); // set attributes of service qs.addattributes(datasource="mydb",name="thequery"); // set sql qs.setsql("select title from posts where isawesome = ?); // set queryparam for dynamic query qs.addparam(value="Awesome",cfsqltype="varchar"); ...rest of processing...
Easy enough. I got to wondering if it would be possible to use a ternary operator as the “value” of the queryparam. Turns out, you can 🙂
// set queryparam for dynamic query using ternary operator qs.addparam(value=form.isawesome==true ? 'Awesome' : '',cfsqltype="varchar");
Here, if a form variable (“isawesome”) is set to true, the value of the parameter will be “Awesome”; otherwise, it will be set to empty string.
I’m not sure how I feel about this. On a certain level, it’s cool that it works. However, it feels kind of hacky to More >

CFScript Alternative to CFContent
Jul 29th
Ran into this issue today. At work, data returned from CFCs have a bunch of content pre-pended. In regular tag-flow coding, this is super-simple to overcome:
<cfcontent type="text/plain" reset="true" /> <cfreturn mycontent />
Using the cfcontent tag, I can “[discard] output that precedes call to cfcontent” (from the docs :)). This strips out all the garbage that I don’t want, and returns only the awesome data that I need.
Since we’re getting ready to upgrade to CF9, however, I’ve been playing around with writing my ColdFusion components in the new 100% script-based syntax. One problem, though: there is no cfscript version of cfcontent, so I’m back to the original problem.
Fortunately, there is a solution. By tapping into the underlying Java methods that are exposed, we can easily recreate similar functionality. Here’s all it takes:
remote any function getdata() {    getpagecontext().getcfoutput().clearall();   �    return supersweetdata; }
Nothing to it.  And for future reference, take 5 minutes to dump out getpagecontext().  You can see all the nice methods that are available…who knows, you might just find something useful 🙂
Share this:
Java String Methods in ColdFusion
Jun 29th
This is nothing new or shocking, but I thought I’d post it anyway. When you’re dealing with ColdFusion content, you have available a number of exposed Java string methods that can be used in addition to the functions that CF provides. You don’t have to invoke any Java objects or nonsense like that–simply call the method and see what happens.
Of course, many from the full list of Java string methods are either already familiar via CF functions or can be replicated quite easily by CF-only functions. Nonetheless, I thought I’d share a quick roundup of what I think are some of the more interesting, along with simple examples of how to use them. I hope you enjoy this Bleach-inspired sampling 🙂
Method Code Result charatvalue = 'Bleach is awesome'; value.charat(3);3 concat
value = 'Bleach is awesome'; addtl = ' because of the epic battle sequences'; value.concat(addtl)Bleach is awesome because of the epic battle sequences contains
value = 'Ichigo Kurosaki'; value.contains('saki');Yes endswith (case sensitive)
value = 'Zanpakutou'; value.endswith('tou');Yes lastindexof
value = 'You can catch new episodes of Bleach on crunchyroll.com, but only if you have a membership for which you pay each month'; value.lastindexof('you');101 split
value = 'Shinigami|Bount|Hollow'; value.split('|');[Shinigami,Bount,Hollow] startswith (case sensitive) More >

ColdFusion 9 and Ternary Operation
Jun 23rd
Just a quickie 🙂
I learned about ternary operators in JavaScript probably about 6 months ago, and absolutely fell in love with it. After all, who doesn’t love to convert something bulky to something clean and able to fit on one line?
THEN:
var myidea = ''; if(thething=='yes) { Â Â Â Â myidea = 'great'; } else { Â Â Â myidea = 'lame'; }
NOW:
var myidea = thething=='yes' ? 'great' : 'lame';
The other day, I was busting out some <cfscript>, and came across a bit of evaluation where a ternary operator would be PERFECT. Having no idea whether or not it would work, I gave it a shot and voila!, it’s magic!
<cfscript> Â Â Â Â myidea = thething=='yes' ? 'great' : 'lame'; </cfscript>
Now after a bit more investigating, turns out this is in the “only works for CF9” domain. Nonetheless, pretty nice–I love saving keystrokes!
Share this:
Migrating a Custom Blog (or blogs…) to WordPress
Jun 11th
When I first got into web development, one of my first projects was to create a custom blog for myself. Apart from the sheer necessity of needing a blog at the time, I embarked on this coding journey because I had read somewhere that developing a blog would provide a good introduction to the nitty-gritty of application design.
While this wasn’t 100% accurate, it also was not terrifically far from the truth. Through many struggles and achievements, I finally wound up with my own custom blog, complete with commenting system, RSS delivery, and eventually automatic posting to Twitter.
This modest blog served me pretty well for a few months, but I quickly outgrew it. I found myself pouring precious hours into little development projects to try to get it to do cool stuff that I came across in other, more robust systems.
Eventually, however, I ran out of time and motivation. First, the continual development stopped. Then, out of total laziness, important things like bug fixes and comment-security fell to the wayside. While I still loved to blog, the sheer effort of posting (my interface was a bit clunky…) was a big hindrance, so the posts became quite sparse.
Then I got my iPhone. More >

Monty Hall Problem…in ColdFusion
Jun 6th
If you saw my post about the Monty Hall Problem, you know that calculating the probabilities in this puzzle, while not terrifically complicated, are nonetheless a bit frustrating to our feelings of common sense. Therefore, I decided to whip up a quick script that would simulate the Monty Hall problem in code.
It turns out that this has been done many times before, and if you head on over to rosettacode.org, you can find scripts for nearly every language you could imagine…except ColdFusion.
Thinking this to be an incredible travesty, I have produced a CF version of the problem, and have posted it over at rosettacode.org.
If you’re too lazy to click a link, however, here is the script in its entirety:
<cfscript> function runmontyhall(num_tests) { // number of wins when player switches after original selection switch_wins = 0; // number of wins when players "sticks" with original selection stick_wins = 0; // run all the tests for(i=1;i<=num_tests;i++) { // unconditioned potential for selection of each door doors = [0,0,0]; // winning door is randomly assigned... winner = randrange(1,3); // ...and actualized in the array of real doors doors[winner] = 1; // player chooses one of three doors choice = randrange(1,3); do { // More >

Update Miscellany
Mar 29th
Wow, it's been far too long since I've posted. I've been quite busy as of late, and have been putting the finishing touches on a couple of pretty decent sized projects.
But perhaps most interesting to followers of this site is the fact that I'll be working with a friend of mine over the next couple of months to completely revamp a site that we think will be pretty sweet in a couple of months. But the coolest part is that we're going to be creating this site–as much as possible–using exclusively ColdFusion ORM. As we make progress, I'm going to do my best to regularly blog about our experiences as we tap into this extremely cool technology that is available in CF9.
So anyway, stay tuned…I hope to have some killer posts up very soon 🙂
Share this:
ColdFusion and ORM…Yummy!
Mar 2nd
The other day, I was flipping through the ColdFusion docs (yeah, super exciting!) and came across the section about ColdFusion's support of ORM. If you're not familiar with it (I wasn't really until a few days ago), ORM stands for "object-relational mapping." While it sounds a bit overly technical, ORM is basically a way to interface objects in code to relational databases that levels the playing field, allowing your code to be more or less agnostic about what kind (or kinds) of databases that it's connecting to.
At first, I was unimpressed, but then I took a few moments to think about it. How often have I had to switch between database systems? Plenty. And how fun was it to have to go back and rework my code to account for the differences in typing and syntax? It wasn't. With ORM, however, alot of these headaches are removed because you can create an abstraction layer in your application using ORM to not really have to worry about what datasource you might be connecting to.
Now obviously, the subject of ORM is much more complex than my admittedly weak description. However, after a lot of reading I feel like I have a decent More >

Ext to ColdFusion…Nice!
Feb 21st
So I know a lot of the posts I’ve been writing recently have been about stuff that’s been around a while–Ext helper functions, CFScript, etc. Nonetheless, I post them because some of the answers to questions I’ve found in developing solutions have been less-than-easy to find, so perhaps repeating some of the same things again will help Google find it a bit easier for someone else someday.
On with redundancy!
Obviously, JSON-related technologies have been around for a while, and with ColdFusion 8, a lot of native JSON handling was added for the creation of some sweet AJAX-y goodness. While I’ve dabbled with these, I’ve never really had a need for them…until now.
I recently developed a remote CFC function that required about 12 different arguments. On the client side, I also developed a quick EXT Ajax.request() method to pass these arguments into the CFC function.
Now with Ext, it’s incredibly simple to pass arguments to server-side functions, as this example illustrates:
Ext.Ajax.request({ url: 'com/functions.cfc', success: successMethod, failure: errorMethod, headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}, params: {method:'setupLife',argument1:arg1,argument2:arg2} });
I like this alot, because it allows me to treat each argument as its own “thing,” rather than stringing together a bunch of “&argument1=arg1” in the query string.
But what if More >

Turning to the Darkside…of <cfscript>
Jan 22nd
During a lull at work the other day, I was reading about the extended capabilities that have been added to <cfscript> in ColdFusion 9, like being able to create queries and entire components…
Honestly, until recently I've not really used a whole lot of . I'm not really sure why…just not something that interested me a whole lot. You think it would: I like JavaScript syntax a lot, and translating these skills to <cfscript> is pretty straightforward. Still, not a whole lot of experience.
Honestly, I think a lot of it is that there's something comforting about the tag syntax. It's easy to see a balance in your code, and even easier–depending on your IDE–to see where you've completely borked something, left out a tag…whatever. Some of it, out of necessity, is that not every tag has a equivalent, although efforts are underway to remedy this…Whatever the reasons might be, it's super-simple to get used to the tags and then feel quite lost in <cfscript>.
The revelation for me was kind of interesting. For starters, outside of the very specific tags like, say, <cfexecute>, what are the majority of the tags that you use in a regular swatch of code? For me, it's a More >