Category Archives: programming

2009 New Years Resolutions

I like to write this sort of thing down so I can look back later and scoff.

User Groups!
There are some really great user groups in my area and I’ve consistently missed many months of meetings. The people are great, there’s a lot of great information being swapped around and it’s FUN! No more excuses.

Open Source Software!
This post is brought to you via the magic of WordPress, MySQL, FireFox and Ubuntu. I love and use a lot of open source software and it’s high time I start giving back. I plan on hunting down some ColdFusion projects to get into the swing of things, but eventually I’d like my own baby.

Plugins!
This goes a long with the previous bullet. I have a few ideas for FireFox and Eclipse plugins that I think would help get me in the OSS swing of things, (To use that trite and tired cliche yet again).

Unmaintained Recurring Income!
This might be a pipe dream, but I’ve been working on the web for a long time I really ought to have something out there making money, even if it’s only enough to pay for the hosting. I’ve got a few top secret ideas that I’ll share once I get into the swing of things.

JavaScript Deck of Cards Pt 2

A co-worker of mine sent me some advice on the JavaScript deck of cards I set up a while back. Everything he said was spot on. Jim, if you’re out there, you’re insight and advice is always welcome and highly respected. Thanks!

Read your blog. 🙂

In the interest of academic feedback (don’t take any of this in a negative way), I have a few comments.

It’s hard to tell from the current function names, but if the “same_suit” and “same_type” Card methods are meant to be “is_same_…” functions, they you need to change the “=” to “==”.

Card = Class.create({
	initialize: function(type,suit) {
		this.type = type;
		this.suit = suit;
	},
	same_suit: function(suit) {
		return this.suit == suit;
	},
	same_type: function(type) {
		return this.type == type;
	},
	toString: function(){
		return this.type + ' of ' + this.suit;
	}
});

JS supports the ‘+=’ operator for strings, so you could change the “message = message + …” to “message += …” in the Deck::toString method.


The first time through the Deck::toString function, the modulo check will be true, resulting in message beginning with a ‘n’ character. Wasn’t sure if that is what you wanted.

Here’s a minor optimization for the Deck::toString function. It removes the modulo operation from the loop, which is performed 52 times on a full deck, and handles the all of the leading/trailing whitespace (tabs and newlines) automatically:

toString: function() {
	var message = '';
	var i = 0, n = this.cards.length - 2;
	for(; i < n; ) {
		message += this.cards[i++] + 'tt' + this.cards[i++] + 'n';
	}
	if (i < this.cards.length) {
		message += this.cards[i++];
	}
	if (i < this.cards.length) {
		message += 'tt' + this.cards[i];
	}
	return message;
}

The following code:

var face_cards = "King,Queen,Jack"
face_cards     = face_cards.split(',');

Could be:

var face_cards = ["King","Queen","Jack"];

I don't think you need the "var i" in the Deck::add_card method.

PS: One other minor update, I got started thinking about UNO and decided to break out the French or Anglo American deck specifications out to a separate class and file.

PPS: Jim caught me using a "=" in place of a "==". These were methods that I hadn't tried yet, but knew that I would need in the future. This is exactly the sort of thing that would have been instantly caught had I written out some tests. I'm a bit late to the game on TDD, but it's something I've been toying with in Ruby and I'm starting to come around. I don't even know where to start unit testing in JavaScript, but I plan on doing a bit of homework on the matter so stay tuned!

Download the code!
JavaScript Deck of Cards V2
Current Version

Ruby Clipboard Directory List Utility

I wrote this little script to copy the filenames of a directory into the clipboard a while back and forgot to post about it. I’ve been particularly surprised about how often it’s come in handy for this or that.

 require 'clipboard'

c = Clipboard.new

list = ''

if ARGV.size == 0
	path =  "."
else
	path = ARGV[0]
end

Dir.foreach(path) {
	|file|
	if(file.length > 2)
		list << file << "n"
	end
}

c.set_data list

To use it, simply call run the script with the directory you want copied to your clipboard as an argument!

Download the code!

Target Practice Pt 2

I made a few small updates to Target Practice tonight. The biggest addition was sound although I made a few other little tweaks under the proverbial hood.

I had originally wanted to pack it up and release it as a single executable file but I was having some issues which I’ll post about once I figure out what the heck I’m doing.

Speaking of lazing, there are a few things I’d like to do differently in Target Practice. Most notably I’d like to abstract out out the media to some manager or another, and also my target manager class has grown rather bloated which I take to be a good indicator that it’s doing more than it should. I don’t care enough about this program to fix either of these issues, but hopefully I’ve learned from these mistakes!

Download it!

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!