Refactored scope

Python, sometimes you scare me

by David on Aug.26, 2010, under Uncategorized

for i in range(0, len(sys.path)):    
    if sys.path[i].find("~") > -1:        
        sys.path[i] = path.expanduser(sys.path[i])
        break
else:    
    sys.path.insert(1,path.expanduser("~/lib/python"))

More duct tape code to allow me to rely on ~/lib/python to store common code (ex. apache log parsing & analysis ) when PYTHONPATH might not be set or
set incorrectly.

Basically if ~ is found in sys.path, the break statement skips the else. Alternatively, if not found then else is executed.
Python compound statements: For loops

Leave a Comment more...

Unnamed project: PHP doc’s on steroids

by David on Aug.20, 2010, under Uncategorized

Been playing with a tool released by Facebook called xhprof, http://mirror.facebook.net/facebook/xhprof/doc.html , which is a
very nice tool for figuring out what exactly is going on in your PHP code.

Meanwhile I used Doxygen a lot, its great for finding out how spread out calls are to individual libraries, has great call graphs, and if setup correctly can draw out the entire hierarchy of even the most complicated of projects.

What I’d like to do is create something that uses xhprof with documentation logic similar to doxygen, to make dynamically generated documentation that not only shows you how a class is defined, but how it’s defined, what depends on it, and what does it depend on.

UI:
I was thinking of something that was intelligent in the ways of MVC frameworks, recording a list of all urls called into a framework and then displaying them as a list broken down by URL components.

A simple example might be a MVC project with one controller called user
User has a standard CRUDE outline so the url’s might be
/user/create
/user/list
/user/edit
/user/save
/user/delete

So the first screen would be:

Entry points:
User – 5 sub points

The sub points part would be a anchor leading to a digest page listing # of recorded profiles to /user/ then maybe a digest of slowest call with the subcompontent ( say save ) to fastest ( delete ), highest / lowest memory consumption, a link to files common to this URI, and then links to progress further down the URL chain.

Clicking on list would lead to /usr/list – again showing the above, but now specific to this URL. At this point there shouldn’t be anymore child components in the URL ( GET arguments are automatically stripped OFF ) so an additional feature would be to click a link to show a visual graph similar to what stock xhprof UI provides.

The fun part would be when you clicked on one of the listed files. Immediately this would bring up a page similar to a doxygen product, but it would have some additional information:
# of dependant URLS that executed this file
# of classes, functions, and methods used in this file by this url path ( /user/list )
fastest and slowest execution speeds plus memory consumption percentage for /user/list.

Clicking on a class, method, or function would cause it to again drill down and show stats JUST for the specified scope.

Considering its taken me 3 months to get PyProxy to stable useful Alpha, this project is probably going to take me a year or more… but it should be fun.

Leave a Comment more...

PyProxy hijack logic

by David on Aug.19, 2010, under Uncategorized

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.

Comments Off more...

Pardon my widgets

by David on Aug.13, 2010, under Uncategorized

Rendering delays are likely.

Comments Off more...

From the dept of questionable ideas: watching make

by David on Jul.27, 2010, under Uncategorized

#watch -n 30 ‘make’

Works great when your webstack uses make to automagically compile multiple files then minify the whole mess down… but your constantly making tweaks and fixes.

Comments Off more...

A simple example of horizontal scaling VS. vertical scaling just with Database’s

by David on Apr.15, 2010, under Uncategorized

My answer to a question of what is the difference between Horizontal & Vertical scaling
Link
(continue reading…)

Comments Off more...

Pulling cheap tricks with JQuery

by David on Mar.29, 2010, under Uncategorized

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.

Comments Off more...

Stupid PHP tricks: The Array builder

by David on Mar.22, 2010, under Uncategorized

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.

Comments Off more...

Hosting local, the ghetto fabulous way

by David on Mar.05, 2010, under howto

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…)

Comments Off :, , more...

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

by David on Mar.02, 2010, under howto

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…)

Comments Off :, more...

Looking for something?

Use the form below to search the site:

 

Archives

All entries, chronologically...