Chris Tate-Davies

An archive of helpful tit bits of information for development, and probably some stuff that is incomplete, wrong or boring…

Viewing events attached to elements via JavaScript

Posted on | September 27, 2011 | 2 Comments

If like myself, you often attach functions to elements using jQuery, for example:

$('.btnName').live('click', function() {
    //do something
});

There is a nice little browser extension that will show all the elements on the page with a little bubble outlining the attached events/functions.

It is written by Allan Jardine, and you can get it from http://www.sprymedia.co.uk/article/Visual+Event

 

 

MySQL Error in create table syntax ‘USING BTREE’

Posted on | September 27, 2011 | No Comments

We had an odd thing today, whilst performing a apply-db-changes we received the error:

You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'USING
BTREE, KEY `index` (`fields`)' at line 1

It worked fine before, so why won’t ant create this table?

Well its down to the USING BTREE on MySQL Server version 5.0 using a InnoDB or MyISAM table. You can only have BTREE as an index and thus any reference to it on 5.0 seems to fail. May as well just take out the reference to the index type.

Annoying if you can’t work out the error, but now you know.

 

 

 

Setting up Class Table Inheritance with Doctrine 2.0

Posted on | September 13, 2011 | 1 Comment

Have had some serious problems getting this working, but after a 4 hour head bashing session, we’ve cracked it.

CREATE TABLE inventory(
    inventory_id INT AUTO_INCREMENT,
    discriminator_column VARCHAR(20),
    category VARCHAR(50) NOT NULL,
    part_number VARCHAR(50) NOT NULL,
    PRIMARY KEY (inventory_id),
    KEY category_part_number (category, part_number),
    KEY discriminator_column (discriminator_column)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE inventory_room(
    inventory_id INT NOT NULL,
    rack_limit INT(6),
    room_type VARCHAR(25),
    KEY inventory_id (inventory_id),
    CONSTRAINT inventory_room_key FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id)
        ON DELETE CASCADE
        ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

You have to have a discriminator field so that Doctrine can connect the tables nicely when its joining them.

<?php
namespace Net\Model\Inventory;
use Doctrine\ORM\Mapping as ORM;

/**
 * Inventory entity
 *
 * @ORM\Entity(repositoryClass="Net\Repository\Inventory")
 * @ORM\Table(name="inventory")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discriminator_column", type="string")
 * @ORM\DiscriminatorMap({"inventory" = "AbstractItem", "inventory_room" = "Room"})
 *
 * @category Net
 * @package  Model
 */
abstract class AbstractItem
{
    /**
     * @ORM\Id @ORM\Column(name="inventory_id") @ORM\GeneratedValue
     * @var int
     */
    protected $inventory_id;

    /**
     * @ORM\Column(type="string")
     * @var string
     */
    protected $category;    

    /**
     * @ORM\Column(type="string")
     * @var string
     */
    protected $part_number;
 }

As you can see in the above class, we have a ORM\GeneratedValue field. This tells Doctrine that this field is an increment field. As this is a one-to-one relationship we do not need one in the inventory_room table as it will be joined on the inventory_id field.

In the next class, this is the child class that extends the abstract. So Doctrine will read the annotations at the top and see that its a joined table using the id field (inventory_id)

<?php
namespace Net\Model\Inventory;
use Doctrine\ORM\Mapping as ORM;

/**
 * Inventory Room entity
 * @ORM\Entity
 * @ORM\Table(name="inventory_room")
 *
 * @category Net
 * @package  Model
 */
class Room extends AbstractItem
{
    /**
     * @ORM\Column(type="string")
     * @var string
     */
    protected $room_type;

    /**
     * @ORM\Column(type="string")
     * @var string
     */
    protected $rack_limit;
}

SVN Externals – how to add them

Posted on | September 8, 2011 | No Comments

When creating a Zend Framework site, its always best to keep the Zend library as an external source. This way you can keep the branch up-to-date with the release of Zend with a simple text file.

To access the externals file, navigate to the root of your site:

> cd /var/www/mysite

And add the external to the svn:externals file. I am using the latest version of Zend Framework for this, but you can use any SVN source you like. Note, it has to be available as an SVN repository.

> svn propedit svn:externals .

This will open a text editor.

To enter an external, just enter the local folder to download to, and the source SVN.

destination source

So, if I want my Zend Framework files to be saved in /var/www/mysite/library/Zend :

library/Zend http://framework.zend.com/svn/framework/standard/tags/release-1.11.9/library/Zend/

The first part is the local, second part is the URL of the repository.

Save and close.

Next time you do an update, svn will go and fetch the external files and save them for you.

Other externals are available, such as JQuery, various wikis and other JS sources.

 

 

 

Add all new files to SVN

Posted on | September 8, 2011 | No Comments

How to recursively add all new files to SVN

> svn add --force *

Saves a whole bunch of time when committing a load of new pages via the command line.

 

 

 

Keeping 2 drives sync’ed with rsync on Linux

Posted on | August 31, 2011 | No Comments

I have an external USB HDD and I like to keep it synchronised with my desktop for backup reasons. I find the easiest way to do this, is to use rsync:

> sudo apt-get install rsync
> rsync -avu /source/ /dest/

For example:

> rysnc -avu /media/externaldisk/ /home/chris/diskbackup/

Will increment copy everything (ignoring older files) from /media/externaldisk to my /home/chris/diskbackup folder.

The options are:

  • a – Archive mode – Will retain the folder/file properties, such as owner, permissions, etc.
  • v – Verbose – Output the progress to the screen (so I know its still working)
  • u – Update – Only update files that have a more recent file modified date.

 

Logo for Pete Watkins

Posted on | August 25, 2011 | No Comments

 

 

Just a quick logo knocked up for Pete:

 

 

 

 

 

 

Get rid of Apple Test Advertisment from iPhone SpringBoard

Posted on | August 17, 2011 | No Comments

I get constantly annoyed by the test apple advert on my phone’s springboard after I’ve quit an app.  But I think I worked out how to stop it:

Install iFile (obviously you need a jailbroken phone to do this as its a Cydia app)

Navigate to

\Applications

And then touch the blue arrow on the right of the AdSheet.app.

Here you will be able to click into the “Name” field and rename it to something memorable (incase you need to roll back this change) – I renamed to “RenamedAdSheet.app”, then press Done.

So far, I’ve not seen any on my SpringBoard…

HOWTO: Rotate a video in Linux

Posted on | August 17, 2011 | No Comments

I videoed something at the weekend on my iphone, but must’ve had the phone upside-down so the video came out that way.

Fortunately there is a little program that will rotate a video for you.

> sudo apt-get install mencoder

Then, to rotate my video clockwise by 90 degrees:

> mencoder -ovc lavc -vf rotate=1 -oac pcm inputfile.ext -o outputfile.ext

I had to do this twice, obviously changing the input filename for the second rotation for the output filename on the first…

Job done. That were easy.

There is more help here: http://en.gentoo-wiki.com/wiki/HOWTO_Mencoder_Introduction_Guide

Stopping Ubuntu opening F-Spot when I plug in my iPhone

Posted on | June 14, 2011 | No Comments

When I installed Ubuntu, every time I plugged in my iPhone it popped up a prompt asking me what to do about the digital music/photos. After clicking “do nothing” for months I decided to let it open F-Spot to import my photos. This is all well and good, but it now pops up f-spot whenever I plug it in, several times a day!

To combat this, open a terminal session and type:

nautilus-file-management-properties

Then, you can click on the Media tab, and choose “Do Nothing” for Photos.

Job done. Thank god!

« go backkeep looking »
  • Chris Tate-Davies

    Hello there. This is my little "repository" on the world wide web. Its for nothing more than documenting things that I might need again in the future. You could describe it as an extension to my memory.

    Also an online collaboration of my thoughts through the day. I'll try to keep the real random stuff out and keep the blog on course.

    Thanks for stopping by... Hope you find what you're looking for...

  • Tags