Personal


2
Feb 12

CakePHP 2 – Hashing passwords before saving.

A quick gotcha here that leverages CakePHP’s inbuilt utilities to hash data before you commit it to the database.

The beauty of this method is that you can still run all your validation checks and then hash the data between validation and saving. Why is that important? Consider you have a rule that says a password should be no more than 15 characters. When you hash it, it would break the rule and your record would never save.

All you have to do is hash your fields in the beforeSave function of your model like this example from a User Model:


public function beforeSave() {
App::uses('Utitlity','Security');
if(!empty($this->data['User']['password'])) {
$this->data['User']['password'] = Security::hash($this->data['User']['password']);
}
return true;
}

One import aspect of this is to always return true. If you don’t your record will NEVER save.


4
Sep 11

Installing mongoDB on Debian Squeeze (and Ubuntu).

There’s no point in me trying to sell mongoDB to you, just go over to the mongoDB site and read up on its excellence.

This is how I got mongoDB working on Debian Squeeze. It should work for other Deb based flavours – I’m thinking Ubuntu. I also have a PHP5x setup so you may need to adapt if you are running earlier versions. I’m also assuming you have git installed to fetch the drivers.

All you have to do follows:

First install the necessary mongo stuff (you need php5-dev also as we need the phpize functionality):

sudo apt-get install mongodb mongo-clients php5-dev

Now fetch the official mongoDB php driver from github:

git clone https://github.com/mongodb/mongo-php-driver.git

Change into the driver directory and run the following commands:

cd mongo-php-driver
phpize
./configure
sudo make install

Copy the driver to php extension dir. To find your extension dir run:

php -i | grep extension_dir

Armed with the location of your extension dir copy the file:

sudo cp modules/mongo.so /path/to/php/extension_dir/

Now create a file to load the driver into php at start up:

sudo vi /etc/php5/conf.d/mongo.ini

with the line:

extension=mongo.so

Now restart apache:

sudo /etc/init.d/apache2 restart

Then start an instance of the mongo server and PHP should be mongo friendly.

If you want to test this go grab a copy of the excellent phpMoAdmin and drop the file anywhere you load it through a browser. It should connect off the bat to mongoDB and you can start creating collections and objects in less time than it takes you to type “CREATE TABLE …”.

Enjoy.


28
Aug 11

Behaviour Driven Development for web developers and their clients.

It sells itself:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Feature: Tutor forums
	As a Tutor
	I want to be able to use the forums
	In order to communicate with other tutors
 
Scenario: View forums
	Given that I am logged in as a Tutor
	And I click on "Tutor Forums"
	Then I should see a paginated list of "Tutor Forums"
 
Scenario: Create forum
	Given that I am logged in as a Tutor
	And I am on the page "Tutor Forums"
	And I click on the link Create forum
	And I enter a Forum title
	And I click "create forum"
	Then I should be able to create a new forum.
 
Scenario: Edit forum
	Given that I am logged in as a Tutor
	And I am viewing a forum that I created
	And The forum was created within the past 15 minutes
	Then I should be able to edit the forum
 
Scenario: View threads
	Given that I am logged in as a Tutor
	And I am on the page "Tutor Forums"
	And I click on the title of a Forum
	I should see a paginated list of threads for that forum.
 
Scenario: Read thread
	Given that I am logged in as a Tutor
	And I am viewing a list of forum threads
	And I click the title of a thread
	Then I should see a list of message for that thread.
 
Scenario: Reply to thread
	Given that I am logged in as a Tutor
	And I am viewing a thread
	And I click "post reply"
	And I enter a reply
	And I click "post reply" button
	Then I should be abñle to reply to a thread
 
Scenario: Edit reply
	Given that I am logged in as a Tutor
	And I am viewing replies to a thread
	And a reply was posted by me
	And the reply was posted within the last 15 minutes
	Then I should be able to edit the reply.

It’s so easy you and your clients can learn it in minutes, and it saves everyone time and clarifies expectations.

PHP users should check out Behat.


13
Jun 11

Removing tracked files from git without deleting them

— DISCLAIMER: someone may tell me where I went wrong shortly after publication —

When I develop CakePHP apps, my local database configiration file is very different from the live one. Therefore, when I am using Git to push my changes to a live environment I want to be sure this file is not pushed. Fortunately Git  has the ability to let me do this with the .gitignore file. I can specify the following:

app/config/database.php

One path to file on each line will ignore those files.

However, I recently found myself in the situation where I had already added files I wanted to ignore to my repository. After reading the docs and several forums, the answer seemed to be using the following command:

git rm --cached filename

I did this, commited my changes, then pushed them live. Horror. The database.php had been removed on my local repo and this was subsequently pushed to the live site which duly collapsed. Fortunately I used Git to quickly revert my changes. I’ve no idea why the command above didn’t work for me, but I did find a failsafe way of removing a tracked file without deleting it.

  1. make sure the path to file is listed in your .gitignore
  2. copy the file outside of your repo.
  3. do a git rm -rf path/to/file.ext
  4. do a git commit to remove the file from the repo
  5. copy the file back from where you placed it in step 2

You should be able to change the file now and when running git status it should not show up.

It may seem long winded and a more-than-likely unorthodox to do it this way, but it makes me feel safer.

 


20
Jun 10

CakePHP Full Text Search

CakePHP’s database abstraction is just one of the reasons to use this powerful framework for agile web development. However, it is not always obvious how to build complex queries. I recently had to implement a MySQL full text search against a music database that searched on titles, descriptions and tags. Full text search is a quick, and not too dirty way to make a pretty decent search, although it does come with a caveat, as described in the MySQL documentation:

Full-text indexes can be used only with MyISAM tables, and can be created only for CHARVARCHAR, or TEXTcolumns.

Continue reading →


19
Jan 10

How to fix the OSX Leopard Set up Assistant Loop Bug.

Today, my G5 (Leopard) started displaying the Set Up Assistant everytime it booted. Even after completing setup it was impossible to access the GUI. It was held in a continuous.

If you get caught in the Leopard Setup Assistant Loop Bug, here is the way to get your Mac booting again with no loss of data.

  1. Boot into Safe Mode by holding down the shift key just after you hear the first boot sound. This takes an eternity so be patient.
  2. Don’t log in to any account. Instead press the back arrow key once (this will highlight an account).
  3. Then click the restart button.
  4. Now just wait while your Mac performs some updates and then reboots as normal again.

Even Macs break occasionally / rarely.


15
Jan 10

Select and Unselect All Checkboxes with jQuery

I’ve been working with jQuery to spice up my interfaces for over 12 months now and figured it’s time to share some of the little techniques I’ve developed on the way.

The first is something I use quite alot when I am giving users the ability to administer lists of items in bulk. That including a checkbox that when checked sets the state of all the checkboxes beside a list of items to “checked”. Naturally unchecking it will uncheck all checkboxes. I’m sure you get the picture here’s the code based on two scenarios depending on your preference. But firstly you need to include the jQuery library in the head of your document (I grab mine straight from Google’s repository to save my bandwidth):

Continue reading →


14
Oct 09

Keep linux scripts running after you have closed a remote shell.

I stumbled across this whilst importing 1.1TB of data from a server to Amazon S3 (more on that another day). What I wanted to achieve was to be able to ssh into my remote server, issue a command to push over 200,000 mp3′s up to Amazon and to be able to exit the shell and keep the process running.

The answer lies in a command line tool called screen.

Screen allows you to start a process on a virtual screen, then detach that screen and do something else (including log out). You can also reattach your screen after logging out and logging in again.

If you dont have the screen command on your remote linux box, first install it either from source or using your favourite package manager. Then login into your remote box and run your desired command prefixed with “screen”. For example:

screen top

Now to detach the screen use CTRL+a followed by d. This will detach your screen and you can go about any other business, including quitting your remote session.

Reattaching you screen at any time is as simple as running the command:

screen -r

You can detach and reatach your screen as much as you want until your running process is finished or you kill it, at which point your virtual screen is killed too.


22
Sep 09

British Sign Language Support – New Zumo Internet Launch

Over at my Web Development Agency in Spain we’ve been busy again and we are pretty chuffed with the results. Once again working with TMax Media we have built and just launched BSL Homework Support a website that offers resources, and assessments for anyone interested in learning sign language.

We cut the XHTML, wrote the CSS and used PHP and MySQL to power the online purchasing and content retrieval system. The site features thousands of video clips that we deliver using jQuery and some elegant third party applications such as Shadowbox and JWPlayer.

If you are looking for something special for your next web project, or you’re a media agency looking for a reliable and talented web development service, please email info@zumointernet.com and we’ll let you know what we can do to you.


10
Sep 09

CEIP Mariana Pineda, Benalmadena, Arroyo de La Miel

Hopefully this may help someone else find the contact number for this school which is not correctly listed on either the Yellow Pages in Spain or the Junta de Andalucia’s website.

The telephone number is 951 293 997

In case you are wondering why it is so hard to find: the school is fairly new and is listed as a plot of land still on the Junta’s site. I’m guessing the amount of paper work needed to get a website change actioned is far greater than the parent’s need to contact a school.

The official listing is here.