Sep 192011
 

If you know Javascript, then this isn’t a suprise:

typeof {a: 4}; //"object"
typeof [1, 2, 3]; //"object"
(function() {console.log(typeof arguments)})(); //object
typeof new ReferenceError; //"object"
typeof new Date; //"object"
typeof /a-z/; //"object"
typeof Math; //"object"
typeof JSON; //"object"
typeof new Number(4); //"object"
typeof new String("abc"); //"object"
typeof new Boolean(true); //"object"

But thanks to some dilligent work by one Angus Croll, you can do something like:

toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
toType(new ReferenceError); //"error"
toType(new Date); //"date"
toType(/a-z/); //"regexp"
toType(Math); //"math"
toType(JSON); //"json"
toType(new Number(4)); //"number"
toType(new String("abc")); //"string"
toType(new Boolean(true)); //"boolean"

Check out the full explanation @
http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/

 

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.

 

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

Jul 032011
 

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.

 

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.

 

WOW, the top answers to this question are amazingly useful

One quick example
Instead of

  if x > 10 and x < 100:
       print "Match"

You can do…..

   if 10 < x < 100:
       print "Match!"

In my opinion, that’s very snazzy.

http://stackoverflow.com/questions/101268/hidden-features-of-python

 

Keep end up going back to this answer repeatedly as I keep forgetting to snapshot a clean slate PHP5 dev. VM.

http://superuser.com/questions/55055/how-to-install-an-updated-version-of-pear-phpunit-on-ubuntu/55072#55072

 

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

http://www.flynsarmy.com/2010/12/better-doctrine-2-module-for-kohana-3/

Doctrine 2

 Uncategorized  Comments Off
May 102011
 

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

 

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.

© 2012 Refactored scope Suffusion theme by Sayontan Sinha