Wikipedia Showdown

I’ve writen before about how sometimes the amount of content in wikipedia on certain subjects disturbs me (here and here.) I have off for the next few days and was looking to work my brain a little bit and wrote this little application that will compare how many characters are written about any two subjects in wikipedia. So for example you can discover that more is written about “blankbabied” then “zombo.com“. So check it out, and come up with and comment on your own crazy showdowns.

Wikipedia Showdown!

In order to do this, I had to rely on CFHTTP to get the job done. I’ve included the cfc that handles grabbing the input from wikipedia in the extended entry.

<cfcomponent>
<cffunction access=”public” name=”stripHTML” output=”false” returntype=”string” hint=”Removes HTML from input string.”>
<cfargument name=”str” type=”string” hint=”String to clean.” required=”yes”>
<cfreturn REReplaceNoCase(str,”<[^>]*>”,””,”ALL”)>
</cffunction>

<cffunction access=”public” name=”weigh” output=”true” returntype=”struct”>
<cfargument name=”search_term” type=”string” required=”yes” hint=”The search term. “>

<cfset search_url=”http://en.wikipedia.org/wiki/Special:Search”&gt;
<cfset return_struct.searchTerm=arguments.search_term>

<cfhttp url=”#search_url#” method=”post” delimiter=”,” resolveurl=”no”>
<cfhttpparam type=”formfield” name=”search” value=”#arguments.search_term#” />
</cfhttp>

<cfif findNoCase(“Search – Wikipedia, the free encyclopedia”, cfhttp.FileContent)>
<cfset return_struct.contents=”There are no records for that search term.”>
<cfset return_struct.length=0>
<cfset return_struct.url=””>
<cfreturn return_struct>
</cfif>

<cfset contents=cfhttp.FileContent>

<cfset contents_start=FindNoCase(“bodyContent”, contents)>
<cfset contents_end=FindNoCase(“catlinks”, contents)>
<cfset contents_len=(contents_end-contents_start)>

<cfset contents=Mid(contents,contents_start, contents_len)>
<cfset contents=stripHTML(contents)>
<cfset contents_crap=14+9>

<cfset contents=Mid(contents, 14, Len(contents) -contents_crap)>

<cfset return_struct.contents=contents>
<cfset return_struct.length=Len(contents)>

<cfset retrieved_location=FindNoCase(“Retrieved from”,contents)>
<cfset article_url=Mid(contents, retrieved_location, Len(contents) – retrieved_location)>

<cfset article_url=replace(article_url,”Retrieved from”, “”, “ALL”)>
<cfset article_url=replace(article_url,””””, “”, “ALL”)>
<cfset article_url=trim(article_url)>
<cfset return_struct.url=article_url>

<cfreturn return_struct>

</cffunction>

</cfcomponent>

Image Manipulation CFC

I was tired of putting so much work to get pictures posted, and my options for third party tools are somewhat limited cause I’m just a wee customer on this host. (I still like them, I just like to do stuff for myself.)

So I went looking for a cfc that would allow for image manipulation. I figured someone must have figured out how to get Java objects to do it. I found Alagad Image Component, which seemed like both functional and cost overkill. But after more digging I found tmt_img.cfc.

Tmt_img does basically everything you need to crop and resize images, so I built a little picture display interface around it so I never have to crop or shrink an image for preview ever again. It reads in an image from one location, checks to see if a preview image has been created for it, and if not create it. It handles the linking, and the sizing, and the writing display html for it. I’ve included my image display cfc below.

<cfcomponent hint=”Handles displaying images.”>

<cfinvoke method=”init”>

<cffunction access=”private” name=”init” output=”false” returntype=”void” hint=”Sets the initial variables. “>
<cfset image_folder=”d:path_to_your_fileswwwrootimages”>
<cfset tn_folder= image_folder & “tn”>
<cfset image_url=”http://www.your_domain.com/images”&gt;
<cfset tn_url= image_url & “/tn”>
<cfobject component=”tmt_img” name=”imageObj”>
</cffunction>

<cffunction access=”public” name=”linkImage” output=”true” returntype=”void” hint=”Show a preview image and link of an image.”>
<cfargument name=”image” required=”yes” type=”string” hint=”The name of the image to preview and link to.”>

<cfset file_type=Right(arguments.image, 3)>
<cfset file_name=Left(arguments.image, Len(arguments.image)-4)>
<cfset tn=Replace(arguments.image, “.#file_type#”, “_tn.#file_type#”, “ALL”)>

<cfdirectory directory=”#tn_folder#” action=”list” name=”directoryList” recurse=”no”>

<cfquery name=”tnFile” dbtype=”query”>
select count(*) as tnExists
from directoryList
where name=’#tn#’
</cfquery>

<cfif Len(tnFile.tnExists) lt 1 or tnFile.tnExists eq 0>
<cfinvoke component=”#imageObj#” method=”resize” returnvariable=”imageProperties”>
<cfinvokeargument name=”source” value=”#image_folder##arguments.image#”>
<cfinvokeargument name=”destination” value=”#tn_folder##tn#”>
<cfinvokeargument name=”newWidth” value=”200″>
</cfinvoke>
</cfif>

<cfinvoke component=”#imageObj#” method=”getDimensions” returnvariable=”imageProperties”>
<cfinvokeargument name=”imgPath” value=”#tn_folder##tn#”>
</cfinvoke>

<cfoutput>
<a href=”#image_url#/#arguments.image#”>
<img src=”#tn_url#/#tn#” alt=”#file_name#” width=”#imageProperties.width#” height=”#imageProperties.height#”>
</a>
</cfoutput>

</cffunction>

</cfcomponent>

Microsoft MOM

Part of my job is to manage multiple Cold Fusion servers. All told my count is at 14, some are running Cold Fusion 6.1 some are ruuning Cold Fusion 7. Luckily as of now, all are running Windows 2003, as opposed to 2000. Keeping track of them has been hard, and I’ve had to come up with some custom solutions to do so.

However it looks like that’s about to change as we’re getting more serious about using Microsoft Operations Manager. I’ve been using it for a couple of days and I have to say I’m shocked at how good it is. I’ll write more as I go on, but for now check it out.

Microsoft Operations Manager.

More Site Nonsense

I have weird little preferences about my site, and I really wanted my links section to to come from my list of RSS feeds. But I use Sharpreader which is is a desktop client so I can’t just pull my links in from another site., or publish, or work any other magic. However, Sharpreader can export to an OPML file, which is just a variant of XML. So I should be able to download a CFML OPML parser. Turns out that by “download,” I mean “construct.” Since I couldn’t find one, I’ve included the source to make it happen. Enjoy, don’t enjoy, use, don’t use, whatever.

<cffunction access=”public” name=”display_opml” output=”true” returntype=”void” hint=”Takes an opml file and outputs a list of links. “>
<cfargument name=”opml_file” type=”string” required=”yes” default=”” hint=”The file location of the opml file to display.”>

<cftry>
<cffile action=”read” file=”#arguments.opml_file#” variable=”feeds”>
<cfset feedsXML=XMLParse(feeds)>

<cfoutput>
<cfloop index=”i” from=”1″ to=”#ArrayLen(feedsXML.opml.body.outline)#”>

#feedsXML.opml.body.outline[i].XmlAttributes.title#

Cfeclipse

I think I’m finally converted to Cfeclipse. For those of you that don’t know, it’s an open source Cold Fusion IDE. I’ve been updating an old project and rebuilding the interface from scratch. I can honestly say that I’ve probably sped up my development by at least 50%, especially when dealing with CFC’s. It might not be for everyone, but I would recommend it to anyone who programs CFML for a living. So let me break down the pros and cons, and you can judge for yourself if you want to give it a try.

Pros:

  • Loads faster and seems more stable than Dreamweaver
  • Code Folding, code folding, code folding.
  • Doesn’t require registry altering install, so easy to remove.
  • New feature sets install very easily.
  • Features are added often.

Cons:

  • Requires Java, and can be temperamental to install if you don’t have the right version.
  • Doesn’t appear to like UNC notation.
  • It’s an open source beta, so your stability mileage may vary.
  • Doesn’t handle web design.

If you’re comfortable doing a little work to get your programming environment setup and mostly code CF instead of designing (or you’re properly using web standards to yield lightweight interface code,) then I would tell you to give it a shot. On the other hand if moving to Firefox seemed a bit edgy for you, I would stick to Dreamweaver.

Cfeclipse.org doesn’t have the best instructions for installing it, but you can find them at the old cfeclipse.tigris.org site.

Https Sockets in CFC

A while back I needed to interact with raw https sockets from Cold Fusion, and the https setting for CFX_RawSocket stopped working. (I think I configuration change on the target machine made this process fail.) Unable to deal with trying to get support for a free product, I felt compelled to write my own way of doing it. Some one in my office had writted a CFX tag very similar to CFX_RawSocket, so I had a starting point.

Turns out, it can be done completely without resorting to CFX writing. It can be done completely using Cold Fusions built in ability to handle Java Objects. I figured I would share the source if anyone else needed it.

<!— ############# —>
<!— https_socket —>
<!— ############# —>
<cffunction access=”package” name=”https_socket” output=”false” returntype=”string” hint=”Allows socket communication over https to occur. “>
<cfargument name=”host” type=”string” required=”yes” hint=”The host to send message to. “>
<cfargument name=”message” type=”string” required=”yes” hint=”The message to send to the host.”>
<cfargument name=”port” type=”numeric” required=”no” default=”443″ hint=”The port to connect to. ” >

<!— Use the sslfactory to create an object based on the Socket class —>
<cfset factory = CreateObject (“java”,”javax.net.ssl.SSLSocketFactory”).getDefault()>
<cfset sock = factory.createSocket(arguments.host,arguments.port)>
<cfset sock.startHandshake()>
<!— Connect to output stream —>
<cfset sout = sock.getOutputStream()>

<!— Connect to input stream —>
<cfset out = createObject( “java”, “java.io.PrintWriter” ).init(sout)>
<cfset sinput = sock.getInputStream()>

<!— I have no clue what is going here. I just know it has to be done this way. —>
<cfset inputStreamReader= createObject( “java”, “java.io.InputStreamReader”).init(sinput)>
<cfset input = createObject( “java”, “java.io.BufferedReader”).init(InputStreamReader)>

<!— Send message to server. —>
<cfset out.println(“#arguments.message#”)>
<cfset out.println()>
<cfset out.flush()>
<!— Get back response. —>
<!— I only need the response header, so I only get the first line —>
<cfset results=input.readLine()>

<cfset sock.close()>

<cfreturn results>
</cffunction>

Timecode Application

I’ve been ossilating between high on pain meds and in fiery pain when the wear off. To keep my mind busy I wrote a PHP and MySQL based timecode application. As my first full application that uses MySQL and PHP, I have to say I much prefer Cold Fusion and MS SQL. There are a couple things that are just much easier to do in Cold Fusion, namely debugging, performance testing, database management, and session management.

All in all though I’m glad I did it. I’m sure that I didn’t get everything right, and that there was some ineffciency. Check it out:
Citizen Wumpus – Production Tools.