Category Archives: Tech

Away with Applications: The Death of Desktop

There is a great talk that went up on Google Videos earlier this month called Away with Applications: The Death of Deskop. In it the speaker, Aza Raskin points out that no work is carried out actually using the computers desktop. He also points out the failing of desktop applications, that you frequently need to [...]

It’s internet with a small ‘i’ now

When I was doing my Computer Science degree our lectures used to make a big deal about making sure you spell Internet with a capital ‘I’, because it’s important and it’s the name of a thing. Apparently it’s now been decided that it should be spelt with a lowercase ‘i’, I wish bloody linguists would [...]

PHP: Swap Variables One Liner

Here's a nifty one liner in PHP which let's you swap 2 variables values.
PLAIN TEXT
PHP:

list($a,$b) = array($b,$a);

Much like the PHP XOR swap there's no real reason this is any better than using a temporary variable, but you might be able to impress chicks with it or something.
/* Pete Graham */

Drupal: Hide Navigation on Forum

If you want to hide certain Navigational Blocks on your Drupal sites forum(s) here’s how to do it:
1. Go to "Administer » Blocks"
2. Click "configure" on the block you want to hide.
3. On Page specific Visibility Settings click the option for "Show if the following PHP code returns TRUE"
4. Enter the following code in the [...]

JS: Unobtrusive Select All Checkboxes

I wrote last week about how I’m trying to improve my JavaScript skills. As a small exercise I have written this function for unobtrusively selecting/deselecting checkboxes in a form.
PLAIN TEXT
JAVASCRIPT:

function selectAll(box)

{

// get the elements name

var id = box.id;

var name = /^([a-z]+)(_select_all)$/i.exec(id);

 

name = name[1];

 

re = new RegExp('^'+name+'_[0-9]+$');

 

// get the elements stauts

var state = box.checked;

 

// get the [...]

SQL: Selecting Specifying Multiple Field Values

Here are 3 different ways to perform a DB select when you want to specify two or more values for a field.
1. Use th OR operator
PLAIN TEXT
SQL:

SELECT * FROM people

WHERE (first_name = 'pete'

OR first_name = 'paul');

2. Use a Regular Expression
PLAIN TEXT
SQL:

SELECT * FROM people

WHERE first_name ~'^pete|paul$';

3. Use an array
PLAIN TEXT
SQL:

SELECT * FROM people

WHERE [...]

PHP: Remove Values from Array

If you need to remove elements from an array that have a particular value(s) here’s a neat way of doing it without any looping:
PLAIN TEXT
PHP:

// our initial array

$arr = Array("blue", "green", "red", "yellow", "green", "orange", "yellow", "indigo", "red");

print_r($arr);

 

// remove the elements who's values are yellow or red

$arr = array_diff($arr, array("yellow", "red"));

print_r($arr);

 

// optionally you could reindex [...]

Bill Gates Urban Myth

There’s an Urban Myth that Bill Gates is so rich that if he was to drop a $1000 bill on the ground, it's just not worth his time to bend over and pick it up. Now it is true that he wouldn’t pick it up, however the real reason for this is he was wedgied [...]

My volatile relationship with Javascript

I started work in web development in 2004 at this point in time JavaScript was hugely unpopular in terms of web trends, this is probably because it was mostly used for annoying pop-ups, animations and whole list of other horrendous Internet crimes. I can recall having a King Herod style culling of all JavaScript from [...]

My Favourite Electrical Connections

People seem to love my lists. Here is one of my favourite electrical connections:

Scart Socket
USB Port
3.5mm Stereo jack
Double phono
2.5mm Stereo jack
Parallel port
Ethernet
PS/2

/* Pete Graham */