Software Blogs

Drupal 6: Programmatically Remove Required Field Property from Form
Last edited on: 19/11/2011 - 13:06

Suppose you are coding a form in Drupal 6 and you have a mandatory (required) field. However, this required field is only mandatory dependent upon the value in another field. This can happen quite often, and I encountered it at a client site the other day. We had a postcode field that was mandatory only if the country in a selection box was set to 'United Kingdom'. Any other country meant that the postcode field was not required.

»   Read more
Drupal 6: Programmatically Create Panels and Nodes in Panels
Last edited on: 28/07/2011 - 14:26

This tutorial provides the wherewithal to create a new node and insert that node in the top pane on a programmatically created Panel. Looking around the net I was surprised that nobody has done this before. The context for my requirements comes from a not-for-profit client of mine - they wanted to be able to create a new type of charitable donation dependent upon a campaign's remit (this would be the node) and then to place that campaign information (node) in the top pane of the panel.

»   Read more
Listing Octal Numerical File Permissions in Linux
Last edited on: 29/04/2011 - 11:05

The other day I needed the output of a directory on Linux showing the octal file permissions. It got me thinking - exactly how do I achieve this? The obvious solution would be the ls command, but a quick read of its man page suggested it couldn't be achieved that way.

In fact, the answer is with the stat command. The following syntax is required:

stat -c "%a %n" *

The -c flag says use the following format, whilst the format itself is:
%a Access rights in octal
%n File name.

So, a typical example would be:

»   Read more
Drupal 6 Checkboxes and default_value
Last edited on: 29/04/2011 - 09:57

The Drupal Forms API comes with some powerful features, including checkboxes which allows a bunch of checkbox options to be grouped together. Included in this functionality is the ability to set default values, i.e. set your chosen boxes to be on.

However, it is not immediately obvious how to programmatically set the default values using the '#default_value' key. The key expects an array, so I tried the usual contenders such as an array of 0s, 1s, 'on', FALSE, TRUE etc etc and just couldn't get it to work correctly.

»   Read more
Linux openSUSE 11.4 Installation on Dell Latitude D430
Last edited on: 24/04/2011 - 11:48

Before you start you will need a copy of the openSUSE 11.4 distribution; don't forget to verify the download if you have downloaded it - even broadband can scramble a few bits in 700MB. I chose the easy option - I happened to see that openSUSE 11.4 was bundled in the free cover disk in the May 2011 edition of Linux Format magazine (UK publication from Future Publishing), and it had one or two interesting articles to read too - hopefully the in-depth review of mythTV will inspire me to build a Linux-based home theater.

»   Read more
Drupal 6 White Screen of Death on Top Level Landing Page
Last edited on: 06/02/2011 - 14:04

I have a number of Drupal sites on the Internet; more than I can possibly check on a daily basis, what with work commitments and all. I pointed my web browser at one of the more infrequently visited sites the other day and was confronted with the White Screen of Death. Disaster! What on Earth can cause that? And how long had the site been down? A quick check of the log gave no evidence of anything amiss, and the integrity of the database looked ok with a cursory glance.

»   Read more
Linux Shell Script to cksum and Compare Local and iPod Disks
Last edited on: 02/01/2011 - 20:09

After being bedeviled with disk problems on my FAT formatted 5th Generation Video iPod I put together a script to checksum (cksum) the drive and compare against the checksum of the music files on my local laptop. In reality, the this script can be used to check any two drives and it is not mandatory one of them needs to be an iPod drive. All the other examples of this sort of script on the Internet I found had one basic problem - they all only checked one directory, whilst I had a tree structure under my ~/Music directory.

»   Read more
Disable Annoying System Beep on OpenSUSE 11.3
Last edited on: 28/11/2010 - 10:17

If you have ever been annoyed or embarrassed by the extremely loud system beep in OpenSUSE then you've probably trawled the Internet for a way of disabling it. There are many solutions out there, most don't seem to work. After a little trial and error I finally have the definitive solution. You need the xset command with the -b flag. So:

badzilla@laptop4:/> xset -b

»   Read more
PHP Algorithm to Evenly Distribute Items into 3 Columns
Last edited on: 09/11/2010 - 16:27

This is the second time in my PHP career I've needed this so thought I'd commit it to a blog for easy access next time and save myself some brain MIPS. I want to evenly distribute items into three piles, making sure that no pile can have more than 1 extra item, and should a pile need 1 more than the other piles, then the item should go to the left-most first. This is better explained by way of a diagram. My pile of items is shown as letters of the alphabet.


»   Read more
PHP Convert Decimal UK Currency To Pounds Shillings Pence
Last edited on: 02/11/2010 - 10:49

I came across an unusual problem the other day. Whilst developing a PHP book / magazine cataloguing system I wanted to output the cover prices of the items that were pre-decimalisation (1971) in the old UK pounds / shillings / pence format.

For a reminder, particularly for those born later than the mid sixties who will have no recollection of the olden days, the British currency had 12 pennies (d) to the shilling [s] and there were 20 shillings to the pound (£). That makes a total of 240 pennies in a pound.

»   Read more
Syndicate content