Author Archives: joe

About joe

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

ColdFusion NPR API Pt. 1

NPR published an API a while back giving easy access to 250,000+ NPR stories.

As I’m still quite the newb when it comes to Object-Oriented Programming I thought I would blog through the process of creating an OO ColdFusion wrapper.

Example Usage:










Download the code!

PS: In order to actually run this you’ll need to register for an account and API key. Also, browse the aggregate to ID mapping info to find yourself some id’s to use!

PPS: A much-love shout-out to my local NPR affiliate WMFE. Support publc radio!

JavaScript List Utility

Here’s a little something I was working on today. The goal was to model an HTML unordered list in JavaScript so I could easily add/remove and display elements. I haven’t gotten around to actually writing all of the display methods because I haven’t exactly figured out how I want to use it yet.

PS: I kinda re-remembered the toString method on this one.

PPS: Requires prototype

Example Usage:

set up the list

list1 = new List();
list1.add('a');
list1.add('b');

list2 = new List();
list2.add('b1!');
list2.add('b2!');

// nest away!
list1.add(list2);
list1.add('c');
list1.add('d');

li data

alert(list1.get_at(1).data);

remove li

list1.remove(4);

alert the list

alert(list1);

BAM!

Download the code!

Simple JavaScript Slider/Iterator…Thing

In keeping with my current “blog-more-about-less” stratagem I thought I’d post a little JavaScript utility I wrote. The idea was just to add “next” and “previous” buttons to an existing gallery, but I thought I’d have a little fun with it, as it may come in handy in the future.

The idea was to create a simple slider object that would keep track of the users position in an array of items. I could cycle through the items, backwards and forwards and fire of item methods. For the gallery I only had to worry about a few basic properties and methods, but I wanted to design this in such a way that adding properties and functionality to my objects would be a breeze.

PS: Current the slider object expects your items contain the methods “update” and “show”. I *know* this is bad, but I’ve had a hard time coming up with a solution that I liked better.

PPS: The example code I’m posting below was done using Prototype and ColdFusion, neither of which are required but are there because I thought it made it easier to get the point across.

Alright, enough gibber jabber.

Image Object:

function Image(thumb,large,caption) {
      this.thumb = thumb;
      this.large = large;
      this.caption = caption;
      this.show = function() {
          showPhoto(this.large,this.caption);
      }
      this.update = function() {
          $('largeImg').src = this.large;
          $('photoCaption').update(this.caption);
      }
  }

Create and fill it up!

gallery = new Slider();
// don't forget to escape those special javaScript characters!!!!

      gallery.add(
          new Image('#thumb#','#large#','#caption#')
      );

Attach the “previous” and “next” methods to my links. <3 unobtrusive JavaScript!

Event.observe(
      'previous',
      'click',
      function() {
          gallery.previous();
      }
  );
  Event.observe(
      'next',
      'click',
      function() {
          gallery.next();
      }
  );

And finally, on the actual thumbnails on the page:


      
      
            
      

Download the code!

As always, this solution is far from perfect, and I’d love feedback!

Ps3 Bad Company Update Problem

I’d tried a few times over the last week to update Battlefield: Bad Company on the PlayStation 3. Every time I tried I would get hung up on the “Downloading update data…” screen. It would stay at 0% for a few minutes and then briefly flash me an error code in the top right corner (8002AD23) and a few minutes after that it’d bounce me to another screen: “An error occurred during the download operation (80710723)”

I googled around for a while. Opened some ports on the router, plugged directly into the wall, restarted. I finally found somewhere that recommended I disable my media server via the network settings and BAM! “fixed”

My “source” for the “fix”: http://www.fixya.com/support/t291065-ps3_system_update_error

Eclipse RDS Problem: Contacting Server…

I’ve been successfully running CFEclipse on Ganymede for a week or two now, but I finally got around to just installing and setting up my ColdFusion 8 Eclipse Extensions (downloaded from the lovely coldfusionportal.org). Everything looked like it went well: “Test Connection” worked. But whenever I would double-click a folder in my RDS Fileview or Dataview I would get hung up on this “Contacting Server…”.

It took a bit of googling, but I finally stumbled upon this post and I wanted to share the link love: http://www.vintagecoding.com/blog/2008/07/24/eclipse-rds-might-be-a-problem-with-ganymede/

Apparently if you click the arrow icon’s in the RDS Fileview and RDS Dataview views it’ll work. It’s a workaround alright, but it works.

Ubuntu Hardy Heron ColdFusion 8 Oopsie

Somehow I managed to bugger up the ColdFusion installation on my beloved laptop. Whenever I would try to start the cf server I would get the following not-very-helpful message.

Running the ColdFusion 8 connector wizard
======================================================================
Configuring the web server connector
(Launched on the first run of the ColdFusion 8 start script)
Running apache connector wizard...
=======================================
There was an error while running the connector wizard
Connector installation was not successful

I googled around enough to realize that since it didn’t appear to be a common problem, that it was probably something I did. And it was.

As you may have figured out by now, I’m not a server-config kind of guy. I poked around a little bit and found an interesting looking shell script at /opt/coldfusion8/bin/connectors/apache_connector.sh. Running that gave me a much better error message:

Could not find directory /etc/apache2/apache2.conf

I opened the file and realized that the paths were all boogered up, meaning the paths I entered when installing ColdFusion where all buggered up. In any case, I fixed the incorrect paths and here’s what the file looks like now:

#!/bin/sh

#
# Configure the Apache connector.
#	-dir should be the *directory* which contains httpd.conf
#	-bin should be the path to the apache *executable*
#	-script should be the path to the script which is used to 
#		start/stop apache
#
../../runtime/bin/wsconfig 
	-server coldfusion 
    -ws apache 
	-dir /etc/apache2 
	-bin /usr/sbin/apache2 
	-script /etc/init.d/apache2 
 	-coldfusion

exit $#

And Voila!

Ruby File Renaming Utility

I wrote a little renaming utility to help me with the all too common task of file re-naming that seems to keep coming up. The class itself is pretty general; the idea is to extend it and override the “valid_file” and “format” methods for whatever specific task I’m doing.

The “valid_file” method is intended to recognize which files need to be renamed in the case you’ve got files you don’t want to touch in the directory. By default the function just ignores the “.” and “..” in the directory listing.

The “format” method is used to to specify the actual rules and routine to use when renaming your file. By default it replaces spaces and dashes with underscores.

Finally, this isn’t “finished” software. No error checking, no notes. It works for me and maybe it’ll work for you too.

Here’s an example class I wrote using the renaming utility. It’ll prepend the string “prepend_” onto all png files in the specified directory. Note that there’s a “safe_mode” variable passed in the constructor. Setting the “safe_mode” to true will prevent the files from being renamed while you’re working on it.

require 'renamer'

safe_mode = false

class Example < Renamer

  def format file
    file = custom_format(super(file))
    puts file 
    return file
  end

  def valid_file file
    valid = super(file)
    valid = valid && file.include?('.png')
    return valid
  end

  def custom_format file
    return "prepend_#{file}"
  end
end

if __FILE__ == $0  
  path = ARGV[0]
  r = Example.new(path,safe_mode)
  r.rename_files
end

Download the code: Ruby File Renaming Utility

Ruby Clipboard Utility

I have a few ruby scripts that I use to make life a little easier at work. Some of said scripts utilize the clipboard. My work machine is windows and my laptop runs Ubuntu. I’m able to use the same scripts on both computers but I have a few qualms with how I’m doing it.

Right now I’ve got classes for gnome and windows, a clipboard wrapper class to be used by my scripts and a basic (and poorly named) OS class I use to determine which class desktop class to use.

First off, the method I’m using to determine OS is…terrible. Currently I’m doing a string comparison in my OS class, but it doesn’t actually tell me which desktop application I’m actually running, so at the moment it’s just a dirty hack but I’m not sure of the preferred way to do it..

def is_linux
  return RUBY_PLATFORM == 'i486-linux'
end

Second, I’m uncomfortable with how I’m importing my desktop specific code in the main clipboard class. Is there a ruby-er way of doing this, or maybe just a smarter way anyone knows of?

class Clipboard
  def initialize
    os = OS.new
    if(os.is_linux)
      require 'clipboard/clipboard_gtk'
      clipboard = GTKClipboard.new
    else
      require 'clipboard/clipboard_win32'
      clipboard = WinClipboard.new
    end
    #other stuff
end

Any help would be greatly appreciated!

Download the code: Clipboard Utility

PS: I realize there’s quite a bit of other stuff I need to do to really get this usable, but you have to start somewhere!

Prima Gravida

New computer begets new blog. That’s just how these things work. I intend this to mainly be a professional blog, but like all professional blogs I actually enjoy reading I’ll also be smushing in some personal stuff here and there.

As for myself, I’m a web developer residing and working in Winter Park, Florida. I work mostly in ColdFusion and JavaScript, but I also dabble a bit in Ruby and a few other techs

I plan on re-beginning this whole blogging thing by posting solutions to some of the little problems I (and anyone else who uses a computer) run into all the friggin’ time.

Ta Ta for now.