lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
Creating Custom Behaviors in CakePHP
The CakePHP manual leaves a lot to be desired on this topic. Here's one important tip that I couldn't find mentioned on the site:

Every method in your behavior class must have a reference to the model passed as its first argument.

Another tip:

If calling another method from within your behavior class, you must include the model reference as your first argument.

I've added a gratuitous example to the test method below.

A simple behavior class that can be used as a template:

<?php

class NormalizerBehavior extends ModelBehavior {

public $name = 'Normalizer';

/*
Initiate behaviour for the model using specified settings.
*/
function setup(&$Model, $settings = array())
{
}

/*
Run before a model is saved.
*/
function beforeSave(&$Model)
{
}


function normalize_date(&$Model, $date_str)
{
return date('Y-m-d', strtotime(trim($date_str)));
}


function test(&$Model)
{
$date = $this->normalize_date($Model, date('Y-m-d'));
printf('testing behavior %s for model %s on %s', __CLASS__, $Model->name, $date);
}
}

?>


If I discover any other noteworthy tips, I'll add them here.

Labels:

A Better Turing Machine
Slashdot reported the results of this year's Loebner Turing Tournament. There's a $100k for whomever can write a chatbot that fools 30% of human interacting with it that it's a human at a keyboard somewhere and not a program. Apparently, one team fooled 25% of the judges.

Slashdot commentors were quick to pounce on the judging and show up online versions of the contestants. One comment:

It took me three questions before Elbot replied with a non sequitur and about five minutes before it started repeating answers. It didn't take me long to realise that it had no concept of context - every reply was a reply to what I had just said, and had no relation to the last-but-one thing I'd said. Some things that tripped it up:

* Asking 'why?' about anything.
* Trying to teach it a new word.
* Asking it the square root of minus two (odd, since last year one of the judges asked questions like this to all of the bots).
* Anything about religion.

That 25% of the judges thought it was human is quite alarming.


Fair enough. But imagine now if you adopted the premise that half the people you engage with on a daily basis are nothing more than scripted chatbots covered in meat. If you made it your mission to figure out who were the bots and who the humans, you'd alienate most the humans pretty quickly.

Which suggests that the most convincing feature a chatbot might have is a well-scripted sense of personal insult or irritation. Things like:

"Dude, what the hell are you talking about?"

Or:

"Why the fuck are you asking me?"

In fact, I wouldn't be surprised if that wasn't the secret ingredient in some of the more successful contestants. (That, and the careful distribution of typos and misspellings.) Nor would I be surprised if it's a feature they turn off in the online non-competitive version of their bots.
NoScript Full Steam Ahead
After reading this article on slashdot today, I visited the Adobe site, purged my Flash cookies, and set NoScript to full power. A friend at work had warned me about the Flash hole a while back, but this article finally got me off my ass.
Sonnet Monkey (alpha)

A project I've been tinkering with for a couple years now. I've released working versions before (and the MILF was released earlier this year). But I recently refactored the javascript interface and reframed the presentation with cakephp. This is the first version approaching stability.

www.sonnetmonkey.com

There's even a Twitter stream, if that's your sort of thing.