A class for normalizing mixed value containers

There are times (like when dealing with simplexml) when you just wish you had an array that you can iterate over for whatever your reasons are (especially when dealing with variable structured multidimensional unpredictable input.) This is also a good example of recursive functions, simplification of difficult specialized problems, and how one might use a class to accomplish large tasks in an encapsulated fashion.
[coolcode]

/**
* A class for [N]ormalizing a [C]ontainer to an array
*
* This will class will take any type of variable container and return a normalized array
* For example this will take the output of simplexml_load_string and render it all into
* a multidimensional array.
*
*
*/

/**
*
*/

class nc2array {

private $original_container;
private $normalized_container;

/*
* Takes a variable, and builds a normalized comtainer out of it
*/
function __construct($container) {
$this->original_container=$container;
if ( is_object($container) ) {
$this->normalized_container=$this->recursive_parse_object($container);
} elseif ( is_array($container) ) {
$this->normalized_container=$this->recursive_parse_array($container);
} else {
$this->normalized_container[]=$container;
}
return($this->normalized_container);
}

/*
* takes an array and parses it recursively, passing objects off to recursive_parse_object
*/
function recursive_parse_array($array) {
foreach ( $array as $idx => $val ) {
if ( is_array($val) ) {
$rval[$idx]=$this->recursive_parse_array($val);
} elseif( is_object($val) ) {
$rval[$idx]=$this->recursive_parse_object($val);
} else {
$rval[$idx]=$val;
}
}
return($rval);
}

/*
* Takes an object and parses it recursively, passing arrays back off to recursive_parse_array
*/
function recursive_parse_object($obj) {
$vals=get_object_vars($obj);
while (list($idx, $val) = each($vals)) {
if ( is_object($val) ) {
$rval[$idx]=$this->recursive_parse_object($val);
} elseif ( is_array($val) ) {
$rval[$idx]=$this->recursive_parse_array($val);
} else {
$rval[$idx]=$val;
}
}
return($rval);
}
}
?>

[/coolcode]

Misc photoblogging

Smile for the camera!

Bravo just cant firgue out why buddy doesnt want to play 🙁 (no buddy isnt young here bravo is just a gigantic Great Dane)

what do you MEAN I’m too dirty to come inside?! BUT DAAAAAAD!

Buddy!

He’s only cute like this when he’s tired!

If I were a little orange man, I’d be thinking “uh oh” right now…


And this is why…

it’s been hot the past few days… time to chill out!

Frisky

This is Frisky. She’s one of the most wonderful puppies in the world. She was found, abandoned, by the Fremont Dog Park and taken in by her new owner (I dont know his name… um… “Frisky’s Dad”) right then and there (he couldnt let a puppy go on without a home.) Soon as we get a place where we can have more than one dog… I’m totally stealing her! She’s wonderful. Playful, energetic, loving… LOVES to rough house and to get pets. She’s about a year old. Totally my favorite dog park buddy!

Things are looking up for apache (no, not the web server)

Apache, who had suffered tissue damage (muscles), and had several inflamed internal organs, and had (possibly) a fracture in her pelvic bone, is recovering. The vet put her on steroids to help with the pain and inflamation. We’re now weening her off of the steroids (she’s now down to one every other day.) And after two more weeks we should be able to let her roam freely again. She’s been confined to a single room for, gosh, 3 weeks now? And she’s hating it. She’s an in/out cat and she really likes to roam the neighborhood. She’s also been eating a lot (because of the steroids) so she’s plumped a little bit. Apache is, however, back to her normal self with us (very effectionate, purring like a little kitty-motor-car) She’s a very good kitty, and I’m glad shes on the road to recovery. Poor thing

7 Things You Should NEVER do at the dog park

    1. Never bring your dog in on a leash
    2. Never loose track of your dog
    3. Never hold just one of two excited dogs back
    4. Never give food to a dog without the owners permission
    5. Never assume that other people know what they are doing
    6. Never EVER being a dog that is agressive (or unsocialized)
    7. Never bring a dog who is not obedient to the dog park

    1. Never bring your dog into the dog park on a leash. It’s safe to assume that a large percentage of “incidents” at a dog park are caused by people who’ve brought their dog all the way into the dog park on a leash. An owner who is nervous or fears for their dog will pull back on the leash and draw the dog into an upright position. Chest and head up, shoulders back, is a dominant and or aggressive position. This forces the other dog to iether bend to the leashed dog and be submissive, or prove its own dominance. If you fear for your dog pick it up and walk out of the park.

    2. Never loose track of your dog at the dog park. First it’s irresponsible for you to leave your dogs droppings lying around the park. Second It’s not anybody elses responsibility to dog-sit your dog. And most importantly if your dog gets in a fight at the other end of the dog park you might not be able to get there until its too late.

    3. Never hold just one dog back. If you feel that playing has gotten too excited, or that there could be problems between your dog and another, holding just one dog back is akin to holding your sons arms so that he cant hit while the school bully pummels him… If you cant hold the other dog back for some reason, pick up your dog and leave the park.

    4. Never give another persons dog any type of food unless they say it’s ok. Dogs, like people, can have alergies. If a dog is alergic to an ingredient in the treat you just gave them it could do anything from making them itch to killing them. Dont do it.

    5. Not everyone is an expert in regards to their dogs. Whether its because the neighbor/friend/child brought the dog to the park, or because they are new to the dog park, or any other reason. Dont assume that people will be responsible for you. Aways be alert and aware and ready to deal with any problems.

    6. Bringing an aggressive or unsocialized dog to the park is a bad thing. If the dog is aggressive then leave it at home. period. always. If the dog is unsocialized that you dont KNOW if it’s aggressive. Try finding a playmate or two, or take him on a trip to the pet store to see how he behaves first.

    7. If your dog doesnt obey off leash then work on obedience first. While this isnt absolutely necessary it is very important, and could even save your dogs life. If he wont come when called how can you prevent him from getting in the middle of a fight and injured? Unless you run faster than he does, you cant!

The shawshank redemption

On Sunday I got (sort of) a day(ish) alone at home while My wife was visiting the central valley. So I dusted off my tried and true favorite alone-time movie: The Shawshank Redemption. I dont know whnat it is about this movie, but somehow I identify with it on a very deep and moving level. I always find myself almost crying at the end (along with several points inside the actual movie itself)…
Hey… like my wife says… I’m wierd…

Apache is hurt

My baby girl kitty is hurt. We dont know what happened to her but she’s definately hurt her shoulder. She isnt purring anymore, and she doesnt want to eat (or presumably drink) hopefully she’s feeling a little better tomorrow. We’re going to keep a close eyhe on her tonight and tomorrow, and keep her quarantined inside the house. She has a vet visit on Wed. But if shes really hurt we’ll end up taking her in tomorrow… Everyone send good vibrations her way. shes the sweetest bestest kitty of all kitties everywhere.