Using Zend Studio with Zend Framework = super fast / easy development.

BBCode PHP Syntax Highlighting For Lazy People

April 26th, 2009 by Ray in Cookbook, PHP/MySQL | Tags: , | No Comments

While working on one of my little side projects, I came across a problem where I wanted to highlight bbcode syle php tags in my text (e.g. [PHP] echo “code goes here”; [/PHP]).

Being lazy and using regex (I love it!), I came up with the following solution:

// test text w/embedded code
$text = "This is a sample text string with PHP style tags. [PHP] echo 'Hello'; [/PHP]
// and I made sure to make this case insensitive.
$pattern = "/\[PHP\](.*)\[\/PHP\]/Uis";
// the magic!
$matchCount = preg_match_all($pattern, $text, $matches, PREG_SET_ORDER);
if ($matchCount !== false && $matchCount > 0) {
    foreach ($matches as $match) {
        // highlight_string forces us to start with at least the php opening tag
        $highlightedCode = highlight_string('<?php'.$match[1].'?>', true);
        // finally, replace the original non-highlighted text with the highlighted text
        $text = preg_replace($pattern, $highlightedCode, $text, 1);
    }
}
echo $text;

Just FYI, this was a quick one-off and wasn’t intended to scale with other bbcode style tags. Also, in my real code, the [PHP] tags are lowercase. The only reason they are uppercase is because the syntax highlighter in Wordpress isn’t smart enough to distinguish the tags in my code and tags to signify syntax highlighting.


Porter Progress – Moved To Secondary Fermenter

April 26th, 2009 by Ray in Brewing | Tags: , , | 1 Comment
Coffee Porter moved to carboy

Coffee Porter moved to carboy

So I took a gravity reading a few days ago (Friday) and it read 1.020. I took a reading again today (Sunday) and it hasn’t changed and I don’t think it will.  So, I decided to clean my carboy and utilities, brew some coffee, and move the brew to the secondary fermenter. Pics are below (I think I’m going to stop using Wordpress Gallery as well…too many limitations with controlling image sizes…meh). What sucks about the low gravity reading is that I will end up with a lower ABV than I wanted (1.043 – 1.020) / .0075 ~= 3.07%. I was hoping for more like 4.5%

Sludge left behind

Sludge left behind

One thing I will note for next time–find a smoother coffee and do a cold brew. I ended up using Maxwell House 100% Columbian coffee (medium dark) because that is what I drink in the morning ;-)  It is smooth but I think it may be a little too bitter for this beer.  As it stands, I am drinking the sample (pic below) and it isn’t all that bad (no coffee in the sample). It has a very minor sour flavor (not sure if that is really how to describe it) but that might be because this was the first amount of beer to come out of the primary fermenter and contains the most yeast from the bottom of the bucket (yum).

[edit] Sorry Joel, I didn’t take your suggestion on the espresso because I was too lazy to leave the house today. I’ll probably try it on the next batch.

Coffee Porter sample (minus coffee)

Coffee Porter sample (minus coffee)

Coffee Porter sample (minus coffee) top shot

Coffee Porter sample (minus coffee) top shot


Coffee Porter Progress

April 24th, 2009 by Ray in Brewing | Tags: , , | 1 Comment

Tonight I decided to take a gravity reading of the Coffee Porter. It has been fermenting since Monday (~5 days) and appears to be doing well. My initial gravity reading was 1.043, perfect! Tonight’s reading was at 1.020, not quiet where I want it since I’m looking for 1.012 – 1.014 for a FG. I’m hoping by Sunday I will reach that level and then I can finally move the brew from the primary to the secondary fermenter where I will add the coffee (still not sure what coffee to use).

The pictures below show what the beer currently looks like…sorry for the blurry image…meh.


Some Homebrew Pics

April 21st, 2009 by Ray in Brewing | Tags: , , | 2 Comments
Ginger beer fail

Ginger beer fail

Tonight I decided to get my camera out and take a few shots of my ginger beer that I have been slowly drinking. I really wanted to take shots of the brew that I did last night (read: Coffee Stout) but I couldn’t find my camera.

The photos of the ginger beer (and other equipment) can be found in the new Home Brewing section in my gallery. I will try and post more shots of the coffee stout as it unfolds.


Zend PHP5 Certification Study Guide Annoyance

April 18th, 2009 by Ray in Computer Related, PHP/MySQL, The Bin | Tags: , | 3 Comments

Zend PHP5 Certification Study Guide by Davey Shafik annoys me in many ways which include grammatical errors and erroneous coding examples.

Today’s rant will be on coding examples:

Page 133.

function __autoload($class)
{
//Require PEAR-compatible classes
require_once str_replace("_", "/", $class);
}
$obj = new Some_Class();

At first glance this looks OK but the author goes on to state that the file, Some/Class.php will be included automagically. WRONG! Autoload passes in the name of the class, not the name of the class plus .php at the end (which is what he is thinking). $class is really Some_Class, so the code above should read:

function __autoload($class)
{
//Require PEAR-compatible classes
require_once str_replace("_", "/", $class) . '.php';
}
$obj = new Some_Class();

I’m annoyed not just because the code is wrong, but because he says “When instantiating Some_Class, __autoload() is called and passed “Some_Class.php” as its argument.” If Mr. Shafik took just a couple of minutes to read the documentation, he would have realized he was wrong, and I could avoid some frustration this book has (and still is) caused me.


Time Warner Cable Remote Control FAIL!

April 8th, 2009 by Ray in Computer Related | Tags: , , | 2 Comments

Today I came home to our Time Warner Cable DVR (Motorola) box not working properly – the DVR function(s) wasn’t working. Taking matters into my own hands I thought it may be an issue with our remote. Some things worked on the remote, such as ch+ ch-, vol, and basic stuff. I WANTED MY DVR FUNCTIONS!

As I flipped the remote over to take the batteries out I saw the following text:

Quick Remote Setup
1) Turn device on.
2) Press Device key (TV, DVD, etc.).
3) Press and hold SETUP (LED blinks twice).
4) Press 9-9-1 (LED blinks twice).
5) Press POWER key.
6) Press CH+ repeatedly until device turns off.
7) Press SETUP when device turns off.

I thought, hrmmm, maybe that will fix the remote. So I tried it. On step #2 I selected the CBL (cable) button on the remote. I got the blinking but the device never turned off.

I got fed up after trying several different things. I called TWC support and they told me they were in fact having issues with their DVR service. After talking with support for a few minutes (very nice by the way…I think I got the Portland office) I explained I followed the instructions on the back of the remote thinking it would reset the remote. The support person said if I did that on the remote when the CBL mode is selected, I cleared out the remote settings. I asked him if there was anyway to reset the remote and he said no. All remotes come pre-configured from TWC and there is no way to reprogram them yourself (unless someone has a nice hack they know of out there). If you pop the battery cover off the back of the remote you will see 6 pins…that’s what they use to reprogram these things.

The reason I am so ticked is because there is NOTHING on the remote that says that following those instructions wipes out the settings and the only way to get the settings back is to call TWC for a new remote! Why oh why would you do this TWC?