MichaelOldroyd.co.uk

A basic date_diff for PHP 5.2

I came across a problem having developed a site with a PHP 5.3 environment, when moving the site to the live environment the server was running PHP 5.2. Whilst the server gets upgraded I looked into getting the code to work in some form in the meantime. The main issues are the functions lcfirst() and date_diff(). The former is a simple fix, a function which lower-cases the first letter of a string — I was surprised this was only introduced in 5.3!

Filed under Development, Snippets

File validation with jQuery and HTML5

I have been dealing with file uploads a lot recently, and I stumbled upon a few different methods for validating files which provide both basic file-type checking and file size checking before uploading.

The web app was already making use of jQuery with the excellent jQuery validation plugin; so I wrote a couple of extended validators.

Filed under Development, Snippets, Web

Filter a category from your WordPress Blog

I’m pretty new to working with the internals of WordPress. It seems very easy to settle for installing hundreds of plug-ins to achieve the simplest of tasks. Plug-ins are awkward for me, as they have the tendancy to not quite do what I want them to. I end up messing with them in some way which breaks updates.

Filed under Development, Snippets

Override core widget output in WordPress

Another snippet for the WordPress theme developers out there. I decided that the category widget didn’t display the post count in a very nice-looking way. So I found a nice support post that demonstrates the user of add_filter() to alter output of the category widget. Not the most ideal way to do things in my opinion, but it does the job.

add_filter('wp_list_categories', 'cat_count_span_inline');
function cat_count_span_inline($output) {
	$output = str_replace(' (','',$output);
	$output = str_replace(')','',$output);
	return $output;
}

Via wordpress.org

Filed under Snippets

Templated 410 Error Pages in WordPress

The 4xx class of status code is intended for cases in which the client seems to have erred. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents should display any included entity to the user. These are typically the most common error codes encountered while online.

via Wikipedia

Filed under Development, Snippets, Web

Record and Wipe CDRW discs via CLI

I find that the GUI tools in Ubuntu are buggy with some disks and drives that I use. The two lines that pretty much make “Brasero” redundant:

Record ISO to Disc

cdrecord -v dev=/dev/cdwriter isofile.iso

Blank a CDRW

sudo cdrecord blank=all -immed dev=/dev/cdrw
Filed under Snippets