Welcome to Magic Hat Development

I'm here to show you that anyone can have a dynamic web application either integrated with a current site or a new site that I put together for you. If you need help reaching others online and organizing your business, organization, family, or group's information, then MHD can help.

Welcome, Taste of Champaign Visitors!

Welcome!  If you've visiting here after meeting me at the Taste of Champaign-Urbana festival this weekend, I just wanted to let you know that you're in the right spot.  Feel free to check out the rest of my site, and if you ever have a web-related question, I hope that you'll keep my card and drop me a line.  As I look out my window this morning, I see that it's raining again and my forecast tells me that it could some more today.  Hopefully that doesn't ruin the final day of the festival for you.  I look forward to hearing from you!

Blogging is Hard

So, I've learned, over the last few weeks, a new respect for professional bloggers. Blogging is hard. If nothing else, it's somewhat difficult to get the creative juices flowing for this blog at times, but I'm hoping to do better in June. It's my first month; hopefully, even the blogging greats out there were slow off the starting block.

I ran into a great post from PHP::Impact that offered up 30 Useful PHP Classes and Components that they've encountered. I was familiar with a number of them, but a new one stood out: the PHP Universal Feed Generator.

I'm somewhat ashamed to say that I've always re-coded feeds from scratch or relied on the internals of third-party blogging software to handle feed generation for me. However, after looking at the information on the PHP Universal Feed Generator, I'm excited to use it for upcoming projects. Looks like I know what I'm tweaking when I work on this site over the weekend!

Data Security in a Digital Age

Bruce Schneier has a wonderful essay up at wired.com today about data security. From the article:

Whoever controls our data can decide whether we can get a bank loan, on an airplane or into a country. Or what sort of discount we get from a merchant, or even how we're treated by customer support.... If a criminal can get hold of enough of our data, he can open credit cards in our names, siphon money out of our investment accounts, even sell our property. Identity theft is the ultimate proof that control of our data means control of our life.

We need to take back our data.

The protection of personal data is something I'm faced with freqently and something I take very seriously. In many cases, it seem to me like people collect too much private information. Why, for example, would you need to enter your birthday to signup for a newsletter. And, even if there is an age requirement for the newsletter, you could always lie about your birthday and, thus, circumvent such "security" measures.

Mr. Schneier goes on to say that it will take years to get to a point where we can truly "take back our data." I agree it will take time, but I think it's up to us -- the web developers of the world -- to truly analyze the data that we collect and make sure that we take the appropraite steps to secure it. Only in that way will we move toward a world where our data is within our control.

Using Prototype to Load Javascript Files

The calendar on this site only appears on pages that show blog-related information. That calendar is enhanced with Javascript allowing you to change the month displayed by the calendar without reloading the rest of the page. So, in order to ensure that these enhancements would be available everywhere the calendar is, I figured I had two options:

  1. Code the inclusion of the Javascript file into every page which requires it. While a good solution, and one that has worked well in the past, sometimes it can be difficult to remember or realize that you've forgotten to include the file when you add new pages that require it.
  2. Find a way to automatically include the file when it's needed. This would avoid the need to remember the need to include it when adding new pages that require it, but would result in a little more Javascript going on when the page loads.

This past weekend, with a little help from the Prototype Framework, I found a solution for #2 above which I am, for the moment, quite pleased with. The following snippet assumes the most recent version of Prototype as of this writing (1.6.0.2):

document.observe("dom:loaded", function() {
var calendar = $("calendar");
if(calendar) {
var script = new Element("script", { type: "text/javascript", src: "/path/to/calendar.js" });
document.observe("calendar:loaded", function() { new Calendar(calendar); });
$$("head")[0].insert(script);
}
});

Here's, essentially, what it does:

  1. Uses the custom dom:loaded event which, since Prototype 1.6.0, determines when the DOM is ready for manipulation to call the anonymous function defined in the snippet.
  2. That function attempts to get a reference to the calendar. If it can't, then nothing else happens. This makes sure that we don't include the calendar Javascript unless we need to.
  3. Once we've found a calendar:
    1. Create a new javascript element pointing its src attribute at the source for the calendar's code.
    2. Tell the document to observe the calendar:loaded event, which is fired from the bottom of teh calendar's javascript.
    3. Insert the javascript file into the head of the document.

It's #3.2 that is the most important step. The calendar.js file makes sure to use the Prototype fire() method to create the custom calendar:loaded event. Thus, when the browser is done performing the necessary work required to insert the calendar.js file, it'll fire the custom event, which will be caught by the document object to instantiate the newly inserted Calendar.

In other words, with a creative use of Prototype's Event.observe() and Element.fire() methods, we not only include Javascript files only when they're needed, but also ensure that we don't attempt to use the code within those files until the browser is ready for it to be used.

The PHP Logo; the letters PHP on a blue oval PHP for the win!

Well, I Missed the Memo

Some days you learn about something so amazingly life altering you know nothing will ever be the same. Most of the time, the average person doesn't encounter such things within a programming language. Today I learned of a fourth argument to the PHP htmlentities() function that ensures that html entities won't get double encoded. So, what does this mean to you? Probably nothing, but if you're running PHP 5.2.3 or greater, you can also benefit from this most joyous of days.

Claiming My Blog

This post serves no purpose other than to "claim" my blog at Technorati.  Seems like a cool thing to do as it could generate some traffic here as I become a more prolific blogger.  According to their instructions all I have to do is add the following link to my blog...

Technorati Profile

... and then return to their site to click a button. 

See you next time!