Category Archives: Uncategorized

Unasked question for stackoverflow, an idea for removing/minimizing a singleton

Problem
——-
I have two cooperative services in twisted, one is a HTTP proxy and the other a HTTP service to power a web console. At the start and end of every proxy request, an overloaded method copies the request ( headers, POST data, etc ) and also the response. Currently I have a singleton data.Store that receives new records and it works except its becoming unwieldy to unit-test.

Ideas
—–
One thought was to implement an in-process synchronous service bus in a module and make it near stateless.

bus.py


    channels = defaultdict(list)


    def register(name, callback):
        global channels
        channels[name].append(callback)

    def callbacks(name):
        global channels
        #use of generator to allow for the caller to apply exception handling logic
        for callback in channels[name]:
            yield callback

   def first(name, default = None):
        global channels
        return channels[0] if count(channels) > 0 else default

A simple example might be

main.py

store = data.Store()


bus.register("store.addRecord", store.AddRecord)

proxy.py


class ProxyClient(proxy.ProxyClient):
     ....
     def handleResponse(self, data):
         proxy.ProxyClient.handleResponse(self, data)
         bus.first("store.addRecord", lambda : return False)(data)

Does this seems sensible? bus.channels can be cleared by setUp logic while testing can use in testcase methods for mocking. Or is there already something like this backed into twisted ( which would be much more preferable as the twisted dev’s can usually be relied on to already have unit-testing )

By the time I got to here, I decided that I DID in fact like this solution. Should but may not update to see how this went.

PyOverlord is now PyProxy aka Proxy Project

https://github.com/devdave/PyProxy

ProxyProject

  • Author: David W
  • Status: Pre-Alpha

Primary goal

ProxyProject is initially meant to resolve one very common and VERY tedious part of Web development,
validating web forms. A developer would place Proxy Project between their browser and their development environment
then run through the process of populating and submitting a form. After the developer would return to the Proxy
Project control panel and click a button, in return a python mechanize script would be presented.

Secondary goals

Since the Proxy is already recording everything, additional features would be the ability to replay the response side
of requestes on demand ( basically caching the respons ).

The ability to mechanize scripts into “story” scripts, to make it easier to re-use and organize them for building up
front loaded system under-test scripts.

Could be nice goals

A tool to marry SQL statements stored in a MySQL general log file to individual responses, perhaps make it easier to add
additional DB level post mechanize

Adding new branch on github

Branch currently uncommitted changes into a new branch
#git checkout -b new_branch
Save your changes
#git commit OR git add & commit whatever
#git push origin new_branch

Done; somewhat odd that this simple task isn’t that well document or from googling has a lot of around the world methods to accomplish the above.

Doctrine2 building Where like expressions

Use case: You have a search form with multiple search criteria “name”, “id”, “type”, etc.

In your entity’s repository you would have a function like

Note, trying to use Gist for inline code, if it doesn’t work/render then go here https://gist.github.com/1039231

It’s important to note the setParameter call is responsible for wrapping the value in %’s and NOT the where expression itself. At the PDO driver layer, it either ignores or is aware of wrapped % symbology and allows those characters to get past the input scrubbers.

Minus the ->select expression, this could conceivably be portable to any and all Entities by shoving an application level EntityRepostory class between the individual entities and the Doctrine EntityRepository.

One battle at a time and eventually win the war

One of my clients has a PHP5.1 environment that was originally configured by a band of rabid monkeys snorting meth. Finally got approval last week to clean slate everything. Unfortunately I’m still stuck with PHP5, but version 5.33 instead. Next hurdle was the other side of the department that is doing something completely unrelated to my side wanted to use Zend Framework. Honestly I was interested in spending some time with ZF but only as a resume bullet and thats not exactly right or fair to my client.

That said, it’s Doctrine 2 and Kohana 3, full speed ahead. In the grand scheme of things, its frustrating as hell to work with PHP5 when there is so many nice things out there like Python, C#, Ruby, and did I mention Python?

Lastly, kudo’s to Flynsarmy for doing the leg work to integrate the two major frameworks into one tidy little package.

Link to blog post ( download links is on there, should read this blog post as it explains how to install it, it’s free, and this guy or girl put in some quality work and deserves your 2-4 seconds of attention ) here

Better Doctrine 2 Module for Kohana 3

Doctrine 2

I’ve been looking at upgrading one of my past clients from Doctrine 1 to Doctrine 2 and so far it’s looking from my end like a done deal.

I started here by paging through this ( http://www.slideshare.net/jwage/doctrine-2-not-the-same-old-php-orm ) slideshare on Doctrine 2 and before I got bored with paging through 94 slides I already had a warm fuzzy feeling.

My initial tests have shown that Doctrine 2 without a doubt needs support from APC or memcached, but with the exception my few and far between dumb/cheap client’s is almost guaranteed to be present. Otherwise I like the decidedly simpler syntax for defining domain models as simple classes without inheriting some super support class.

Last bit, my stackoverflow answers regarding doctrine 2 so far
http://stackoverflow.com/questions/5954618/does-doctrine-2-0-pre-generate-model-classes-like-propel-1-5-does/5955400#5955400

Ping documentation in progress

I’ve been writing class/method level documentation and ideally plan to make a step by step explanation of what the heck is going on inside the Ping toolset. Until then it’s pretty doubtful anyone will want to use it. Never mind everything is still in Alpha state and there is very little guarantees that something won’t be written.

Eh

First thing I do after getting a new Ubuntu server running

#apt-get install vim -y

Not sure what its called, but the default vi install isn’t friends with putty and neither am I.