Browse > Home

| Subcribe via RSS

The Greatest PHP Debugging Function of All Time

December 22nd, 2009 | Comments | Posted in Techie

I normally try to keep the tech stuff to a minimum on the blog, but this function is in high demand from anyone who’s ever had it and then worked on another codebase without it.  Simple, but mind-blowingly useful. Without further ado, I present, YO.

NOTE: This is a re-write of some code I wrote at Yahoo!, so I wanted to give credit to the two folks who had a hand in the debugging system we built there, from which this is derived: Chris and Sara.

You’re welcome, America.

<?php
 
/**
 * The greatest debugging class in history. Here's why:
 * 
 *  - outputs to both the error log and optionally the screen.
 *  - formats output nicely so you can see your debugging output
 *  - shows you where the yo() call is IN THE OUTPUT so if you
 *    leave a yo() in someplace, you can track it down easy-peasy.
 *  - accepts multiple args just like var_dump
 *  - feel free to use the sub functions too (like var_dump_str)
 *   
 * @author Jacob Rosenberg <themasterof@rightuptop.com>
 * @author Sara Golemon
 * @author Chris Draycott
 *
 */
class Yo {
 
 
    /* {{{ */
    /**
     * getCallerLine
     *
     * gets the calling line of the function it was called from,
     * i.e., this function's grandparent.
     *
     * @returns string Name of calling function
     */
    static public function getCallerLine($levels = 2)
    {
        $bt = debug_backtrace();
 
        $file = isset($bt[$levels]['file']) ? $bt[$levels]['file'] : '';
        $line = isset($bt[$levels]['line']) ? $bt[$levels]['line'] : '';
 
        return array($file, $line);
    }
    /* }}} */
 
 
    /* {{{ */
    /**
     * getCaller
     *
     * gets the calling function of the function it was called from,
     * i.e., this function's grandparent.
     *
     * @returns string Name of calling function
     */
    static public function getCaller($levels = 2)
    {
        $bt = debug_backtrace();
 
        if (isset($bt[$levels])) {
            $caller = $bt[$levels]['function'];
 
            if (isset($bt[$levels]['class'])) {
                $caller = $bt[$levels]['class'] . "::" . $caller;
            }
        } else {
            $caller = 'main';
        }
 
        return $caller;
    }
 
 
    /* {{{ */
    /**
     * var_dump_str
     *
     * var_dump, but with returned output.
     * OB capture is gross, but print_r($x,1) sucks compared to var_dump.
     *
     * @param mixed PHP Variable to be var_dump'd
     * @returns string var_dump representation of that variable
     */
    function var_dump_str($var)
    {
        ob_start();
        var_dump($var);
        $out = ob_get_contents();
        ob_end_clean();
        return $out;
    }
    /* }}} */
 
    /**
     * isInternal
     *
     * determines if a user is an internal user.
     *
     * @return bool true if the user is internal and should see debug output
     */
    public static function isInternal()
    {
        // feel free to add some code here that
        // turns on debug output for only a subset of users.
        //
        return true;
    }
 
    /* }}} */
 
    /* {{{ */
    /**
     * yo - figure it out yourself, dummy
     *
     * @param mixed Variable(s) to be dumped (var args)
     * ...
     */
    public static function do_yo()
    {
        $internal = self::isInternal();
 
        $caller = self::getCaller();
 
        if ($internal) {
            echo "<pre><h1>YO!!: $caller</h1>";  
        }
 
        error_log("YO!!:: $caller");
 
        foreach (func_get_args() as $var) {
            $output = ($var === false) ? 'bool(false)' : Yo::var_dump_str($var);
            if ($internal) {
                echo htmlentities($output, ENT_QUOTES, 'UTF-8') . "\n";
            }
            error_log($output);
        }
 
        if ($internal) echo "</pre>";
    }
    /* }}} */
 
    /* {{{ */
    /**
     * yo_bt - figure it out yourself, dummy
     *
     */
    public static function do_yo_bt()
    {
        $internal = self::isInternal();
        $caller = self::getCaller();
 
        if ($internal) {
            echo "<pre><h1>YO bt!!: $caller</h1>";
        }
        error_log("YO bt!!:: $caller");
 
        $bt = debug_backtrace();
 
        foreach ($bt as $line) {
            if ($internal) echo $line['function'] . "\n";
            error_log($line['function']);
        }
 
        if ($internal) echo "</pre>";
    }
    /* }}} */
}
/* }}} */
 
// shortcuts! ------
function yo() { return Yo::do_yo(); }
function yo_bt() { return Yo::do_yo_bt(); }
Bookmark and Share
Tags: , ,

Harrison Ford: By The Numbers

August 20th, 2009 | Comments | Posted in Entertainment, Movies

Anyone who knows Jesse is aware that he has a penchant for delightfully long rants about various icons of pop culture, which he then usually emails or (sends via Facebook) to a list of people who care about such things.  It’s a short list, and I consider myself privileged to be on it.

Recently, I stumbled upon this clip thanks to Videogum (which, by the way, is currently tied for first place on the List of My Favorite Things Ever [with The Best Show on WFMU]).  Being that he and I are both connoisseurs of Harrison Ford’s work (we’ve had a Harrison Ford-related music project in the works for a few years now), I figured he’d enjoy it, and I sent it his way.  Take a look-see for yourself:

In response to this video, I received the following email:

From what I can tell, these are the what clips are from:

  • Air Force One
  • Firewall
  • Frantic – they have quite a bit from the underrated Frantic (one of the only Roman Polanski films I really like, probably because Ford is in it).  This is the one where he is going around asking about his wife being kidnapped (Someone should do this with Polanski and films featuring bad things happening to women – Frantic, Rosemary’s Baby, Tess, and incest in Chinatown).
  • The Fugitive
  • Random Hearts
  • Patriot Games

In the 29 feature films Ford has starred in, 6 of them he is married and something happens to his family.  These are all the above films.  I am not counting [Indiana Jones and the Kingdom of the] Crystal Skull, although he gets married in the finale and he is ostensibly fighting for his family throughout the film.  I am also not including What Lies Beneath, in which he murders his wife.  That’s about 20%.  Note: the first film he did this in was the aforementioned Frantic.

In those same 29 feature films, Ford is married in 12 of them (again, not counting Crystal Skull), which means he is predominantly single in his film career (60% of the time).  However, ever since Presumed Innocent, he has been married in 10 of those 15 films, meaning that since 1990, he has been way more married than the first half of his career.

I don’t know about Crossing Over, the film he did earlier this year.  It was only a limited release.

Writing these kinds of emails is what Jesse does, and I don’t think it’s just luck that he happens to associate with folks like me who appreciate them to no end.  But I thought that this analysis might have a little more impact with some visual flair, so I whipped up some art to help bring this data home.  I therefore proudly present the Harrison Ford “Get Off My Family” breakdown:

Harrison Ford Chart #1

Harrison Ford Chart #2

A few things to note here, aside from what Jesse already pointed out about What Lies Beneath and Crystal Skull:

  • I chose Mosquito Coast instead of Presumed Innocent to start the second count, because it’s Ford’s first starring role in which he is married. That film was shot in early 1986, while Ford was 43. I guess Hollywood decided he finally looked old enough to play a family man.
  • We’ve assumed Ford is single in all films in which that topic is not specifically addressed; if I’m not mistaken, that is true in both Force 10 from Navarone and K-19: The Widowmaker. I can’t remember if the topic comes up in The Frisco Kid.
  • One could argue that Ford’s family isn’t exactly living in the safest of conditions in Mosquito Coast, but I think that goes against the spirit of what we’re doing at here.  We’re looking at cases in which Harrison Ford is specifically struggling to find or protect his family, which is why What Lies Beneath doesn’t fall into the “Family in Trouble” category either.
  • It is also interesting to note that in three of the twelve films in which Ford is married, he has committed adultery (What Lies Beneath, Presumed Innocent, Regarding Henry).  That’s a 25% adultery rate, just below the average rate for American males, which MSNBC puts at 28% (though obviously that’s a tough statistic to measure accurately).  It is also interesting to note that all three of these indiscretions took place before the start of their respective films; as far as I know, Ford has never committed adultery on screen (unless you count Hanover Street, in which he is the other man).

Lord knows it’s been a rough fifteen years for us Ford lovers (he is, in my opinion, two for ten since Clear and Present Danger), but let’s all just hang in there, and here’s hoping he gets back on track.

Bookmark and Share
Tags: , ,

When Gretchen Carlson thinks you’re an idiot…

July 14th, 2009 | Comments Off | Posted in Politics

…perhaps you need to reevaluate the inane schlock that is dribbling out of your trap?

This clip slipped under my radar until yesterday, but on July 8, Brian Kilmeade of Fox & Friends apparently lost his damn mind:

Unalbe to show flash video

Thanks to Gawker for the clip.

I’ve addressed this “purity” argument before on this blog; it is experimentally disprovable as well as being just plain stupid.  Simple common sense and a basic understanding of genetics will tell you that “purity” is what happens when cousins marry, and that two parents with more genetic variation have the potential to make a daywalker.

Unalbe to show flash video

But what’s mind-blowing is to hear this drivel coming not from some fringe white supremacist or universally reviled hate-monger, but from an anchor of a core show on a major news network.  I simply could not believe this; I dug through the internets to find the full clip, to make sure this wasn’t taken out of context. It wasn’t. Even his co-host, Gretchen Carlson, was making incredulous faces and tried to rein him in verbally, but to no avail. Let me repeat that: Gretchen Carlson thinks this is fringe crazy talk.

gretchy2

Congratulations, Brian Kilmeade.  You are officially that girl in that episode of House who has poo coming out of her mouth. This is you. This is what you look like:


Poo Mouth Cover Image

Seriously though, how is this guy not being made to apologize for being an idiot?

Related stuff:


Update: Kilmeade apologized for these comments this past Monday, saying “I made comments that were offensive to many people. That was not my intention, and looking back at those comments I realize they were inappropriate. For that I sincerely apologize. America [is a] huge melting pot, and that is what makes us such a great country…”.

He looked very sincere. That was sarcasm.

Bookmark and Share

Congrats to Sasha and Jen!

April 7th, 2009 | Comments Off | Posted in Personal

As of this weekend, my brother is engaged to his awesome girlfriend fiancée. I could not be more excited for both of them, or more stoked about having a new sister.

When he told me, all I could think about was a conversation he and I had in Istanbul in the summer of 2006.  We were sitting near the Blue Mosque at a cafe, and he was talking about his new girlfriend in a way I’d never seen him talk about a girl before.  I thought to myself, “He’s toast. He is definitely going to marry this girl.”

Way to go, dude!

Bookmark and Share

South by Southwest Awards ’09

March 25th, 2009 | Comments Off | Posted in Entertainment, Music, Personal, Photos

This is the last SXSW post for a while, I swear, but it’s the only one that really matters. Ladies and gentlemen, it is my great honor to present to you the second annual (last year’s awards are here and here) SXSW awards, which I am hereby affectionately dubbing “The Rutty Swesties.” Get it? Too bad. Let’s begin with…

Best Suprise

Monotonix (Tel Aviv, Israel)

Holy moly. I’m not even sure if I’m that into these guys’ tunes, but you cannot help but be completely hypnotized by their antics. They seriously spent more time crowd surfing or climbing up the walls than standing on the stage, and most of the time they were playing their instruments on top of the crowd.  Did I mention the fifteen minute drum solo while they changed an amp that they blew in the middle of the show? I’ve pretty much never seen anything like this, and what a way to close out the trip.  If only they did fire tricks… OH WAIT:

The “I Can’t See These Guys Enough” Award

Gil Mantera’s Party Dream (Youngstown, OH)

Two clinically insane geniuses who strip down to their banana hammocks while simultaneously dancing their asses off, playing the shit out of matching Lucite guitars, and blowing everyone’s minds with their incredibly catchy electro-pop (which is drenched in vocoder vocals, brain-crushing hooks, and Stevie Nicks covers). Just go with it.


Runners up: Marnie Stern, Still’ Flyin

Most Overrated

Vivian Girls

My take on the Vivian Girls record was that it was highly mediocre, so I was sure there was a reason these ladies were getting so much attention.  I figured the live show was the key, and I really wanted to see what they were all about.  Turns out they are all about: being somewhat cute, wearing short shorts, and not being able to play their instruments (or faking as such, which is even worse).  I’ll take Marnie Stern’s sick chops any day of the week over this derivative slop.

Worst of the Worst

Kevin Devine and the Goddamn Band

THEY ARE CALLED KEVIN DEVINE AND THE GODDAMN BAND.

Best Show of the Festival

Titus Andronicus

The Titus Andronicus debut The Airing of Grievances is an odd and invigorating combination of erudite wordplay and punk rock sensibility; these guys have no problem quoting a few lines from an existentialist philosopher and then closing a song by screaming “Fuck you!” at the top of their lungs.  It’s weird, and kinda great. But walking into a show after hearing an album like that, it’s tough to know if you are going to get the punks or the professors.  About five seconds into their set, it was clear that the punks had come out to play.  The setting was perfect: no stage, just a cleared out corner of a parking lot at a backyard barbecue. The crowd was stocked with uber-hipsters and gutterpunks alike, and everyone in attendance was treated to a simple, unpretentious, and completely furious ass-rocking.  Kudos to you, Titus Andronicus.  You win SXSW.

Runners up: Mojo Nixon, Monotonix

Technical awards:

  • Most Likely to Die in a Horrific Stagediving Accident: Ami Shalev of Monotonix (Tel Aviv, Israel)
  • The “Nastiest Chops” Award: Marnie Stern (New York, NY)
  • The “Prima Donna” Award for longest and fussiest soundcheck: The Rosebuds (Raleigh, NC)
  • The “Please Don’t Ever Hang It Up, I Don’t Care HOW Fat You Get” Award: Mojo Nixon (Chapel Hill, NC)
  • Shortest Shorts: Hutch Harris of The Thermals (Portland, OR)
  • The “Nice Job Pissing Off The Meatheads In Front of Me” Award: HEALTH (Los Angeles, CA)
  • Most Judy Garland T-Shirts Per Capita: Abe Vigoda (Los Angeles, CA)
  • Most Brew Grooves Jammed: Still Flyin’ (San Francisco, CA)

And if you think I am going on about Marnie Stern’s chops too much, suck on this:

Bookmark and Share
Tags: , , , , , , ,