PyProxy hijack logic

So PyProxy is a mostly operational death star able to successfully sit between any website and the browser, one of the latest additions I made was the following inject for html payloads:

<script>
    (function(){
        var original = document.write;
        document.write = function(arg1){
                        console.group("document.write");
                        console.log("doc.write: " + arg1);
                        console.groupEnd();
                        original.apply(document, arguments);
        };
    }());
    
    (function(){
       var truImage = Image;
       window.Image = function(width, height){
        try{
            
            this.root = new truImage(width, height);
            this.__defineSetter__("src", function(val){
                console.log("New Image @ " + val)
                this.root.src = val;
                
                });
        }catch(Err){
            console.log("New Image Err");
        }
       }
    }())
</script>

It’s abomination code yes, but it is also extremely useful for further illuminating what exactly is going on in the time prior to document.onLoad plus exposes image beacons generated using Javascript Image objects… something that normally doesn’t show up any where in the DOM, hence I don’t believe FireBug or Chrome inspector panels can report it.

Normally to get something like this into a website would require adding it into development, which then opens the risk of it slipping into production.

The functional beta of PyProxy should be released this weekend if I don’t go on a bender.

Pulling cheap tricks with JQuery

Let’s say you got some tabular data with input button/anchor tags that ideally will cause previously hidden data to appear.

Attempt 1 went like:

 
//Simulated row
<td>
  <a href="#" onclick="$('#my_SubData<?= $currentRecordId ?>').slideToggle(); return false">Click me to show stuff!</a><br>
  <div id="my_SubData<?= $currentRecordId; ?>" style="display: none "> Blah blah blah....</div>
</td>

I hate messy code, but unfortunately this is PHP so there’s only so much one borderline pyschotic developer can accomplish. Or is there?

 
//prior to my table
            $('a.actionable').live('click',function(){                
                $($(this).attr('href')).slideToggle();
                return false;
            });
 
//Now 
<td>
  <a href="#my_SubData<?= $currentRecordId ?>')" class="actionable">Click me to show stuff!</a><br>
  <div id="my_SubData<?= $currentRecordId; ?>" style="display: none "> Blah blah blah....</div>
</td>

It’s almost elegant if you ignore the PHP inject. JQuery’s .live handler automatically routes all unhandled click events to the closest “.actionable” classed element, then inside the live event handler, you grab the anchor’s href value to get the element Id of what you want to edit.

Stupid PHP tricks: The Array builder

class ArrayBuilder {
    public function __set($name, $value){
        return $this->$name = $value;
    }
 
    public function __call($name, $value){
        if(count($value) == 1){
            $this->$name = $value[0];
        }else{
            $this->$name = $value;
        }
        return $this;
    }
 
    public function toArray(){
        return get_object_vars($this);
    }
 
    public static function FACTORY(){
        return new ArrayBuilder();
    }
 
}

Usage:

  $x = ArrayBuilder::FACTORY()->hello("World")->digits(1,2,3,4,5)->foo("BaR?")->toArray();
  var_dump($x);
   array(3) {
  ["hello"]=>
  string(5) "World"
  ["digits"]=>
  array(5) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(3)
    [3]=>
    int(4)
    [4]=>
    int(5)
  }
  ["foo"]=>
  string(4) "BaR?"
}

Works great for factory scenarios and confusing the $*&! out of the unwary.

Hosting local, the ghetto fabulous way

One of the first big draws of Ruby on Rails in late 2006 was the ability to host my development environment locally. Not only did this cut down on the chore work of developing in an environment, but it probably also boosted productivity for me substantially. A year later when I started teaching myself Python, another nail was hammered into the coffin that is my opinion of PHP. That said, I’ve toyed with a lot of different idea’s of hosting a PHP environment locally but to a degree stymied in the effort.
Continue reading

Bridging the gap: GIT & SVN, B.F.F.

Background

I’ve been using SVN for several years now, since late 2005 or early 2006, and its done me well since then. But a new darling has entered my life and its name is Git. I like git for some very specific reasons: It’s stupid easy to work with and as good or better then SVN for reliability. Also it helps that my preferred IDE, Komodo, recognizes and works with Git as well.
That said, I use google code for hosting my public projects and it only supports SVN and HG. So one night I read up on git and noticed that it had a plugin/support for bridging to a SVN managed repo. So began my journey.
Continue reading

Canvas tag: Collision detection & pixel decay

UPDATED: March 14, 2011 here

Continuing my tests/experiments with the Canvas tag has led to the Ping prototype. I had 3 minimal things I wanted to accomplish: Detecting the intersection of a 360 degree arc of ray/line segments to previously defined in map shapes; a visual decay/fade out of intersection points on the canvas, and lastly a test of performance. In addition I decided to experiment with another approach to Javascript object construction in the hopes of getting a performance gain.
Continue reading