Category Archives: howto

Python json.tool module

Python documentation here

Example usage:

$ echo '{"json":"obj"}' | python -mjson.tool
{
    "json": "obj"
}
$ echo '{ 1.2:3.4}' | python -mjson.tool
Expecting property name: line 1 column 2 (char 2)
   

All argument patterns are:

  • piped json string | python -m json.tool which syntax checks then outputs the results to stdout
  • python -m json.tool input_file.json which reads the path relative file and outputs the results
  • python -m json.tool input_file.json output_file.json only difference here is that the output is directed to the specified file

My thoughts, this could be part of some sort of data validation check, looking for corrupted json static files.

Example

$ echo '{"a":123, "foo":"bar" }' | python -m json.tool && echo "IS valid" || echo "Is not valid"
{
    "a": 123,
    "foo": "bar"
}
IS valid
$ echo '{"a"1:123, "foo":"bar" }' | python -m json.tool && echo "IS valid" || echo "Is not valid"
Expecting : delimiter: line 1 column 4 (char 4)
Is not valid

Using py DBGP to debug cherrypy – Work in progress

I will freely admit I am heavily addicted to the DBG protocol these days. For the uninformed, DBGp when combined with a proper client, allows for symbolic debugging of live and or remote applications in PHP and Python. I’ve used xdebug, the PHP implementation of DBGp for several years now and it has been a tremendous time saver debugging weird issues in staging and testing environments.

I’ve also used DBGp for simple Python applications, but have never been able to get the same functionality with more advanced products like cherrypy…. until now. I’ts kind of hokey, but all I needed to do was insert a python dbgp call liked

    from dbgp.client import brk
    
    def someCode(*args)
          ....
          brk(host="192.168.56.1", port = "9000" )

And voila I got a session started inside one of my controller methods while it was walking through handling an OpenId response.

Very happy about this I must say as it will make it ever so much easier to figure out where the hell I’ve gone wrong.

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