Translating from Roman to Decimal Numbers

Ray posted an entry on his blog dealing with converting Roman Numbers to decimal numbers. I ran his code and pointed out that IIX returned 10 instead of 8.

A debate ensued on whether IIX is valid. Ray replied:

Now I'm going to ask you to put up or shut up! ;) If you can find me proof that IIX (or IIC, etc) is valid, I'll support it. ;)

It is still undecided if IIX is valid. I felt it should return the correct value or no value at all. But then I thought, if the number was ever used, the converter should convert it. So I took Ray's code, made some changes and now it should convert any Roman Numeral you throw at it.

EDIT: I found a serious flaw in the logic. Here is the correct code, even though the other did work in most cases. The first code failed on MCCCIIIX. It returned 2107 instead of 1307.

view plain print about
1<cfscript>
2/**
3 * Converts Roman numerals to decimal.
4 *
5 * @param input      Roman number input. (Required)
6 * @return Returns a number.
7 * @author Raymond Camden (ray@camdenfamily.com)
8 * @version 1, February 2, 2010
9 */

10function romantodec(input) {
11    var romans = {};
12    var result = 0;
13    var pos = 1;
14    var char = "";
15    var thisSum = "";
16    var subSum = 0;
17    var nextchar = "";
18        
19    romans["I"] = 1;
20    romans["V"] = 5;
21    romans["X"] = 10;
22    romans["L"] = 50;
23    romans["C"] = 100;
24    romans["D"] = 500;
25    romans["M"] = 1000;
26
27    while(pos lte len(input)) {
28        char = mid(input, pos, 1);
29        subSum += romans[char];
30        if(pos != len(input)) {
31            nextchar = mid(input, pos + 1, 1);
32            if(romans[char] == romans[nextchar]) {
33                pos++;
34            } else if(romans[char]
< romans[nextchar]) {
35                result = result + romans[nextchar] - subSum;
36                subSum = 0;
37                pos += 2;
38            } else {
39                result = result + subSum;
40                subSum = 0;
41                pos++;
42            }
43        } else {
44            result = result + subSum;
45            pos++;
46        }
47    }    
48    return result;
49}
50</cfscript>

I am pretty sure there is a better way yo do this, so please feel free to leave suggestions and ideas.

Potential ColdFusion information Solr disclosure issue

Adobe released a securitry bulletin for ColdFusion 9 today.

ColdFusion by default allows collections created by the Solr Service to be accessed from any external machine using a URL. This allows users to access information about the collections as well as search and index them.

Adobe recommends affected ColdFusion customers update their installation using the instructions below:

Follow the instructions below to disable external access to the Solr collections:

1.Open the file jetty.xml located at {ColdFusion-home}/solr/etc for Server install or {Solr-Home}/etc directory for other type of installs.

2.Look for the following property. There are two occurances of the property in the jetty.xml file. Locate the uncommented property.

view plain print about
1<Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>

3.Add the following property just below the above property

view plain print about
1<Set name="Host"><SystemProperty name="jetty.host" default="127.0.0.1"/></Set>

This will set the access to the Solr collections from the browser to localhost only

4.Restart Solr Service.

0000-00-00 00:00:00 to TIMESTAMP

I read ColdFusion Bloggers every day to learn what is going on in the ColdFusion community. Today I came across a blog entry that solved an old problem with MySQL and the zero timestamp.

In MySQL, if a timestamp is blank, it is set to 0000-00-00 00:00:00 and this causes a problem for ColdFusion, which will return an error of: Cannot convert value '0000-00-00 00:00:00? from column X to TIMESTAMP. Thanks to John Sieber at Thoughts from the mountains we have the simple answer. IN the ColdFusion Administrator, go to Data Sources, edit the MySQL (4/5) data source, click on Show Advanced Settings and enter

view plain print about
1noDatetimeStringSync=true&zeroDateTimeBehavior=convertToNull

in the Connection String dialog box.

This will make my job a little easier.

Thanks John.

Learning Mura

Early this month Charlie Arehaert announced a series of online meetings dealing with converting his site to Mura CMS. I had never heard of Mura, but I know what a CMS is. I have been looking for a solution for three websites that I maintain and took a look at what Mura could do.

I downloaded Mura, installed it and had a basic site up in less than 10 minutes. There are configuration options for nearly everything one would want to do. There seems to be a lot of support offered by several websites and blogs. A great source of information is The Mura Show, which has shows recorded in Acrobat. I intend to follow along with Charlie and learn while he converts his site to Mura.

It looks like Mura can be used to solve many website problems and I look forward to learning how to use it.

Now I just have to convince Ray Camden to make BlogCFC a plugin for Mura.

ColdFusion and LCDS

Things I need to know about ColdFusion and LCDS. This is so I can keep track of some links.

http://gregsramblings.com/2010/01/15/lcds-2-5-rtmp-mxconsumer-not-able-to-resubscribe-after-disconnect-coldfusion-8/

http://justjoshn.com/entry/integrating-coldfusion-8-01-with-livecycle-ds-2-6-beta

http://www.dcooper.org/blog/client/index.cfm?mode=entry&entry=B1400F9C-4E22-1671-59487184325DD3C5

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WS24F7B531-FE69-4fdb-8B85-9F5EFBF3692A.html

http://slidesix.com/view/LCDS-Data-Management-for-Mere-Mortals

End of special reporting periods

This is mostly for those that have these same dates and I am sure others can benifit from this code.

[More]

There is a report for that

I spend a great deal of programming time writing reports. On the surface that does not sound very challenging. With all that is required, it is extremely challenging, but that is another blog entry.

Having dozens of datasets to collect from different sources, and that the date criteria is different from day to day and report to report, poses a unique problem. This makes knowing what to pass to each function a little confusing. The functions know what data they want, but the calling page does not.

[More]

Recording start and finish times for a function

The previous post showed how to get the name of the called function in a component. This post will show how this is used. Each function has the following three lines.

view plain print about
1<cfset var myName = getFunctionName( getPageContext().getCurrentLineNo() ) />
2<cfset var myResult = application.reportEODCollectData.start( arguments.endDate, "#myName#" ) />
3<cfif myResult EQ "Start">

[More]

Getting the called function name in CF8

The agency where I work lives on reports and data sets. I have been converting the old reporting system from Microsoft Access to ColdFusion. Every new report meant a new data set.

I wrote a CFC to contain the functions to collect each data set, then a ColdFusion page that would call each function. I needed to know how long each function took to collect the dataset. Each function would record the start and end time when it ran, and then write those times, along with the function called, to a table.

[More]

Removing dynamically added form fields

About a year ago, Ray Camden posted an article on Using jQuery to add form fields - with validation, which he showed how to dynamically add form fields to a form. This proved to be very useful code.

One thing I found was that those darn users love to push buttons and many would add more form fields than needed. A way to remove the unwanted form fields would be necessary in some cases. Using Ray's code as a base to work from, with just a few modifications this is possible. The entire code page is listed below.

[More]

More Entries