Facial Recognition in 14 Lines Of ColdFusion

Posted By : todd sharp Posted At : January 21, 2010 2:05 PM Posted In: Java, ColdFusion

46

I was doing a bit of research on a potential project when I stumbled across faint, a Java facial recognition library and decided to give it a quick try.

The bad news is that the documentation is literally non-existent. So I did a bit of poking around the Jar and quickly found an 'OpenCVDetection' class. I dropped the faint Jar in my class path, restarted CF and about 5 minutes and 14 lines of code later I got the following result:

Building A Better Search For SlideSix - Part 1

Posted By : todd sharp Posted At : October 22, 2009 8:47 AM Posted In: Java, ColdFusion, SlideSix

2

After finishing up a few outstanding fixes and enhancements for SlideSix the other day I decided to give search a bit of love. Well, I didn't quite decide it; it was more of the gentle reminder from Sean Corfield about the existing search not really working all that well that prompted me to action. Regardless, I learned a few things about search that I'm going to share over a few blog posts that will use this alliteration littered title.

A Tale Of Two API's

Posted By : todd sharp Posted At : April 28, 2009 8:15 PM Posted In: Java, ColdFusion, SlideSix

5

SlideSix, like many other social networks these days, has long offered the ability to import a contact list from your favorite webmail client for the purpose of sending a quick invitation to your friends to join. Some people aren't a fan of such services, but as my favorite TV personality likes to say - "that's another show".

In all reality, it's quite a handy feature to have - and a good way to get some viral marketing out of your users that are really excited about your product. Make it dead simple for them to tell a lot of friends about your service and you just might find word spreading quickly.

So as I stated above, we've offered this service for quite some time now. But recently I took notice that despite the fact that a lot of users were actually hitting the page, no invites were being sent. I found it a bit curious so I logged in and ran a quick test which yielded zero contacts in my Gmail account (of which I knew there were hundreds). My first reaction was that I had inadvertently introduced a bug into my code but a quick check confirmed that I hadn't made any changes. My next step was to head off to the support site for the service that I had been using to abstract the contact list import - a service called Rapleaf. I did some quick searching around there site, but I couldn't even find the API documentation for their address book API. I eventually found the documentation which contained the following note at the top of the page:

NOTE: Since Rapleaf is now focusing on our core set of APIs, we are no longer offering support for the Address Book API

I should state that I don't have a problem with a company changing gears and focusing on a different, most likely more profitable part of their business. It happens every day and it only makes sense to focus on elements that bring in the most bang for the buck. What I do have a problem with is the fact that I had to search, pretty hard I might add, for the fact that the API was no longer supported. Since I had taken the time to actually sign up for an API key I think it would have been decent of them to send a quick email out to developers letting them know that they were no longer supporting it. I'll give them the benefit of the doubt and assume that they did send a message but I somehow overlooked it or it got caught by a rogue spam filter.

Unfortunately at this point I was left high and dry without a service to use to import contacts. I could have taken the time to build my own service, but since my existing service was not functioning I didn't have the luxury of time on my side. So off I went to do some searching for a new alternative. I quickly found a paid option from a company called Octazen Solutions. They offer a huge set of supported webmail clients and sell a library for most popular programming languages. After a bit of research I decided to go with their package.

I should note that although they do offer their library in ColdFusion (my language of first choice) I chose to go with the Java library instead. Why? First off they don't show any ColdFusion samples on their site so I had no idea what they're offering (custom tag? CFC?). Secondly, I found it kinda silly that the ColdFusion option was priced at $200 and the Java option was priced at $88. Why is that silly? Well, since ColdFusion runs on Java I could easily save myself more then a hundred bucks by purchasing the Java library and creating the Java object directly within ColdFusion. Long story short I went with the Java library, and thanks to Mark Mandel's JavaLoader I got the package up and running in about 2 lines of code. Seriously.

<cfset simpleAddressBookImporter = variables.loader.create("octazen.addressbook.SimpleAddressBookImporter").init() />
<cfset contacts = simpleAddressBookImporter.fetchContacts(arguments.user,arguments.pass) />

Which returned a nice array of contacts like such:

octazen contacts

Thankfully I have the feature back up and running, and now better then ever since I can offer support for way more clients than I was before. Octazen was pretty quick to ship my license and even quicker to respond to a licensing question I posed to them. If you're looking for a contact importing solution I'd recommend taking a look at their product. You can also try it out on SlideSix (must be logged in).

More CF+Java: Compiling Classes And Persisting Objects

Posted By : todd sharp Posted At : May 28, 2008 12:05 PM Posted In: Java, ColdFusion

10

Last week I blogged about a simple proof of concept that I had come up with for compiling Java classes on the fly in ColdFusion. I played a bit more with my proof of concept over the weekend and came up with a bare bones application that does the following:

  • Compiles a directory of '.java' source files (and subdirectories) into a single JAR file
  • Drops the JAR into a local 'lib' folder
  • Loads the JAR (with Mark Mandel's JavaLoader)
  • Loads db4o (an Object database)

So once all that is done (in onApplicationStart) the application can immediately do the following:

  • Create an instance of any objects within the just compiled Java classes
  • Set properties on that class
  • Persist the object into db4o

Now why is this cool? Well for one there is not object to relational data mapping required. The object is persisted as is - composite objects/data and all. db4o supports a few query methods to retrieve the objects - none of which I've dug very deep into yet. Another benefit to this method is speed. Initialization is a bit of a hog (I was seeing around 2000-2500ms for onAppStart) but object creation is around 0-2ms.

I'm not planning on releasing any of the code yet (maybe ever). Plus it's all super rough around the edges right now. But I'm really interested in what folks think about this. Has anyone used an object database in their Java projects? Is it worth moving forward with this, or is it all just cool to know you can do it but not real practical?

Compiling Java Classes On The Fly In ColdFusion

Posted By : todd sharp Posted At : May 23, 2008 4:39 PM Posted In: Java, ColdFusion

10

I'm sure I'm not the first to ever figure this out, but through a bit of tapping into some underlying Java in CF I devised a method yesterday to compile Java into usable classes on the fly.

Given a directory called 'src' that contains one or more '.java' files I call:

<cfset compiler = createObject("component", "compiler") />
<cfset src = expandPath("src") />
<cfset compiled = compiler.compileJava(src) />

Which returns an array of structures. Each element contains feedback on the individual files processed. So for three java files I'd get the following if I dumped the result:

Now what is really cool about this is that by default I drop the compiled '.class' files into 'WEB-INF/classes' and they are immediately available to be created and invoked by CF. So without restarting CF I do:

<cfset e = createObject("java", "Employee").init("Todd", "Sharp", "100.0", "3") />
<cfdump var="#e#">

And I get:

Pretty cool, but I've yet to determine if there is really a good use case for this method. I do have one idea that I'm going to try if I get some time this weekend, but other then that it seems like not much more then a novelty to me. Also, since I'm pretty naive at all things Java I've not yet figured out a way (if there is one) to create packages. I tried using cfzip to jar up a few classes, drop them in the CF class path and restarting CF, but it didn't seem to work. Anyone have any ideas or thoughts on use cases here, or is this just another "Wow, that's cool" thing?

More Thoughts on HTML To Image (Plus Code)

Posted By : todd sharp Posted At : April 5, 2008 8:08 AM Posted In: Java, ColdFusion

4

Yesterday I posted a demo of a UDF that I had been working on to convert HTML (via a URL or raw HTML) to an image. The UDF works OK, but to be honest it's not all that great. Let me quickly explain the process (as some had guessed in the comments on that post yesterday).

Handling Java Nulls In ColdFusion

Posted By : todd sharp Posted At : December 15, 2007 10:06 AM Posted In: Java, ColdFusion

2

I'm putting the finishing touches on my PowerPoint utils component when I came across a weird Java error. I've seen it before and it may very well be my lack of Java experience that is causing my lack of understanding here.

Say you have a Java method getFoo() that is expected to return a string. I've found that sometimes ColdFusion doesn't properly handle Java nulls so when you try to set a value you'll get something like so when trying to reference it:

Element foo is undefined in a CFML structure referenced as part of an expression.

ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem.

It seems that ColdFusion simply chokes on it. I came up with a hacky fix by passing the value to another method which properly returns an empty string:

<cffunction name="fixNull" access="private">
    <cfargument name="valueToFix" default="" />
    <cfset rStr = "" />
    <cfif isDefined("arguments.valueToFix")>
        <cfset rStr = arguments.valueToFix />
    </cfif>
    <cfreturn rStr />
</cffunction>

Seems a bit hacky but it works. If someone can shed a little more light on the subject I'd appreciate it.