Monthly Archive for June, 2007

Create a random thumbnail of a video file

Create a random thumbnail of a video file

Looking at sites like YouTube, you may think it’s quite hard to create a lot of different thumbnails from video files, and have them from random times within that file. But, no, it’s not! As this article shows, by using the very fabulous FFmpeg library, it’s actually a very short amount of code that’s required to create all those lovely random thumbnails.

Continue reading ‘Create a random thumbnail of a video file’

Slider - part 2 - using a mouse wheel

Following on from the previous post, I thought it’d be nice to have the handle move on a mouse wheel. Looking around for mouse wheel integration, it seems that it’s only a short amount of code to update Prototype to use the mouse wheel. When it’s not in the core code, I don’t know, as it seems rather handy. The mouse wheel code is listed at the Prototype Event Extension article over at Ajaxian.

Continue reading ‘Slider - part 2 - using a mouse wheel’

Scriptaculous slider trick

Yesterday I was looking at the Scriptaculous library, in particular the slider bar. I had used it once before with some success, using a graphic for the track and gripper. But that’s was boring! What I wanted was to see the bar fill up with colour when it was slide. Something like this:

Slider demo

I hadn’t seen anything like this around (not saying it hasn’t been done, just that I hadn’t seen it!), so after a bit of playing I found out it was actually very easy to create. And this is how I did it…

Continue reading ‘Scriptaculous slider trick’

Create a registration key

This simple function allows you to generate a random registration key in the format, '1224-54B1-7D35-5EF7'.

PHP:
  1. function registration_key()
  2. {
  3.     return strtoupper(substr(chunk_split(sprintf('%03d%s',
  4.                       rand(0,999), uniqid('')), 4, '-'), 0, -1));
  5. }

Validate a UK postcode

You've probably seen this before, if not a thousand times, but here's a simple function to check the format of a UK postcode.

PHP:
  1. function valid_uk_postcode($postcode)
  2. {
  3.     return (preg_match('/^([A-PR-UWYZ][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {0,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/i', $postcode)) ?
  4.         true : false;
  5. }