Posted in Javascript

Preface: These APIs are still quite new and subject to change. As of the time of writing, the following tutorial works in Chrome 18.0.1025.168. Firefox 12 supports full screen but not mouse lock.

I’ve been having a little play with some HTML5 features and worked up an example of Pointer Lock and Full Screen APIs. As it stands at the moment, pointer lock is tightly coupled with full screen, so you won’t be able to use it without first loading up full screen mode.

You’ll need to enable Enable Pointer Lock in about:flags in Chrome then restart the browser for mouse lock to work.

You may request full screen mode like so:

element.requestFullScreen =
	element.requestFullScreen    ||
	element.mozRequestFullScreen ||

Once in full screen mode, pointer lock should become available:

navigator.pointer = navigator.pointer || navigator.webkitPointer;
	function() {
		console.log('Pointer lock');
	function() {
		console.log('No pointer lock');

Note in the above two scripts, element is a DOM element

Check out the working demo here. I’ve also added some JS to determine the direction the locked pointer is travelling and output the data to the screen. View page source for details.

Read More »

Posted in Linux

If you’re a Ubuntu user, you may be familiar with ppa-purge. It’s a handy little automated script to remove a PPA and roll back the version of any apps installed from that PPA. Debian doesn’t have this nicety by default but there’s a relatively simple way to get something close.

Firstly, remove your PPA from /etc/apt/sources.list or from the /etc/apt/sources.list.d/ directory.

Do an update:

sudo apt-get update

Find any packages that are now obsolete:

aptitude search '?obsolete'

For me this returned the following:

# aptitude search '?obsolete'
i A libmysqlclient18      - MySQL database client library                                                                           
i A mysql-client-5.5      - MySQL database client binaries                                                                          
i A mysql-server-5.5      - MySQL database server binaries and system database setup                                                
i A mysql-server-core-5.5 - MySQL database server binaries                                                                          
i A ruby-passenger        - Rails and Rack support for Apache2 and Nginx

Now just remove the listed packages with apt-get remove and reinstall as necessary. It’s not quite the automated tool that ppa-purge is, but it’s a pretty good start.

Read More »

Posted in Linux

I’ve been getting alot of frozen messages with Exim and needed to find out what they were so figured I’d document a few handy commands for doing so:

List messages in queue:

exim -bp

Show message header/body:

exim -Mvh <id> #For header
exim -Mvb <id> #For body

Delete all messages in queue:

exim -bp | exiqgrep -i | xargs exim -Mrm

Read More »

Posted (Updated ) in Linux

It seems Gnome 3 removed the button allowing users to add specified applications into the ‘Other Applications’ list under ‘Open With’ in file properties. Until the functionality is restored, you can add applications manually by doing the below:

cp /usr/share/applications/gedit.desktop ~/.local/share/applications/your_app.desktop

Modify the contents of your_app.deskop to look something like the below:

[Desktop Entry]
GenericName=Your App
Comment=Edit text files
Exec=your_app %U

You can copy any .desktop file from /usr/share/applications so pick the one that closest resembles the application you’re adding. Below you can see komodo added to mine:

Komodo has been added to my 'Open With' list
Komodo has been added to my ‘Open With’ list

Read More »

Posted (Updated ) in Linux, PHP

I’ve been seeing up an Amazon EC-2 server with Debian Squeeze and used tasksel to install Web Server and Mail Server. Like all things debian, this worked pretty well after the installation completed and everything ‘just worked’ however I wasn’t happy with the default from name and email address assigned to emails sent by PHP – www-data <>.

I discovered a quick and simple fix to change these defaults for all mail sent with PHP:

Open /etc/php5/apache2/php.ini and set

sendmail_path = '/usr/sbin/sendmail -t -i -Fno-reply'

You can see a list of sendmail arguments and what they do here.

Restart apache and you’re good to go:

sudo service apache2 restart

Read More »

Posted in Javascript

Anyone attempting to do cross domain AJAX will be familiar with the following message:

XMLHttpRequest cannot load Origin is not allowed by Access-Control-Allow-Origin.

However if you own the server you’re AJAXing data from, there’s a simple way to make this possible using a callback. Here’s an example:

server.php (On a different domain):

	$response = 'your response here'.
	if ( !isset($_GET['callback']) ) $_GET['callback'] = '';
	echo $_GET['callback'] . '('.json_encode(array('response'=>$response)).');';

client.php (with JQuery):

$.getJSON('', function(json) {
	alert( json.response );

That’s all there is to it. Remember the ?callback=? URL segment or it won’t work.

Read More »

Posted in Linux, PHP

I’ve been looking for ways to speed up my site recently and came across this interesting article on seamlessly integrating nginx with Apache to handle asset files without requiring a CDN subdomain. This works by checking the requests file extension for .js, .jpg, .pdf etc and if not found, proxies the request to Apache and serves the results.


You won’t need to modify all your pages/posts updating asset locations to point to a subdomain! Everything will ‘just work’.


There are 2 issues I’ve found with this setup:

  • Because Apache is now running on port 8080, your mod_rewrite redirects will now redirect to that port. You won’t be able to use RedirectMatch anymore, however below is the solution I came up with:
    RewriteEngine on
    RewriteRule ^foo\.php$ http://%{HTTP_HOST}:80/bar.php [R=301,L]
  • You can no longer use .htaccess redirects for any asset files nginx is serving. Instead, use nginx redirects. Below is an example:
    rewrite ^\/foo\.jpg$ permanent;

    For more information on nginx redirects, see the official documentation.

Read More »

Posted (Updated ) in Linux

A couple of times now we’ve needed to forward to If you’re running postfix here’s how to do that.

nano /etc/postvix/virtual


then run

postmap /etc/postfix/virtual

If the above doesn’t work, make sure you have the following line in /etc/postfix/

virtual_alias_maps = hash:/etc/postfix/virtual

and type

service postfix reload

Thanks to Matt Simmons of ServerFault for his answer.

Read More »

Posted in Linux
Pidgin Attention button successfully hidden
Pidgin Attention button successfully hidden

Ever since the developers added the Attention button to Pidgin, one of the most common questions asked is how to remove it. I finally set some time aside to answer this question.

  • Download the plugin that does exactly this from the Pidgin developer page.
  • Install the Pidgin developer dependencies if you haven’t already:
    sudo apt-get install ubuntu-dev-tools subversion g++ pidgin-data libpurple0 libpurple-dev pidgin-dev libgtk2.0-dev

    This step is important or you’ll receive errors like the following:

    $ make
    [CC] hide_attention_button.o
    Package pidgin was not found in the pkg-config search path.
    Perhaps you should add the directory containing `pidgin.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'pidgin' found
    Package purple was not found in the pkg-config search path.
    Perhaps you should add the directory containing `purple.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'purple' found
    Package gobject-2.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gobject-2.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gobject-2.0' found
    Package gtk+-2.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gtk+-2.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gtk+-2.0' found
    hide_attention_button.c:24:20: fatal error: plugin.h: No such file or directory
    compilation terminated.
    make: *** [hide_attention_button.o] Error 1
  • Drop the .c and Makefile into a folder and in a terminal run the following commands:
    sudo make install

    If all went well you’ll see:

    $ make
    [CC] hide_attention_button.o
    $ sudo make install
    mkdir -p /`pkg-config --variable=prefix purple`/lib/purple-2
    install /`pkg-config --variable=prefix purple`/lib/purple-2

Restart pidgin and enable the plugin under Tools – Plugins – Hide Pidgin Attention Button.

Close but not Perfect

Although this plugin really does hide your Attention button, it still exists if you hover over where it used to be:

The button is much smaller but still clickable
The button is much smaller but still clickable

At least it’s much smaller now and less likely to be accidentally clicked!

Read More »

Posted (Updated ) in Javascript, PHP

Even though it hasn’t worked for quite some time now, my previous PHP WebSocket chat application has garnered quite a bit of attention and is still one of my most heavily trafficked posts. As a result I thought I’d provide you all with a working script as of Feb 15, 2012. Also, because I’m your typical lazy developer, I’ll be building on top of other peoples’ work – most notably PHPWebSocket.

You can download the final script here. According to the Wikipedia article on WebSockets, it should work in IE10+, Firefox 7+ and Chrome 14+. Personally I tested with Chrome 17.0.963.46 and Firefox 10.0.1.

I want to stress that this tutorial is designed to be extremely basic and as such does not give alot of functionality out of the box (but provides all the tools required to add more). It’s simply a working example of a PHP-based WebSocket server.

Read More »