RSS Merge v0.2.0


Description

Typically, printing several RSS feeds from various blogs on a single page is known as aggregation. This script not only aggregates RSS feeds however, it also merges and sorts them by date using the merge sort algorithm. The result is a blog of postings from several blogs.

Requirements
  1. You will need to include the RSS parser class known as lastRSS. Click here to download it from their web site.
  2. Each item must have a pubDate child element. RSS 2 will work, but RSS 1 will not.
Recommendations

This script was written to make use of the Wordpress stylesheet and can be integrated into your current Wordpress blog. Click here for detailed instructions.

Download
Changes

v0.2.0 (2005-02-25)

  • Added support for content:encoded tag to display complete posts.

Author

Brad Touesnard - http://brad.touesnard.com

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Demo

Below is a merging of the RSS feeds from the following blogs:

Posted Monday 8 February 2010 at 6:31 pm in General on sean mcgrath's weblog



7/365 - Medicated (Part 2):

Carrying on with my “medicated” series on this one.

I have had this pill container that looks like a large pill for a while now and seeing it a few days ago is what sparked the idea for this medicated series actually.

This shot was processed with a new photoshop action that I’ve been working on lately that I plan on giving away with my Lightroom presets.

Strobist:
Main light is from a large window camera right.
SB-900 for fill, camera left into 48” lastolite diffuser, trigger with Nikon CLS at -1ev

View my most interesting photos

Become a Fan on Facebook

Follow Me on Twitter

Posted Monday 8 February 2010 at 12:36 am in General on sean mcgrath's weblog



6/365 - Daddy’s Girl:

Just a note: This was shot for a client and is not my baby. :)

Here is a shot you see all the time done with a child and a mother, but I think Dads need to be represented every now and then as well.

Shot with all natural light pouring in through a large window.

This was from a client shoot this weekend so tomorrow I will be getting back to my “medicated” series.

NIKON D90, AF Zoom 24-70mm f/2.8G
f/2.8, 1/250, ISO 800, 52mm

Posted Saturday 6 February 2010 at 3:31 pm in General on sean mcgrath's weblog



5/365 - Medicated (Part 1):

Throughout my 365 I have plans to do little mini series of photos that center around a central theme. My first theme will be “medicated” in an attempt to create some images that have a bit more meaning and emotional response than the current photos in my 365..

This is mainly out straight out of the camera except some contrast adjustments. Underexposed on purpose and had the white balance set to tungsten to create the mood.

Strobist:
SB-900 bounced off wall to camera right to provide a little bit of fill.

NIKON D90, AF Zoom 24-70mm f/2.8G
f/2.8, 1/200, ISO 400, 70mm

Posted Friday 5 February 2010 at 2:23 pm in General on sean mcgrath's weblog



4/365 - Sleepy Hollow:

Just a dead end called Sleepy Hollow. Edited using only my Blueish Awesomeness lightroom preset available here: mcgstudios.ca/presets.html

I’ve really fallen in love with diptychs lately, so expect to see some more of them in my 365

Posted Friday 5 February 2010 at 11:53 am in General on sean mcgrath's weblog



3/365 - Grunge

This shot started as a proof of concept for a shot I plan on taking some other time in my 365 journey. I’m sure this shot has been done a million times before cause it is so easy to do, but I promise I will 1up it at some point in my 365.

I’ve started writing down lots of ideas for things I want to shoot, so assuming I have the motivation for some of them I have enough to keep me going for a while now. I think today I’ll get outside for a change.

Strobist info:
SB900 camera left pointed at ceiling at 1/8 power
SB900 above camera, through ezybox at 1/8 power
Triggered with Skyports.

Posted Wednesday 3 February 2010 at 3:58 pm in General on sean mcgrath's weblog



Damn you Canon for making video on the 7D so awesome!

Into the Wild with Malin on Vimeo (via Vimeo)

Posted Wednesday 3 February 2010 at 2:47 pm in General on sean mcgrath's weblog



2/365 - Feng Shui:

It is day two and I am already feeling the challenge!

If anyone has any ideas of things to shoot, or concepts please feel free to leave them in the comments.

Also, my friend Dave is doing a 365 and off to a killer start. Check his progress at www.davidmacvicar.com/365/

NIKON D90, AF Zoom 24-70mm f/2.8G
f/2.8, 1/160, ISO 200, 24mm

Posted Tuesday 2 February 2010 at 3:32 pm in General on sean mcgrath's weblog



1/365 - Leah and Graham:

Today I start my 365 project. This will be a huge challenge for me. Working from home is really going to be a crutch for me, so hopefully this will inspire me to get out more.

My rules will be slack to help me complete it. I may use photos I took a day or two ago (like in this case) and I will typically post a photo the day after I take it. I am also going to strive for the best images I can and try not to settle for a mediocre shot.

Read more about my project here.

NIKON D90, AF Zoom 24-70mm f/2.8G
f/2.8, 1/125, ISO 200, 52mm

Posted Friday 29 January 2010 at 3:38 pm in General on sean mcgrath's weblog



Another Boudoir:

Strobist: SB-26 into Lastolite Ezybox, camera right. Trigger with skyports.

Posted Friday 29 January 2010 at 2:31 pm in General on sean mcgrath's weblog

““Be like a duck. Remain calm on the surface and paddle like hell underneath.””

- Michael Caine

Posted Friday 29 January 2010 at 1:07 pm in General on sean mcgrath's weblog



I really love this video. The quality beats the pants off of my D90. Really hoping the D700 replacement steps up the video to something like this.

Canon 1D mark IV…maybesomesunwilldomegood on Vimeo (via Vimeo)

Posted Thursday 28 January 2010 at 7:23 pm in General on sean mcgrath's weblog



Just bought a new booked titled Rules for my Unborn Son that is filled will all sorts of great rules to live by.

Posted Wednesday 27 January 2010 at 4:04 am in General on sean mcgrath's weblog



Band Promo Posing 101

Posted Tuesday 26 January 2010 at 12:56 pm in General on sean mcgrath's weblog



whirbangsigh:

A Still

Posted Tuesday 26 January 2010 at 12:54 pm in General on sean mcgrath's weblog



Chris from 16th Avenue. Amazing drummer.

Posted Tuesday 26 January 2010 at 12:52 pm in General on sean mcgrath's weblog



I think I just reached fanboy status.

Posted Tuesday 26 January 2010 at 3:23 am in General on sean mcgrath's weblog



Band Promo Posing 101

Posted Monday 25 January 2010 at 2:08 pm in General on sean mcgrath's weblog



What a Mess:

I’ve never laughed so hard during a shoot in my life. This is my friend Mike. You may recognize him from this photo: www.flickr.com/photos/mcgraths/3289448299/

This started out as a simple exercise of me teaching him how to use off camera flashes, and quickly turned into this.

Mike made a good point that my Flickr stream is really all over the map, and he is right. Photography is something that is still new to me, and I’m still trying to find myself as a photographer, so in the process I am literally trying out EVERYTHING. Hopefully someday the experimentation will die down and I’ll emerge with a certain style and vision, but until then hang on and enjoy the ride.

Strobist:
SB-900 high camera right through ezybox, 1/8 power
SB-900 camera left bounced off a hanging white bedsheet, 1/16 power
SB-26 above subject for hair light, 1/32 power i think
Trigger with skyports, SB-26 trigger optically

NIKON D90, AF Zoom 24-70mm f/2.8G
f/8, 1/100, ISO 250, 70mm

Posted Saturday 23 January 2010 at 5:52 pm in General on sean mcgrath's weblog



Badger & Blade:

I recently started shaving this way and, wow, what a difference. Shaving is now a more enjoyable experience for me.

Strobist:
Nikon SB900 fired into 48” gold reflector, camera right. Triggered via CLS. 0ev.

NIKON D90, AF Zoom 24-70mm f/2.8G
f/4, 1/100, ISO 640, 40mm

Posted Friday 22 January 2010 at 2:48 pm in General on sean mcgrath's weblog



Craig:

Here’s a shot of my friend Craig taken at a local pool hall.

It is shots like this that make me love shooting at high ISO on my D90. This was shot at ISO3200 and only editing was the black and white conversion in Lightroom.

Posted Thursday 21 January 2010 at 8:57 pm in General on sean mcgrath's weblog

Medium Format Love:

It is photos like these that inspire me to want a medium format film camera. Each one of these is truly remarkable.

Posted Thursday 21 January 2010 at 5:09 pm in General on sean mcgrath's weblog



Been drooling over medium format cameras lately. Maybe I’ll get one in the summer.

Yashica 24 TLR (via purplemattfish)

Posted Thursday 21 January 2010 at 12:07 am in General on sean mcgrath's weblog

Really been tweaking my photography workflow lately, since what I had before was a mess and wasn’t really working for me. After finding the amazing tool Photo Mechanic my workflow is much faster now. My newest workflow is as follows:

1. Ingest photos on memory cards with Photo Mechanic to my “In Progress” folder under a folder for the project.

2. Photos are renamed and sequenced while ingested.

3. Add IPTC metadata and GPS information to photos once ingested.

4. Use Photo Mechanic to weed out the throwaways and delete them from disk.

5. Create a new Lightroom catalog in the project folder.

6. Import all keeper photos.

7. Process photos accordingly using Lightroom and Photoshop.

8. Export the best photos to my master Lightroom catalog as full resolution JPGs* where they are tagged appropriately.

9. Archive the project folder to redundant storage.

* Done to keep the size down, as well as to force me to make any future edits in the original Lightroom project

Posted Wednesday 20 January 2010 at 5:46 pm in General on sean mcgrath's weblog



Such an amazing shot for such a simple lighting setup.

Caylen (via christianyves)

Posted Thursday 3 September 2009 at 10:02 am in Portfolio on bradt.ca

A Place of Mind is a web site created for the University of British Columbia to aggregate their content from a variety of online sources like YouTube, Flickr, Twitter, and blogs. The site is configured to pull feeds from these sources and import specially tagged posts. The impressive creative work was produced by Fjord Interactive, who delivered wireframes and a PSD. I was charged with converting the PSD to a working Wordpress theme and coding the custom Contribute form and feed importer. Visit the site »

Posted Monday 31 August 2009 at 11:52 pm in Articles on bradt.ca

I received this amusing Firefox error message when opening Firefox this morning. The strange thing is that Firefox still let me load all my tabs from the previous browsing session, so I’m not sure if there was actually a problem. I upgraded an extension as I was opening, but I’m not sure if it was related.

I’ve been very happy with Firefox 3.5 and enjoying the speed improvements.

firefox-error-embarrassing

Posted Wednesday 22 July 2009 at 12:38 am in Portfolio on bradt.ca

I got involved with the Pirate Party of Canada simply by participating in the discussion forums early on. I then took on the role of establishing the brand, creating a web site design, and developing a Wordpress theme. Visit the site »

Posted Saturday 18 July 2009 at 12:37 pm in Articles on bradt.ca

After a lot of debugging, I was able to figure out that Media Temple’s (dv) configuration was responsible for the “Missed schedule” errors I was getting in Wordpress.  By default, the /etc/hosts file looks like this:

127.0.0.1  yourdomain.com yourdomain localhost localhost.localdomain

To execute cron tasks, Wordpress needs to post to the URL http://yourdomain.com/wp-cron.php?doing_wp_cron. This isn’t usually a problem, but with the above hosts file and Plesk’s Apache configuration, that URL will actually result in a 404 error.

I tried removing yourdomain.com and youdomain from the hosts file:

127.0.0.1  localhost localhost.localdomain
Unfortunately, when you restart the VPS using Virtuozzo in Plesk, yourdomain.com and yourdomain will just be added back in.  However, after some exhausting Google searching I found out that you can just move them down to the next line with the proper IP address:
127.0.0.1  localhost localhost.localdomain
xxx.xxx.xxx.xxx yourdomain.com yourdomain

Now when you restart the VPS, these changes to the hosts file will remain.

I looked at several other possible solutions to fix the “Missed schedule” problem.  One solution was setting the “ALTERNATE_WP_CRON” constant in the wp-config.php:

define('ALTERNATE_WP_CRON', true);

This activated some very messy redirecting for the user as they browsed the site though.  Not a great solution.  Another solution I was considering was just executing wp-cron.php from a cronjob every hour. Something like this:

0 * * * * /home/yourdomain/htdocs/wp-cron.php >/dev/null
Posted Wednesday 15 July 2009 at 2:29 am in Portfolio on bradt.ca

I was contacted through this web site by Ash Conway and quickly started working with him to help shape what has become SmokinApps.com, a web site featuring mobile app reviews and ratings. Although Ash handled the majority of the design work, I helped him refine it, providing feedback to improve the user experience. My primary role however, was to develop a custom Wordpress theme and integrate Wordpress plugins into the site. Visit the site »

Posted Monday 6 July 2009 at 3:15 am in Articles on bradt.ca

sharurlLast year around this time I decided to pursue an idea for a simple file sharing service without any real planning. Although it shouldn’t have taken more than a few months of part-time work, I just managed to launch SharURL today (you will need this invite code to signup: p9q1h). I made a lot of mistakes along the way and the following are a few of the lessons I learned.

Define requirements

I must have thought it would be a waste of time defining the requirements of such a simple system. I was wrong. At least half of the time I spent developing SharURL involved adding, removing, and reworking features. Features that could have been thought out and fully defined in writing from the beginning.

No matter how simple the project appears to be, define it in detail before jumping into design and development. After all, if the project is so simple, it won’t take long to write out the requirements.

Avoid scope creep

Even if you have defined requirements, it’s a slippery slope when you start making exceptions mid project. It’s surprisingly easy to believe that the project will fail if such and such a feature isn’t incorporated. Then another feature becomes essential to success, then another. With user experience carrying so much weight these days, these feelings can be difficult to ignore.

“It’s going to annoy users if we don’t have this feature.”

It’s important to accept that the system will never be perfect. Establish requirements from the beginning and stick to them. When you get the feeling that a feature outside the scope is essential to success, write it down. Make it a “Phase 2″ feature. It will help alleviate the feeling and allow you to continue focusing on the initial requirements.

Decide on a business model

Getting bought out by Google is not a business model. But it is the backward mentality I started with. The plan was simple: give everything away for free, gain a massive user base, and get bought by some conglomerate or at least get the attention of investors. If it worked for Facebook, YouTube, and MySpace it can work for me.

Around the end of 2008, I listened to a talk by David Heinemeier (Ruby on Rails / 37signals) that really opened my eyes. I realized I had gotten caught up in the hype of getting bought out instead of figuring out the value of the service and charging a price.

The free model is an especially bad plan when the service involves giving away storage space and bandwidth. It’s expensive. Who is going to front the cash in the beginning? As Heinemeier says, “It’s not rocket surgery.” If your app is great, people will pay to use it. Just charge a price.

Design is important

Usually I start a project with design. Work things out in Photoshop then jump into coding. When I started building SharURL I decided to ignore design and go right into coding. This was a mistake.

It turns out the design phase really helps flush out bad ideas, reshape poorly thought out ideas, and generate new ideas that can be shelved for later.  It is especially helpful when there is no established requirements.

One project at a time

“Bah, I think I’ll write a framework too.” On a whim I decided that as I was coding SharURL, I would build a framework that would appeal to Wordpress developers. It turns out writing a tidy, generic framework ready for public consumption as part of a project is very distracting to that project. Juggling two different sets of priorities splits focus, hinders progress, and likely sacrifices quality. Prioritize the sets of priorities. Focus on one set of priorities until they are complete and tackle the rest later.

During SharURL’s development, I built and released a Facebook application and made some progress redesigning thesimpsonstrivia.com (still in progress). If you’re as spastic as myself, the urge to start a new project can be difficult to control. If you build web sites as your day job, you just have to keep reminding yourself that you don’t have enough spare time for multiple projects. When you get the urge to start something new, it may help to take a deep breath or get off the computer for a bit.

Don’t be afraid of launch

Every time I thought about launching SharURL I worried. I worried that people would think its a dumb idea. I was worried no one would use it. Fear of rejection and failure is something every entrepreneur faces sooner or later. But good entrepreneurs persevere. They reassure themselves it is a great idea. It will succeed. By all means welcome constructive criticism, but ignore the naysayers.

While building SharURL, I also worried that I wouldn’t be able to afford to pay the bills as I gained a massive user base. If it is ridiculous to worry about failing, its even more ridiculous to worry about being too successful. You’re in control. You can turn off signups whenever you like. You can control the growth of the service with an invite-only system.  If you’re app is great, slowing down growth is not going to result in failure.

Despite being unhappy with the design, unsatisfied with the user experience, and the fact that users can’t even update their account details yet I have launched.  There’s probably three dozen other things that I would like to have done before launching, but the reality is they aren’t necessary to launch. SharURL works great for sharing files.  The rest of the features are nice-to-have.

About SharURL

SharURL is a convenient way to share files with friends and family. You simply open your web browser to sharurl.com, click the big blue button, and select files from your computer. Then you watch as your files are uploaded, packed into a zip file, and a short, unique URL is created for you to share.

The idea was born when I asked a friend to send me their photos, to which they replied “I’ll just burn you a CD.” It seemed ridiculous they would need to burn a CD, but when I looked into it there weren’t great alternatives. There were file sharing services that allowed you to upload a single file at a time and others that involved installing software, but nothing as convenient as what I had in mind. So, with plenty of room in the file sharing market, I dove in and here we are a year later.

Be sure to subscribe to the SharURL blog or follow @sharurl on Twitter for feature announcements, etc. I won’t be cross posting here.

Posted Sunday 5 July 2009 at 10:57 pm in Portfolio on bradt.ca

After about a year in sporadic development, I finally managed to launch a startup called SharURL, enabling people to easily share large files like photos or video. I came up with the concept for SharURL after hearing a friend say they would burn a photo CD to share photos. SharURL was built on a custom PHP/MySQL framework I developed for the project. For more details behind the development of SharURL, see my blog post Developing SharURL: Lessons learned developing a new startup. The site is currently in invite-only beta, so the following invite code is needed to signup: p9q1hVisit the site »

Posted Thursday 25 June 2009 at 6:57 am in Articles on bradt.ca

The latest article by Rands, “A Toxic Paradox“ struck a cord with me.  It describes three basic types of personalities/relationships in the office: those that are natural, those that require work, and those that are toxic.

When asked a simple question, a toxic person would burst out:

THIS ISN’T A SMALL CHANGE. YOU HAVEN’T THOUGHT THIS THROUGH. WHY WASN’T I CONSULTED EARLIER? HOW COULD WE CONSIDER THIS GIVEN WHAT I SAID 14 MONTHS AGO ON THIS VERY TOPIC WHEN I WAS IGNORED…

You just have to scroll down to the comments to see that this resonates with a lot of people.  But not managers. People who believe they are or have been the toxic offender.  People who thought they fit the culture of an organization, started out great, then went sour and burst out with similar statements.

This reminded me of a tricky thing about organizations that I’ve experienced: subcultures.  Often times the subcultures appear between business units.  You could find yourself in a group of creative, novelty t-shirt wearing, environmentally conscious people who share the same ideals.  Yet 70% of your time is devoted to dealing directly with the members of another business unit and their distinct subculture.  Your group really values going out for Friday lunch and relaxing after working hard all week, yet the other group periodically schedules meetings around noon on Fridays.  The other group frowns upon your novelty t-shirts as inappropriate office attire and you scoff at their sweater vests.  They love their gas guzzling SUV and you love the cycle home from work.

It can be difficult for members of these groups to spend 70% of their time interacting with one another and in such situations it is a good idea to put a distance between them.  Maybe appoint a liaison from each group, someone who is responsible for communication between the two groups and funneling all communication through them.  Putting a physical distance between the groups may help as well.

When looking at an organization from the outside, it can be very difficult to spot subcultures as well.  You could accept a job offer at company that you believe aligns with a majority of your ideals, only to end up in a group that doesn’t.  It is most important to know the people who you will be dealing with daily and focus on them. Interview them, Google them, do to what it takes to find out what culture they belong to.  Don’t assume you know the people because you know the company.

Posted Wednesday 17 June 2009 at 7:27 am in Portfolio on bradt.ca

Flippa is an online auction house for buying and selling web sites and domain names. Although Flippa is sort of a startup, it is actually a spinoff of the SitePoint Marketplace. Working directly with SitePoint co-founder Mark Harbottle, I was charged with developing a new brand and designing the interface for the new web application. In 13 days, I produced 32 mockups and refined the user experience for the entire application.

My role in this project was strictly user experience design. I handed off Photoshop files and a style guide and the SitePoint team handled the rest.  Check out the mockups above and compare with the live site.

Posted Monday 8 June 2009 at 5:36 am in Articles on bradt.ca

Have you ever had the pleasure of reading PHP code with lines and lines of HTML jammed into strings and a ton of escape characters? I have. In fact, a lot of Wordpress plugins are guilty of this. Perhaps you’re guilty of it yourself?

This article will show you how to separate your HTML markup from your PHP code using only a few simple lines of PHP — something I’ve been calling “micro templates.”

For this article, I rummaged through my ancient projects to find an authentically bad snippet of code. It didn’t take long to find. The following snippet I pulled from Uncultured.com, a custom blogging system I built nine years ago:

Snippet #1

<?php
function printMenu($menu_items) {
    echo "
    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
        <td class=\"borders\">
            <table border=\"0\" cellpadding=\"3\" cellspacing=\"1\">";

            for ($i = 0; $i < count($menu_items[0]); $i++) {
                echo "
                <tr>
                    <td class=\"buttons\">»</td>
                    <td class=\"buttons\"><a href=\"" . $menu_items[0][$i] . "\">" . $menu_items[1][$i] . "</a></td>
                </tr>";
            }

            echo "
            </table>
        </td>
    </tr>
    </table>";

} // end printMenu
?>

The above PHP code isn’t too awful, but it does violate a best practice rule that I’ve adopted since: Avoid placing blocks of HTML in a string. Placing HTML in a string as demonstrated in the code above is unmanageable. All the double quotes need to be escaped, embedding variables is not very elegant, and it’s just ugly to read.

Of course, the alternative to echo’ing strings is simply to use PHP’s embed tags <?php ?> In fact, that’s what they were designed for! Using PHP embed tags, the above code becomes the following:

Snippet #2

<?php
function printMenu($menu_items) {
    ?>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td class="borders">
            <table border="0" cellpadding="3" cellspacing="1">

            <?php
            for ($i = 0; $i < count($menu_items[0]); $i++) {
                ?>
                <tr>
                    <td class="buttons">»</td>
                    <td class="buttons"><a href="<?php echo $menu_items[0][$i] ?>"><?php echo $menu_items[1][$i] ?></a></td>
                </tr>
                <?php
            }
            ?>

            </table>
        </td>
    </tr>
    </table>
    <?php
} // end printMenu
?>

Much better! Now, let’s say our requirements have changed and our printMenu function is now a getMenu function and needs to return the HTML as a string. My former self (from nine years ago) probably would have just replaced the echo statements from the first snippet with a string concatenation, like this:

Snippet #3

<?php
function getMenu($menu_items) {
    $out = "
    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
        <td class=\"borders\">
            <table border=\"0\" cellpadding=\"3\" cellspacing=\"1\">";

            for ($i = 0; $i < count($menu_items[0]); $i++) {
                $out .= "
                <tr>
                    <td class=\"buttons\">»</td>
                    <td class=\"buttons\"><a href=\"" . $menu_items[0][$i] . "\">" . $menu_items[1][$i] . "</a></td>
                </tr>";
            }

            $out =. "
            </table>
        </td>
    </tr>
    </table>";

    return $out;
} // end printMenu
?>

Unfortunately, this has the same problems as the first snippet plus it suffers from the inefficiencies associated with string concatenation. From my limited experience with C programming, I know that every time a string is concatenated, a memory reallocation operation is executed which is a relatively expensive operation. Some programmers would do something even worse (I’ve seen it many times), building a string for each line of HTML, like this:

Snippet #4

<?php
function getMenu($menu_items) {
    $out = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
    $out .= "<tr>\n<td class=\"borders\">\n";
    $out .= "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\">\n";

    for ($i = 0; $i < count($menu_items[0]); $i++) {
        $out .= "<tr>\n<td class=\"buttons\">»</td>\n";
        $out .= "<td class=\"buttons\"><a href=\"" . $menu_items[0][$i] . "\">" . $menu_items[1][$i] . "</a></td>\n";
        $out .= "</tr>\n";
    }

    $out =. "</table>\n</td>\n</tr>\n</table>\n";

    return $out;
} // end printMenu
?>

This code just gives me the urge to smack the developer who wrote it. They’re trying to “clean up” the code by adding even more string concatenations. This code is just awful. In addition to being a nightmare to read, with an increased number of string concatenations, it is horribly inefficient.

So, ideally we want to use embed tags <?php ?> (Snippet #2) and somehow return a string of the output. But how do we do that? Output buffering is the answer. And the surprising thing is that it is painfully simple. Basically, we just take Snippet #2 and add ob_start() to the beginning of our function and ob_get_clean() at the end.

Snippet #5

<?php
function getMenu($menu_items) {
    ob_start();
    ?>
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td class="borders">
            <table border="0" cellpadding="3" cellspacing="1">

            <?php
            for ($i = 0; $i < count($menu_items[0]); $i++) {
                ?>
                <tr>
                    <td class="buttons">»</td>
                    <td class="buttons"><a href="<?php echo $menu_items[0][$i] ?>"><?php echo $menu_items[1][$i] ?></a></td>
                </tr>
                <?php
            }
            ?>

            </table>
        </td>
    </tr>
    </table>
    <?php
    return ob_get_clean();
} // end printMenu
?>

Adding ob_start() starts the output buffer before any of the HTML in our function has been output. Now anything we try output (using echo or embed tags) gets stored in the output buffer. After we’ve captured all our output we can retrieve it from the output buffer using the ob_get_contents() function or ob_get_clean() which gets the buffer contents and clears the buffer.

Output buffering is also a handy way of creating “micro templates” in your PHP applications that don’t have the luxury of a full fledged template engine. The following function simply takes a file as an argument and returns a string containing the output generated by that file:

Micro Template Function

<?php
function get_template($file, $vars = array()) {
    ob_start();
    if (file_exists($file)) {
        include($file);
    }
    return ob_get_clean();
}
?>

Because we’re including the template file within a function, variables from the caller are not available. The optional argument $vars allows you to pass in an array of values from the caller for use in the template file.

I often use micro templates when developing Wordpress plugins. They work great in these situations where one of the goals is to keep the overhead low. For large applications I would still recommend using a strong template system like Smarty.

Posted Tuesday 6 February 2007 at 1:24 pm in General on Pierre Grandmaison Personal Blog

After two years of working my finger muscles, I have decided to finally get out and start working out with my fiance Melissa and my friend Allain. At this old age we’re getting, we figured it’s time to get in shape to stay healthy :D
Look for us at the 2010 olympics in the weight lifting division!!!

Posted Tuesday 6 February 2007 at 1:16 pm in Events on Pierre Grandmaison Personal Blog

The farthest I had been so far in my life was Edmonton Alberta. Well, in less than 2 weeks I’ll be heading further to Victoria, BC and Vancouver, BC to go visit a nice customer we have over there. What’s nice is that I think it’s been a couple years since I saw Brad, it’s about darn time we meet again after running Zenutech successfully all these years.
It should be pretty interesting.

Posted Tuesday 6 February 2007 at 1:09 pm in Computers on Pierre Grandmaison Personal Blog

Just thought I’d write a litle something on the new laptop I aquired last week on a dell business lease.
I went for the Inspiron 9400 for maximum screen space (17 inch). I can never seem to have enough screen space, especially on a laptop.
I think it will last me for a good 3 years with the specs I upgraded to. (2 GB RAM, etc)
I will be mostly useful on my trips when I visit my parents and business trips, as carrying my desktop had become way too pain-in-the-butt.

Dell Inspiron 9400

It’s definitely not the most liteweight laptop though, but that’s the price to pay when you want 17 inch.
Brad tried to convince me on a mac. I dunno but I don’t think I’ll ever be able to switch over. I hate having to learn how to re-use a computer. Same like Ill likely have a hard time upgrading to windows vista. I use my computer for getting work done, and I don’t really care how windows stores my pictures :)

Posted Sunday 4 June 2006 at 2:41 am in General on Pierre Grandmaison Personal Blog

Well, it’s about that time of the year to get in shape…
So I’ve joined the Fredericton Ultimate league, and the Fredericton Beach volleyball league.

It looks like it’s going to be lots of fun. Melissa’s also on the ultimate team. Oh and we won our first ultimate game of the season…we played amazing. Go Deep Throat go! (Hey, I didn’t pick the name, don’t blame me!)

Unfortunately, I wasn’t so luck on the sand playing volleyball. Our team took a loss against one of the best teams of the league. We’ll try again next Monday against a likely-to-be less-experienced team.

Posted Sunday 4 June 2006 at 2:27 am in Zenutech on Pierre Grandmaison Personal Blog

Brad and I have been working very hard in the last couple months to continue to improve both our business and its services.
We’ve recently launched a new front page on our web site as an effort to convert more visits to sales. We both believe that this new front page better showcases the great features of Zenutech.

We’ve also recently entered in several new marketing campaigns and things are looking great so far. The ROI so far has been attained, and it can only be surpased once WOM kicks in (word of mouth)

In the last month, we’ve purchased a new server and a new cisco switch. Next week I’ll be going to Montreal and we will be moving all servers to a new data center (Canix 2) where a brand new room with new cabinets are waiting for us. The current data center has run out of room and we don’t have space for new servers!

We have several greats things on the horizon for Zenutech:

1) Migration to a BGP4 high quality network. This will be a great improvement in redundancy. Currently, we rely on the high quality peer1 bandwidth solely. In the new BGP4 infrastructure, we will be receiving bandwidth from multiple high quality providers (to ensure we stay up if one provider such as peer1 is down)
2) Addition of PHP5, FastCGI and Ruby on Rails (oooooohhh , yes Brad - it’s coming!)
3) Addition of JSP/Java servlet hosting services
4) New features in the control panel
5) Addition of Windows Web Hosting coming soon as well

The addition of all these improvements will obviously span several months, but that is what’s hapenning at Zenutech!

Posted Sunday 29 January 2006 at 3:42 am in General on Pierre Grandmaison Personal Blog

Bungee Jumping

As I havn’t posted since I started this blog, I figured I would give a summary of the year 2005.
The fun really started in the summer. The summer in Ottawa with my girlfriend and a great group of co-ops was an absolute blast. Events like beach volleyball, busriding, bungee jumping, swiming in the coldest lake ever, more bus riding, almost playing golf, go kart racing in pooring rain & thunder and lightning & more… all in good fun.
Oh and did I mention the parties and poker tournements? Poor Alan at Showfields, a little too much drinkin’ huh? I hope you’ve recovered by now!

I am posting a bunch of pictures from 2005 in the pictures section. Feel free to look.

Posted Thursday 7 July 2005 at 2:13 am in General on Pierre Grandmaison Personal Blog

Some updates under way:
- fixing the pictures section a little more the way I want it
- Post pictures
- Doing a better Contact page

So it’s coming along…

Posted Sunday 3 July 2005 at 5:08 am in General on Pierre Grandmaison Personal Blog

Set your alarm for a couple days in the future, and when it goes off, come back here.

It’s not ready yet!