World Cup 2010 countdown

Technical Info 3 Comments »

I have just made a little World Cup 2010 countdown widget for one of my sites, and though I would share it in case anyone would like to use it. The thermometer goals chart I made a while back gets lots of use, so hopefully this will be useful for someone.

World Cup 2010 countdown

If you want to use this image on your site, simply add it to your page as follows:

<img src=”http://www.thinksynergy.co.uk/scripts/worldcupcountdown.jpg” alt=”World Cup Countdown”/>

Note: If you cut/paste the above, please make sure the “” are pasted correctly, and dont end up curly quotes!

Converting a PHP string number into a numeric value

Technical Info 4 Comments »

Despite seeming like a very basic procedure, this evening I found I had wasted half an hour, split between Googling for the answer and trying to work it out for myself.

I have a number that needs to be stored in a string format in PHP. However, I need to use this value at some point to run a calculation, for which I need the true value as opposed to the string. If I had just wanted a whole number the answer is very simple, use the PHP (int) method to convert it.

It is not that easy when you are working with decimals. Unless I am missing something (in which case feel free to embarass me in the comments below!) there is no easy way to do this. Here is what I came up with:

$string = "3.142";        // The source number, as a string
$a = explode(".",$string);            // Split the string, using the decimal point as separator
$int = $a[0];                        // The section before the decimal point
$dec = $a[1];                        // The section after the decimal point
$lengthofnum=strlen($dec);            // Get the num of characters after the decimal point
$divider="1";                        // This sets the divider at 1
$i=0;
while($i < ($lengthofnum)) {
$divider.="0";                    // Adds a zero to the divider for every char after the decimal point
$i++;
}
$divider=(int)$divider;                // Converts the divider (currently a string) to an integer
$total=$int+($dec/$divider);        // compiles the total back as a numeric value

If anyone knows of a quicker / cleaner / better / more funky way of doing this simple task please do let me know… if not then I hope this little snippet at least lets you avoid losing the half our of your life that I lost this evening!

UPDATE: Thanks to Xobman, who Twittered me this little gem:

Try $foo = “3.123″; $bar = (float) $foo;

LOL… low and behold, it works! That’ll teach me to post my (oh so clever!) code on the Interweb for all to see :D

Thanks Xobman!

Forum vs Wordpress

General Interest, Technical Info 7 Comments »

Please bear with me on this one, I know they are very different beasts but I have been experimenting with a new concept (to me) over the weekend and would like to invite comments.

I have a site I have been running for a while which I would like to turn from a blog where comments are invited to a community. As much as I like forums in certain circumstances they can be a little bland when compared to a blog. This made me wonder what the potential is to combine the two.

A site I use on a daily basis is hotukdeals.com. This site uses a highly customised vBulletin installation to present the information in a blog-esque format. It works well, people can vote items hot and cold, but they have to register to comment.

Looking into it in a bit more detail it seems there are positives and negatives to using a forum vs using Wordpress.

As much as people love Wordpress (I do!), it seems to me to be a platform designed to publish information and then get comments on it. If you want a community then everyone needs the ability to publish. This is possible with Wordpress but it’s a bit messy and still involved the back end. With a forum people can hit new post and post within the site itself.

The disadvantage of the forum is users generally have to register in order to comment. You can turn this off but forums don’t cope with this quite as well as Wordpress does. This may deter the passing comment and rely on people buying in to the site.

My theory is to run a forum on the site but use the RSS feed to link the information to the front page, run by Wordpress, replacing the usual blog posts. This way I have Wordpress running the page areas of the site but the front page content is dragged in via an RSS widget. I don’t yet know how well this will work or whether a forum portal would be a better solution, but I guess I will find out once I have it up and running.

So…

Am I being crazy?

Are there benefits I am missing to using one over the other?

Does using both make sense?

This all came to me on a whim, so I apologise for the lack of in-depth research, I just thought at this point it may be a good idea to poll the readership.

How wide should your site be?

General Interest, Technical Info 6 Comments »

This is an age old debate, trying to strike a balance of usability between the users with older setups and smaller screen resolutions and those with modern wide-screen (or just plain hi-res) displays.

I have followed this debate for many years and the argument seems to always cater for “what the site looks like full-screen”. I don’t know how you work, but personally I have lots of things happening on my desktop and many windows open. I cannot remember the last time I opened a browser window full-screen.

That said, if I was running in 1024 x 768 resolution then maybe I would work differently, I don’t know because I have not used that resolution in 10 years.

The thing I love about hi-res displays is they allow me to have a browser windop open, still see parts of my desktop, have email visible (albeit not the whole window), but running full-screen just feels claustrophobic to me.

That said, I am less bothered about the upper end of the scale, they don’t HAVE to run full-screen, and providing the site isn’t too narrow then I’m sure they will manage.

This leads us to the question of “how narrow do we have to go?”. I am seeing more and more sites with quite large widths. A few years back 750px used to be the norm, then 850px. Nowadays a lot of sites are over 1000px wide. Is this too wide?

There is no answer to this, hence it has been an ongoing debate for years. How wide is too wide?

The other question to bear in mind is whether the content on the right makes a difference to how wide you are willing to go. If everything to the right of the 850px mark is adverts for example, does that mean that the fact that the users on lower resolutions (the minority) can see the navigation and the main body content make it an acceptable width?

My gut feeling was crossing the 1000px mark was a little bit much, but with a little bit of investigation I have found that some of the most widely used blog templates actually cross this boundary.

Has the width-creep occurred while I have been asleep?

In my mind these themes look fine. I even opened them on my secondary monitor (1280×1024) and it looks fine. I can’t say I would want it to be any wider, but still it looks fine to me.

What do you think? How wide is too wide?

Displaying a random image using PHP

Technical Info 5 Comments »

Lyndi posted about displaying an image at random the other day. Her solution was to use javascript as it enabled the page to do this even if the server had caching on. It was a good solution, but it got me thinking about going in a slightly different direction…

The solution relied on the image names being hard coded into the script. I thought it would be quite cool to come up with a solution that simply looked in a directory for all the JPG’s or GIF’s, and plucked one at random.

This is what I came up with:

<?php
$dir = “images”; // The directory where your images are
$filetypes = (“jpg”||”gif”); // Whatever images are valid. You could add “png” etc

srand((double)microtime()*123456789); // Generates a random number seed
$count = 0; // Initialises the counter

$dirOpen = opendir($dir); // Opens the image directory

while(($im = readdir($dirOpen)))
{
if($im != “..” && $im != “.” && substr($im,-3)==$filetypes) // Disregards “..” and “.” (direcrory structure)
{
$image[$count] = $im; // Reads an image
$count++; // Increments the counter
}
}

closedir($dirOpen); // Closes the directory

$randname = rand(0,(count($image)-1)); // Generates the random number
echo ‘<img src=”‘.$dir.’/’.$image[$randname].’” alt=”Random Image” />’; // Publishes the image

?>

I have commented the code, so it should be fairly self-explanatory how it works.

It is a bit rough and ready, but it does the job. To implement this on a website, simply use:

<? include(‘randimg.php’)?>

The beauty of this solution is you can add as many images as you like to the images (or whatever you call it) folder. Add and remove them at will and the script just picks from the images that are there at the time.

Let me know what you think.

Backup strategy revisited

General Interest, Technical Info 9 Comments »

I am taking my Macbook Pro in for repair today, so I spent most of last night backing up all the data (critical and non-critical) in case the system needs restoring or it has to be away for a while. It made me re-evaluate my backup strategy a bit.

I do the majority of my work on my Macbook pro (120Gb) on my home wireless network. I also have a Linux machine as a backup solution. This backs up to an external 250Gb hard drive overnight, using rsync (so as to only backup the changed files).

This solution is not great, and it is a bit cumbersome. I plan to replace this with a solution that will involve RAID-1 (two hard drives mirrored. If one fails nothing is lost).

There are a few ways to do this:

  • I could add RAID 1 to the Linux machine. This is a little difficult as it is a tiny machine that sits underneith the TV and there is really not the room for a second hard drive.
  • I could replace the external hard drive with a USB enclosure that uses RAID 1. This is not too expensive, but adds a second device which also needs space and power.
  • I could invest in a NAS box, such as a Synology, QSNAP or Thecus.

BUT, it’s not that simple…

As I do most of my work on the Macbook the first and formost important thing for me is to backup that data, live data that I am working on at the time.

As I work on a wireless network I dont want to transfer 120Gb every time I backup. This leaves be two options:

  • I could use a backup program that detects changes
  • I could use OSX’s built in Time Machine

Time Machine takes hourly backups of the current dat, along with weekly and monthly backups as space allows. The problem is it only works (properly) using Apple Airport hardware. There are hacks around for getting it working on a normal NAS, but there are pitfalls as well.

I have experimented with rsync options and even those seem to interfere with the operation of the macbook while I am working. Time Machine (from what I see) is fairly seamless.

So…

That leaves one option, the Apple Airport Extreme.

Although it does not (as standard) use RAID the data is actually in two places anyway, the Macbook and the backup drive. This is a perfect solution for the Macbook backup, but what about archives?

Archives work a little differently. Data is passed from the Macbook to the Airport-attached hard drive. Once it is there it gets deleted from the Macbook.

This means that is the hard drive fails the data is lost… back to RAID!

After consideration I feel my best solution is to use the Apple Airport Extrme with a hardware RAID external hard drive. This means that the macbook live data is actually on 3 hard drives, and the archive data is on 2.

What do you guys use for your backup solution and archive data?

Forum modifications – worth it?

Technical Info 3 Comments »

A week ago I got an email letting me know the forum software I use had released an update. As one of my sites runs on this software I planned to do the update this Sunday (today). I awoke at 8:30am and decided to crack on with it, but as I turned on my laptop I received another email… there was ANOTHER update!

“Great”, I thought!… oh… how wrong was I?!!!…

The problem was, the forum I run is quite a large one, with lots of members and a few modifications. As it is a worldwide forum there is a mod on there letting members display a little flag showing their nationality. This is a great little mod, and people like it a lot, but upon upgrade it broke! After the upgrade happened the flags were no more.

The problem

The problem is the way the forum software works is not very “mod friendly”. It’s not like Wordpress where your mods are protected somewhat, modifying a forum required major surgery to the core files… not nice when it comes to upgrade time!

Anyway, all in all there were two mods that broke, the flags and the “quick reply” feature. The quick reply was an easy fix, as it only involved alterations to a single file, so fairly low maintenance, but the flags mod was a lot of work to find out what went wrong.

By the time I had finished with this fiasco it was well into the afternoon. This made me think, are these mods really worth it? Fair enough, if the version of the forum was fixed, great, but it’s not… there will always be fix released and bug patches going on, each giving the possibility of your mod breaking.

…and so…

I have learned a lot of the the past year or so, but I am learning that sometimes it is necessary to simplify things in order to give the reliability necessary to keep a site running, in order to maintain your own sanity, and not give your entire Sunday up in the quest to get “the little flags working”.

By the time I think about all the time I have spent making sure these modifications survive all the upgrades, these aren’t half expensive little flags!

Changing your post title can be a bad idea!

Technical Info 3 Comments »

I posted recently about the importance of setting the correct blog post title. This made me think of something I came across a while ago. Once again it is something quite simple yet very important, that is getting your blog post title right, first time!

Here’s why…

If you blog like I do you may blog fast and furious manner, in a quest to hit that Publish button. You may or may not give a tremendous amount of thought to checking things like spelling (you should, but then it’s easier said than done) until after it’s published.

In the case of spelling it’s not the end of the world. Enter the admin panel again… manage… posts… select… edit… save… DONE!

Where things come unstuck occasionally is changing the title, or more importantly changing the permalink that goes with it.

Why is this?

Basically, under the hood of your Wordpress installation lies the UPDATE section (under settings/writing). This contains something like http://rpc.pingomatic.com/ and means when you post a blog article it updates various feeds from Google to Yahoo to Technorati.

This is all well and good, but what happens if it updates them with your latest and greatest post, only for you go back in there and change the title and permalink? That’s right, it won’t be able to find it!

I would have thought it was intelligent enough to go back in there and update these services, maybe it’s supposed to, who knows? All I know is I have looked at my stats on occasion and found attempted visits trying to find the old page, only to be greeted by a 404 error.

There are plugins out there that will handle this sort of thing and maintain a list of old pages and their corresponding new ones. Personally I find it easier just to spend a little time hovering over the Publish button, checking the permalink is correct before I submit the post.

The benefit of taking time doing this is you can craft your permalink to take out the irrelevant words, leaving a short, accurate, keyword rich description of your post.

How important is a blog post title?

General Interest, SEO, Technical Info 4 Comments »

The importance of a blog post title is something I thought I had covered before, but looking back it seems I never posted it.  The title of a post is one of the most important aspects in terms of getting your post seen. The content of the post is actually more important in terms of the total post, but if you rely on visitors from search engines then they need to arrive at the post before they can read it, right?

There are several things that dictate how well a post is ranked by the search engines, some of the most important are:

  • The title of the post
  • The URL of the post
  • The title PROPERTY of the post (in the browser header)
  • The value of the headings
  • The amount of keywords in the body

The list does go on, but for the purpose of this post I will focus on the title.

If you are anything like me you will be quite enthusiastic about your blog post. When you write it you may be brimming with ideas, full of enthusiasm and excited to post. You write your post and come up with a great (sometimes funny) title to give the post the POW! factor.

This is a very easy trap to fall into, I have done this many times myself. It is easier to illustrate through an example.

Take this post… it is basically about the title of a blog post. Instead of naming it :

How important is a blog post title?

… I could have called it:

The risks of the POW factor

Ok, that’s not necessarily the best title in the world, but what I am getting at is I could use the title to make a newspaper headline type statement, to intrigue the reader and make them want to read on. There is an argument that actually that is the right way to do it, but we need to be aware that while a reader may be enthused by that, Google may not.

Of course, the holy grail is to combine the two, but in my opinion it is more important to optimise your post to allow people to find what they are searching for, not just from google, but from your internal search engine. If someone searches for this post 6 months down the line they may search for “post title”. This post will appear on the list, whereas it may not (or be lower down the list) if I gave it a funny title.

Some of this may seem like common sense, in that case great, but like a lot of these simple aspects to web design and blogging, it’s only simple once you know about it.

As always, comments (and other angles) are always appreciated.

Password protected pages and Wordpress (404 error)

Technical Info 3 Comments »

I have recently been doing some work that I wanted to ring-fence in a password protected directory. The problem is, as soon as you put a password on a directlry Wordpress gives a 404 error.

Ok, so wordpress is giving a 404 because it can’t find the directory you typed in, right?

WRONG!

The problem is actually not this at all. The problem comes from the rewrite engine Wordpress uses to make search friendly URL’s. Wordpress makes a .htaccess file in the root of it’s install (the root of my website, in my case) which looks like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Part of what this code does is takes any unknown URL and throws it at Wordpress to sort out and server the appropriate page, or error.

In the case of my password protected page it wants to tell me about the 401 situation I am in (authentication) but my server has a default location for this, and there is no file there. When Wordpress gets wind of this missing file it tries to be helpful and tell us about it, hence passing us a 404 error.

The Solution

The solution is actualy very simple. Open the .htaccess file and add the following before all the Wordpress entries:

ErrorDocument 401 default

Save the file and retry to navigate to the protected directory. You will now get the popup box you were expecting in the first place, so you can enter your details and gain access as normal.

A very simple solution to a simple (but very confusing) problem.