Sunday, September 24, 2006

Solid Foundations

The following is an extract from a comment I made during an ongoing discussion with fellow blogger Custard on his blog.

I give you this analogy: Before you walk into a building, you don't know how structurally safe it might be, and whether or not it might collapse on top of you. You might be 50% certain - either it will collapse, or it won't. You decide that your accumulated experience with buildings is a good guide, and enter the building. If you repeatedly return to the same building, and it doesn't collapse on top of you, your previous experience leads you to the conclusion that this building is structurally sound, and is unlikely to fall down while you are inside. You go further into the building each time you visit, increasing the risk of being trapped or hurt if it does start to collapse. You might be 80% sure, or 90%, or given long enough, 99.999999% sure. You can never be 100% sure, but you conclude that given the evidence and experience, the likelihood of this particular building collapsing with you inside is remote in the extreme.

Now, if you have carefully and clearly documented every visit, it would be the most sceptical, fearful and unreasonable of people who would refuse to enter this building on the grounds that your report does not show that the building is 100% safe, and might collapse. Of course, no-one should be compelled to enter, but this type of reaction would be unwarranted.

Taking the analogy further, if the building has been carefully planned and thoroughly tested, well designed and constructed, it will survive all manner of adversity unscathed: fires, floods, earthquakes, strong winds. By the same token, small defects might be uncovered after such events, and these deserve much scrutiny and enquiry, and ultimately some resolution.

It is probably rather obvious that the 'building' I am describing in this analogy is science, and that's exactly how I feel about it.

Thursday, September 21, 2006

Jcalendar Code & Instructions

Thanks to Tom Switzer and via LinuxQuestions.org, I am able to present to you the code - fully copyable and pasteable - for Jcalendar.

Disclaimer: I strongly urge you to back up your blog template before you make any changes to it. Copy the entire template code into a new file called something obvious like my_blog_template.html and put it somewhere obvious like your personal folder for easy retrieval in case something goes wrong.

Copy and paste the following style rules into your blog template's <style> area; as the last entry is probably a good place, so that it's easy to find:

/* Jcalendar style rules
----------------------------------------------- */
table.calendar {
font-size: x-small;
width: 100%;
}
caption.calendar {
color:#cc0000;
text-transform:uppercase;
letter-spacing:.2em;
}
table.calendar td {
text-align: center;
}
td.calendar_ntm {
color: silver;
}
td.today {
text-decoration: underline;
}

This will give you a basic style, but of course you're free to modify it.

Next, copy this Javascript into the <head> of your blog template. This contains all the inner workings:

<script type="text/javascript">

/** THIS IS MY SELF-UPDATING JAVASCRIPT CALENDAR APP.
* FEEL FREE TO STEAL IT AND PASTE IT INTO YOUR OWN BLOG.
* THERE IS A SCRIPT SECTION PLACED IN THE SIDEBAR PORTION
* WHICH CALLS THE FUNCTIONS HEREIN, SO YOU ALSO NEED TO
* COPY THAT TOO.
* THE STYLE INFO IS JUST ABOVE, BUT YOU CAN DO WHATEVER YOU LIKE :)
* HAVE FUN!
* J.L.
*/

// setup arrays and variables
var d = new Date();
var x;
var months = [ ["January", 31],
["February", 28],
["March", 31],
["April", 30],
["May", 31],
["June", 30],
["July", 31],
["August", 31],
["September", 30],
["October", 31],
["November", 30],
["December", 31] ];

var day_name = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var today_year = d.getFullYear();
var today_month = d.getMonth();
var today_date = d.getDate();
var today_day = d.getDay();

d.setDate(1); // NOT DEBUGGING! LEAVE THIS IN WHEN DONE

var first_date = d.getDate();
var first_day = d.getDay();

// is it a leap year? TRUE if year % 4 == 0
var leap = false;

function set_feb_days()
{
if((today_year % 4) == 0)
{
leap = true;
months[1][1] = 29;
}
return leap;
}

function open_table()
{
document.write('<table class="calendar">');
}

function write_caption()
{
document.write('<caption class="calendar">' + months[today_month][0] + ' - ' + today_year + '</caption>');
}

function write_header()
{
document.write('<tr>');
for (x in day_name)
{
document.write('<th>' + day_name[x] + '</th>');
}
document.write('</tr>');
}

function write_body()
{
document.write('<tbody>');
var a = 1 - first_day;
var b = 41 + a - (months[today_month][1]);
if(today_month == 0) // if January, set last month to December
{
var last_days = months[11][1];
}
else
{
var last_days = months[today_month - 1][1];
}
var j = 1;
var k = 1;
for(i = 0; i < 6; i++)
{
document.write('<tr>');
for( ; a < 1; a++,j++)
{
document.write('<td class="calendar_ntm">' + (last_days + a) + '</td>');
}
for( ; !(j % 8 == 0) && (a <= (months[today_month][1])); a++,j++)
{
if(a == today_date)
{
document.write('<td class="today"&lgt;' + a + '</td>');
}
else
{
document.write('<td>' + a + '</td>');
}
}
for( ; !(j % 8 == 0) && a > (months[today_month][1]) && k <= b; a++,k++,j++)
{
document.write('<td class="calendar_ntm">' + k + '</td>');
}
j = 1;
document.write('</tr>');
}
document.write('</tbody>');
}

function close_table()
{
document.write('</table>');
}

</script>


Lastly, copy and paste the following Javascript into the sidebar somewhere. If you want to have your calendar appear just under your profile like I have it, paste the code just after the </MainOrArchivePage> tag:

<script type="text/javascript">

set_feb_days();
open_table();
write_caption();
write_header();
write_body();
close_table();

</script>


Well, let me know how you get on. I'd be keen to hear of sucesses, and will try to help with any problems that crop up when 'installing'. Happy hacking!

Sunday, September 10, 2006

Jcalendar 1.0 Released

Yes. I know you have all been eagerly awaiting this moment.

Jcalendar is a little Javascript calendar app I have been working on in my spare time over the last week. If you take a look over to the right, you'll see it in quiet action, nestled under my profile.

Feel free to copy and paste the code* into your own blog, and also to modify it as you see fit. Be aware that there is no guarantee, warantee or manatee with the code, but should it blow up or do something strange of its own accord, please let me know and I'll look into it.

* To view the code, select 'view source' from your browser's menu. I tried putting it all in text boxes, but Blogger kept inserting <br />'s all over the place - i.e. it wouldn't work when copied and pasted. If anyone really objects to this, post a comment and I'll make the code and instructions available as a complete post in its own right.