Download Firefox -  a safer, easier to use web browser. Return to iribbit.net - Leap into the online experience! Return to iribbit.net - Leap into the online experience! iribbit.net - Leap into the online experience!

Project News :.

The latest project to launch was the site for Gorilla Offroad Company. Aside from their main site, a social media strategy was develop to launch the company into various industry specific automobile enthusist discussion board communities as well as popular social media fronts like Facebook, Pinterest, and Twitter.


Valid XHTML 1.0 Transitional

Valid CSS!

Section 508 Compliant

powered by: Macromedia ColdFusion MX

made with: Macromedia Dreamweaver MX

What is RSS

XML - often denotes RSS Feed information.

Macromedia - ColdFusion Programming
white horizontal rule

ColdFusion News :.

To bring a little life to my site, I've pulled a couple What is RSS Feeds into this page. You can currently choose between the technology related news stories from the following news sources:



You are currently viewing and RSS Feed from coldfusionbloggers.org.



Return multiple resultsets using cfstoredproc
So last week I found out that returning multiple resultsets to coldfusion from a stored procedure call is a simple matter of adding extra cfprocresult arguments to the cfstoredproc call.
(Tue, 23 Sep 2014 00:00:09 GMT)
[view article in new window]

ColdFusion 11 Updated, and my (non)appearance at the ColdFusion Summit
First, the good news. Today Adobe released the first update to ColdFusion 11: ColdFusion 11 - Update 1. You can update via the normal admin interface. Please note that this update includes a connector update for IIS. If you are using IIS, first, I'...
(Mon, 22 Sep 2014 12:00:17 GMT)
[view article in new window]

ColdFusion 11 Update 1 now available

The first update for ColdFusion 11 is now available to you for install from within the administrator via the update mechanism.

Here is the link for the associate technote which details out the important issues fixed.


(Mon, 22 Sep 2014 10:00:07 GMT)
[view article in new window]

queryExecute
Backport of QueryExecute in CF11 to CF9 & CF10
(Mon, 22 Sep 2014 08:00:05 GMT)
[view article in new window]

Who needs caps lock anyway

I've been obsessing over my keyboard layout recently, stumbling upon typing.io and acquiring the awesome Das Keyboard 4 Ultimate. One thing I've noticed that kills my typing rhythm is using the arrow keys to navigate code; in particular, having to move my right hand from its "home" typing position and back again once I've finished (something that Vim artists don't suffer from).

In Windows, I had found an excellent utitlity called TouchCursor, it allows you to use the space bar as a modifier key and maps spacebar+i, spacebar+k, spacebar+j and spacebar+l to up, down, left and right (plus a whole bunch more). I couldn't find an equivalent utility for Linux after much searching, so set about hacking out a workable solution.


(Mon, 22 Sep 2014 02:00:18 GMT)
[view article in new window]

PHP: generators
G'day:
Duncan's my muse today. Like me, my mate Duncan has recently moved from our defunct CFML team to the PHP team. And like me, Dunc now needs to learn PHP. He's logging his progress as well, and if this sort of thing interests you (following our progress), then maybe keep an eye on what he's doing too.

Part of Dunc's problem today ("Project Euler: problem 2 (PHP)") involves the Fibonacci sequence, and this quickly gave me an in to blog about something I noticed PHP had the other day: generators (PHP's implementation). This is a concept CFML doesn't have, and I've raised this with both Railo (RAILO-2942) and Adobe (3555025).

Basically a generator is a function which defines logic which describes a sequence, and return an Iterator to traverse the sequence. This is implemented by using a yield statement to return the next value in a sequence; the difference being the next time the function is called, processing resumes after the yield statement, rather than from the beginning of the function. PHP wraps all this up in an Iterator object, so one fetches the current value by calling current() on the iterator, and progresses to the next item in the sequence by calling next().

The logic behind the Fibonacci sequence is a sitter for this sort of thing:

// fibonacci.php

function createFibonacciSequence(){
$queue = [0,1];
while (true){
$currentSum = array_sum($queue);
array_push($queue, $currentSum);
$nextInSequence = array_shift($queue);
yield $nextInSequence;
// the next call will resume here
}
}

Notes:

  • The logic behind the Fibonacci sequence is the next number is the sum of the preceding two numbers. So at any given time I need to remember only the last two numbers, as we can generate the next one from those.
  • I seed an array with the first two elements in the sequence;
  • and loop for the full length of the possible sequence (which is "forever" in the case of the Fibonacci Sequence);
  • Whilst we have these two numbers, we need to remember what their sum was...
  • ... and it'll be the value the sequence returns in two values' time, so stick it at the end of the array.
  • The next value to return is the first element in the array, so extract it...
  • ... and return it.
  • The next time the function is called, it'll resume after the yield... so go back to the top of the loop.

That's pretty simple logic.

To create a new Fibonacci iterator is just a matter of calling the function:

$fibonacciSequence = createFibonacciSequence();

Now I can call methods from the Iterator interface on $fibonacciSequence. In this case I just need current() and next() to get the first ten numbers in the sequence:

for ($i=1; $i++ <= 10;){
$nextFibonacciNumber = $fibonacciSequence->current();
echo "$nextFibonacciNumber ";
$fibonacciSequence->next();
}

This outputs:

0 1 1 2 3 5 8 13 21 34

Cool.

The code to do the sequence is more complicated than Duncan's, but I think it makes for cleaner code (I'm still trying to coerce Dunc into reading Clean Code...), as it nicely separates-out the logic behind the Fibonacci stuff from the rest of the logic of his exercise which is to conditionally tally them. For such an easy exercise this might be overkill, but I think compartmentalising one's code as a general practice is a good starting point when writing any code.

But, anyway, this article is not a critique of Dunc's work, it was simply an excuse to try out generators. I think they're the sort of thing that initially one goes "hmmm... yeah, OK?" in a not very convinced way, but after one gets a handle on them, I think they're the sort of thing one will start finding uses for all over the place. Besides that, I've learned a few more things about PHP today, which is a definite win. I think I deserve a Guinness now (I'm in Galway today).

--
Adam
(Mon, 22 Sep 2014 02:00:09 GMT)
[view article in new window]

Answering my first PHP question on Stack Overflow
G'day:
It's really quite interesting. With any CFML question someone might ask me, I am brimming with confidence (or bravado, perhaps), am self-assured, and have no problem either backing myself to be correct, or happy to say "dunno, but I'll find out". I've decided I had better start answering PHP questions on Stack Overflow, as answering questions is a really good way to learn stuff. Especially if one doesn't know the answer to start with.



So, today someone asked this question: "Displaying array chunks in php":

im trying to display a specific chunk of an array where an element is located.

for example, lets say this is my array

Array
(
[0] => Array
(
[1] => a
[2] => b
[3] => c
[4] => d
[5] => e
)

[1] => Array
(
[6] => f
[7] => g
[8] => h
[9] => i
[10] => j
)
)


how do i search the array for the 10th key for example, and choose only the chunk its located in?
It's amazing how quickly answers appear for PHP questions - obviously it's a much bigger community than the CFML one - but I found the quality of answer to be about the same. Read into that comment what you will.

I spotted an "in" for using a technique that hadn't been mentioned yet, so I decided to answer.

I decided to use PHP's equivalent of Array.filter(): array_filter().

Here's the solution in CFML to compare to:

// array_filter.cfm

array = [
{
1 = "a",
2 = "b",
3 = "c",
4 = "d"
},
{
5 = "e",
6 = "f",
7 = "g"
},
{
8 = "h",
9 = "i"
},
{
10 = "j"
}
]


function findChunks(array, key){
return array.filter(function(struct){
return struct.keyExists(key)
})
}

chunk = findChunks(array, 7)

dump(var=chunk)

I've changed the data structure to be an array of structs here, because that's closer to what the PHP code has. Here's the output:

Array
1
Struct
5
stringe
6
stringf
7
stringg

This is correct.

And in contrast the PHP equivalent (I'll omit the array definition to save space):

// array_filter.php
// [...]
function findChunk($array, $key){
return array_filter($array, function($subArray) use ($key){
return array_key_exists($key, $subArray);
});
}

$chunks = findChunk($a, 10);
var_dump($chunks);

Firstly: got PHP is ugly compared to CFML! All thoser bloody dollar signs and underscores. Bleah.

The other thing... I had all sorts of problems getting the closure bit to work... because one has to tell PHP which variables to enclose!! Yikes.

Still: that works quite nicely, IMO, with the following caveat I put in my answer:

Note: this will return multiple chunks if there are multiple chunks with the same key in them (which is entirely possible, depending on your data structure).

If you definitely only wanted the first chunk which matched, array_filter() is possibly doing too much work, as it will traverse the entire outer array whether you need it to or not. That that might matter is down to how big your arrays are.

If performance was more important than clarity of intent, then using a more traditional conditional loop might be more the ticket.
I'm pleased PHP has these iteration functions. I haven't checked them all out yet, but I think I perhaps will, shortly.

Anyway: I half expected to get pilloried for my answer for some reason I just don't know about with PHP, but we'll see. I am moderately pleased I was actually able to answer a question though. Cool.

--
Adam
(Mon, 22 Sep 2014 02:00:09 GMT)
[view article in new window]

PHP: iterators
G'day:
I'm now at the pub (see "PHP: generators"), and have just started my third Guinness. I've not yet worked out what this does to my writing style, so that could be a good or a bad thing. [shrug]: it's my blog.

Anyway, In the article linked to above, I talked about generators, and in the process I mentioned PHP has the notion of iterators, but didn't really have a close look at what those are in the context of PHP. Obviously we all know what an iterator is, but I figured part of my learning process had better be to get a good handle on PHP's implementation.



Firstly... this is where PHP demonstrates itself as being a bit more of a mature language than CFML is. Yes, I know they "came up" at about the same time, but CFML spent a lot of time going out of its way to dumb itself down beyond all belief (thanks for that, Macromedia and Adobe), before Railo came along and jollied things along a bit. So whilst PHP was progressing like a maturing language should, CFML acted like one of those adolescents who didn't see any point in living beyond the age of 18.

(OK, I just detected the difference in my writing when I am doing it at the pub ;-)

My point being that both CFML and PHP has the notion of interfaces, but PHP is slightly more grown up in that it provides interfaces that one's code can implement so as to better interact with other language features. ColdFusion (and Railo, admittedly) seem to be lack-lustre here an provided interfaces and then went "yeah, but... um... dunno why you'd want that": interfaces are simply something we'd use in our own code, not something that CFML itself really kind of "got". I've actually mentioned this in the past to Adobe in the context of their custom serialisers, but it never got any distance at all.

PHP has provided an interface Iterator, which if one implements it on a class, then the class can be used where PHP itself would normally expect an iterable object. Let me demonstrate.

The Iterator interface demands five methods be implemented:
  • current(): returns the current element in the collection
  • key(): returns the current key in the collection
  • next(): moves to the next element in the collection
  • rewind(): moves back to the first element in the collection
  • valid(): returns whether there's an element at the current position in the collection (eg: next() could move past the end of the collection).
If one implement Iterator and those methods (and one'll get a compile error if one doesn't implement the methods, having stated the class does implement Iterator), then one can use an object in situations wherein PHP needs an iterable object. Like a foreach() loop (which normally one would give an array).

Here's a demo.

<?php
// Numbers.class.php

class Numbers implements Iterator {

private $numbers;
private $index;

public function __construct(){
$this->numbers = [];
$this->index = null;
}

public function push($english,$maori){
array_push($this->numbers, ["english"=>$english, "maori"=>$maori]);
$this->index = sizeof($this->numbers) - 1; //stoopid zero-indexed arrays :-|
return $this;
}

public function current(){
return $this->numbers[$this->index];
}

public function next(){
$this->index++;
}

public function key(){
return $this->index;
}

public function valid(){
return array_key_exists($this->index, $this->numbers);
}

public function rewind(){
$this->index = 0;
}

}

NB: I really hate zero-indexed arrays. It's so leaden after using human-natural one-indexed arrays in CFML. And, yes, I know plenty of modern languages get it wrong and use zero-indexed arrays, but they're all wrong too.

Anyway, here I have a class which holds an array of numbers in both English and Maori. I've implemented the most simple versions of current() / key() / next() / rewind() / valid() possible. And here's some basic tests:

<?php
// numbers.php

require "Numbers.class.php";
require "../../debug/dBug.php";

echo "<h3>before populated</h3>";
$numbers = new Numbers();
echo sprintf("valid(): %b<br>", $numbers->valid());

echo "<hr><h3>after adding one</h3>";
$numbers->push("one", "tahi");
echo sprintf("valid(): %b<br>", $numbers->valid());
echo sprintf("key(): %d<br>", $numbers->key());

echo "<hr><h3>after adding 2-4</h3>";
$numbers -> push("two", "rua")
-> push("three", "toru")
-> push("four", "wha");
echo sprintf("valid(): %b<br>", $numbers->valid());
echo sprintf("key(): %d<br>", $numbers->key());
echo "current()";
new dBug($numbers->current());

echo "<hr><h3>after rewind()</h3>";
$numbers->rewind();
echo sprintf("key(): %d<br>", $numbers->key());
echo sprintf("valid(): %b<br>", $numbers->valid());

There's no surprises here, so I won't dwell on it. Just proof of concept stuff. Output:

before populated

valid(): 0



after adding one

valid(): 1
key(): 0


after adding 2-4

valid(): 1
key(): 3
current()
$numbers->current() (array)
englishfour
maoriwha

after rewind()

key(): 0
valid(): 1


But here's an example of the actual iteration in action:

echo "<hr><h3>while loop</h3>";
while ($numbers->valid()){
$number = $numbers->current();
echo sprintf("English: %s; Maori: %s<br>", $number["english"], $number["maori"]);
$numbers->next();
}

Output:

while loop

English: one; Maori: tahi
English: two; Maori: rua
English: three; Maori: toru
English: four; Maori: wha


This demonstrates the fact that the iterations works. Here's the good bit though: foreach() usually takes an array - when I'm using it anyhow - but one can iterate over an object as well and it will output the public properties, like this similar situation:

<?php
// Days.class.php

class Days {

public $days;
public $index;

public function __construct($days){
$this->days = $days;
}

}


<?php
// days.php
require "Days.class.php";

$days = new Days(["Rāhina","Rātū","Rāapa","Rāpare","Rāmere","Rāhoroi","Rātapu"]);

echo "<h3>foreach loop</h3>";
foreach ($days as $key=>$value){
echo "$key ";
}

Ouptut:

foreach loop

days index


So it does the usual thing of iterating over the public properties.

But because our Numbers class implements Iterator, foreach() knows to use the Iterator methods to iterate over our Numbers object:

echo "<hr><h3>foreach loop</h3>";
foreach ($numbers as $number){
echo sprintf("English: %s; Maori: %s<br>", $number["english"], $number["maori"]);
}

(The output is the same as the previous iteration loop, so I'll spare you the repetition).

That's cool. And there's a direct analogy back to CFML here. If you give an object to a for/in loop, you'll get much the same as with the Days example above. Not much use to anyone. But in CFML there's no sense of an Iterator interface to implement to change this behaviour. Someone should raise tickets for this sort of thing for Railo an ColdFusion (normally I'd do this, but I need to start moving on, and leave it to people still in the CFML community to chase this stuff up).

I tried to go one step further and see if array_walk() would accept a Numbers object and iterate over it properly:

<?php
// array_walk.php
require "Numbers.class.php";
require "../../debug/dBug.php";

$numbers = new Numbers();
$numbers -> push("one", "tahi")
-> push("two", "rua")
-> push("three", "toru")
-> push("four", "wha");


array_walk($numbers, function(){
new dBug(func_get_args());
});


Result:
func_get_args() (array)
0
array
0
array
englishone
maoritahi
1
array
englishtwo
maorirua
2
array
englishthree
maoritoru
3
array
englishfour
maoriwha
1Numbersnumbers
func_get_args() (array)
03
1Numbersindex

So this did not work, but that's fair enough: the function is designed for taking an actual array, after all. There's probably a case for a generic "walk" function though. Equally, this would be another requirement of the Iterator interface if CFML was to implement it: provision for each() (and perhaps go the whole hog: each(), sort(), filter(), map(), reduce() etc... perhaps there's more than one interface in there: Iterable, Sortable, etc).

The last thing I checked was to see how serious PHP was about its return types for the interface methods. I don't like the way the do/while loop needed to work: calling valid() and next() separately. It'd be great if next() returned a boolean or something, to compress the logic a bit. As PHP is less typeful than CFML, I wondered if I could get next() to at least return this, so I could chain the valid() call. I made a quick variation of the Numbers class, instead implementing Colours:

<?php
// Colours.class.php

class Colours implements iterator {

private $colours;
private $index;

// [__construct() & current() removed for clarity]

public function next(){
$this->index++;
return $this;
}

// [key() and valid() removed for clarity]

public function rewind(){
$this->index = 0;
return $this;
}

}



and the test:

<?php
// colours.php
require "Colours.class.php";

$colours = new Colours(["Whero","Karaka","Kowhai","Kakariki","Kikorangi","Poropango","Papura"]);

echo "<h3>while loop</h3>";
do {
$colour = $colours->current();
echo "$colour ";
} while ($colours->next()->valid());


And that worked fine! Output:


while loop

Whero Karaka Kowhai Kakariki Kikorangi Poropango Papura

For completeness I checked if foreach() still worked:

echo "<hr><h3>foreach loop</h3>";
foreach ($colours as $colour){
echo "$colour ";
}


And it did (same output as above).

I think that covers all the superficial bases of PHP's handling of the Iterator interface. I'm pleasantly surprised at their implementation here, as it seems to have kept the stupidity to a minimum.

Sláinte

--
Adam
(who is now on his fifth Guinness, and starting to write his next article...)
(Mon, 22 Sep 2014 02:00:08 GMT)
[view article in new window]

PHP: a fractal of [etc]... yeah, I'm now getting where you're coming from
G'day:
Null.


CFML has had a spotted history with the concept of null, and this has been very embarrassing and bloody inconvenient to boot. Fortunately it's finally getting there though (more in Railo than ColdFusion).

But today I had the misfortune of having a run-in with null in PHP.

This code demonstrates:

<?php
// test.php

$tests = [
"null == 0",
"null >= 0",
"null <= 0",
"null > 0",
"null < 0",
"null == 1",
"null == -1",
"null == true",
"null == false",
"null === false"
];

foreach ($tests as $test) {
echo "$test<br>";
$statement = "\$result = $test;";
eval($statement);
if ($result){
echo "You're having a laugh, PHP<br>";
}else{
echo "Not so. Well that's a relief<br>";
}
echo "<hr>";
}

Output:

null == 0
You're having a laugh, PHP


null >= 0
You're having a laugh, PHP

null <= 0
You're having a laugh, PHP

null > 0
Not so. Well that's a relief

null < 0
Not so. Well that's a relief

null == 1
Not so. Well that's a relief

null == -1
Not so. Well that's a relief

null == true
Not so. Well that's a relief

null == false
You're having a laugh, PHP

null === false
Not so. Well that's a relief



What the actual fuck?

OK - for reasons that should have resulted in the developer(s) involved being given a dose of projectio in profluentem - PHP considers null to be false, but... it just seems so wrong that null == 0 and null == false. I suppose it's just a fundamental flaw in the language: null is supposed to mean nothing other than "it's not anything", so prescribing that to mean "but it will also mean boolean false" is even worse than CFML's decision to reflect null as ""; at least CFML doesn't make concessions beyond that ("" is neither true not false, because it's a bloody string). I always thought that was the worst treatment of null I had seen. No. PHP is even worse.

Oh... the fractal thing, if you didn't know, is this: "PHP: a fractal of bad design".

--
Adam


(Mon, 22 Sep 2014 02:00:07 GMT)
[view article in new window]

Mailgun and ColdFusion
A while back I was playing around with Ghost, a blogging platform written for NodeJS. Crazy simple to setup, one of the nuggets that I found during the 5 min install was a reference to Mailgun. Mailgun is advertised as "The Email Service For Developers", allowing you to send 10,000 emails for free every month. It has a nice API, and is very simple to use. A common problem that many ColdFusion developers have, when writing an app, is having access to an SMTP server solely for development practices. You can setup a local server, use some Windows SMTP service, or traffic mail through your personal accounts, but it really is better to have a sandbox that's a bit more separated, for security, sanity, and other reasons. ColdFusion 10+ have a built in SpoolMail utility (based loosely on Ray's project), but sometimes you just need to see the real output in a mail client instead of the browser. Setting up an account was easy on Mailgun. Right from the homepage was a link to the free sign up page. Once the account was created I was given a Mailgun Subdomain. This is my sandbox to play in, so I clicked on the domain name, for the domain admin page, then clicked on the "Manage SMTP Credentials" link on the "Default SMTP Login" line item. From this page I was able to create a new sender (you can use the default if you wish, but sometimes I'll setup separate addresses for specific tracking purposes). The final stage is to put the settings in the ColdFusion Administrator. From the mail settings area I entered my new "sender" address as my SMTP server username, the password that I created with the account, set the SMTP server address to "smtp.mailgun.org", and changed the SMTP port to 587. (The default port 25 will NOT work, but 587 with no other settings changes will work fine.) Now I can send mail with ColdFusion from my dev environment without having to load my own SMTP server or subbing out my personal addresses.
(Sun, 21 Sep 2014 20:00:09 GMT)
[view article in new window]


© The connection to the CFBLOGGERS_FEED's RSS feed has timed out - please try again later. We are sorry for any inconvenience this may have caused.