lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
PHP: In Support of Heredoc
One of the thing that puzzles me about many of the projects I've worked on is the seeming aversion to heredocs. The neat freak in me love heredocs. They make it so much easier to separate business logic and presentation logic. And that helps make code much cleaner.

I figured there were two reasons why they aren't used more extensively. 1) Programmers used to other languages don't know about them or feel comfortable with them. 2) There's a significant efficiency cost.

On the second point, I just discovered this: PHP string benchmark (php.net)

Cutting to the chase:

single quotes : 173ms
double quotes : 161ms
heredoc : 130ms


So I'm going to be a little more outspoken in my support of heredocs. Until I see some compelling evidence to the contrary, at least. Of course, it should be noted that this does not compare directly escaping PHP.

Here's my model for implementing heredocs in a web page framework: klenwell scriptframe

Labels:

Greqo: The Russian Blog-Spammer's Class of Choice?
Noticed a few clicks on my Klenwell wiki from a site called klikforum.com. (It's worth clicking just to see the banner art.) Traced it to this post:

Main Forum > Spam > What to think! To blogoFermu it is must! (Babelfish translation)

Ran the page through Babelfish and I think I got the gist of it. Someone is promoting some kind of spamming tool which may be using the Greqo class. If this was the case, it might be a violation of the Greqo GPL license (unless they were making the source code available.)

In any event, although I'm not thrilled to learn spammers might be misappropriating Greqo, I'm not too concerned about it. Yes, you could use it to spew blog spam, but there are plenty of tools out there that probably do a much better job. And Blogger limits the number of posts one can post a day (as the Last Google blog regularly discovers.)
The Ultimate Psychic Challenge
Open up a browser. Browse to your webmail page (e.g. Gmail). And then invite them to log into your account. To be fair, they are allowed to look into your eyes or massage your temples before they attempt to do so. But they are not allowed to look at any of the post-its attached to your monitor.
moshi 2.0 released
click here for the details and to pick up your copy

The first new moshi myspace stylesheet in, what, 6 months? And now that the mainstream media has launched the myspace death watch, probably the last.
PHP: Memory Usage Script
The following function can give you an idea of how much memory your script is using. It's based off a script found on the php.net site.

function memory_get_usage($echo=0)
{
$mb_usage = ''; // return

static $last_measure = 0;

$_OUT = array();

// Windows (requires tasklist.exe in C:\WINDOWS\system32)
// to download: http://www.computerhope.com/download/winxp.htm
if ( substr(PHP_OS,0,3) == 'WIN' )
{
exec( 'tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $_OUT );
if ( isset($_OUT[5]) )
{
$usage = preg_replace( '/[\D]/', '', $_OUT[5] ) * 1024;
$mb_usage = round(($usage / 1024 / 1024), 3);
}
else
{
trigger_error('tasklist failed to exec');
}
}

// Unix
else
{
$pid = getmypid();
exec("ps -eo%mem,rss,pid | grep $pid", $_OUT);
$output = explode(" ", $_OUT[0]);
$usage = $_OUT[1] * 1024;
$mb_usage = round(($usage / 1024 / 1024), 3);
}

if ( !empty($last_measure) && $echo )
{
$m3m = $mb_usage - $last_measure;
$m3k = $m3m * 1000;
echo "<pre style='color:#c33;'>memory usage: $last_measure -> $mb_usage | difference: $m3m MB, $m3k KB</pre>";
}
$last_measure = $mb_usage;

if ( $echo ) echo "<pre>mem usage in MB: <b>$mb_usage</b></pre>";
return $mb_usage;
}


Find a test script in the Klenwell code repository: test.mem_usage.php

Labels:

Wikka: A New Page Handler Model
A while ago, I was looking at wiki packages for the LAMP platform. I had worked with mediawiki, but felt it was a bit too much for what I wanted to do: lightweight wikis for a few small websites and my local development server.

I found wikka, tried it out, installed it, and haven't had any regrets. Still, for all its virtues, one thing I discovered with wikka is, from a web designer's point-of-view, it's not the easiest thing in the world to modify. Granted, you can edit most features through the stylesheet easily enough. But if you want to really re-arrange the layout and need to touch the html markup, well, that's where things get a little hairy.

You can see what I mean here -- that's the latest version of the code in question. Here is my proposed revision. It preserves all the current elements of the code and implements a controller logic to make everything a little more orderly. I've brought it attention to the developers of wikka (Ticket #532). I suspect it may conflict with some of their project conventions. Nevertheless, conceptually, I believe it would provide a much cleaner basis for rendering display pages and I imagine it would be relatively easy from here to integrate into the main framework class as a simple templating system.

Labels: ,

Praise for Greqo Blogger
Just noticed this comment from last week. Funny, at first I thought the comment was just blog spam because of the Grego. Then I thought Klenwell or Tom must translate as "Grego". Finally, it dawned on my that Grego must be Google's translation from Russian of "Greqo".

In any event, happy to be of service.
VBS: vbDataset
One of the first things that struck me when I first started working with vbscript was, "Wow, arrays in vbscript are really crappy." I was ready to go on a whiny little tirade when I caught myself and said, "Well, maybe I'm just being spoiled after working with Php and Javascript. I'm sure in the old days, C programmers had to build their arrays with raw bits using their bare hands." I soon learned, however, that I'm not alone in lamenting vbscript array support:

VBScript Weaknesses: Unforgivably Bad Array Support

Still, I've tried to resist the temptation to bitch and moan and, instead, just make it work. Since vbscript does support classes, I figured I could whip up my own list-like data structure. While it has not been a slam dunk, I think I've come upon a decent solution that isn't outrageously convoluted. I call it vbDataset.

It's tailored to the project I'm working on at the moment, but may have more general applications. I've added it to my google code repository. If interested, you can find it there:

svn repository: vbDataset

It includes a test script.

Labels: