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 Saturday 13 March 2010 at 1:31 am in General on sean mcgrath's weblog



35/365 - White Mountains:

Well I finally have some downtime on this trip and thought I’d post a few pictures to catch up on my 365. I have a photo for everyday I’ve been away, which is better than I thought I’d do. Now I just need the time to upload the all.

The views here are really breathtaking. Carrie and I rented a snowmobile and drove it up through the mountains, where I snapped this shot. Snowmobiles are scary scary machines, and I think I’d be happy to never ride one again.

You can see Mount Washington in the upper left of this picture.

Once I am back on Sunday, I’ll be stopping by all your streams to catch up on all the great shots I’ve missed the last week.

Posted Saturday 13 March 2010 at 1:30 am in General on sean mcgrath's weblog



34/365 - Tom Yum:

Well I finally have some downtime on this trip and thought I’d post a few pictures to catch up on my 365. I have a photo for everyday I’ve been away, which is better than I thought I’d do. Now I just need the time to upload the all.

We ate at a really great Thai place in North Conway, and had some really great natural light at our table so I snapped a shot of my favorite soup.

Posted Saturday 13 March 2010 at 1:26 am in General on sean mcgrath's weblog



33/365 - The Lamp Post

Well I finally have some downtime on this trip and thought I’d post a few pictures to catch up on my 365. I have a photo for everyday I’ve been away, which is better than I thought I’d do. Now I just need the time to upload the all.

I snapped this shot while I was waiting for Carrie, who was shopping.

Posted Thursday 4 March 2010 at 1:40 pm in General on sean mcgrath's weblog



31/365 - Escape:

Really had no idea what to shoot for today’s shot, so just ended up doing a simple self portrait.

Tomorrow, I leave for vacation for over a week so my 365 may not get updated for a while. I plan on taking the photos everyday, but I have no idea if I will have internet or not.

Thanks to everyone who has been following my 365 so far! I’m very happy to have made it this far already!

Strobist:
Bare SB900 directly to the right of the subject. 1/64 power.

Posted Wednesday 3 March 2010 at 3:51 pm in General on sean mcgrath's weblog



30/365 - Don’t Move:

I’m kind of cheating on this one since it is the from the same shoot as yesterdays photo, but I really liked it so here it is.

Strobist:
SB-900 into DIY screen (see comments below), zoomed to 200mm, 1/32 power.

Posted Tuesday 2 March 2010 at 1:44 pm in General on sean mcgrath's weblog



29/365 - Confession:

I had this idea for a while, and tonight as I was setting it up for a self portrait…my beautiful wife (who is pretty shy in front of the camera) volunteered to be my model! Lucky me, as she gave me lots of great shots! I’ll post a few more in the comments.

I actually had to build the screen that the light is going through. It is made from gutter filters from Home Depot. See the setup shot in the comments below.

Strobist:
SB-900 into DIY screen (see comments below), zoomed to 200mm, 1/32 power.

Posted Monday 1 March 2010 at 1:20 am in General on sean mcgrath's weblog



Hunny, dry those tired eyes.

Posted Monday 1 March 2010 at 1:18 am in General on sean mcgrath's weblog



Trophies.

Posted Sunday 28 February 2010 at 4:04 pm in General on sean mcgrath's weblog



27/365 - Two Towers and a Murder

Posted Saturday 27 February 2010 at 2:35 pm in General on sean mcgrath's weblog



26/365 - Shoot Pictures, Not People:

My dad just recently gave me this pin that he found in his old camera bag from the 70s, I really liked it so I thought I’d make it a 365 shot.

Posted Friday 26 February 2010 at 1:09 pm in General on sean mcgrath's weblog



25/365 - The Perfect Cup:

Following yesterday’s shot of tea leaves, I thought I’d share the tea in it’s final state.

My last white backdrop for a while, I promise.

Strobist:
SB-900 into lastolite diffuser panel, behind subject.

Posted Thursday 25 February 2010 at 1:27 pm in General on sean mcgrath's weblog



24/365 - Liquid Heaven:

Hi my name is Sean, and I am a tea addict.

There is no question that I love tea and drink several cups every day, so I thought it was only fitting that I do a few shots in my 365 of my preffered beverage of choice.

This tea is one of my favorites, a green tea called Jasmine Dragon Pheonix Pearls from Teavana.

I shot this particular shot so I could use it as a destop wallpaper, so feel free to grab the large size and do the same! Grab an alternate version here if you have 2 monitors: flickr.com/gp/mcgraths/PV8dQ1

Strobist:
SB-900 into ezybox camera left
SB-900 into diffuser panel in the background
Sheet of white paper camera right for fill
Triggered with skyports

Posted Wednesday 24 February 2010 at 8:21 pm in General on sean mcgrath's weblog



Posted Wednesday 24 February 2010 at 8:19 pm in General on sean mcgrath's weblog



She’s gorgeous. I’m lucky.

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



23/365 - Shadowplay:

This photo is largely inspired by this shot taken by a friend.

I didn’t want to texture this shot, but the wall in this photo was so rough and terrible I had to cover it up some how! ;)

Strobist:
SB-900 far camera left, at 200mm, triggered with skyports

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



22/365 - The Mixed Tape:

This is my tribute to the once mighty mixed tape.

There is just something about making a mixed tape that you don’t get today with burnt CDs and MP3 players. The amount of work it took in finding the songs, aligning them and planning the tape so that you could get the most music on both sides. Not to mention, the recording was done in REAL time! For those who’ve never made one…it would take a couple hours to plan and make a good mixed tape.

Then there was that first listen once it was finished that made all the hard work totally worth it.

Strobist:
SB-900, bare camera right, zoomed to 200mm, triggered via CLS

Posted Tuesday 23 February 2010 at 12:38 pm in General on sean mcgrath's weblog



21/365 - Jackalope

View On Black

This is my brother inlaw Jack. I had this idea for a funny portrait and knew he was the perfect one to pull it off. Of all the portraits I’ve done I think these are some fo the best at capturing the subject’s personality.

Turns out balancing antlers on your head is next to impossible, so that is why he is up against the wall in 2 of the photos.

Strobist:
Single SB-900 into Ezybox high overhead camera at 1/32 power. Triggered with Skyports.

View my most interesting photos | Become a Fan on Facebook | Follow Me on Twitter | Tumblr

Posted Tuesday 23 February 2010 at 11:54 am in General on sean mcgrath's weblog



Posted Tuesday 23 February 2010 at 12:44 am in General on sean mcgrath's weblog



A summer ago

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





A few snaps that were 365 contenders from the other day. Taken uptown Saint John.

Posted Monday 22 February 2010 at 5:12 pm in General on sean mcgrath's weblog



Amazing cover of a great song.


Bon Iver — Your Love (Cover) (via jack02051990)

Posted Sunday 21 February 2010 at 3:37 pm in General on sean mcgrath's weblog



20/365 - The Changing Room:

I thought I’d mix things up a little bit and post an iPhone photo today.I’ve been shooting a lot on 4 different formats lately so I’d like to try and incorporate as much variety as possible.

Those four formats are: Nikon DSLR, iPhone, Medium Format film, and a Fuji Instax

This shot was taken while I was waiting for my wife in the changing rooms, and processed use the ShakeItPhoto iPhone app.

Posted Saturday 20 February 2010 at 4:07 pm in General on sean mcgrath's weblog



19/365 - Another Scan:

Another scan from my first roll today. This will be my last til the next roll comes in.

I’m not sure why I like this picture so much, just something about it. I can’t really see anyone else liking it, so really this one is just for me.

Yashica 124 - Fuji Pro 160S - Medium Format - No post at all

Posted Friday 19 February 2010 at 3:41 pm in General on sean mcgrath's weblog



18/365 - Atticus on Film:

Finally shot my first roll of film ever (other than when I’d use my parents film as a child), and I must say I’m pretty happy with the results. The photos aren’t mind blowing or anything, as I just shot them quickly so I’d be able to see if the camera was actually working. I am just happy that they turned out, and that I know that the old camera I bought on eBay actually works!

The camera is a Yashica Mat-124 medium format TLR. The first roll I used was Fuji Pro 160s. I had it processed and scanned at a local lab.

You can see a few more shots from my first roll over here: mcgraths.tumblr.com/post/398490015/first-roll

Yashica 124 - Fuji Pro 160S - Medium Format

Posted Friday 19 February 2010 at 3:34 pm in General on sean mcgrath's weblog



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!