Made of Everything You're Not

Personal blog of PHP programmer Eric Lamb.
  • Blog
  • Portfolio

Archive for March, 2011

The Commodity HTPC Dream is Finally Realized

Posted in Brain Dump on March 08th, 2011 by Eric Lamb – 0 Comments

Ever since I first heard about home theater PCs (HTPC), way back in 2002, I've wanted one. Badly. To me, an HTPC is one of those killer products that offered what I would consider to be a perfect experience; the ability to have all my media centralized around a single interface and made for a more traditional entertainment experience. The problem though was that, until recently, setting up a system was a little outside my comfort zone when it came to the costs. It was fucking expensive to set up back then. But, that was then and the times they do a change. It's not only ridiculously easy to build an HTPC but also quite reasonable in terms of the costs.

The HTPC Dream is Finally Realized

Back in 2002 I was a lowly intern level scrub with the pay to match and computers capable of running Windows Media Center were a little expensive and required a shit ton of upgrades hardware wise. You couldn't just buy an inexpensive model off the show room floor and expect to have any cash left over. I don't recall the specific prices involved for all the components but I do remember knowing with a complete and total certainty that getting an HTPC at that time just wasn't going to happen. So, broken hearted, I moved on and focused on my career and drinking for the next 9 years.

Then, last August, I started looking into getting one put together again. I had some other, business, needs that required a dedicated desktop computer, to be placed in a closet, and I just figured, what the hell, why not kill two birds with one stone; have my utility computer and look into getting a Windows Media all at the same time. I mean, why not? The main purpose was for a backup machine which would only be ran on a slim time window and the rest of the time it'll just be sitting there. Kind of a waste to just leave it sitting there doing nothing most of the day, right? Right?

Now, since I had done all the research into what it would take to build an HTPC back in the day I started looking up all the parts to build one. For my preferred system I was thinking about:

  1. ATX Media Center case $75
  2. An ATX Mother Board that can have a decent amount of RAM $299
  3. A decent amount of RAM $149
  4. A processor to match the motherboard $269
  5. HDMI Video Card $99
  6. 1 Blu Ray Disk Drive $90
  7. 500 Gig HDD (with a few extra external terabyte drives for the media) $60

I figured I'd get the parts and put it together myself; these things are like legos with how everything snaps together only where it belongs. Add a little MythTV (go FOSS) and I'd be good to go for a bit of time and around $1,100 (after shipping). But, the practical side of me couldn't accept that like I assumed I would. $1,100 is still a lot of money regardless of how you look at it and, I couldn't kid myself, it was going to take a bunch of effort to learn MythTV as a platform, not to mention how long it would take to put the thing together (I try to never underestimate my ability to procrastinate). So I decided to look up good old Dell and see what my options were. My mind blew.

Turns out that the lowest Dell desktop model available at the time had HDMI outputs native and is only $299. I don't know when it started to be "standard" for commodity PCs to come with HDMI outputs but that was a good call. Plus, since the Dells come with Windows 7 Premium, and that it comes with Windows Media Center as a part of the OS, there's no need to learn MythTV (something I just wasn't motivated to do).

Still, the specs for the Dell wasn't really all that great; only 2 Gigs of RAM and a Celeron processor (why do they still make these?) just wasn't going to cut it. After upping the specs on the CPU and ordering 6 Gigs of RAM from Crucial the total cost ran around $450 and came with a year warranty which was something unexpected but nice.

It's pretty cool that getting a home HTPC set up is now as easy as ordering any other computer.

Practical PHP Reflection

Posted in Brain Dump, Code, Programming on March 01st, 2011 by Eric Lamb – 13 Comments

The Reflection API in PHP is one of those language features that can kind of creep up on you; it's just not needed for a vast majority of projects. In fact, I'd wager there are a bunch of professional developers who have never had to make use of the Reflection API. Hell, I spent 8 years writing code professionally before I ever had to use it (though, because of some unrelated .NET research I was peripherally aware of it). It's just not something that really comes up all that often in the day to day coding tasks.

Then, one day, out of nowhere, it comes up. The perfect problem where the Reflection API appears to be the perfect solution. For me this came up a couple months ago while I was working on a European zip code radius project that had to be built using one of those obfuscated and ill documented 3rd party commercial programs (nothing worse than when the platform is forced on you). So, I had to use this program that was intentionally encoded to prevent me from doing what I wanted to do. I couldn't even look at the code; it was completely obfuscated.

Before getting into things it should be noted that the Reflection API is capable above and beyond what I'm outlining; usually for the kind of high level stuff like core Zend Framework components and anything you'd want way abstracted.

So, yeah, weird problem.

This is where reflection comes in for me. It was made for problems like the above; according to the manual:

PHP 5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions, methods and extensions. Additionally, the reflection API offers ways to retrieve doc comments for functions, classes and methods.

So, the theory was that I could use the Reflection API to look into the obfuscated code and get some insight into what was going on and what I had to work with. I figured that, at the least, if I could see what methods, properties and comments the code had; maybe I'd get some clue about what the code was about. Using, for example, the internal PHP class "SimpleXMLElement" it's real simple to get a nice map of the class by calling the class ReflectionClass and passing the name of the class you want to get details on as a parameter like the below:

1
2
3
4
<?php
$reflector = new ReflectionClass("SimpleXMLElement");
echo $reflector;
?>

The above outputs an eye gouging but verbose class map:

Class  {
 
  - Constants  {
  }
 
  - Static properties  {
  }
 
  - Static methods  {
  }
 
  - Properties  {
  }
 
  - Methods  {
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
 
    Method  {
    }
  }
}

As you can see, the above lists every property, method and constant about a class along with any parent classes and interfaces. If there were any variables the methods accepted it would also list those as well but SimpleXMLElement doesn't have any.

It's also possible to get the individual elements on a one by one basis while using the ReflectionClass object; for example the below methods returns the class name, any comments (if they're in docblock format), the constants, parent class, constructor and default properties for the class DateTime.

<?php
$reflector = new ReflectionClass("DateTime");
echo "Class name: ".$reflector->getName()."\n";
echo "Doc Comment:".var_dump($reflector->getDocComment())."\n";
echo "Contants: ".var_dump($reflector->getConstants())."\n";
echo "Parent Class: ".var_dump($reflector->getParentClass())."\n";
echo "Constructor: ".var_dump($reflector->getConstructor())."\n";
echo "Default Properties: ".var_dump($reflector->getDefaultProperties())."\n";
?>

Outputs

Class name: DateTime
Doc Comment: bool(false)
Contants: array(11) {
  =>
  string(13) "Y-m-d\TH:i:sP"
  =>
  string(16) "l, d-M-y H:i:s T"
  =>
  string(13) "Y-m-d\TH:i:sO"
  =>
  string(16) "D, d M y H:i:s O"
  =>
  string(16) "l, d-M-y H:i:s T"
  =>
  string(16) "D, d M y H:i:s O"
  =>
  string(16) "D, d M Y H:i:s O"
  =>
  string(16) "D, d M Y H:i:s O"
  =>
  string(13) "Y-m-d\TH:i:sP"
  =>
  string(16) "D, d M Y H:i:s O"
  =>
  string(13) "Y-m-d\TH:i:sP"
}
 
Parent Class: bool(false)
Constructor: object(ReflectionMethod)#2 (2) {
  =>
  string(11) "__construct"
  =>
  string(8) "DateTime"
}
Default Properties: array(0) {
}

Check out the documentation; there are a bunch of other details you can get from other methods.

This is really just the tip of the iceberg though. There are other classes that allow even deeper insight into functions, methods, extensions and much more. Definitely worth checking out.

  • Subscribe: Entries | Comments
  • About Me

    Email Email
    Twitter Twitter
    310.739.3322
  • Categories

    • Brain Dump
    • Business
    • Code
    • IT
    • Programming
    • Rant
    • Servers
  • Archives

    • February 2012
    • October 2011
    • August 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
  • Advertisement

Copyright © 2008 - 2013 Eric Lamb - All rights reserved