Archive for September, 2010

h1

Refactoring Code

September 29, 2010

I just finished Martin Fowler’s book describing code refactoring. Refactoring is a process of changing code to make it easier to understand and easier to build on. Its a process software engineers should go through regualrly whilst working with software, always asking the question could this be done better. The ultimate aim is to build functionality faster although at first it may seem like you are going to be slowing down as reworking code initially has no new functionality built in. However, the benefits when you start adding code become obvious in terms of creating the code faster and requiring less debugging later as the new code tends to get to a working state sooner. Later, when the code is revisited for additional improvements, you will find it easier to read and easier to rework.

http://www.amazon.co.uk/Refactoring-Improving-Design-Existing-Technology/dp/0201485672/ref=sr_1_1?ie=UTF8&s=books&qid=1285755036&sr=8-1

h1

Copying out of Vim

September 29, 2010

Occasionally I need to be able to copy text out of a Vim terminal window into another application. Setting mouse=a in my .vimrc disabled the terminal windows copy and paste functionality. However, Vim does have a key combination which will yank into the global clipboard. The keys are:

"+y (copy)
"+x (cut)
"+p (paste)

Note that you need the quote, the plus and the letter.

Unfortunately, this only works if your vim is compiled with +xterm_clipboard. Run the following to see if it is:

vim --version | grep xterm

If you see +xterm_clipboard in the output you are good to go, if it says -xterm_clipboard or is missing then this will not work.

For those of you without this an alternative is to hold down shift while dragging the mouse which allows the selection to be copied by the terminal.

h1

Character encoding with PHP and MySQL

September 21, 2010

Today had a problem reading UTF-8 encoded characters from MySQL using PHP. After connecting to the MySQL database I needed to explictly set the character encoding standard, PHP MySQL driver did not seem to automatically know what the db was set to. I am using the PDO method with PHP and MySQL…

$PDO = new PDO('mysql:host=myhost;dbname=db', $username, $password);
$PDO->exec('SET CHARSET SET utf8');