Do not install Nero 9 lite
February 15, 2010 by Adam · Leave a Comment
I recently had an issue with an iso that wouldn’t burn using Windows 7′s in-built iso burner, I installed Nero-9 lite to solve the problem (which it did) however trying to uninstall Nero once it gets onto your system is a pain in the ass.
Some quick research shows you need to uninstall it, then use a seperate tool to actually remove it. You can find that here:
http://www.nero.com/enu/tools-utilities.html#tab4
Simple Sluggable Behavior for CakePHP
November 18, 2009 by Adam · Leave a Comment
For quite a while now pretty much the defacto standard for generating automagic slugs in CakePHP has been the Sluggable Behavior by Mariano Iglesias (mariano) in the Cake Bakery (http://bakery.cakephp.org/articles/view/sluggable-behavior). I’ve never quite gotten on with this behavior, it’s not that it doesn’t do what it says, it just seems like it uses a lot of code to do it, and I prefer all of my code to be as simple as possible.
I’ve been using my own Sluggable Behavior for a while, and today I found myself needing a little more customisation, I made a few changes and now it works in exactly the same way as Mariano Iglesias’s, but using less code (and CakePHP’s built in Inflector::slug). So here is my Sluggable Behavior.
<?php
class SluggableBehavior extends ModelBehavior {
/**
* Defaults
*
* @var array
* @access protected
*/
var $_defaults = array(
'seperator' => '-',
'label' => 'title',
'field' => 'slug',
'extension' => '.html',
'length' => 100,
'overwrite' => false
);
/**
* Initiate Sluggable behavior
*
* @param object $Model instance of model
* @param array $config array of configuration settings.
* @return void
* @access public
*/
function setup(&$Model, $config = array()) {
$settings = array_merge($this->_defaults, $config);
$this->_settings[$Model->alias] = $settings;
}
/**
* Before save method. Called before all saves
*
* Overriden to transparently manage creating and populating the slug field
*
* @param AppModel $Model Model instance
* @return boolean true to continue, false to abort the save
* @access public
*/
function beforeSave(&$Model) {
extract($this->_settings[$Model->alias]);
if(!empty($Model->data[$Model->alias][$Model->primaryKey]) && !$overwrite) {
return true;
}
if(!is_array($label) && empty($Model->data[$Model->alias][$label])) {
return false;
}
if(is_array($label)) {
$slug = '';
foreach($label as $key) {
$slug .= ife(!empty($slug), ' ', '') . $Model->data[$Model->alias][$key];
}
} else {
$slug = $Model->data[$Model->alias][$label];
}
$slug = Inflector::slug($slug, $seperator);
$slug = low($slug);
if(strlen($slug) > $length) {
$slug = substr($slug, 0, $length-1);
}
if(!empty($extension)) {
$slug = $slug . $extension;
}
$i = 1;
while($Model->find('count', array('conditions' => array($Model->alias . '.' . $field => $slug))) != 0) {
if (!preg_match ('/'.preg_quote($seperator).'{1}[0-9]+$/', $slug)) {
if(!empty($extension)) {
$slug = $slug . $seperator . ++$i . $extension;
} else {
$slug = $slug . $seperator . ++$i;
}
} else {
$slug = preg_replace('/[0-9]+$/', ++$i, $slug);
}
}
$Model->data[$Model->alias][$field] = $slug;
return parent::beforeSave($Model);
}
}
?>
Usage
var $actsAs = array(
'Sluggable' => array(
'label' => 'name',
'extension' => false
)
);
// or
var $actsAs = array('Sluggable');
Buggy Firefox Rant
October 29, 2009 by Adam · Leave a Comment
I’ve been an advocate of web standards (and therefore a user of Firefox) since before most people knew there was a browser other than IE6. Firefox is arguably the browser that brought us out of the dark-ages of the web, however since the v3 upgrade Firefox has been plagued with memory leaks, and the infamous “Firefox is already running on this system” issue.
I hoped 3.5 would fix this, and whilst the latter is now better than it was, it is not eradicated (it would appear they’ve done something to stop it happening rather than fixing what caused it), and nothing has changed with regards to the memory leaks.
In my job my browser is open all day, and by the end of the day Firefox is using around 30% CPU and several hundred MB of ram, it would appear that a lot of other people are having this problem, so lets hope that Firefox 3.6/7 addresses these properly so we can all resume normal service.
In the mean time I’m using Google’s Chrome for my day to day browsing, and Firefox for my debugging (as Firebug is the most valuable tool available to a web developer at the moment!).
Rant over.
This is going to be…
August 27, 2009 by Adam · Leave a Comment
This is going to be the weblog of Adam Brett. I am currently a Senior PHP Developer for Image+ Ltd in Coventry England, and also work as a Freelance Developer, through my own company, Votive Media Ltd.
You can expect to find things relating to PHP, especially CakePHP, my framework of choice for both Image+ and Votive Media, but also related technologies, such as Javascript, Scriptaculous & Prototype, Open Source systems such as Joomla and Magento, Microsoft Technologies such as C# and .NET, as well as general programming issues, project management, and freelance business.
This is aimed at anyone who would find the small things I discover in the course of my job to be useful, and more specifically, contribute something back to the network of bloggers who have helped me when I’ve been stuck on any number of issues over the many years I have been developing code.