Posted (Updated ) in PHP

This morning I was loading WPMU in a custom script and all get_option() lookups were returning the details for the main blog despite being in a switch_to_blog() block. After a bit of debugging it turns out this was due to get_option() caching its values from the main blog and never expiring its cache when switching. There’s a pretty easy action you can use to fix this:

ini_set('display_errors', true);
function find_wordpress_base_path() {
	$dir = dirname(__FILE__);
	do {
		//it is possible to check for other files here
		if( file_exists($dir."/wp-config.php") ) {
			return $dir;
	} while( $dir = realpath("$dir/..") );
	return null;
define( 'BASE_PATH', find_wordpress_base_path()."/" );
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require(BASE_PATH . 'wp-load.php');

Below is a script in its entirety for loading WPMU, switching to blog 31 and grabbing its name:

function switch_to_blog_cache_clear( $blog_id, $prev_blog_id = 0 ) {
    if ( $blog_id === $prev_blog_id )
	wp_cache_delete( 'notoptions', 'options' );
	wp_cache_delete( 'alloptions', 'options' );
add_action( 'switch_blog', 'switch_to_blog_cache_clear', 10, 2 );

Read More »

Posted (Updated ) in Linux

The below is a collaboration of useful information I’ve found while attempting to build and maintain a RAID5 array consisting of 4 HDDs. This tutorial is a work in progress and I’m learning everything as I go. I’ve left relevant links in each section for more information and if you spot anything that could be done better or that I’m missing let me know in the comments below!

Read More »

Posted in Uncategorized

SublimeCodeIntel is perhaps the most useful and heavily installed package for Sublime Text but it’s also very difficult to get working. The most common issue people run into is the dreaded endless

Info: processing `PHP’: Please wait…

This can be fixed by navigating to the SublimeCodeIntel package directory and running For to compile we first need to install two things: pcre and XCode Command Line Tools. Annoyingly this is around 1.6GB of files!


Installing XCode Command Line Tools

Head over here and click View in Mac App Store. Hit install and watch your progress in the Purchases tab.

Once installed open it up and go to XCode – Preferences – Downloads – Components and install Command Line Tools.


Installing pcre

This little script is required by the scintilla package of SublimeCodeIntel. First install MacPorts then run:

sudo port install autoconf
sudo port install pcre
sudo cp /opt/local/include/pcre.h /usr/include/

You’re done! Navigate to the SublimeCodeIntel package directory and run sh src/ If all goes well at the end of compilation you’ll see a done! message. Restart Sublime Text and you’re good to go.

Read More »

Posted (Updated ) in Linux

So I don’t forget, here’s a tutorial on installing the RocketRaid 2760a drivers and management utilities on Ubuntu 12.10. I’m using 64-bit but 32-bit should be the same – just substitute where appropriate.

Installing the Driver

The installation disc comes with an out of date version of the driver and kernel module. The way the installation works, we need to download and compile the kernel module then download the driver installer, drop the module into place and run the installer. Make sure you have appropriate compiler tools installed – to be safe just run

sudo apt-get install ubuntu-dev-tools

Download and extract the ones with kernel 3.x support from the HighPoint website:

mkdir ~/driver
cd ~/driver
# driver
tar -xvzf rr276x-ubuntu-11.10-x86_64-v1.1.12.0502.tgz
# kernel module
mkdir module
cd module
tar -xvzf  RR276x-Linux-Src-v1.1-120424-1734.tar.gz

Build and compress the kernel module for our driver installer:

cd rr276x-linux-src-v1.1/product/rr276x/linux/
# Ignore the warning about not being able to find him_rr2760x.o...doesn't seem to matter
gzip rr276x.ko
mv rr276x.ko.gz ~/driver/boot/rr276x$(uname -r)$(uname -m).ko.gz

And finally install the driver

cd ~/driver
sudo bash

This step succeeded! Now you can press ALT+F1 to switch back to the installation screen!

sudo bash

Update initrd file /boot/initrd.img-3.5.0-17-generic for 3.5.0-17-generic
Please reboot the system to use the new driver module.

sudo shutdown -r now

That should be everything! You can now test with

cat /proc/scsi/rr276x/*


Installing the RAID Management Software

Annoyingly the RAID management console is difficult to install to say the least. The GUI deb packages error when trying to install and HighPoint don’t even provide a deb for the command line version and to top it off the version of the command line utility on the driver CD is newer than the version on their site! For this reason I’ve provided the newer command line RPMs here.

Let’s get this thing installed.

Web version:

mkdir ~/driver/utility
mkdir ~/driver/utility/console
mkdir ~/driver/utility/web
cd ~/driver/utility/web
echo "rr276x" | sudo tee -a /etc/hptcfg > /dev/null
tar -xzvf WebGUI-Linux-v2.1-120419.tgz
sudo apt-get -y install alien
sudo alien -d hptsvr-https-2.1-12.0419.$(uname -m).rpm
sudo dpkg -i hptsvr-https_2.1-13.0419_amd64.deb


Command Line version:

cd ~/driver/utility/console
sudo alien -d hptraidconf-3.5-1.$(uname -m).rpm
sudo alien -d hptsvr-3.13-7.$(uname -m).rpm
sudo dpkg -i hptraidconf_3.5-2_amd64.deb

Run the web server:

sudo hptsvr

You should now be able to connect to it from your browser by navigating to http://localhost:7402 with username RAID and password hpt.


Further Reading

HOWTO: Get GUI hptsvr & hptraid 3.13 working on Ubuntu
HighPoint driver download page for RocketRaid 2760a

Read More »

Posted in Linux

The below is a quick guide to creating partitions on a newly purchased, unformatted disk. For this guide I’ll be formatting a new WD 2TB Black.


Find the disk you want to partition

# lsblk

sda 8:0 0 55.9G 0 disk
├─sda1 8:1 0 53.6G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 2.3G 0 part [SWAP]
sdb 8:16 0 1.8T 0 disk
sdc 8:32 0 1.8T 0 disk

Partitions appear as subitems. Notice sdb and sdc have no partitions – those are the disks I want to format.


Create the partition

# sudo fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd3e43840.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help):

Below I’m using the default values to create one large partition for the whole disk.


Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended

Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-3907029167, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167):
Using default value 3907029167

Command (m for help):

All done? Write!


The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

That’s all for partitioning! Take a gander at your fancy new partitions:

# lsblk

sda 8:0 0 55.9G 0 disk
├─sda1 8:1 0 53.6G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 2.3G 0 part [SWAP]
sdb 8:16 0 1.8T 0 disk
└─sdb1 8:17 0 1.8T 0 part
sdc 8:32 0 1.8T 0 disk
└─sdc1 8:33 0 1.8T 0 part


Format to NTFS

I’m choosing a quick format. You may choose instead to remove the -f argument for a proper one instead.

# sudo mkntfs -f /dev/sdb1

Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.


Optional: Name the drives

Because I’m running NTFS I can give the drives labels. Make sure you have ntfsprogs installed then enter:

# sudo ntfslabel -f /dev/sdb1 YourLabel


More Information

For more information on partitioning check out Chris Wakefield’s post here.
For a short and sweet howto on  formatting as NTFS check here.
Information on NTFS labels here.

Read More »

Posted (Updated ) in Uncategorized
Removed 'Clear Scrollback' shortcut

Removed ‘Clear Scrollback’ shortcut

This would have to be far and away the most annoying ‘feature’ of Pidgin.

In just about every web browser, Ctrl+L is used to highlight the URL bar allowing easy navigation via the keyboard. In pidgin it’s used to clear the scrollback of the active window. As a web developer I’m always hitting Ctrl+L in the browser however every now and then I won’t take notice to which window is active on my desktop at the time and use it while Pidgin is active, clearing out the conversation I’m having with my contact at the time. Frustrating!

There was a bug post here about it but as usual the devs don’t particularly care and instead just pointed to their FAQ page. For convenience here’s how you remove the shortcut:

Open ~/.purple/accels and change

; (gtk_accel_path "<PurpleMain>/Tools/Preferences" "<Primary>p")


(gtk_accel_path "<main>/Conversation/Clear Scrollback" "")

Remember to remove the semicolon at the start of the line!


Read More »

Posted (Updated ) in Uncategorized

One week from this post I will be publishing an update for my Banner Slideshows module for LemonStand which upgrades it to use the newly released Nivoslider 3. This will provide a few nice benefits however the implementation isn’t completely backwards compatible so your frontend code may need updating. Details inside.

What do I need to do?

Simply press the Update slideshow button on your slideshow page in the Administration:

Hit the update button indicated above

Hit the update button indicated above

Then remove your existing slideshow code on your sites frontend and follow the instructions on the marketplace page (to be updated when the module update is released) to add the new version.

How does this benefit me?

The biggest benefit is its new responsive design which resizes with your browser – making it easier to build sites that scale from a desktop monitor all the way down to a mobile phone. I’ve whipped up a live demo to see this feature in action. Open it up and resize your browser window. Notice the slideshow resizes with the window.

Also new in this version of the module is full HTML support for slide descriptions:

HTML support for slide descriptions

HTML support for slide descriptions

Read More »

Posted (Updated ) in Uncategorized

Creating custom widgets with the Widgets module for Lemonstand is a quick and painless process. Below, I’ll describe how to build a widget for Lemonstands Contact module. I’ll call this module Simple Contact Widget.

Download the completed module from my GitHub repo.

While this tutorial will go over everything you need to do to build a complete and working module, it would be very beneficial to also know the basics of module development, naming conventions and so on. Take a look at the documentation Developing LemonStand Modules if you haven’t already done so.

Read More »

Posted in Database, PHP

Here’s a very quick set of SQL snippets for updating a WPMU domain. This might be useful when building a site on a development domain before moving to a production one later on.

Firstly update the wp_blogs table:

UPDATE wp_blogs SET domain='';

There will be a bunch of wp_options and wp_posts tables – one per site. Find all the tables:

SHOW TABLES LIKE "%_options";

and for each table, perform the following query:

#_options tables
UPDATE <tablename> SET option_value=REPLACE(option_value, '', '');
#_posts tables
UPDATE <tablename> SET post_content=REPLACE(post_content, '', '');

This was enough to get the sites working for me. Additional tweaks are probably required afterwards – if you find anything let me know in the comments below.

Read More »