Tag Archives: coldfusion

Ruby Line Formatting

I wrote a little utility to turn something like this

this=that,
something_else="something else entirely"

Into the much easier to read

this           = that,
something_else = "something else entirely"

I use it in conjunction with my clipboard utility so I can just copy, run, paste. I mostly use this when I’m working with ColdFusion, so it also works for those pesky cfsets.

Usage: (After copying your target text to your clipboard)

ruby clipboard_format_set.rb

Download It!

PS: I’d love to set some of my scripts up as Eclipse shortcuts so I’ve been toying with the idea of writing an Eclipse plug-in to act as a proxy. I realize you can set up and run “External Tools”, but I have yet to see a way to bind a key. I’d like the plug-in to take care of the “pasting” to save me that extra ctrl-v. Maybe this would make a good New Years Project?

CFEclipse/Ganymede Line Number Problem

My tray line numbers weren’t showing up in CFEclipse since upgrading to the Ganymede version of eclipse. My preferences were set correctly. I did a bit of googling but I didn’t actually find the solution until a few links down, so I thought I’d share the link love!

http://blog.critical-web.com/blog/index.cfm/2008/8/3/Enabling-Line-Numbers-In-CFEclipse-1316-On-Eclipse-Ganymede-34

1. In directory
[workspace]/.metadata/.plugins/.org.eclipse.core.runtime/.settings/

2. Edit (or create) a text file called
.org.cfeclipse.cfml.pref

3. Add the following line:
lineNumberRuler=true

4. Restart Eclipse

How to Recover a Deleted File in Eclipse

I don’t know how (yet) and I can’t recreate it, but I swear that Eclipse ate two of my files while in the CFEclipse perspective. Neither of which I had placed under version-control yet. (DOH!) I was able to recover one of them from a nightly back-up.

When trying to figure out exactly what the heck happened, I took a peek at the local history for my back-up file and Eclipse still had the record of my changes up to the moment I lost the file!

Sooooo I re-created my lost file, right-clicked “Compare With” and “Local History” and I was able to re-cover the latest version of my file!

Phew!

Thoughts on Bolt

As anyone subscribing to MXNA has heard en masse today, the big news ’round the CF Circuit is the announcement of a ColdFusion “development tool” affectionately titled Bolt. (Although Adobe does has a habit of changing titles on us)

Here’s what I’m on about.

1. Will it run on Linux?
This is a requirement for me. Since it’s an “Eclipse based development tool” I assume it will, but I’d like to see it asserted. I don’t mind paying a reasonable sum, but not if I have to wine or vm it.

2. Is it a plug-in or an IDE?
I hope by “development tool”, they mean plug-in. At the time of this writing there are 1101 plug-ins listed on eclipseplugincentral.com and I’d like to be able to use any and all of them if I so choose. If I want to run Spket instead of JSEclipse, I don’t want any grief about it. Also, I like having an agnostic editor. I want one IDE to rule them all. Chances are that if I have to keep eclipse around for my other languages then I’ll probably going to just stick with it.

3. Bloat-i-ness?
I’m a little worried about Bolt being tacked onto eclipse along with a laundry list of exciting! new! features! that I won’t use past the first week, but making for great upper-management selling points. I’m drowning in features as it is. This wouldn’t be such a big deal except that I’ve noticed eclipse can be a memory hog. I know it’s not an accurate measurement but it irritates me when I pop open the task manager on my windows box and see eclipse running well into the hundreds of megs, especially when e does most of what I want with a fraction of the memory and cpu usage.

All I really need out of an IDE is multi language and OS support, code-highlighting, snippets, RDS, auto-tabbing and intellisense. I signed up for the beta; if you can do this better than Eclipse, Adobe, I’m all yours.

Chase Paymentech / CFHTTP Problem

I was working on implementing a ColdFusion payment processor for Chase Paymentech, but I kept running into the same error (which I’ve formatted so nicely using my ruby clipboard format utility!)

<?xml version='1.0' encoding='UTF-8'?>
<Response>
    <QuickResp>
        <ProcStatus>05</ProcStatus>
        <StatusMsg>PTI43,TEXT/XML; CHARSET=UTF-8 is not supported</StatusMsg>
    </QuickResp>
</Response>

I knew that PTI43 was part of the MIME Header Content-Type I was passing, so I did a little bit of poking around in the docs and came upon this. Apparently setting a cfhttpparam type of “xml” “identifies the request as having a content-type of text/xml.”.

In order to send a valid message to chase you have to specify a particular MIME header setting “Content-Type”, which ColdFusion was garbling. Thankfully all I had to do to fix it was switch the cfhttpparam type attribute to “body” in order to fix it.

<cffunction name="Authorize" output="no">
    <cfargument name="vars" required="yes"/>

    <cfset var cfhttp = ""/>
    <cfset var i = ""/>

    <cfheader name="POST /AUTHORIZE HTTP/1.1">
    <cfhttp url="#GetURL()#" port="#GetPort()#" method="POST">
        <cfloop collection="#arguments.vars#" item="i">
            <!--- header variables --->
            <cfif i NEQ "XML">
                <cfhttpparam
                    type="header"
                    name="#i#"
                    value="#arguments.vars[i]#"
                />
            </cfif>
        </cfloop>

        <!--- set the type to "body" NOT "xml"!!! --->
        <cfhttpparam
            type="body"
            value="#arguments.vars["XML"]#"
        />
    </cfhttp>

    <cfreturn cfhttp/>
</cffunction>

I hadn’t run into this problem before, so I thought I’d share!

ColdFusion MySQL Search Utility

There’s a legacy app I work on that currently requires adding 4 columns and a couple rows (in different tables) every time you add a row to another table. It doesn’t happen often and it would be a nightmare to refactor so I wrote little script that would search the database for any columns named ‘x’ as well as any fields with a value of ‘x’ and return an array of the offending tables.

I cleaned it up a little bit and cfc-ized it in case I ever have to do anything similar. I haven’t tested it at all aside from the one time I ran it today so use it at your own risk. It’s really simple to use, you just need to pass in the ColdFusion datasource name and the search term.

Example Usage:



Looking for column #search_term#



Looking for value  #search_term#

Download ColdFusion MySQL Search Utility!

PS: it won’t search numeric columns if you aren’t searching for a number.

JavaScript Tile Puzzle

I was tinkering a bit while watching the tube tonight and I thought it might be fun to make a simple JavaScript tile puzzle. Might look terrible in other browsers.

First step was to write a little ruby script (using the GD Graphics Library) to read in a file and cut it up into individual tiles. (Photoshop is for wussies)

if __file__ = $0
  #pass the image name, tile size through the command line
  t = Tile_Cropper.new ARGV[0], ARGV[1].to_i
  t.crop_tiles
end

Then I used a slightly modified method I read about in Ben Nadel’s blog to scramble the tiles.


	
	
	
	
		
	
	

A little bit of CSS magic:

#puzzle {
	width:      500px;
	margin:     0px;
	padding:    0px;
}
.piece {
	list-style: none;
	display:    inline;
	margin:     0px;
	padding:    0px;
}
img {
	border:     1px solid gray;
}

And finally I used scriptaculous and prototype for the obnoxious drag-and-drop sorting. Not that I’m complaining. the Sortable methods weren’t intended to be used for something like this.

function init() {
	Sortable.create('puzzle');
}

Complete the puzzle to find out what I was watching!. Here, I’ll give you a hint. It’s Dexter.

Download the code.

JavaScript Game Of Life Pt 1

I thought it would be fun to implement Conway’s Game Of Life. I used ColdFusion a bit in my example to ease some typing but the “engine” is all JavaScript. Beloved Prototype is also being used a bit behind the scenes.

So without further ado, here’s a

// set up a game of size 30 x 30

g = new Game_Of_Life(30);

// set some random tiles, note that you
// have way more of these for a size
// 30 board.

g.set_tile(2,26,1);
g.set_tile(19,20,1);

// draw inital board

g.draw();

// run the game, 1/25s "frame-rate" 
g.run(.25);

Click to see a demonstration.

And, as always: Download the code!

PS: It looks like terrible in Internet Explorer. No comment.

ColdFusion NPR API Pt. 2

I’ve dug a little deeper into the NPR API. I’ve added 3 new components. Feed.cfc represents the data returned from the api call. Story.cfc models the actual stories that make up the feed.

The 3rd object is a simple object that I extend to share some common methods to between my other components. I generally consider this bad practice and there are a lot of tools designed specifically to address this problem.

I did it for a couple of reasons. First, I wanted this to self-contained and stand alone. I wanted it to be as easy as possible to drop it into whatever project YOU have, with whatever tools YOU have set up and get it going. Second, I wanted to focus more on the real meat of the product without getting too hung up on the implementation details. Besides, I can always refactor!

Stay Tuned!

Example Usage:


 







	

Download the code!