Matt Hines Development

Matt Hines.
Sys Admin/DevOps and developer.
This blog is mainly to display my different projects, as well as a place for me to share and discuss technology news and interests.

Recent Tweets @MattDevUK


So, sometimes you feel the need for a quick way to print a database table as HTML in order to get something done, or to verify the output of a query. Since I’ve struggled with this quite a lot of times I’ll leave a function here that helps quite a lot.


 * This function takes a array that it will output as  element containing 
 * @param mixed[] $row
function print_row($row) {
    foreach($row as &$cell) {$cell = sprintf('<td>%s</td>', $cell); }

    $out = '<tr>';
    $out.= implode(PHP_EOL, $row);
    $out.= '</tr>';

    return $out;

 * You will need to pass an array of arrays to this element. Just like the one
 * PDOStmt::fetchAll() gives you.
 * @param mixed[][] $assoc
function print_table($assoc) {
    $fields = array_keys(reset($assoc));

    foreach($assoc as &$row) {$row = print_row($row); }

    $out = '<table>';
    $out.= print_row($fields);
    $out.= implode(PHP_EOL, $assoc);
    $out.= '</table>';

    return $out;

Simply copy and paste the functions into a simple php file and call echo print_table($stmt->fetchAll()) wherever you need it in your code.

These functions are pretty basic and do not recognize what you’re throwing at them when you pass wrong args. Right now they require an array that is declared like this.

$array = Array( Array('a' => 1, 'b' => 2), Array('a' => 'a', 'b' => 'c') );

I’ve used this kind of function a ton of times when debugging databases since the output is much cleaner than whatever print_r() is able to produce. You can always use some classes or styles in the declarations if you need it.

In case this function is making any non-sense just let me know via my ask box and I will do my best to help.

Spent my day battling with variable scopes in Puppet. I must have been trying to do something totally unconventional for it to be so difficult. Finally at around 7PM I had found another way and fully implemented it to production.

Maybe it’s something I will revisit at a later date if I have free time, to see exactly how to get what I was trying, working, and if it is indeed a good idea or the best way to achieve it. But for now, the alternative works fine :)



Okay so I’ve been a bit behind with these updates. It’s hard to do so when I don’t have my apartment to live in with decent internet :(

Luckily there’s not too much to update, mostly been focusing on setting up the PuppetDBQuery module and working out how best to use it in our scenario. That seems to be done and working now. One thing I did notice, which I believe to be an issue with PuppetDB, was that overnight our Puppetmaster process increased it’s RAM usage consistently until bu the morning it was high enough to stop itself from successfully updating it’s own catalogue. After stopping the process and letting it release it’s resources it seemed to keep itself under control again and right up until now, 10PM the following night, it seems to be working fine so maybe it was just a one-off glitch but will have to keep it in mind in the next few weeks.

Not related to either of the above points, but one issue had to deal with lately was the particular syntax for selecting an array item with Puppet.

If it is being used in an ERB template the correct format is <%= @array_name [0] %> The important part being the space between the array name and the index. If this space does not exist, then the parser will not be able to read the variable and will leave it blank.

If the variable is being used via string interpolation, the correct format is $variable="${arrayname[0]}". The important part being the lack of the space between the array name and the index. I found, especially when using Puppet’s host resource, that if you put a space, it will fail to read the variable properly and leave it empty, throwing an error if used as the ip property.

The final scenario I came across, was if you were using string interpolation to generate another array. this one sounds a bit complicated so I’ll show an example.


Is this situation, it doesn’t matter if there is a space or not between the array name and the index.

These aren’t complicated things to remember but if you don’t know about them and suddenly after an update everything’s going crazy and you’re staring at one of them going “but it looks perfectly fine” you’ll kick yourself if it comes down to a simple space in the wrong place!

I don’t think there’s anything more to update you guys on.

I will say, that tomorrow (Thursday 24th) there is a webinar conducted by PuppetLabs to explain and explore the new features in Puppet Enterprise 3.3 - Link

There is also a webinar by Atlassian tomorrow too, about using Git for Continuous Integration - Link

Sorry guys, it’s really hard to remember to do these updates when I have little to no internet or access to a PC >_< I’ll try do one today before I leave work, and I’ll incorporate the last couple of days too D;


I watched a really good presentation on InfoQ from QCon San Francisco Called “Cooperation, Collaboration, and Awareness”. The guy presenting was John Allspaw, and he is the VP of operations at Etsy (a popular web startup), and formally Flickr:

Cooperation, Collaboration, and Awareness



Computer Science Cards Against Humanity


Got an email from Amazon last night telling me my free tier was running out and they’d move me over to a charged rate automatically. In a panic I logged in and deleted my account. Let’s hope that also stopped any instances I had :P