SB Twitter Plugin

November 21st, 2009 by Sean 3 comments »

Let’s get this straight, I hate Twitter with a vengence on account of it being a pointless waste of time. However, I can see that some people enjoy using it and also want to share their exciting lives with other people.

I have just had the need to develop a very basic plugin to put a Twitter widget (not a Wordpress widget) on a website. I didn’t see the point in forcing the user to put masses of code onto their page each time they wanted to include the widget so created a shortcode to do the same job.

I have rather imaginatively called it SB Twitter and it allows the user of a shortcode to put the Twitter flash widget onto a post or a page.

Usage

[sb_twitter name="you_user_name"]

You can optionally include width=”" and/or height=”" to manipulate the size of the box.

Download

The download file contains a readme which essentially says to upload the file to your plugins directory, activate it and use the shortcode provided.

SB Twitter (2.29 KB)

Screenshots

Example output of SB Twitter plugin

Live Countdown Timer using Javascript

October 10th, 2009 by Sean 2 comments »

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 by Sean No comments »

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.

Learning Event Generator

September 26th, 2009 by Sean No comments »

The learning event generator is something which I was shown on the first day of my PGCE. It was demonstrated and was intriguing to say the least! It would be an interesting way to allow the children we teach to decide their own activities.

I have been in a coding mood today so thought that I would bash together a tiny little PHP script to emulate the same thing. Yes it’s basic but works from two text files which are defined in the first few lines of the file itself. It’s not the most elegant bit of code I have ever written but if you know anything about PHP or have a web server then why not have a fiddle and see what you can make it do?

Consider this… it doesn’t have to be learning events. Why not use it as a kind of ‘What shall we do tomorrow?’ kind of thing. eg: ‘Do a 5 mile run with a friend dressed as a horse’ or ‘Do go out and get a bit merry’.

The Code

<?php

$cwd = getcwd();
$outcome_source = $cwd . '/' . 'activities.txt';
$method_source = $cwd . '/' . 'methods.txt';

$outcomes = file($outcome_source);
$methods = file($method_source);

$outcome = trim($outcomes[array_rand($outcomes)]);
$method = trim($methods[array_rand($methods)]);

echo 'Do ' . $outcome . ' as a ' . $method . '.';

?>

The Download

The file is available as a download here: Learning Event Generator (1.23 KB)

References

The original idea is available on the following website and is credited to John Davitt