Archive for January, 2005

Site is Broken

Monday, January 31st, 2005

I’ve been completely revamping the code that handles database queries. Much more versatile and easier to use now. But things will remain slightly broken until at least tomorrow, if not for longer. About 1500 lines of code added in four hours…ouch.

Updates to Langosta

Saturday, January 29th, 2005

Major Changes

  • Standardized template switch controller makes use of Events in order to communicate with other objects and determine which parts of the page should be shown (for example, the user login box should not be shown on the registration page).
  • New name! Langosta is Spanish for “lobster”. There’s a funny story about that…
  • Calendar object added, hooks into the entry display system and allows for really awesome navigation of the site (changing the calendar changes the entries that are displayed).
  • Added about 800 lines of supporting code.

Minor Changes

  • Small updates to theme to improve readability.

TODO

See previous Langosta entry.

This Breast for Rent

Friday, January 28th, 2005

I learned today that a Nebraska college student sold advertising space on his forehead to a California pharmaceutical company. The company makes a drug meant to reduce snoring called SnoreStop. How did he sell the space? Over eBay. Surprise, surprise. We’ve seen worse things sold there, like the infamous ham sandwich that I believe ended up getting pulled from the listings by eBay authorities.

But the real eye-opener here is not the concept (Chris Pirillo famously sold space on his chest for advertising) - it’s the price. For a space that probably amounted to about 15 square inches (assuming a standard-size forehead), the pharmaceutical company paid the college student (20-year-old Andrew Fischer) nearly $38,000. That almost makes me want to start selling ad space too. Other people have certainly caught on, with a pregnant woman offering space on her stomach (much bigger than a forehead, she says) and another woman offering space on her ample bosom (trying to keep it clean here).

Here’s a link to the ABC News article.

Reshackled

Friday, January 28th, 2005

Yeah, I’m back in school. Do I like it? No. But not because this school is in Wisconsin, and not in Arizona, but because it’s school. Any word that begins with ’sch’ strikes fear into the hearts of many a student - the reminder that they are slaves to the stress of public school is painful for all.

Am I being overdramatic for your entertainment? Yeah. But school is still not a good thing. I got my winter break, even if most of it was spent unpacking or sobbing quietly in a corner, but now all the familar feelings are rushing back: depression, stress, general unhappiness…it’s all there. And not having the support of all my old friends doesn’t help things.

In truth, my friends were never that supportive. While I knew they cared, and I cared about them, we were never just friends. There was always a lot of making fun and taunting and so on in middle school, and I think it is because of that that we never talked about anything profound or deep about ourselves later on. Yes, we discussed Russian politics and Postmodernism and all sorts of things that most normal kids don’t talk about, but we never said anything about our own feelings, like which girl we liked, or how we were depressed because of [insert unhappy event here].

I guess that probably is why I have a blog.

Type C

In Health class, I’ve been learning all about how bad a person I am. Seriously. Most of the class is based around these little minisurveys that we take and score ourselves on to see where we rank on such things as physical fitness, mental fitness, ability to deal with stress, and overal wellness. At first, I was enthusiastic. I was truthful in my answers (they weren’t turned in for points or anything). But eventually it all just began to weigh on me.

The truth it, I am not well in any sense of the word. Part of the problem may be the temporary shock of moving, but I think there is much more to it than that. Most people who know me already know that I’m not physically fit, that I don’t do sports or anything that “normal” teenage boys are supposed to do. So I think I’ll just skip that part. But the mental part…that was what kind of shocked me.

Today we talked about how adrenaline (epinephrine) affects people over time, and how adrenaline built up from stress can adversely impact your health. And I think it was only then that I realized just how much stress I was under last semester, both from school and from the crisis that loomed consistently over my head until that fateful December day when everything ended. I actually think I felt it in my arms and legs: a need to get out from under the great weight pressed upon me.

As my health teacher said, some of the weight will never go away, unless I actively try to dispel it. And that’s why I can still feel it, even a month after leaving. It’s why I’ll probably still feel it six months after leaving, as I walk home on the last day of school knowing that my friends were out three weeks earlier and were already enjoying their vacations.

Two of the tests we took today were different renditions of the same survey. According to the tests, a person was one of three types: A, B, or C. None of the types was better than the others, but people of different types had to deal with stress differently. The A type was the highly-competitive, rushing, ambitious type, the one that can’t turn down a contest and does millions of things at once. The B type was easy-going, laid-back, and though not stressed out, was prone to procrastination. The C type…that was the interesting one. Most people are A or B; actually, I think everyone in my class was one of the two. But not me. I was a C. And the reason why the C type was interesting is because a C person swings wildly toward both ends of the spectrum. I am not competitive, but I have a strong desire to succeed. I don’t often rush, and I don’t care that much one way or the other about things - on the outside. On the inside, it’s full-steam ahead. I multitask all the time, I plan ahead for things that most people don’t even think about, but I’m also lazy. I procrastinate. I should be doing math homework right now. My teacher gave each of us another test so that we could see where in between A and B we landed, and most people (I think) scored pretty far to one side or the other. Me? On the first question, I was an 8, the farthest possible toward a B personality. On the second, I was a 1, the farthest away from B (an A). And so it went on, all the way down to question seven or eight (don’t remember the exact number of questions). Every time I answered 1, I would answer an 8 to compensate. That’s rare. Disparity like that can tear you apart, I think. Another C would have something like 4, 6, 3, 7, 5, and so on, right around the middle but still equaling out. But my two halves are night and day different from one another. And yet they work together, for better or for worse.

I know I shouldn’t put much by surveys, since they are usually flawed and can never give an accurate reflection of the complexity that makes up a human being (I feel the same way about standardized tests, even though I do well on them). But that doesn’t keep these tests from Health class from feeling like a wake up call, telling me that someday the weight will be too much, and that even though I think I can continue to bear it (too stubborn to back down), I can’t.

Right now….I dunno what I’m doing. I don’t know if I care about school or not, whether I want good grades or if I feel like I proved myself enough last year. But even as I write this, even as I entertain the very thought of relenting, of quitting…I know I can’t. It’s addictive. I don’t even know why. The reception from OHS has been evidence enough that the reward of working hard in school is limited. Yeah, I know there’s college to work toward, but…I don’t know if I care about that either. Right now I kind of want to spend some time caring about myself…I kind of want to free myself from the shackles that bind me. For these manacles weren’t put there by some short-sighted bureaucrat in the department of education - I put them there.

Changes in Version 0.1.4

Monday, January 24th, 2005

Here are the major changes in Langosta version 0.1.4.

Major Changes

  • Switched from ADODB to Creole for my database abstraction library because ADODB is bloated and scary while Creole is organized and written just for PHP 5.
  • Eliminated per-request database query caching. This is where, each time a query is made, the result is stored in a temporary array (like a Perl hash) so that the same result can be used again when the same SQL is executed. This can cut down on queries big time, but my DBCache object was failing for some reason, so it got pitched. There was no real change in generation time anyway.
  • Rewrote large parts of Events object so that multiple observers (listeners) could watch for the same event. For some reason I hadn’t implemented that already.
  • Added user registration and login UI, with validation on the registration half. Validation object is new and probably unstable, but it follows loosely the method used in PEAR’s HTML_QuickForm. Need to figure out better way to validate with custom functions.

Minor Changes

  • Applied Savant trimwhitespace filter to all outputted HTML.
  • Added BlogMetadata object as a temporary fix for fetching a recent entries list and the labels data. No UI for either yet.
  • Added version number, build date. Visible under main blog title on every page.
  • Added two template switches to control appearance of certain page elements (user login form, etc.).

TODO

  • Figure out a standardized method for all SQL queries. Already have a pretty good one for SELECT, need same for INSERT and UPDATE. Also, need standalone modules so that labels and user can be retrieved without going into GroupCommon::get methods.
  • Need standardized template switch controller.
  • Replace BlogMetadata with standalone modules described above
  • Put comments with entries, copy over old comments from WP database.
  • Validation on login form
  • Better/standardized method for redirecting users after filling out a form (should they be redirected or should there be a confirmation page)
  • UI, code for user preferences (labels to show, font-size, presentation, etc)
  • Some sort of basic HTML UI so that it doesn’t have to all change later.
  • Rewrite DBCache, try to make it work (savings is worth it). Maybe plug it directly into Creole.
  • Add more event hooks so that objects can have more capabilities later on.
  • Need search-engine-friendly .htaccess rewriter thing
  • Firefox promo button
  • Begin work on admin area, hate posting through phpMyAdmin

New Blogging CMS Online!

Sunday, January 23rd, 2005

The Story So Far

I thought I couldn’t do it. I thought I wouldn’t do it. But I was wrong. Behold, the thus-far-unnamed homegrown blogging backend written entirely by yours truly. It has bugs, as I’m sure you will notice, but I promise, this version is much better than a few builds (not that the code is compiled or anything) ago when my statistics module was reporting upwards of four-hundred SQL queries on every request. For those who don’t speak computer, this means that, each time someone went to Organon, the database where all the entries are stored would be hit 400 times for various pieces of data in order to build the page. By comparison, a “good” or “normal” amount is around 25 (hopefully even less than that, if possible).

And so now we’re down to a lovely eighteen queries per request, which just plain kicks ass, considering the amount of code there is behind-the-scenes.

Your next thought is probably, “If there is so much backend code, why does the page look so horrible? I mean Arial? C’mon, you can do better than that!”
Yes, I can do better than that, but no one has the time to finish a custom blogging system in a night, and I certainly didn’t either. For now, this is what you get. But I’m on a roll, so look out for more features/better design in the next week or two.

Under the Hood

For you programmers out there, or if you’re just curious, I thought I’d write a bit about the more ingenious coding that makes up this project. I won’t describe everything line-by-line, but I’ll at least put in a few bits about the parts that I am particularly proud of.

Versatile Event System

There are many situations in programming when you need one part of the program to react to the actions of another part of the program automatically, without having to explicitly tell it to do so. To handle this, programmers use an event system, which basically acts as the go-between between the two separate parts of the program and communicates what each part is doing so that the other can react.

Now, most event systems (there is probably a better term for this, but I’ll just use mine instead) are complex and require a lot of coding around by the programmer to make sure that they will work correctly. Mine, however, is almost completely transparent, only coming into being when I need it. Here’s how it works:
An object called Page is designed to construct the HTML page that users see. In the Page object’s constructor function, which is essentially the ‘”setup” program for that particular object (objects are parts of a program), the Events object (the event system) is passed to the Page object so that it can be used. This is the only prerequisite for using the events system: any object that uses it must have it passed to it in its constructor.

Once the Page object has finished building the page, it needs to connect to the database and perform a query to get some final data. When the query is performed, the Page object also calls the recordEvent function of the Events object; in other words, the Page object is telling the Events object what it has done. At the same time, the Page object passes the query_id of that particular query to the Events object as well, just so that other objects that are watching for that particular event (a database query) to take place have a little bit more to work with. Objects that watch for a certain event are called “listeners” or “observers”.

Let’s recap a bit. We have a Page object that has just sent the Events object a quick notification that it is doing a database query. How will the Events object respond?

Before we get to that, I should note that not every object can be a listener. If an object wants to be a listener, it must first register with the Events object, telling it that a) it wants to listen, b) which events it wants to listen to, and c) what it will do if a particular event occurs. In our example, we have a third object, Statistics, that has already registered with the Events object and told it that, if a SQL_QUERY_EXECUTED event occurs (a database query), the Events object should call one of the methods of the Statistics object, “incrementQueryCount”.

Now, what is a method, exactly? Well, if an object is a part of a program, then a method is a part of an object. More specifically, it is a block of code that has the sole purpose of performing a specific function, which in this case is to add one to the query count. When the Page object executes a database query, the event is recorded by the Events object, which then looks through its registry (nothing like the Windows registry, don’t worry) for objects such as Statistics that have requested that Events tell them that this event has occurred. When it sees that Statistics is one of these objects, Events acts according to Statistics’ initial instructions - it calls the “incrementQueryCount” method, which adds one to the query count statistic.

So how is this useful? Well, though I only said that Page was trained to report a database query as SQL_QUERY_EXECUTED, all other objects were instructed to do so as well. As the program runs, dozens of SQL_QUERY_EXECUTED reports are forwarded to Events, and each time it tells Statistics to increment its query count by one. Just before ending the program’s execution, after all instructions have been followed and most of the page has already been send to the user, the program will get the finaly query count from the Statistics object and put it somewhere on the page. (You can see this on Organon at the bottom of every page.) While knowing the query count is of no use whatsoever to visitors, it is extremely important to programmers. Had I not checked the query count at the bottom of the page, I would never have known that I was racking up over 400 queries per page view, and most likely that error would not have been fixed. So indirectly the query count does help you, the visitor, because it helps the programmer keep the page generation time low.

There you go, a crash course in object-oriented programming, which is probably a college-level subject. I know it took me a while to get my head around it. But if it’s all you know to begin with, it really isn’t a hard thing to grasp.

The real reason that I was so ecstatic over developing this code (only 75 lines, which is unbelievable) was that because of the way the Events object acts as a go-between. The listener and the listenee (?) never have to know each other exist. It’s sort of like the way the newsmedia acts as the middleman between an American and the war in Iraq. I don’t know every single thing that happens there, and I’m pretty sure there aren’t any Iraqis who know me or who I am, but I know about the important things that are happening because the newsmedia (like the Events object) gets reports from Iraq and passes the ones I’m interested on to me. (Unlike the newsmedia, the Events object can’t be biased or warp the truth, however, so it is much more dependable.) The Iraq war and I can go on separately, but because I am “listening” to events happening there, I can then act on what I hear (though I probably wouldn’t do much in this case).

How was that? I was trying to teach you something without overwhelming you or babying you. That can be hard to do, because the line between them is a fine one. Only the best technology writers are able to walk it. (Not that I would count myself as one of the best, or even good.)

Edit: One More Thought on Events

Theoretically, my Events object could be used to link together an infinite number of other objects, resulting in a fully-autonomous program that would need only to be started up to function beautifully. Hmm…

Organized Data Pulling

When you click on a Read more link, a lot of things have to happen to get all the information pertaining to a single entry and present it on the page. The base data, such as the entry content, title, date, etc. is easy to grab. It can be done with one query, even. But there is also more data, such as the labels and their names, titles, and descriptions, as well as the comments (turned off for now) and the information for the user who posted the entry (also turned off). More queries must be performed to get each little chunk of information, sometimes two or more just for a small thing, like the names of an entry’s labels.

You see, in the database, most things rely upon unique identifiers to relate to one another. Every user (posting user, not visiting user), label, comment, and entry has its own unique ID that no other piece of data of its type will have. Rather than store information like this: “The user Aristotle has posted this entry,” it is better to do it like this: “The user with unique id #5 has posted this entry.” (Not in that format, of course, I’m just using English rather than SQL, which is the language that database queries are represented in.) Why is this better? Because users might want to change their username, and they can’t change their username and still keep authorship of their blog entries if the username is used to describe authorship. The unique ID number will never change and is unknown to the user, so it is ideal for this. Also, in the event that two users have the same username, there could be some problems figuring out which one was the actual author of an entry in the database. But since they each have unique ID numbers, it is easy for the database server to tell the difference.

When the base data for the entry is pulled from the database, the user ID for the entry’s author comes with it. In order to get the rest of the information about the author, such as their username and email address, another query is performed using the user ID to find the author’s information. Normally, this would all be squashed together with queries to get the comments and the labels and such. But I have chosen to farm out task-specific work to certain methods of the Entries object. For example, the “getUser” method does exactly that - it gets the information for the user who authored the entry. Likewise, the “getComments” method gets the comments, and the “getLabels” method gets the labels. All nice and simple, and all I have to do to put them all together is execute all the methods in rapid successions. In some respects, the methods provide plugin-like functionality similar to the way the Flash plugin adds extra functionality to your web browser (which had better be Firefox (or Safari). Again, we’re talking about separation of parts of code from one another. This is important because, if you have too many pieces of code all intermingling and breeding with one another (okay, maybe not breeding, but it could happen), any attempt to change one of the base pieces of code results in the entire program falling apart, like a house of cards. So you have to be careful.

END

I hope you enjoyed my little outpouring of tutorial goodness, even if it was all on programming theory and not anything practical. I’ll try to put in some practical examples soon.

By the Way

RSS hasn’t been reimplemented. Guess you’ll have to live with my horrible design for a while, then you can go back to your fancy NetNewsWire and FeedDemon and Sage (which I use) and so on. And if you haven’t checked out RSS yet, I highly suggest it. Google for it, and I’m sure you’ll figure it out. No time to talk about it here. Late. Need sleep. *thunk*

Changes in Blogging Style/Format

Friday, January 21st, 2005

As readers will have noticed, I unfortunately can no longer keep up the lengthy, “running thoughts” writing style that I used to use. Two-thousand-word entries are no more. I just don’t have the time. But otherwise, you’ll still get that raw, fresh Brettiness that you’ve come to expect from Organon.

Other Noteworthy Changes

Content

  1. Entries will be divided up with the WordPress ‘more’ tag, conserving space on the front page and making it a quicker download for dial-up users. You’ll have to click ‘Read More’ to see the full entry, but it will be easier to see them all in one glance. No more scrolling!
  2. More HTML will be used to mark up things like this list. Also, I plan on linking everything worthy of a hyperlink. Hypertext is a great medium for writing because you can direct users to other sources in an unobtrusive fashion. I just haven’t been using it as much as I should be.
  3. Smaller entries will be combined into a sort of digest.
  4. A few articles will be published. These will be sectioned off and paginated to make them a bit more professional and easier to read.

Presentation

  1. I promise, I will redesign this blog as soon as I can. The new design will be all of the following:
    • Not compatible with any version of Internet Explorer. Sorry, but I’m tired of dealing with it. My other websites will remain hobbled by IE’s lack of solid support for anything, but for this one I plan on pulling out all the stops: PNG alpha transparency, fixed-positioned elements, perhaps even a horizontally-scrolling layout (with an alternate traditional one for people who can’t handle it). So much is possible when you take IE out of the picture.
    • More refined, with an emphasis on readability. You don’t come here to look at my pretty design. You come to read the blog. Heck, some of you don’t even come here to read - you do it through RSS readers. And that’s okay. But I want to provide a better reading experience, one that gives you a reason to come here instead of reading via RSS.
    • Some freaky colors. Maybe even - wait, I dare not say it…oh, all right: PINK!
  2. I want to improve the metadata for each entry, too. I especially like the way Wired Magazine lays out the information for each article on their website, putting it at the top of the page with a nice description. I also like the clean way that Dan Cederholm, the much-admired web design trendsetter, does the dates for each of his Notebook entries. It used to be that more information was better, but now I think people are moving toward cleanliness, both on blogs and news sites and on corporate ones as well. Sites that are more tailored toward their user’s needs are popular, too. For example, if I go to the Target website, I am presented with hundreds of links and pictures of merchandise. I would much prefer to simply fill out a quick form on my first visit with the categories that I most like to browse and have the website present only items from those categories, with a few random ones thrown in from the other departments. Expect to see some kind of preferences system on Organon as well

Backend

While I love WordPress, it doesn’t do everything that I need it to. And I could write plugins for it, contribute to the community, but I think I’d rather have my own code. Doing it myself would result in a lighter, faster system free from the necessary bloat that comes from having to appeal to the needs of a large user base. And I could implement all those things that I’ve been meaning to implement, like entry labels (rather than categories; inspired by GMail), better statistics (WP doesn’t really have any statistics, or at least not any that I am aware of), and other fun things. And it would be a challenge, one that I have attempted in the past but have never gotten anywhere with. But I am a much more experienced programmer now, so I think actually finishing a blogging system (albeit one with less features than a mature program like WordPress) wouldn’t be too hard.

Not Now, But Soon

While most of these changes are long in coming, I’ll try to roll out the first few as soon as I can. Remember, now that I’m not working on CSHSWeb.com anymore, I’ll have a lot more free time. Hopefully that time will be put to good use.

Linux Virtual Server…Should I?

Friday, January 21st, 2005

A company called Redwood Virtual sells space on its servers for $200/year. But you get much more than just “space.” Using the power of User-Mode Linux, which has to be one of the most awesome Linux apps ever coded, you can run multiple versions of Linux (different distributions, different everything) side-by-side on the same computer at the same time. This is not dual/triple/quadruple booting. This is a realtime, virtual server. Wow. This has certainly got me interested.

Right now, I pay about $100/year for an eight-domain hosting package with most standard hosting features. But with a Redwood Virtual LVS, I could run anything I wanted, from a Half-Life 2 game server to a web server to a file server…the possibilities are endless. The only question is: am I ready for the responsibility of maintaining my own server? If the only thing I was going to put on it was my own website, then it wouldn’t be a big deal. Save for some interruptions in my email, there would be no problem if the server went down because I did something stupid. But if my tiny web design/hosting business grows, I will be managing others’ accounts as well, and losing their data would be catastrophic. Then there’s the fact that I wouldn’t have cPanel or any of the other commercial control panels that I’m used to. While I could probably figure things out and configure stuff myself, my clients would have to always ask me to do things for them rather than change settings themselves in their own personal cPanels. So I dunno…

The main reason that I originally wanted more control was because my current web host, MediaCatch, had not yet moved to PHP 5.0.x, and I wanted to be able to take advantage of PHP5’s new features. But today I learned that they do in fact have a PHP5-enabled server, and all I had to do was ask to be moved to it. (They never announced it.) So I asked, and hopefully they will respond back and say that they can do it. That’s out of the way, finally (been waiting since July for this).

The best thing that I could do is have an LVS and regular hosting, but unfortunately because of financial constraints, it has to be one or the other. I guess I’ll just have to think it over.

Spaminator Rocks!

Thursday, January 20th, 2005

The plugin has blocked about fifty spam comments already. I guess putting the word ’spam’ in an entry is just an invitation for more. To the spammers, I say, “Do your worst.”

Spammed for Hating Spammers

Wednesday, January 19th, 2005

It appears that spambots have become smart enough to search out phrases such as “comment spammed” and comment on those entries. See this one, which I wrote after getting my first round of it. Looks like it’s off to the WordPress Plugin Repository to find a spam blocker.

Update

Kitten’s Spaminator plugin has been installed. Goodbye, comment spammers!

One More Thing

While on the subject of spam, I should note that I had 580 messages in my spam box today. I dunno why they even try anymore; it’s not like I would ever read any of it.