Skip to content

Blog Magic Eye – Redux

Dear Reader,

Ok, when I put up the original Blog Magic Eye, some of you who read it felt it might have been a bit too subtle. Personally, I love subtle, that’s probably why I like British sitcoms. Unlike their American counterparts, they don’t feel the need to explain the joke to you. Some of you didn’t even get why I referenced Kathy in the original. Well, I’ve made some code changes and by now it should be pretty clear. If not, well, sorry.

Until next time, last night in the valley.
(l)(k)(bunny)

=C=

Another WP Plugin

Dear Reader,

Through the fog of Birthday induced depression, I found the time to work on another WordPress plug-in. Building on the work of Jarno Ristaniemi and Clay Smith I’ve added an options page to allow you to set all the options from within wordpress. You can see it in action of you look at my sidebar. This one was fun because it was the first one I did with an options page. Again, kudos to the WP team. I was able to squeeze it all into a single file. Granted it’s still not as complex as some plug-ins I’ve seen but I’m getting there.

Read the install page and download here.

Until next time, the final countdown has begun.

=C=

My First WordPress Plugin!

Dear Reader,

I looked up at the clock last night and it was midnight. I’d been tinkering with this idea for 5 hours without stopping. (God, I love it when I get a burr under my saddle!) You programmers in the audience will know what I mean.

This is not an original idea. I saw the guys at Zimbra demo this feature in their mail client at Web 2.0. It struck me as a cool and easy to implement idea. So I set about implementing it. I first did it manually on my resume…just because I start all good projects with my resume. Once I had it working I decided I wanted it in my blog but I really didn’t feel like going back and retrofitting all the URLS with the mouseOver and mouse Out attributes. So I decided a plug-in was in order.

Also, I wanted to see how easy it was to write a WordPress plug-in. My hat is off to you guys. The plug-in was the easiest part of the whole task. Actually getting both IE and FF to play nice was the hard part! When I implemented it on my resume, the JavaScript code to find the current mouse position in IE was:


posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;

For some reason in the WP environment, that does not work. I had to modify it to say:


posx = e.clientX + document.documentElement.scrollLeft;
posy = e.clientY + document.documentElement.scrollTop;

I’m not sure why it worked in one environment and not the other so I’m gonna research that. Other than that it was pretty easy and a fun way to kill an evening! (Well, I stopped for Veronica Mars but c’mon…who wouldn’t!)

Anyhow, here it is if you want to implement it on your own blog.

Until next time, it’s cold here too…just not AS cold. :)

(l)(k)(bunny)
=C=

Building a “Tag Cloud” in PHP

Dear Reader,

Just a few more and I promise I’ll get off the programming kick. I was working on my AJAX based resume last night (what, doesn’t everybody have one?) and got everything but the Skill Cloud” done. My idea of a skill cloud comes from the latest toy that people are deploying on the web, tag clouds. It seemed to me that it should be pretty straight forward to create one and so I dove off the board before making sure there was water in the pool.

Not being very good at math, I was struggling with how to take my list of x skills and evenly space them into a maximum of 10 categories. (tagcloud_1 – tagcloud_10) Here’s a quick rundown of what I came up with.

My data set is my list of skills deployed at a given company. Each bullet point for a company has a list of skills attached to it. Each skill has a weight that is determined by how proficient I am at that particular skill. (1=nubie…10=demigod) For each company, I gather the list of skills I used and sum their weights. For those of you in the valley, I will explain. If I used FoxPro on 3 bullet points in a job and my FoxPro weight is 10 (which it is) then my FoxPro score for this job will be 30. If I also used Java on 1 bullet point at this job and my Java weight is 1 (which it is) then my Java weight for this job will be 1.


$ceiling = 1;
$floor   = 99999999;

First, compute the boundaries of the current weights. I thought about using array_walk in this situation but I eventually want to OOpify it and I’m not sure if array_walk can play nice in an OOP world.


for($lcvA=0;$lcvA<count ($rsArray);$lcvA++)
{
	$ceiling = ($rsArray[$lcvA]['weight']>$celing
		?$rsArray[$lcvA]['weight']
		:$ceiling);
	$floor  = ($rsArray[$lcvA]['weight']<$floor
		?$rsArray[$lcvA]['weight']
		:$floor);
} // for($lcvA=0;$lcvA<count($rsArray);$lcvA++)

Now get the spread. The spread is the difference between the ceiling and the floor.


$difference = ($ceiling-$floor);

Ok, now break the spread into 9 different buckets. We already know what 1 is, it’s the floor. Since we want a total of 10 total categories we divide the spread by 9.


$increment = $difference/9;

Finally, take the current weight for each item and shove it into the proper bucket.


for($lcvA=0;$lcvA<count ($rsArray);$lcvA++)
{
	$rsArray[$lcvA]['weight'] = 
		intval(($rsArray[$lcvA]['weight']-$floor)/$increment)+1;
} // for($lcvA=0;$lcvA<count($rsArray);$lcvA++)

That’s it. Now the array contains weights that are comparable to their original weights but are in the range of 1-10. Now in the output, I use a span tag to wrap each skill and the ID of the span tag is tagcloud_x where X is the weight. Add 10 IDs to my style sheet and it’s done. This code is overly verbose mainly because I’m using it as an example. Also, please forgive my lack of OOP. Version 2 will be OOpier, I promise!

Here are the styles I added to mine for reference.


#tagcloud_1 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:16;
} 

#tagcloud_2 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:16;
	font-weight: bold;
} 

#tagcloud_3 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:16;
	font-style: italic;
	font-weight: bold;
} 

#tagcloud_4 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:20;
} 

#tagcloud_5 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:20;
	font-weight: bold;
} 

#tagcloud_6 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:20;
	font-style: italic;
	font-weight: bold;
} 

#tagcloud_7 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:24;
} 

#tagcloud_8 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:24;
	font-weight: bold;
} 

#tagcloud_9 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:24;
	font-style: italic;
	font-weight: bold;
} 

#tagcloud_10 
{
	font-family: Arial, verdana, sans-serif; 
	font-size:28;
} 

Until next time, love you bunches,
(l)(k)(bunny)
=C=

How NOT to write a FOR loop in PHP

Dear Reader,

Ok, so I’m on a programming roll right now…sue me.

Here’s a piece of code I saw yesterday on a mailing list. At first I thought it was borked and started to reply that there’s no way it would work…son-of-a-gun if it doesn’t…sort of.

< ?php 
for ($j=A; $j <= Z; $j++) 
{
    echo $j."\n";
    if ($j==Z) break;
} 
?>

I’ve never seen anyone increment a character value before. It intrigued me so I played with it for a few minutes. First let me say if someone on one of my teams every wrote code like this…well, it’s a ‘Career Limiting Move’. Character values are just that, characters. If you need to build a list of the letters of the alphabet, do it the way programmers have been doing it for at least the 23 years I’ve been programming, iterate through the numbers 65-91. Use the chr() function to get your letter. (c’mon, other than the numbers changing, we even did that on my old C=64!)

The second problem with this code is that without the IF statement, that it doesn’t do exactly what you would expect it to do. Run the code without the IF and look at the output. I’m not sure I know why it does that. I’m not sure why $j does not evaluate to == Z when it actually displays the Z. I could probably dig in and find it but I really don’t care.

For those interested, a better way to do this would be:

< ?php 
for ($j=0; $j <26; $j++) 
{
  echo chr(65+$j)."\n";
} 
?>

It’s fewer lines of code and we are not using string types as numbers.

This is a good example of “Just because you can, doesn’t mean you should.”

Until next time, my prayers are with you today.
(l)(k)(bunny)
=C=