15
May 12

Reading HTML email from within Mutt.

Mutt is a fantastic terminal based email client that has all of the capabilities of its GUI based equivalents. One thing I always found annoying was being unable to read emails that have been sent as HTML only (ugh). Well, here is a nice fix that let’s you use a terminal based web browser to view the emails as soon as you load them, in mutt, with as much formatting as possible maintained.

  1. First close Mutt down.
  2. Make sure you have the terminal based browser lynx installed (e.g apt-get install lynx)
  3. Create (or edit) a file in your home directory called .mailcap and add the following lines:
    text/html; lynx %s; nametemplate=%s.html
    text/html; lynx -dump %s; nametemplate=%s.html; copiousoutput
  4. Add the following to your .muttrc file:
    auto_view text/html
  5. Restart Mutt

Now you can start enjoying your HTML email from within Mutt.

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

01
May 12

Alternating row colours with jQuery

I covered a very simple way to implement alternating table row colours with PHP in another post (6 years ago!). Here is a way to achieve the same client side using jquery. It could easily be used for any set of elements (e.g. li)

$('.table').each(function (i, e) {
if (i % 2 == 0) {
$(this).addClass('highlight')
}
});

All you need then is a .highlight rule in your css to do the styling.

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

02
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.

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

04
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.

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

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.

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

09
Jul 11

CakePHP Development

The new website for my CakePHP development company, Zumo Internet is now live.

I’ve been building with PHP for 10 years, but over the past 2 years all of my projects have been built using CakePHP. I’ve never looked back as far as stability and speed of development is concerned.

So if you are looking for a CakePHP developer, please visit and maybe hire me.

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

17
Jun 11

Using CakePHP without a database

I enjoy CakePHP’s structure and methods so much that I have started  using it for my non-database driven projects and for prototyping big projects.

However, when no database is present CakePHP throws a warning that it can’t connect to the database. The solution is to create a dummy database connection to convince CakePHP that all is ok. And, it’s as simple as this:

Create a new folder app/models/datasources/dbo

Create a new file at app/models/datasources/dbo/dbo_dummy_db.php and add the following:

1
2
3
4
5
6
7
<?php   
    class DboDummyDb extends DboSource {         
                 function connect()  {                
                          $this->connected = true;
                          return $this->connected;
                  }
            }

In your app/config/database.php find the default connection array – a line that starts $default = array
and replace the line for the driver from
'driver' => 'mysql',
to
'driver' => 'dummy_db',

And that’s all there is to using CakePHP without a database.

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

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.

 

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

13
Apr 11

Astronomics – is science following the right path?

It’s not often that Something For the Weekend - BBC2′s Sunday morning easy-watching offering –  completely changes one of my fundamental beliefs. Though that may because it’s not often that I watch it. The truth is, that had it not been for this tweet by @profbriancox, the ragged trousered cosmologist, I’d have no doubt been out walking the hills. I digress.

You see, Brian made a statement that really hit home with me. In the midst of almost dumping the wrong ingredients into a blender he announced that there are no facts in science, only theory. And he’s right.

It struck a chord with me because it something I’ve been thinking about for quite some time: How do we know that science is right?

Continue reading →

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email

12
Sep 10

SEO friendly URL slugs with CakePHP.

The CakePHP framework API is a treasure trove of often undiscovered methods and functionality. Recently I came across the Inflector Class methods and noticed the “slug” method close to the bottom of the documentation, which is documented thus:

Returns a string with all spaces converted to underscores (by default), accented characters converted to non-accented characters, and non word characters removed.

Continue reading →

  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • StumbleUpon
  • LinkedIn
  • Reddit
  • Netvibes
  • email