Monday, May 13, 2013

CF Returnformat=json to php Array

So we have a client that wants data returned from our database.

We have CF8 here and building a CFC to dump a query based on some variables was pretty easy.
Define query arguments and return as Query then they say returnformat=json and us CF developers are done.
But as we all know in order to save bandwidth CF does an array of 2 COLUMNS and DATA which contains arrays of data.

This is smart b/c god knows we don't want 4000 foreign_table_key for each integer in the data. But those php developers get a bit frustrated. So I did it for them
function convertColdFusionJSONtoArray($jsonObject) 
    { 
        $s = json_decode($jsonObject, true); 
        // check valid object 
        if(!array_key_exists('COLUMNS', $s) && !array_key_exists('DATA', $s))
  { 
            // put error trapping here 
            $php_errormsg('invalid coldfusion object passed to convertColdFusionJSONtoArray');
 echo $php_errormsg; 
        }
        $returnArray = array(); 
        //Loops through serialObj and matches the columns 
    
        for ($i=0; $i <= count($s['DATA']) -1; $i++){
            $temp = array(); 
            for($j=0; $j < count($s['COLUMNS']); $j++)
            { 
               $temp[$s['COLUMNS'][$j]] = $s['DATA'][$i][$j]; 
            } 
            // save the new row with column names 
            array_push($returnArray, $temp); 
        } 
        return $returnArray; 
    }
So there you have it.

 BTW thanks to: Arlo Carreon for his his Javascript version of the same thing: Click the link to view.

Monday, August 1, 2011

How I got started in ColdFusion

Steve Bryant had the great idea of making August 1st "How I Got Started In ColdFusion" Day. He proposed that every blogger write a post about their beginnings in ColdFusion. This is my story.

In 97 I was a coordinator of secretarial services for the Archdiocese of Chicago's Office for Religious Education.

I got this position because I had streamlined a lot of the Office's process' by taking old Paradox tables and putting it into a normalized Access Database and then created a number of class registration databases that were all stored on 3.5 floppy discs. We did this to prepare for the office being put on an Network which is the real reason I was there.

I had a passing interest in programming and was reading QuickBasic, Visual Basic book and Java programming books as well as teaching myself C++ (because if you wanted to be a game programmer your really needed to control the stack), some friends knew of my interest and had a consulting company they ran. They gave me a call and asked me if I knew Access, I said yes, do you know ColdFusion, I said no. . .

"Do you know HTML?"

"Yes"

"Same thing."

University of Chicago had a position to convert some WebDB (later acquired by MicroSoft and made into asp) application to ColdFusion.

On day one I learned form posts (what does cgi mean?), on day 5 I had my first cfform completed. Yes it was written on Access and it likely wasn't the best app I ever wrote, I downloaded a trial of Cold Fusion Studio (originally I was working with Notepad and File manager) and was so blown away I convince UofC to get me a copy.

Four months later I started my first development job on a ColdFusion Intranet and support for a large technology re-seller.

I progressed and to survive learned a number a varying technologies but I always wonder why ColdFusion isn't the web server technology for any application that's being created. It gets too bad a rap from too many people just 'picking it up'.

It needs a bit of a boost.

Friday, July 22, 2011

Marketing your Product: My tip for Electronic Publishing

here's a popular author's views on the topic.

While I don't grab pdfs of anything I would like to pass on a thought.

It may be true that you are losing some small bit of revenue to those 27 or so that grab your content from [site]. Now you do have a limited distribution, but as you may see your material free on [site] and tons of others as electronic media as our friend already pointed out, I still find myself purchasing hard copy content from my local gaming store especially if I want it passed around the table.

In addition gamers may not read too many reviews but when a game master pulls out good third party content for his game it sparks the most valuable of advertising. Word of Mouth.

Gamers are notoriously frugal with their funds. It was stated by opponents of file sharing "The point of concern is the fact that the vast majority of people that steal products never pay for them." I would be surprised if any of the people that steal from the site would have ever touched the product in the first place, so that wasn't actually revenue they could say they would have gotten . . . ever.

I know of one person who pulled content for free, a game that was on the Torrents prior to it's publication , you know what happened? He demonstrated the product to folks didn't know it, this helped sell the product to folks whom, without the demo, may have never purchased the product.

Indeed since then I have 7 physical copies of various versions (of the same book) none of which were stolen, which mean that the revenue was realized the electronic media that I "stole". My buying habits completely negate the cost of me having the electric media content as well as at least 2-3 times the expected revenue from a single consumer.

Think of it this way. For every 1 person that has no qualms about grabbing free content there are roughly 8 others that they expose who will be interested to pay for a legal version of the media because they do have issues (it is illegal). If the media you produce in anyway stands out against the illegal copies (adding functionality in the electronic media, easy to use, navigation tools for a digital product) then that number would actually grow likely by a factor of 10 or more. (because what you sell is that much better than the free version). If it's good then it rockets and you will have no idea what to do with yourself (we can all hope).

But you really need to do nothing than expose the product to see a realization in revenue.

If you were get upset and then ask someone to pull the illegal product down. He does, and your third party content competitor doesn't. Whose product get's seen?

Whose product get's sold?

-Joshua

Wednesday, January 26, 2011

2011 Adventures in Code

So I'm ramping up my code this year going to dive into some tools that I've got my hands on and that I want to play with.

I want a project but little ones to work on instead of big ones.

Maybe my son's V-Volcano web site.

Recently I threw down some Ruby, Google Aps and GWT

I'll have a link soon.

Sunday, October 17, 2010

Ain't a date and not Null

#1/1/1900# or #12:00:00 AM# or #1/1/190012:00:00 AM# is neither null or a date so life isn't simple when working with it. So this would help.

Private Function IsDateNull(ByVal lDate As Date) As Boolean
Dim comparerDate As Date = Nothing


If lDate.CompareTo(comparerDate) <> 0 Then
Return False
Else
Return True
End If
End Function

Thursday, September 2, 2010

Getting what I need from Javascript (dumpProps)

Today I needed to access something that existed in a telerik library, essentially to do put a date selected in a calendar in a custom text box (Since I needed the text box to take M/yyyy, yyyy, and M/DD/yyyy and the input control in the nifty datePicker control wouldn't let you do that as far as I could tell).

Here's a link that will get you started
Date Picker populate a text field however while that works for calendar be careful because my script needed a different method: get_newValue.

Probably because the calendar control is only a subcontrol of the RadDatePicker Control.


function OnDateSelected(sender, eventArgs) {
//dumpProps(sender);
if(sender._clientStateFieldID.indexOf("<%= rdpStartDate.ClientID %>") != -1){
var textbox = $find("<%= rtbStartDate.ClientID %>");
}
if (sender._clientStateFieldID.indexOf("<%= rdpEndDate.ClientID %>") != -1) {
var textbox = $find("<%= rtbEndDate.ClientID %>");
}
textbox.set_value(eventArgs.get_newValue());
}


Now the way I created this was to cheat a bit, I didn't know what properties the sender would have so I decided to dump it with the following trick I found online.



function dumpProps(obj, parent) {
// Go through all the properties of the passed-in object
for (var i in obj) {
// if a parent (2nd parameter) was passed in, then use that to
// build the message. Message includes i (the object's property name)
// then the object's property value on a new line
if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
// Display the message. If the user clicks "OK", then continue. If they
// click "CANCEL" then quit this level of recursion
if (!confirm(msg)) { return; }
// If this property (i) is an object, then recursively process the object
if (typeof obj[i] == "object") {
if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
}
}
}


Next step is to move the calendar back to the text box. But this should help you find any properties of objects in those vast library's that are being used these days. Telerik or otherwise

Wednesday, July 21, 2010

Contest

Troll in the Corner has a contest on their site to promote the Aruneus project you can enter it if you click on the word contest.