Last Post on this Server
Alright, due to the incredible slowness of the website, I am migrating it to a different hosting environment. There will be some down time as I transfer the domain name and content, but this is what is neccessary to get a decent speed of hosting. Domain.com is going to refund me a prorated amount of the hosting cost, and with that I will be moving to a godaddy.com server. Also, I'll probably buy dustinmoorman.com and/or dustinmoorman.org as temporary/alternate domain names while I transfer thehacktavern.com
I gave Domain.com a shot, primarily because of Hak5. Call it a bad experience, because that sure is what it is. Slow servers and to be honest, the tech support I have received has been way less than what I would have expected for a company that wanted to keep its customers.
The flip side of that, I have several other Godaddy.com domains, and let me tell you.. Their customer service is where it's at, and I've had no issues with remote database connections or server speed (domain.com, domain.com) and above all, some may find this annoying, but about 15 minutes after registering my last domain and hosting with them, I received a call from one of godaddy's representatives just giving me thanks for registering with them, and letting me know if I needed any assistance with any of the features I elected, to let him know. Plus he sent me a few PDF's explaining how to get the products I selected set up, and let me know if I had any questions or trouble, they'd be sure to handle it. Have I had to contact support @ Godaddy.com for anything before, in order to validate the offer of this good service? No. Because I have never had any trouble with anything on their end.
To me that's another selling point.
Till then - on the new server!
(this site may be called dustinmoorman.com for a while!)
Installing PHPUnit via PEAR on XAMPP
XAMPP is my favorite *AMP stack. I love it for its ease of use and cross platform compatibility. Recently I had to do a fresh installation of an Apache/MySQL/PHP on my new workstation at my new company. As I entered the game a few years ago in my last company, the environment was set up, so I had nothing to worry about. This time around it was a fresh slate, so after installing XAMPP I had to install PHPUnit with PEAR, this is a quick markup on how to do it, step by step how-to for first timers and for myself. (Because I am forgetful
)
1. After installing XAMPP, open a command prompt and cd toc:\xampp\php or on linux to the corresponding xampp/php dir.
2. The pear executable should be in this directory. (On windows it's pear.bat) We are going to now make sure you have the correct channels in pear in order to install PHPUnit. If you get the message "Channel <channel name> is already initialized" Don't worry about it, it just means you're ahead of the game
Issue the following commands:
- pear channel-discover pear.phpunit.de
- pear channel-discover components.ez.no
- pear channel-discover pear.symfony-project.com
[PHP WOTD]: 4 – sprintf
Today's PHP Word of the day, is sprintf. sprintf allows for string manipulation, which is really cool.
string sprintf ( string $format [, mixed $args [, mixed $...]] )
This function is very versatile. The first parameter, $format, allows you to specify a string, that may contain what PHP refers to as conversion specifications, a good way to understand this, is to take a look at an example:
$number = 10;
$animal = "chinchillas";
echo sprintf("Johnny McJohnnerson was attacked by %d %s.", $number, $animal);
This outputs the following to the screen:
Johnny McJohnnerson was attacked by 10 chinchillas.
That's interesting, take a second to see how that works. The sprintf function searches the first parameter ($format) for the conversion specifications, and replaces the occurances with the arguments passed to sprintf, formatting them based on what the conversion specification is inside the $format string.
You can also designate in the string what order you want the arguments to be in. This is useful if you are doing a multilingual application or if you are doing something that would change the value in the $format string parameter so that the variables are the same but the context is different, like this:
$number = 10;
$animal = "chinchillas";
$johnny_has_been_attacked = 1;
if (!$johnny_has_been_attacked)
{
$format = "Johnny McJohnnerson was attacked by %1\$d %2\$s.";
}
else
{
$format = "Johnny has not been attacked by the %2\$s, and there are %1\$d of them.";
}
echo sprintf($format, $number, $animal);
Careful about using the order identifier when you are using smart quotes (the double quotes) as the PHP interpreter will try and read %1$d as the variable $d which won't exist in this scope. The above output will be:
Johnny has not been attacked by the chinchillas, and there are 10 of them.
So you can see, sprintf is pretty neat. Hopefully you used this PHP WOTD to sharpen your brain a little. I'm going to do my best to make them more regular!
What’s going on?
Wow, first of all let me say alot has changed in this fast paced 3 week span between now and my last update.
I'll start by saying I've changed jobs. I'm now solely a PHP developer. I've stepped out of the System Administration game. It was a tough decision to make, but it's going well. Being in the full-on development life really lets you concentrate on it. It's nice. I know I'll miss the users, and their problems
I will. But this is nice.
There you have the lobby. Yes, that vase does look as good in real life as it does in the picture. I'll end the speculation ahead of time
All that being said, pretty much all my time right now, work and recreational, is spent on PHP when it's not on family matters. And that's surprisingly awesome. I don't know about you guys, but I'm already ready for Lonestar PHP! It's in a few months, but I have this feeling that it's going to be better than last year. I need some more PHP stickers and a new lanyard for my keys!
With all my time being on PHP, I'll have more regular PHP words of the day, and actual other content that's development related besides that. I know I've said it before but this time I mean it!
Another thing.. I'm working with Domain.com right now to try and see why my site is so slow. It's being incredibly slow right now, in the past it's done this when I was looking in to using CloudFlare. I used it for a while, then I just had this suddenly incredibly slow loading speed all over my website. All it is, is a wordpress blog! I'm not trying to cure cancer here or anything, and wordpress was even installed by Domain.com's web interface! The first few months of hosting with Domain.com were just excellent, and I had no qualms, so I attributed the slow slow loading to CloudFlare. That might have been falsely placed blame, and if that's the case, I'll be bringing CloudFlare back after the guys at Domain.com fix the broken server that hosts my website. It's gotten better since they have looked at it last week, but still, it shouldn't be this slow.
[PHP WOTD]:3 – array_walk
Today we're going to do an array function, array_walk! This one allows you to cycle through array elements and apply a user defined function to them. Here's the PHP documentation signature:
bool array_walk ( array &$array , callback $funcname [, mixed $userdata = NULL ] )
as for usages, let's take a simple look at iterating array values with array_walk
$a = array("hello", "it", "is", "rainy");
array_walk($a, "print_out_the_contents_of_this_array");
function print_out_the_contents_of_this_array($array_element){
echo $array_element." ";
}
Outputs hello it is rainy to the screen! That's pretty neat, you can see in the function above, it will immediately pass the array element value to the callback function.. for free! It literally costs you nothing. There's something else it can do for free as well, that's pass the key pretty easily. Just specify a second parameter in your callback function, and it will automatically be the key. Check it out:
$a = array(
"first word: " => "hello",
"second word: " => "it",
"third word: " => "is",
"fourth word: " => "rainy");
array_walk($a, "print_out_the_contents_of_this_array");
function print_out_the_contents_of_this_array($array_element, $array_key){
echo $array_key.$array_element."<br />";
}
Output:
first word: hello
second word: it
third word: is
fourth word: rainy
So you can see there's a bunch of things you can do with array_walk if you are looking for a way to handle arrays. You could even combine this with the filter_var function you learned last time.
$a = array(
"first word: " => "hello",
"second word: " => "it",
"third word: " => "is",
"fourth word: " => "rainy");
array_walk($a, "print_out_the_contents_of_this_array");
function print_out_the_contents_of_this_array($array_element, $array_key){
echo filter_var($array_key.$array_element."
", FILTER_SANITIZE_STRING);
}
Now that's an ugly example, because it outputs this:
first word: hello second word: it third word: is fourth word: rainy
But you get the picture, you could get more creative with it. And actually, there's another solution to the code I just presented to you, you can use (probably the next word of the day) filter_var_array!
[PHP WOTD]:2 – filter_var
The second word of the day, is one of my favorites. It's one of my favorites because of the versatility of it. It's also very fun to use!
mixed filter_var ( mixed $variable [, int $filter = FILTER_DEFAULT [, mixed $options ]])
Looks interesting, what does it do? Well it applies filters to the variable passed in the first argument slot (seen above as $variable). These filters can do different things, and there are a bunch of them! There are 2 main 'types' of filters we have here, then there is one special one.
- Validation Filters - Primarily used for form validation, these return based on if the variable being tested meets certain criteria, usually what will happen is, if you pass the filter, the value of $variable will be returned.
- Sanitization Filters - Sanitizing filters clean things and return the portion of the $variable after being cleaned.
- and special FILTER_CALLBACK
- With this, you can actually provide a User Created function or class method that will do the filtering, that's handy.
So lets take a look at some examples of usages. We'll start with Validation Filters since we listed them first.
echo filter_var(123, FILTER_VALIDATE_INT);
Here, the output to the screen would be 123.
echo filter_var("one two three!", FILTER_VALIDATE_INT);
Here, there would be no output to the screen.. Now I'm about to get tricky on you. Pay attention:
echo filter_var("123", FILTER_VALIDATE_INT);
That... outputs 123! Yes, because the filter_var applies the similar logic as the '==' so if you did this:
echo (123 === "123") ? "true!" : "false";
You'd get false. But on the other hand, if you did this:
echo (123 == "123") ? "true!" : "false";
You'd get true, every single time.
You can take a look at all the Validation filters you can apply here on the manual.
So then for the Sanitation Filters. The FILTER_SANITIZEE_STRING filter will remove things such as HTML or Script tags, it's really great for cleaning input. Check it out:
echo filter_var("<br /><u>test</u><br/>", FILTER_SANITIZE_STRING);
Outputs just test, no fancy line breaks or deprecated underlined tags. A great way to prevent XSS, watching for those <script>'s.
Other Sanitize filters can be seen in the manual, just check them out here!
I was going to show you the magic of using the callback filter, but I can't due to time constraints. Enjoy this PHP WOTD and find out more about filter's you can use with your new filter_var function here! I'll do a post on the callback filter var soon, just have to cut due to work in the morning. Happy coding!
[PHP WOTD]:1 – is_a
The first word of the day function!
bool is_a( object $object , string $class_name [, bool $allow_autoload = FALSE ] )
This is a useful PHP built in function that allows you to perform checks on objects to make sure they are what you are expecting, and will return a bool result if it matches the suggested class name.
class Application {}
$app = new Application();
echo is_a($app, "Application");
Evaluates to true, so 1 will get rendered to the screen.
class Application {}
class WebApplication{}
$app = new WebApplication();
echo is_a($app, "Application");
1 also gets rendered to the screen in this scenario!
Pretty neat, can be used for some polymorphic goodness.
Autoloading PHP with DirectoryIterators
I have a project directory on one of the websites I'm working on that looks like this:

In order for me to get stuff done and actually LEARN some PHP, I need an autoloader! I can't have my time be waylaid by having to write a bunch of requires and include statements! What do?
Create a master autoloader!!!!!
I did that. That worked out well for.. maybe the one or two directories that I added, then I got bored of modifying the autoloader for each new directory that I added to the project. I was bored of it preventing me from learning PHP. So I made this:
Function:
function iterateDirectoriesForAutoload($directory_in_question = __DIR__){
foreach (new DirectoryIterator($directory_in_question) as $file){
if ($file->isDot() || strstr($file->getFilename(), ".")) continue;
if ($file->isDir()){
echo "dir: <strong>".$file->getFilename()."</strong> ".
$file->getPath()."/".$file->getFilename()."/ <br />";
iterateDirectoriesForAutoload($file->getPath()."/".$file->getFilename());
}
}
}
Note to fellow programmers: The $file->isDot checks to make sure the directory we are iterating is Not '.' or '..' and as a safeguard, I added the strstr to ensure that it doesn't pick up my .idea folder (PHPStorm settings.. or any other '.foo' directories) from within my project directory.
Implement it by putting it in the root directory of your project, like so:
iterateDirectoriesForAutoload();
The output should say the following:
dir: inventory /var/www/console/inventory/
dir: cases /var/www/console/cases/
dir: financial /var/www/console/financial/
dir: reporting /var/www/console/reporting/
dir: util /var/www/console/util/
dir: abstracts /var/www/console/util/abstracts/
dir: objects /var/www/console/util/objects/
dir: interfaces /var/www/console/util/interfaces/
Alright... great. It shows all the directories, but what does that do for me as far as my autoloader goes?
We'll take the original function and modify it slightly to make a Plug and Play style autoloader. We will then do a require_once at the top of every file that points to the location of our bootstrap.php file, and our bootstrap file will look something like this:
function __autoload($class_name){
findAndRequireClass($class_name);
}
function findAndRequireClass($class_name, $directory_in_question = __DIR__){
foreach (new DirectoryIterator($directory_in_question) as $file){
if ($file->isDot() || strstr($file->getFilename(), ".")) continue;
if ($file->isDir()){
if(file_exists($file->getPath()."/".$file->getFilename()."/$class_name.php")){
require_once $file->getPath()."/".$file->getFilename()."/$class_name.php";
return;
}
findAndRequireClass($class_name, $file->getPath()."/".$file->getFilename());
}
}
}
And Finally! We can start to learn some PHP!
Where one ends, a new journey begins!
I spent all weekend getting my development environment set up on my laptop so we can start learning PHP! Today will be the first day that I'll get some hardcore PHP action, and start my journey towards the ZCE. I've set a date to take the test for the first time, on my 22nd Birthday. I should be ready by then to at least see what it's all about.
Some things to look forward to coming very soon from the hack tavern:
- PHP functions of the day!
- Class autoloading
- much more!
This is going to be fun!
I’ve done it
You are mine.
And what a trip it has been.
Today, 4 months of solid study has paid it's dues. I am now a certified MCTS. It's kinda strange really, you get in to a groove where you spend your time thinking of ways to prep harder for something, get off work and go home to study as hard as possible until you have to sleep, then repeat the next day. The first thing I wanted to do today was crank up a CBT nuggets video, listen to what James Conrad had to say about imaging, and break out my Poulton book to look at some of the DirectAccess diagrams.. It's funny, I literally had to stop myself and think.. What now? I feel like a single mother who has ween'd an only child off to college.
The 70-680 Exam is one of the most failed exams that Microsoft currently offers. It's such a broad spectrum that you get folks taking the server test prior to even attempting the 70-680, as the topics in the 70-680 overlap those in the 70-686 and 70-685, and one needs a complete coherence of what is happening both on the server level and the client level in order to pass this test; or there are those who have failed multiple times at the 70-680, digress and move on to something different. Unfortunately, I didn't hear about the fact that it was so hard to pass until it was too late, and I had already been studying it for several months. Matter of fact, I didn't even look in to it until two weeks prior to testing.
I don't like to waste my time. It's frustrating to me. So I decided to stick with it. Albeit hearing the horror stories of those who have entered confidently to sit for the 70-680 exam, get crushed miserably in its wake, I decided to give it all I got.
My test was scheduled for 10:00AM on January 31, 2012. I woke up at my normal time of 6:00 AM today, kicked on the Professor Messer playlist, and went through my normal morning ritual and instead of getting dressed for work, I got dressed for school. Jeans and a comfortable jacket. Anticipating the travel time would be well over google's estimate of 19 minutes going north on I-75 from central I-30 at 8:00 on a Tuesday morning, I completed about a list of 16 items that I needed to refresh my mind on via Microsoft TechNet before heading up there. Started at 7:00 AM with this, the scope being random executables to key factors that I knew were going to be on the test, and was able to complete it in time for my 8:00 commute. Traffic was a drag as I expected, but I actually arrived at the testing center at about 8:40AM. Which I didn't consider as 'too bad'. I knew I needed breakfast though, so I scoped out the testing center and the parking area, then headed up Coit to get some Jack in the box... Number 23 with and Orange Juice. Not bad. Pretty much a breakfast jack with bacon on toasted bread. It did the trick. I got back to the Exam facility at about 9:20, had a last minute chit chat with my girlfriend for good luck, enjoyed a solo diet mountain dew I had brought along for the ride, then headed inside.
Place was not too shabby. Kinda felt under dressed, as a bunch of well attired people were sitting in the waiting area. I had a puma ferarri jacket and some blue jeans on with my perry ellis kicks - maximum comfort factor. Got my name taken by the receptionist, given a page I needed to sign and instructions to drop my crap off in the lockers behind the front desk. Took care of that, used the bathroom for the last time (9:20 diet mountain dew kicking in), then headed in to the proctor. She explained the rules and I signed in for the test.
Walked inside the exam room, probably 20 people currently engaged in exams.. In there I saw more lax dressed individuals.. dude in a lime green hoodie and sweat pants. Alright, I thought. The proctor waved me over to the desk with the Dell Optiplex GX520 that I'd be taking the exam at. "Station 1", what do you know? Sat down and logged in with the information I was given, and the test began.
Lead off with some introduction/protocol such as the Microsoft NDA and a 12 question reception evaluation exam, got those out of the way ASAP and got into it.
Exam duration was 3 hours flat. I finished in the first hour and 15 or so. Went back over them and rounded up the entire ordeal to cost about 2 hours of the day. I inventoried the questions that I believed that I had answered correctly, and those that I had some doubt about (Many of the questions were those where two options were Definitely Not the answer, and two of them Could be... while Several questions offered VERY similar answer choices, where any of the options could be the correct answer). And came to the conclusion that even with the ones that I did not know about, I may have a winning answer set on my hands here... and nervously hit the 'End Exam' option.
I was expecting a bunch of fluff, post exam surveys, and me waiting in line at the proctor to find out how I've come on the exam. Instead I was greeted with about a half second of a "Loading" dialog box before seeing "Congratulations! You have PASSED this exam! The minimum score to pass is 700, you have scored 760!"
I was bedazzled.
Pretty happy indeed
I couldn't let all of this effort go to waste. No telling how many more questions away I was from failing.. but hey.. that's a good update from me to you today. They have been few and far between since blogging takes time and I had none to spare with all my studies. I'm in the late hours of my consideration for What is next on the list of exams.. and it's looking like I'm going to let my last post about the subject take over. The ZCE is notoriously hard, but... worth it. My only other option right now that I'm contending for.. would be the CCNA. I have studied for this in the past, but never motivated to actually exam on it. I'm considering capping the CCNA flag just to get another certification up on my plate.. plus all the benefits of holding a CCNA.
I'm still tossing them around. We'll see! I'm deciding soon. I'm growing bored already with nothing to study
See you space cowboys,
Dustin Moorman, MCTS




