Code
Being a professional Web Designer I often find myself needing (what I think are) simple standalone functions and, not wanting to reinvent the wheel, I hit Google. However of course there are always a few that I have to either invent myself from scratch or seriously bodge from another code snippet.
So in order to give something back to the general community of developers I call on, here are some of my most useful functions.
Selecting a Random Set of Records With MySQL
Yeah I know, there are loads of suggestions for this sort of thing on the net but I spent ages searching around for the code and many of the solutions were seriously obfuscated. So here is a direct replacement for an 'order by rand() statement:
 
SELECT * FROM my_table ORDER BY RAND() LIMIT 10
 
Can be directly replaced with:
 
SELECT my_table.*, FLOOR(1 + RAND() * max_pseudo_table.max_id) AS random_index
FROM my_table, (SELECT MAX(id) - 1 as max_id FROM my_table) max_pseudo_table
ORDER BY random_index LIMIT 30
 
And with the right indices you will save a world of processor effort :)
Using Mod Rewrite to Make Pretty URLs the Safe Way
I know many many sites out there have tutorials on Mod Rewrite but I had to piece this together from a number of them and it seemed like a fairly common thing to want to do. If you're using the classic controller/action/id schema for your site and want to prettify your links so that the values can be simply broken by slashes but you also want relative paths to any subfolders (for images, CSS etc) to work and you don't want your subdomains to break then try this code in a .htaccess file in your web root. Of course you may need to change the naming of your root file and arguments.
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f                        [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d                        [NC] 
RewriteRule .* -                                          [L]

RewriteRule ^([^/]+)/?$ index.php?controller=                                    [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?controller=&action=                  [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/?$ index.php?controller=&action=&id=   [QSA,L]
PHP - Recursively Including Classes
Recurses down a directory tree and includes all the files it finds.
function autoload($dir) {
	if($handle = opendir($dir)) {
		$dirs = array();
	
		while (false !== ($file = readdir($handle))) {
			if($file{0} != ".") {
				if(!is_dir($dir.'/'.$file)) require_once $dir.'/'.$file;
				else array_push($dirs, $dir.'/'.$file);
			}
		}
	
		closedir($handle);
	
		while(count($dirs) > 0)
		{
			$this->autoload(array_pop($dirs));
		}
	}
}
Java - Create MD5 Hash on a File
Pass it a filename and it'll pass you back the Hash. Simple as that!
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public String getMD5Hash(String fileName) {
	String hash = "";

	try {
		File file = new File(fileName);
		FileReader fileRead = new FileReader(file);
		MessageDigest md = MessageDigest.getInstance("MD5");

		char[] chars = new char[1024];
		int charsRead = 0;
	
		do {
			charsRead = fileRead.read(chars, 0, chars.length);

			if(charsRead >= 0) {
				md.update(new String(chars, 0, charsRead).getBytes());
			}
		}
		while(charsRead >= 0);

		hash = new BigInteger(1, md.digest()).toString(16);
	}
	catch (NoSuchAlgorithmException e){}
	catch (IOException e){}
		
	return hash;
}
Java - Parse a Configuration File
Read a config file, parse it and add key/value pairs to a hashmap
import java.io.*;
import java.util.HashMap;

/**
* @param configFile the location of the configuration file
* @return the produced HashMap
*/
public HashMap<String, String> irisReport(String configFile) {
	HashMap<String, String> config = new HashMap<String, String>;

	try {
		BufferedReader bufRead = new BufferedReader(new FileReader(configFile));

		while(bufRead.ready()) {
			String line = bufRead.readLine();

			if(!line.startsWith("#") && line.indexOf("=") != -1) {
				//Trim out whitespace, explode at equals and put 

key/value pairs into the config HashMap
				int splitPos = line.indexOf("=");
				String key = line.substring(0, splitPos).trim();
				String value = line.substring(splitPos+1,

line.length()).trim();

				if(!key.equals("") && !value.equals("")) {
					config.put(key, value);
				}
			}
		}

		bufRead.close();
	}
	catch (FileNotFoundException e) {
		System.out.println(e.getMessage());
	}
	catch (IOException e) {
		System.out.println(e.getMessage());
	}

	return config;
}
Java - Store System Properties
Store the system properties in an XML file
import java.io.*;

/**
* @param fileName the file to save the properties in
*/
public void storeSystemProperties(String fileName) {
	try {
		Properties prop = System.getProperties();
	
		FileOutputStream fileOut = new FileOutputStream(new File(fileName));
		
		prop.storeToXML(fileOut, "Properties");
		fileOut.flush();
		fileOut.close();
	}
	catch(FileNotFoundException e) {
		System.out.println(e.getMessage());
	}
	catch(IOException e) {
		System.out.println(e.getMessage());
	}
}