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.



UX question, handling notifications
Ok, just a random note. I was going to post this on Google+ but figured I'd get a broader reach here on my blog. Lately I've run into two sites that handle notifications in a way that kinda bug me. I wanted to see if it bugs you too. I'm also curio...
(Thu, 02 Oct 2014 12:00:15 GMT)
[view article in new window]

Creating Signed Java Byte Values Using ColdFusion Numbers
Ben Nadel looks at how to create native, signed Java Bytes using ColdFusion numbers, which are generally represented as Integers....
(Thu, 02 Oct 2014 08:00:15 GMT)
[view article in new window]

timeZoneNow
Show the current date/time for a given time zone.
(Thu, 02 Oct 2014 08:00:05 GMT)
[view article in new window]

Woocommerce testing if a product is in a descendent category
To test whether a WordPress post is within a particular category or any of its subcategories, there’s a handy snippet in the WordPress codex here: http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category For WordPress noobs like me (and what environment has more noobs than WordPress?), though, it’s not obvious how to make that work for Woocommerce product categories. There are two […]
(Thu, 02 Oct 2014 00:00:23 GMT)
[view article in new window]

Vote for Railo on Bitnami
Please vote to get Railo added to Bitnami.
(Thu, 02 Oct 2014 00:00:12 GMT)
[view article in new window]

Nano-optimsation of looping code. Fascinating but pointless
G'day:
It's PHP, Railo and ColdFusion today. A few days ago I was researching my "PHP: looking at some interesting "unexpected" behaviour with references" article which related to a StackOverflow question: "Assign by reference bug". One statement in one of the answers fascinated me:
(using reverse looping mostly because not enough people remember that's a thing you can do, and is more efficient than a forward loop =)
Interesting. And sounded like something I could get my teeth into and have a look at.

I didn't immediately get why this would be the case, but did some Googling and found a bunch of interesting articles / Stack Overflow questions/answers, and the reasoning made sense.

Consider a generic for loop:

for(initialisationStatement; conditionalExpression; iterationExpression)

EG:

for (i=1; i <= 10; i++)

  • The initialisationStatement is executed once at the beginning of the code block.
  • The conditionalExpression is evaluated at the beginning of every iteration. When it's false, processing skips to after the end of the block.
  • The iterationExpression is executed at the end of each iteration.
  • All three are optional.
  • The conditionalExpression needs to evaluate to a boolean value.

Let's consider one of these loops, over an array:

for ($i=0; $i < count($array); $i++)


  • $i=0 is run once
  • count($array) is run ten times
  • and its result is compared to $i ten times
  • $i is incremented ten times

Loosely speaking there's 31 operations there (some are weightier than others, I know).

Now consider this:

for ($size=count($array)-1; $size-- >= 0;)
  • $size is initialised once
  • count($array) is called once
  • $size-- is compared to a static value ten times

12 operations. With the weightiest one - count() - now being run once instead of ten times.

Oh, and yeah, the boolean check and the decrement could be considered two operations, but you get my point: there's still fewer operations. Also remember that as a boolean expression, it's lighter weight than the previous example as it's not comparing two variables.

This can be "improved" even further. Consider what happens when we do i--:
  • The current value of i is stored
  • i is decremented
  • The previously stored value is returned
If we used --i instead, it's this:
  • i is decremented
  • and returned

More relevant-ish reading on quirks of these sort of operators: No, the ++ operators are not thread safe.

If you have any sense, you'll be rolling your eyes about all this as the sort of optimisations we're talking about here are shrinkingly inconsequential, and require somewhat unorthodox code. So is it worth it?

Let's see. Here's some tests in CFML:

// baseline.cfm

URL.size = URL.size ?: 1

function getSize(size){
return size
}


timeJob = function(message, job) {
var start = getTickCount()
job()
var end = getTickCount()
var duration = end - start
echo("#message#: #duration#ms<br>")
}


echo("<h3>Running #size# iterations</h3>");

timeJob("Baseline (ascending)", function(){
for (var i=1; i <= getSize(URL.size); i++){
var b = i
}
})

timeJob("Using variable for length (ascending)", function(){
var iterations = getSize(URL.size)
for (var i=1; i <= iterations; i++){
var b = i
}
})

timeJob("Post decrement (descending)", function(){
for (var i=getSize(URL.size)+1; i--;){ // (n-1)-0
var b = i
}
})

timeJob("Pre decrement (descending)", function(){
for (var i=getSize(URL.size)+1; --i;){
var b = i
}
})

timeJob("Pre decrement with additional operation (descending)", function(){
for (var i=getSize(URL.size)+1; --i;){
var b = i
var c = i
}
})

Notes:
  • There's a ColdFusion 11 version of this file here: baselineColdFusion.cfm.
  • I'm not using an array here, but a faux function call which gets the number of iterations to run. The reason being that the number of iterations I need to do to amplify the results until they were distinct was killing my PHP install (out of memory). Pleasingly, Railo coped OK, but I wanted a like-for-like test, so just ran with code which would work on both platforms
  • I have a function which times a job.
  • And a bunch of calls to it. All the jobs simply loop the number of times requested, doing a small amount of work.
  • Note that one of the loops iterates (n-1) to 0 instead of n to 1; the important thing in these loops is the number of iterations, not the index value.
  • Each job in turn refines the looping strategy, inline with my discussion above.
  • The last job has twice as much work to do within each iteration.
Here's the equivalent PHP code:

// baseline.php

$size = isset($_GET["size"]) ? $_GET["size"] : 1;

function getSize($size){
return $size;
}


$timeJob = function($message, $job) {
$start = microtime(true);
$job();
$end = microtime(true);
$duration = (int)(($end - $start) * 1000);
echo sprintf("%s: %sms<br>", $message, $duration);
};


echo "<h3>Running $size iterations</h3>";

$timeJob("Baseline (ascending)", function() use ($size){
for ($i=1; $i <= getSize($size); $i++){
$b = $i;
}
});

$timeJob("Using variable for length (ascending)", function() use ($size){
$iterations = getSize($size);
for ($i=1; $i <= $iterations; $i++){
$b = $i;
}
});

$timeJob("Post decrement (descending)", function() use ($size){
for ($i=getSize($size); $i--;){ // (n-1)-0
$b = $i;
}
});

$timeJob("Pre decrement (descending)", function() use ($size){
for ($i=getSize($size)+1; --$i;){
$b = $i;
}
});

$timeJob("Pre decrement with additional operation (descending)", function() use ($size){
for ($i=getSize($size)+1; --$i;){
$b = $i;
$c = $i;
}
});

OK, so how does this lot fare? I had to run 100000 iterations to get results I could see, so the TL;DR of all this is "it's simply not worth worrying about". But there is a real difference. Check this out:

Railo:

Running 100000 iterations

Baseline (ascending): 120ms
Using variable for length (ascending): 51ms
Post decrement (descending): 57ms
Pre decrement (descending): 51ms
Pre decrement with additional operation (descending): 46ms


ColdFusion:

Running 100000 iterations

Baseline (ascending): 207ms
Using variable for length (ascending): 9ms
Post decrement (descending): 3ms
Pre decrement (descending): 3ms
Pre decrement with additional operation (descending): 3ms


PHP:

Running 100000 iterations

Baseline (ascending): 72ms
Using variable for length (ascending): 29ms
Post decrement (descending): 7ms
Pre decrement (descending): 7ms
Pre decrement with additional operation (descending): 8ms


All these results are a fair "standard" result, when checking about 20-30 runs for each platform.

Interestingly... ColdFusion is fastest. Also interestingly: Railo is overall a lot slower (comparatively). Well: Railo seems better at calling functions (the top result): but for basic looping operations, it's quite a bit slower.

But... come on... a few (or few tens) of milliseconds over 100000 iterations? Who the hell cares?

I included the last test in there - the one with the doubling-up of the operations - as I wondered whether any looping improvement would be lost in the noise of what the looped code was actually doing. In this example it was not really the case. Everything just ran fast. Obviously though, if the loop had heavier duty operations in it like DB hits or a bunch of function calls... a better place to make gains would be too optimise that code. It's simply not worth optimising the looping construct.

What I would attempt to do is to make the looping code clear in its intent. I'd generally never use one of these general purpose loops to - for example - loop over an array. If I was wanting to do something with each element, I'd call Array.each() (perhaps array_walk() in PHP); if I was wanting to update each element of an array, I'd call a map() function; if I wanted to derive a value from an array, I'd call reduce(). etc. Write code that best describes what you're doing. Don't piss about writing non-descriptive code because you think it might be a bit faster. Because - almost always - that would not matter. And I'd not even use a generic solution (for(value in array) in CFML or foreach($array as $key=>$value) in PHP); I'd use the functionality that best describes the operation.

Interesting stuff, but also a lesson in "what not to bother with", I reckon. It's kinda nice to be aware of the differences of the "inner" workings of things though, eh?

Righto.

--
Adam
(Wed, 01 Oct 2014 18:10:48 GMT)
[view article in new window]

Hypermedia API Client Success
Mike Admundsen visited the Lonely Planet offices recently and spent all day discussing the current state of API development, and thoughts on what the future holds – for those brave enough to take the risk. One thing that I walked away from the day-long event with was the thought, “Ok, so we’ve mostly been doing […]
(Wed, 01 Oct 2014 18:00:17 GMT)
[view article in new window]

Thanks for making ColdBox Developers Week 2014 a success!

As we're recovering from our third annual ColdBox Developers Week, we'd like to give a shout out of thanks to everyone who participated. From our sponsors, to the speakers and the attendees; everyone helped play a part in making these 21 training sessions fun and informative. We hope everyone had as much fun learning as we did putting this on.

Prizes

Thanks to our sponsors, Ortus Solutions and Computer Know How, we had tons of prizes to give away. Here's a recap of the winners. Congratulations!

Furthermore, we offered additional prizes to the first two people to submit new packages to ForgeBox-- CFML's newest and most comprehensive code repository. The following two people stepped up:

Recordings

The most common question I've gotten is, "Was this session recorded?" The answer is, YES! Every session including our special guest session by Gert Franz of Railo was recorded and is posted along with the slide decks over on the CBDW 2014 recording page.

http://www.coldbox.org/media/cbdw2014

Resources

Hopefully you came away from CBDW excited to try out some of the tooling you learned about. We're here to help you with that. Here's some links for you to get started:

Donate

Ortus Solutions spends a lot of time putting on free training for the CFML community. If your company benefited from this free event, please consider donating back so we can do even more free stuff for the CF community.

Secure Donation via PayPal


(Wed, 01 Oct 2014 18:00:08 GMT)
[view article in new window]

Cordova, Plugins, and Determining What Supports What

Earlier today a user on the Cordova development list asked if plugins are tested against only the current release of the SDK. This brought up an interesting discussion that I'm summarizing here.

First, there is still an idea of "core" plugins versus "third party" plugins. Core plugins include the things that have traditionally been part of the core feature set, like Camera and Geolocation. While there is no firm list of what is considered core, I'd say anything under the org.apache.cordova namespace is core. You can see a list of them here: http://plugins.cordova.io/#/search?search=org.apache.cordova

The question was - in general - when a new version of a plugin is released, is it tested against the most recent version of Cordova.

The answer is yes. Nice and simple. Michal Mocny (Apache Cordova committer) had this to say:

"When we do a platform release, we test with the latest plugins to make sure the platform isn't breaking things. When we do a plugins release, we test with the latest platforms to make sure the plugins are not breaking things."

Again, nice and simple. Michal also mentioned something I hadn't noticed before. If you go to plugins.cordova.io and view an individual plugin, you may see this:

This comes from the plugin's plugin.xml file containing the engine tag. As an example:


<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>

Unfortunately, not all plugins use this, and obviously you have to trust the developer when they said they've tested something.

It is also worth nothing that the engine referenced above refers to the CLI, not an individual platform release. It should still be relatively safe, but keep that in mind as well.


(Wed, 01 Oct 2014 12:00:25 GMT)
[view article in new window]

Looking at PHP's OOP from a CFMLer's perspective: object serialisation
G'day:
This continues my series which is thusfar:


The next section in the PHP OO docs is actually "Magic Methods" (oh please), but two of these are __sleep() and __wakeup(), and these relate to object serialisation, so I decided to have a look at how this works, and __sleep() and __wakeup() at the same time.



Firstly, here's a quick CFML example (this will run only on Railo, not ColdFusion, as it leverages stuff only Railo have thusfar implemented):

// Movie.cfc

component {

public Movie function init(required title, required year, required Person director) {
variables.title = title
variables.year = year
variables.director= director

return this
}

public function get() {
return [
title = title,
year = year,
director= director.getFullName()
]
}

public function getDirector(){
return director
}

}

// Person.cfc
component {

public Person function init(required firstName, required lastName){
variables.firstName= firstName
variables.lastName = lastName
return this
}

public function getFullName() {
return "#variables.firstName# #variables.lastName#"
}

}

<cfscript>
// movie.cfm

movie = new Movie("Once Were Warriors", 1994, new Person("Lee", "Tamahori"))

serialisedMovie = serialize(movie)
dump(serialisedMovie)
echo("<hr>")

deserialisedMovie = evaluate(serialisedMovie)

dump(var=deserialisedMovie.get(), label=getMetadata(deserialisedMovie).fullName)

director = deserialisedMovie.getDirector()
dump(var=director.getFullName(), label=getMetadata(director).fullName)
</cfscript>


Here we have a simple Movie class which has title, year and director, with the director being an instance of another class Person. I use Railo's serialize() function to serialise the movie, have a look at what it outputs, and then deserialise it again using - of all things - evaluate(). I then dump out the results of the deserialisation to check it's actually worked properly.

Here's the output:

stringevaluateComponent('scribble.shared.scratch.php.www.experiment.oo.serialisation.Movie','62aa1eb53f27541110d76b787d585ef6',{},{'DIRECTOR':evaluateComponent('scribble.shared.scratch.php.www.experiment.oo.serialisation.Person','b459ac28aa7dd48158ddfb3466213bfe',{},{'LASTNAME':'Tamahori','FIRSTNAME':'Lee'}),'YEAR':1994,'TITLE':'Once Were Warriors'})

scribble.shared.scratch.php.www.experiment.oo.serialisation.Movie
Array
1
stringOnce Were Warriors
2
number1994
3
stringLee Tamahori
scribble.shared.scratch.php.www.experiment.oo.serialisation.Person
stringLee Tamahori

Excellent.

OK, now for PHP. Here's code roughly analogous to the CFML code above:

<?php
// Movie.class.php

class Movie
{
use Message;

private $title;
private $year;
private $director;

public function __construct($title, $year, $director)
{
$this->title = $title;
$this->year = $year;
$this->director = $director;
}

public function get()
{
return [
"title" => $this->title,
"year" => $this->year,
"director" => $this->director->getFullName()
];
}

}


<?php
// Person.class.php

class Person
{
private $firstName;
private $lastName;

public function __construct($firstName, $lastName)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
}

public function getFullName()
{
return "$this->firstName $this->lastName";
}

}


<?php
// movie.php

require_once "./app.php";

$movie = new Movie("Once Were Warriors", 1994, new Person("Lee", "Tamahori"));

$serialisedMovie = serialize($movie);


echo "<pre>$serialisedMovie</pre><hr>";

$deserialisedMovie = unserialize($serialisedMovie);

new dBug([get_class($deserialisedMovie), $deserialisedMovie->get()]);

And the result is equivalent too:

O:5:"Movie":3:{s:12:"Movietitle";s:18:"Once Were Warriors";s:11:"Movieyear";i:1994;s:15:"Moviedirector";O:6:"Person":2:{s:17:"PersonfirstName";s:3:"Lee";s:16:"PersonlastName";s:8:"Tamahori";}}

[get_class($deserialisedMovie), $deserialisedMovie->get()] (array)
0Movie
1
array
titleOnce Were Warriors
year1994
directorLee Tamahori

Nice one.

__sleep() / __wakeup()

What about these __sleep() and __wakeup() methods? They don't actually play much of a part in the serialisation - which clearly works fine without them - but are just basically event handlers. If you need to do anything before serialising, or before deserialising. The docs use examples of, say, committing data before serialising, or reestablishing DB connections etc before deserialising.

Here I've updated Movie and Person to have stub methods which simply report they were called:

<?php
// Movie.class.php

class Movie
{
// ... snipped for clarity ...

public function __sleep()
{
SELF::message(__CLASS__, __FUNCTION__, func_get_args());
return ["title", "year", "director"];
}

public function __wakeup()
{
SELF::message(__CLASS__, __FUNCTION__, func_get_args());
}

}

<?php
// Person.class.php

class Person
{
// ... snipped for clarity ...

public function __sleep()
{
SELF::message(__CLASS__, __FUNCTION__, func_get_args());
return ["firstName", "lastName"];
}

public function __wakeup()
{
SELF::message(__CLASS__, __FUNCTION__, func_get_args());
}

}

Output:

Movie->__sleep() called with arguments:
[]


Person->__sleep() called with arguments:
[]


O:5:"Movie":3:{s:12:"Movietitle";s:18:"Once Were Warriors";s:11:"Movieyear";i:1994;s:15:"Moviedirector";O:6:"Person":2:{s:17:"PersonfirstName";s:3:"Lee";s:16:"PersonlastName";s:8:"Tamahori";}}

Person->__wakeup() called with arguments:
[]


Movie->__wakeup() called with arguments:
[]


[get_class($deserialisedMovie), $deserialisedMovie->get()] (array)
0Movie
1
array
titleOnce Were Warriors
year1994
directorLee Tamahori

You can see that the __sleep() handler from both Movie and Person were called during the serialisation process, and __wakeup() for both called during deserialisation.

Cool.

Note how I'm returning a list of properties from __sleep():

return ["title", "year", "director"];

That's the list of properties that will be included in the serialisation. I'm just gonna change that to:

return ["title", "year"];

And run this test instead:

<?php
// movieWithoutDirector.php

require_once "./app.php";

$movie = new Movie("Once Were Warriors", 1994, new Person("Lee", "Tamahori"));

$serialisedMovie = serialize($movie);
echo "<pre>$serialisedMovie</pre><hr>";

$deserialisedMovie = unserialize($serialisedMovie);
echo "<pre>";
var_dump($deserialisedMovie);
echo "</pre>";

And the output:

Movie->__sleep() called with arguments:
[]


O:5:"Movie":2:{s:12:"Movietitle";s:18:"Once Were Warriors";s:11:"Movieyear";i:1994;}

Movie->__wakeup() called with arguments:
[]


object(Movie)#4 (3) {
["title":"Movie":private]=>
string(18) "Once Were Warriors"
["year":"Movie":private]=>
int(1994)
["director":"Movie":private]=>
NULL
}

Here the director property has been completely ignored from the serialisation process, and accordingly when it was deserialised the director is null.

Serializable

There is another approach one can take with this. PHP has a Serializable interface, which requires two methods being implemented: serialize() and unserialize(). In this case, when an object is (de)serialised, these methods are called instead.

Here's an updated version of the Movie and Person classes:

<?php
// Movie.class.php

class Movie implements Serializable
{
// ... snipped for clarity ...

public function serialize()
{
SELF::message(__CLASS__, __FUNCTION__, func_get_args());
$arrayToSerialise = $this->get();
return json_encode($arrayToSerialise);
}

public function unserialize($serialized)
{
SELF::message(__CLASS__, __FUNCTION__, func_get_args());
$deserialisedArray = json_decode($serialized);

$this->title = $deserialisedArray->title;
$this->year = $deserialisedArray->year;

$director = Person::unpackFullName($deserialisedArray->director);
$this->director = new Person($director["firstName"], $director["lastName"]);
}

// ... snipped for clarity ...

}


<?php
// Person.class.php

class Person
{
// ... snipped for clarity ...

public static function unpackFullName($fullName)
{
$asArray = explode(" ", $fullName);
return [
"firstName" => $asArray[0],
"lastName" => $asArray[1]
];
}

}

There's nothing particularly gripping here (and note the added method to Person is just to assist unserialize() from Movie), I simply use JSON as the serialisation method. Here's the output:

Movie->serialize() called with arguments:
[]


C:5:"Movie":68:{{"title":"Once Were Warriors","year":1994,"director":"Lee Tamahori"}}

Movie->unserialize() called with arguments:
["{\"title\":\"Once Were Warriors\",\"year\":1994,\"director\":\"Lee Tamahori\"}"]


[get_class($deserialisedMovie), $deserialisedMovie->get()] (array)
0Movie
1
array
titleOnce Were Warriors
year1994
directorLee Tamahori


Note that __sleep() and __wakeup() are not called when using Serialisable (this is documented, and by design).

That's about it, as far as my findings go with PHP's object serialisation. Other than some dodgy function names, the implementation seems fine to me.

--
Adam
(Tue, 30 Sep 2014 17:52:54 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.