Author Archives: joe

About joe

.NET developer and board game geek located in the greater Atlanta region.

JavaScript Deck of Cards

I wrote up a basic model for a 52 card deck of playing cards in JavaScript (using beloved Prototype. I plan on using it to make some very simple card games in the near future. I thought it’d be interesting to post this before I actually used it anywhere so I could take a look at how much it changed after I actually implemented it.

There’s not much to see at the moment. You can just shuffle and get a card dump:


    
        JavaScript Deck of Cards
        
        
    
    
        
    

Download the code!
JavaScript Deck of Cards V1
Current Version

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.

Ruby Line / Curve…Thing

Remember these?

During a brief period in elementary school drawing these things was quite the cool thing to do. I’ve been messing around with the GD2 module a bit lately and I thought it’d be fun and easy to write a little script to generate one.

It was.

The drawing algorithm

@nodes.times do |i|
    adjustment = i * @node_size
    pen.move_to adjustment, 0
    pen.line_to 0, @size - adjustment
end

Example Usage:

#takes in the output image size and the number of nodes
c = Curve.new 180, 30
c.draw
c.export "test.gif"

Download it!

*Note: If your output size doesn’t divide evenly by the number of nodes then the image will actually reduce the size of the output image.

Ruby Resize Utility

I wanted to demo an ad rotator the other day at work and I wanted to load up a bunch of images of various sizes to make it look legit. It would have taken forever to do it ad by ad, so I wrote a little ruby script to automatically resize all the images in a directory. Then I used my directory listing utility to copy the files into my clipboard. Pasted into the database from there!

(Requires GD2)

Usage:

 r = Resizer.new input_path, output_path, width, height
 r.crop_files

Download it!

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.