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 »

Posted (Updated ) in Linux

Tonight I discovered I had an entire folder of dual audio MKV files with the wrong default language and wrong default subtitle track. I could have used mkvpropedit to manually change each file but that’s such a hassle. Instead, here’s a handy one-liner to do them all at once:

find . -name "*.mkv" -exec mkvpropedit {} --edit track:a1 --set flag-default=0 --edit track:a2 --set flag-default=1 --edit track:s1 --set flag-default=0 --edit track:s2 --set flag-default=1 \;



At first glance they may look a bit complicated, but let’s break it down a bit:

Find all .mkv files and execute an operation on them:

find . -name "*.mkv" -exec ... \;

Do an mkvpropedit on the current matched file:

mkvpropedit {}

Set the first audio track to not be default, the second audio track to be default, and do the same with the subtitle tracks:

--edit track:a1 --set flag-default=0
--edit track:a2 --set flag-default=1
--edit track:s1 --set flag-default=0
--edit track:s2 --set flag-default=1


You’ll need mkvtoolnix installed for the mkvpropedit command. To determine what the various tracks contain, do a

mkvinfo /path/to/file.mkv

or mkvinfo -g for you GUI users 🙂 This can be a bit tricky to read though so I tend to just open the file in VLC and look at the audio and video tracks that way.

As an added bonus, here’s the Windows equivalent of the above script:

@echo off
FOR /f "tokens=*" %%G IN ('dir /a-d /b') DO (
	mkvpropedit.exe "%%G" --edit track:2 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:3 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:4 --set flag-default=1
	mkvpropedit.exe "%%G" --edit track:5 --set flag-default=0

I’ve been told the Windows version works but haven’t tested personally.

Happy viewing!

Read More »

Posted (Updated ) in PHP

Last night I was getting a strange error in LemonStand administration area when attempting to edit a product or category:

Fatal error: Maximum function nesting level of ‘100’ reached, aborting! in /path/to/phproad/modules/phpr/helpers/phpr_inflector.php on line 322

If you’re also experiencing this error, it’s caused by XDebug and can be solved by adding

ini_set('xdebug.max_nesting_level', 200);

to your config/config.php file.

Thanks to Aleksey Bobkov and EHLOVader for their help in solving this issue. Here is the official LemonStand forum thread on the issue.

Read More »

Posted (Updated ) in Database, Linux, PHP

Tonight I had to move my WPMU install from my local development machine to the live server – this meant a change in installation path which is always a hassle with WordPress. Below I’ll detail my issues and the corresponding fixes in the hopes it will make life easier for others experiencing the same problems.

Redirection to wp-signup.php

First thing I noticed was that when loading the site on a live domain, I’d get instantly redirected to With a bit of Googling I came across this forum thread which recommended adding the following to my wp-config.php:

define( 'NOBLOGREDIRECT', '' );
define( 'SUBDOMAIN_INSTALL', false );

Don’t do this! It will get the site closer to working order but it’s not going to help you in the long run – especially when you need the other domains working too. Instead here’s what you should be doing:

#Dump your DB
mysqldump - u<username> -p<password> -h<host> <dbname> > test.sql
#Update folder path to that of the new servers
sed -i "s/path\/to\/install/new\/path\/to\/install/g" test.sql 
#If you installed into localhost/foo/bar/mysite, change that to your live servers domain
sed -i "s/url\/path\/to\/site/www\.domain\.com/g" test.sql

This is pretty standard behavior for moving WordPress sites, however if you load the above dump up on your live domain you’ll probably be greeted with the dreaded Error establishing a database connection.

Error establishing a database connection

Heading to will shed a little more light on the situation – you need to update your wp_blogs table for the main site. WPMU is currently using your development servers URL from this table and ignoring what’s in wp-config.php. To play things safe we’ll update any occurrances of our test servers domain in test.sql:

#Update your live servers subdomain in wp_blogs to your live servers domain
sed -i  "s/yoursite\.localhost\.com/www\.yourdomain\.com/g" test.sql

This should do the trick. Load that bad boy into your live server and you should be good to go!

Read More »

Posted (Updated ) in Linux

For users not running Bumblebee or Ironhide, you’ve probably noticed alot of heat, low battery life and a roaring fan even when idle. This is almost entirely due to the nVidia graphics card. If you’re like me and don’t need that card at all, you have the option of disabling it entirely. To do so you’ll need to install acpi_call as a kernel module and use it to shut the GPU down.

Read on for a tutorial on how. I’ve also included some bonus Intel GPU tweaks!

Read More »

Posted in Database

MySQL’s built in FROM_UNIXTIME() function only handles positive numbers however we can still convert negative integers to dates using its handy DATE_ADD() function like so:


which gives:

1969-07-30 10:00:01

Note that this also works with positive numbers, so if your database contains a mixture of both it’s still safe to use.

Credit to user fat_kid for his tutorial here.

Read More »

Page 8 of 16« First...678910...Last »