Don’t rush it…

Just don’t. Ever.

Good grief, that’s been a frightening few days. And all because I rushed something on Tuesday night that wasn’t that urgent after all. Now, who’s going to place bets that this (finally) teaches me a lesson. 200-1, I reckon.

But it does give me a good excuse to post my first proper code example. This one is classic ASP (VBScript), and is very useful when you need to hard-write a lot of files with only minor changes such as the title, keywords, description and a bit of page content between them. You can always see it in action as well, if you want. Oh, and one more thing, this (and any code peovided on this blog) is given without any guarantees or warranty whatsoever.

' all you need to do to that is create your html template and replace some
' of the elements in it with the codified equivalents. here's a list:
' page title = %%pagetitle%%
' meta keywords = %%pagekeywords%%
' meta description = %%pagedescription%%
' page content = %%pagecontent%%
' level (string of ../'s to the root, for image paths etc) = %%lev%%

' grab the template file
templatepath = "template.htm"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath(templatepath), 1)
bodytext = f.readall
f.Close
Set f=Nothing
Set fs=Nothing

' this is the function that is called to create the final HTML code
function getBody(bodytext,pagetitle,pagekeywords,pagedescription,lev,pagecontent)
getbody = bodytext
getbody = "" & vbcrlf & getbody
getbody = replace(getbody,"%%pagetitle%%",pagetitle)
getbody = replace(getbody,"%%pagekeywords%%",pagekeywords)
getbody = replace(getbody,"%%pagedescription%%",pagedescription)
getbody = replace(getbody,"%%lev%%",lev)
getbody = replace(getbody,"%%pagecontent%%",pagecontent)
end function

' start your loop (from a database, for example)
' for each item create the HTML and save the file like this:
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile(server.mappath("path/to/your/file.html"))
tfile.Write getBody(bodytext,"Page title","keywords","description","../../../","This is the page content")
tfile.close
set tfile=nothing
set fs=nothing
' go to the next item
%>

How could I ever survive……

Without undelete tools? That’s the second time in as many days that I’ve deleted something important with … less care than I should have had. But, in my defence, I rarely make mistakes like that.

It’s all the other mistakes I make that are the real problem.

Perhaps this says something about humans in general. When we think we’re pretty good at something, that’s when we get lax. Start cutting corners, acting quickly without care or thought. And, obviously, that’s when the errors occur. Now with an inexperienced user this could be forgive, but for someone who is meant to be good at this stuff, oh dear. Now, deep breath and…

Undelete

Long Live Mozilla Firefox…

On the auspicious occasion of my company disabling web access for Internet Destroyer Explorer and instead promoting the use of Mozilla Firefox I thought I’d finally start the techy blog I’ve been threatening people for ages about. So, I don’t really have much more to say, but this comment (from a .net developer) when he found out that IE is no more, sums up a lot of attitudes I come across in my job:

It?s ponytail software written by ponytails for ponytails!
What next? Do we all have to wear heavy metal T-shirts and listen to The Maiden??