I just installed a set of MT plugins which I hope will make it easier to post entries in general, and code samples in particular.
The plugins are MT-Textile, SmartyPants and MTCodeBeautifier.
Respectively they should let me format my entries, use proper quote characters, and format code samples.
The installs are pretty basic, just copy the files or directories as specified in the install instructions. I also added some CSS to my stylesheet to support MTCodeBeautifier. The CSS changes support the syntax highlighting and also set up code blocks to have scroll bars if needed.
The rest of this post will just test out these plugins. I just noticed that MT-Textile added a "Textile 2" text formating option for my entires. I'll try that out and also use some text formatting. Already in previewing this post I can see that SmartyPants is being used to quote Textile 2 properly.
This paragraph has some text formating tests. Here's strong text. This is emphasis text. This is bold text. This is italic text. There's lots more.
Let's try some character replacements like the © copyright symbol, the ¢ cent sign, and an ... ellipsis.
- Here's
- a
- simple
- list.
And finally some code samples.
A simplistic contact form in PHP -
<?php
// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "some_email@somedomain.com";
$Subject = "contact message from somedomain.com";
$Name = Trim(stripslashes($_POST['Name']));
$Website = Trim(stripslashes($_POST['Website']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Let's try some Perl now:
#!/usr/bin/perl
use DBI;
use strict;
my $user = 'someuser';
my $password = 'somepw';
my $dsn = 'DBI:mysql:cpu_stat:localhost';
my $dbh = DBI->connect($dsn, $user, $password,
{ RaiseError => 1, AutoCommit => 0 })
or die "Couldn't connect to database: " . DBI->errstr;
my $insert_cpu =
$dbh->prepare_cached("INSERT INTO vm_stat VALUES (CURRENT_TIMESTAMP,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
my $vm_stat = `vmstat`;
$vm_stat =~ m/(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/;
$insert_cpu->execute($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
or die "Couldn't insert row into cpu_stat table: " . DBI->errstr;
$insert_cpu->finish();
$dbh->disconnect();
That's all for now. One thing I like is that I can choose what sort of text formatting to use on each entry. That's nice. I can leave my old entries alone and use Textile 2 whenever I need it.