Archive for October, 2009

Live Countdown Timer using Javascript

October 10th, 2009

Been done? Yes of course it has! However you don’t learn anything unless you get stuck in and have a go yourself and that is exactly what I did during an empty half hour period I had the other day (slow lecture). Whilst at university I am doing a lot of timed tasks (ten minutes etc.. as opposed to days) and the timers used are always a mobile phone timer or horrible Powerpoint countdown presentation. I wanted to write something which is simple to build on to create a JS version to ultimately integrate into online resources and lessons (Eg: this task will take you ten minutes. Click here to turn on the timer…).

The  code at the bottom of this post is the raw HTML file I wrote. I obviously made it into a WordPress plugin as well. see below example.

Example

Yes, it’s basic but it works well for demonstrative purposes.

Countdown from:

Usage

write sb_countdown in square brackets in a post or page and you will get the above example. If you want to edit the text or style it then just open the plugin file and right near the top is a few defines to get you going. I didn’t spend a lot of time on it so didn’t create an admin page. I may well do in the future though.

The Download

SB JS Countdown Timer (1.42 kB)

Raw HTML Version

<html>
 <head>
 <title>Countdown Timer</title>

 <style>
 body {
 font-family: tahoma;
 }

 #countdown_div {
 font-weight: bold;
 font-size: 56px;
 }

 #body_wrapper {
 padding: 10px;
 margin: 20px;
 }
 </style>

 <script>
 function do_countdown() {
 var start_num = document.getElementById("value").value;
 var unit_var = document.getElementById("countdown_unit").value;

 start_num = start_num * parseInt(unit_var);

 var countdown_output = document.getElementById('countdown_div');

 if (start_num > 0) {
 countdown_output.innerHTML = format_as_time(start_num);
 var t=setTimeout("update_clock(\"countdown_div\", "+start_num+")", 1000);
 }

 return false;
 }

 function update_clock(countdown_div, new_value) {
 var countdown_output = document.getElementById(countdown_div);
 var new_value = new_value - 1;

 if (new_value > 0) {
 new_formatted_value = format_as_time(new_value);
 countdown_output.innerHTML = new_formatted_value;

 var t=setTimeout("update_clock(\"countdown_div\", "+new_value+")", 1000);
 } else {
 countdown_output.innerHTML = "And... Stop!";
 }
 }

 function format_as_time(seconds) {
 var minutes = parseInt(seconds/60);
 var seconds = seconds - (minutes*60);

 if (minutes < 10) {
 minutes = "0"+minutes;
 }

 if (seconds < 10) {
 seconds = "0"+seconds;
 }

 var return_var = minutes+':'+seconds;

 return return_var;
 }
 </script>
 </head>

 <body>
 <div id="body_wrapper">
 <form id="countdown_form" onsubmit="return do_countdown();">
 Countdown from: <input style="width: 50px;" id="value" />
 <select id="countdown_unit">
 <option value="1">Seconds</option>
 <option value="60">Minutes</option>
 <option value="3600">Hours</option>
 </select>
 <input type="submit" value="Go" />
 </form>
 <div id="countdown_div">&nbsp;</div>
 </div>
 </body>

</html>

Spammers go funny!

October 7th, 2009

Just a quick one today but I had to comment on the hilarity of the steps that spammers take these days. It appears it has only been the last few weeks but a new technique I have noticed in my WordPress spam has been jokes! The general content of the comments is still rubbish and they still link back to some malicious site however after the silly content is ‘here is a joke for you…’.

I must admit I haven’t enjoyed checking my spam comments as much as I have recently. Spammers, your comments arent getting through but they do deserve a good chuckle now and again. Here are a few I have had recently:

What geometric figure represents a lost parrot? A polygon – My Favourite

What goes black and white, black and white, black and white, boom? A nun falling down the stairs.

What is three feet long? A yard.

What do sea monsters eat for lunch? Fish and ships.

What lies at the bottom of the ocean and twitches? A nervous wreck.

Why do turkeys eat so little? Because they are always stuffed!

What do you get when you have a cow and a duck? Milk and quackers.

Why did the big moron fall off the roof and the little moron didn’t? Because he was a little more on.

Did you hear about the flasher who was thinking of retiring? He decided to stick it out for one more year!

What insect does well in school? A spelling bee.

What kind of bird can write? A penguin.

Why did the bald man put a bunny on his head? He wanted a full head of hare.

Why wouldn’t the bike move very fast?? It was too tired!!

What do the letters D.N.A. stand for? National Dyslexics Association.

What kind of shoes do lazy people wear? Loafers.

Why did the man put wheels on his rocking chair? He wanted to rock and roll.

What do you call cheese that isn’t yours? Nacho cheese.

Where does a bird go when it loses its tail? The retail store.

What do Eskimos get from sitting on the ice too long? Polaroids.

Did you hear about the red ship and the blue ship that collided? The survivors were marooned.