Category: Life

Random thoughts on life

  • Webpage language translation

    Google provide some excellent tools for adding translation facilities to your website. They also provide browser tools so that you can quickly translate a page that you might be on.

    With that in mind they’ve taken the appropriate step of adding facilities for web developers to override this.

    For example, to stop translation on a section of your site add class="notranslate" to the appropriate tag, such as DIV or SPAN.

    To prevent translation on an entire page, add the following to the <HEAD> section…

    <meta name="google" value="notranslate">

  • Finding the number of users online

    I often wondered how sites detected the number of users online. After some digging I’ll admit to be no closer to the answer. The problem is that once a page is delivered to someone you have no idea what they’re doing unless, and if, they then do something – go to another page of yours, click a button, etc. They could have immediately left the site and gone elsewhere… you simply don’t get back the level of interaction that would tell you this.

    So my solution was based on simple maths. Using Google Analytics and the like I work out how long an average user spends looking at a page on the site. Let’s say it’s 90 seconds.

    I’m using PHP and MySQL for this example. So, create a new table named users_online and create two fields for it – the first named timestamp and the second ip_address.

    With your database already open execute the following PHP, pre-setting the variable $online_seconds with the figure we discussed a couple of sentences ago (in my example, 90). This should be at the top of each page.

    $timestamp = time();
    $timeout = $timestamp-$online_seconds;
    $insert=mysql_query("INSERT INTO users_online VALUES('$timestamp','$REMOTE_ADDR')");
    $delete=mysql_query("DELETE FROM users_online WHERE timestamp<'$timeout'");
    $result=mysql_query("SELECT DISTINCT ip_address FROM users_online");
    $user_num=mysql_num_rows($result);

    This will add the period of time (90 seconds) to the current timestamp and insert a row into the table with that as a “timeout”. We then delete any rows where this timeour has now passed. Finally, we read the number of distinct IP addresses – this is the number of users currently online and is returned as $user_num.

    How does this work? Well, the idea is that after 90 seconds if the user hasn’t moved onto another page or refreshed the current one then they’re gone. If they do, a new row with their IP address is created and they’re counted once more as still being active. Quite simple really. Possibly not the most accurate but without using host-side JavaScript, for instance, then I’m not sure how you would.

    If nothing else it’s handy to have an idea as to how many people are online before you upgrade your site and potentially break it 😉

  • Create new useful links for your site

    Google have announced a new feature in their Webmaster Tools. In a nutshell it will display all pages that link to a missing page on your site – you have a chance to fix it or take advantage of it.

    So, if a site was linking to an erroneously spelt page then you could create a redirect for this to the correct page – ensuring you still get the visitors to the appropriate page.

    BMTG was okay (apart from a misspelling on my own blog, so I was able to correct that) as was Copy+. However, I can see the advantage of this tool and will be keeping an eye on it in future.

  • Bin and gone

    Some time ago, probably a few years now, the company I worked for removed individual bins from under their desk and replaced them with recycling points dotted around the office. These consist of a series of bins where items can be separated – different bins for different areas, but usually, at least, a general bin for “miscellaneous” disposal. Even at the time this seemed a little odd because it might going out of your way each time you want to throw away an apple core, sheet of paper of paper cup (and odder still as 2 of those 3 items they don’t recycle – not food waste, including tea bags, or paper cups). Of course, there’s probably 2 reasons for these changes…

    1. They have a third party contract for cleaning. I suspect not having to empty individual bins around the office saved them quite a bit of money
    2. It’s environmentally sound

    Which of these you think was the priority depends on how cynical you are I guess.

    Anyway, I brought in my own bin for general waste. I provide my own bags and empty it myself. Recyclable materials I take to the appropriate bins. It remains environmentally friendly and doesn’t cost anything more for cleaning costs.

    None-the-less I have been hassled by management ever since. Yesterday it happened again with a threat of confiscation (how does this work if it’s your own property?) so I’m taking it home. I’ve had enough. I’ll just pile my apple cores and yoghurt pots up on my desk. Nice. And one more hit against my work morale.

  • I have a new shower!

    Remember me saying how things seem to keep going wrong at the moment (of the “it’s going to cost me money” sense)? Well, today is another such day.

    I get to work to get a very early phone call from my wife. The shower’s not working. The light on the pull switch is on but the standby light on the shower is doing nothing.

    So, I ring an electrician who says that it is, quite probably, the shower so I should get a new one and then ring him again and he’ll come around and fit it. Now, I don’t want it to be a big job and I don’t want new holes in my bathroom tiles, etc, so I decide to plump for the same shower (or as near as damn it) – a Mira Sport Max. I ring around the local DIY shops and none have it in stock. The local plumbers merchant don’t have it “but could order it”. Bum. My plan was to get one today and get the electrician out tomorrow.

    Anyway, if I can’t get that model I’d get something similar so confident, I’ll get something at least, I ring the electrician back to ask him to pop around. “May be able to do this week – maybe last thing Friday”. Oh. Well, I’d ideally like a shower earlier than that, but it will have to do.

    Meanwhile I’m chatting to my work colleague Ganesh. He asks if I’ve tried ScrewFix, a company I’m aware but haven’t bought from before. Sure enough they stock it. Great, I can get it for next day. Even better, I’m told, there’s a depot just around the corner. So I visit and pick one up.

    Well, the day’s getting better I guess. The stress of the shower has already stopped me eating.

    Then a van driver backs into my car in the ScrewFix car park. No damage is done other than a small ding in my number plate, but I take some details anyway (although he seems strangely reluctant to give any).

    My colleague had also said that showers were dead simple to fit in, so I should do it myself. Yea. Stupidly, I tried it. Well, I say “stupidly” without meaning it – because I did it! One fitted shower, all working. Better than the original.

    However, I have a dinged car and I’m lighter by £240 (yes, that’s how much the shower cost!) plus petrol. At least I don’t have to pay the electrician – which reminds me, I should cancel his visit. After we’ve tried the showers in the morning 😉