Sunday, 30 October 2011

Restoring a single file from git

Okay, so you've done a few commits, pushes and pulls - but you've made a mess of a file? How do you get it back?

Simplest way is to first get the commit number from the log

git log

Then use git checkout with the commit number

git checkout [commit-ref] [filename]
Simples :)

Tuesday, 25 October 2011

Web apps for mobile

Very simple, use jquery for mobile :)

Thursday, 13 October 2011

Tracking slow MySql queries

Useful tool to track slow queries, no need to do any coding, just need to change the MySql config :

gksudo gedit /etc/mysql/my.cnf

Search for "slow" and change the lines to

log_slow_queries = /var/lib/mysql/mysql-slow.log
long_query_time = 1

Restart mysql 

sudo service mysql restart

Run your applications, then any queries that take longer than 1 second will be stored in the log. This can be viewed with

sudo mysqldumpslow | more

This will display the slowest queries first. Useful to keep running while in production to optimise your system.

To see the queries with the actual data

sudo more /var/lib/mysql/mysql-slow.log

Credit and thanks to Laurent David @ TDM

Tuesday, 11 October 2011

Really really simple method to export data from php to excel or another other spreadsheet.

// Excel export using The KISS method
$filename = $_REQUEST['name'] ? $_REQUEST['name'] : 'excelreport';
$contents = $_REQUEST['data'] ? $_REQUEST['data'] : "testdata1\ttestdata2\ttestdata3\ntestdata4\ttestdata5\ttestdata6\n";

if (substr(strtolower($filename)-4,4)!='.tsv') {
$filename .= '.tsv';

// header('Content-type: application/ms-excel');
header("Content-Type: text/tab-delimited-values");
header('Content-Disposition: attachment; filename='.$filename);

echo $contents;

Monday, 10 October 2011


Had a fantastic week last week working at Kineo on behalf of TDM. Really great working environment - relaxed but fast paced and very friendly people. Things would just turn up like boxes of fruit and packets of doughnuts that we could all tuck into as well as constant supply of proper coffee.

Mainly bug fixing on a Totara project using PHP but also picked up a bit about Postgresql (database), Trac (ticketing system), Passpack (shared passwords) and single sign on.

Aside from that... Brighton is a fab place!! Highly recommend it