Wednesday, May 22, 2013

Zato, an open source ESB in Python

Zato | home page

Zato is an ESB (Enterprise Service Bus) which is written in Python. It is free and open source (LGPL).

http://en.m.wikipedia.org/wiki/Enterprise_service_bus

Tibco was one of the first ESB products and Mule is an open source one.

According to the Zato site:

It supports HTTP, JSON, SOAP, Redis, JMS WebSphere MQ, ZeroMQ, FTP, SQL.

It has a web admin GUI, a CLI and an API.

Documentation and commercial support are available.

I got to know about Zato recently from the main  developer, Dariusz Suchojad, who had earlier written to me  regarding my blog post about PyMQI:

PyMQI, Python interface to IBM WebSphereMQ (formerly IBM MQSeries):

http://jugad2.blogspot.com/2013/02/pymqi-python-interface-to-ibm.html

Dariusz was a maintainer of PyMQI and also a developer on Spring Python, which is sort of a port of the Java Spring framework to Python.

Zato docs (quite detailed):

https://zato.io/docs/index.html

Part 1 of a basic Zato tutorial:

https://zato.io/docs/tutorial/01.html

I took a look at the tutorial. Broadly, it shows how to install Zato, create a simple Zato service in Python, that talks to PostgreSQL and Redis, and deploy it. Two servers get created, behind a load-balancer, and the service gets hot-deployed to the servers. Then curl is used to access the service. (This tutorial does not create a real client; curl is used to simulate one.)

Zato looks interesting and powerful (and somewhat complex, but that is to be expected for a product like an ESB).

I will check it out more and then report on my findings.

- Vasudev Ram
dancingbison.com

Tuesday, May 21, 2013

A partial crossword solver in Python

A Cryptic Crossword Clue Solver ←

Saw this via Twitter.

It is a partial crossword solver, because it only helps solve a particular category of crossword clues - those in which the clue (which is usually a sentence or phrase) contains both a "definition" of the answer as well a hint of some kind that leads to the same answer. This solver tries to compute the answer using both the definition and the hint, and checks whether the results match. Ingenious.

I found it interesting because this is a somewhat difficult problem, and yet the author managed to create a solution (involving NLTK and parsing) that works in many, if not all cases.

Also, long ago, in college days, I had written another kind of partial crossword solver (in BASIC); it was much simpler, using a brute force method - what it did was help solve the kind of crossword clues in which the answer is a permutation of a substring of the characters comprising the clue sentence or phrase. The program would generate and display on the screen, all possible permutations of all possible substrings of the sentence, that were of the same length as the answer. Then you had to view those permutations and guess whether any of them was the right answer, based on the clue.

I wrote the permutation-generation code by hand, but saw recently that the Python itertools module has methods to generate permutations (as well as combinations) from sequences:

http://docs.python.org/2/library/itertools.html

http://en.m.wikipedia.org/wiki/Permutation

http://en.wikipedia.org/wiki/Crossword

- Vasudev Ram
dancingbison.com

Charge your phone in 20 seconds

Teen's prize-winning invention may charge your phone in 20 seconds - CNN.com

Interesting  ... She got a $50,000 award for it at an Intel Science competition for high school students.

Monday, May 20, 2013

HuffShell suggests aliases for your Unix commands

paulmars/huffshell · GitHub

huffshell is a gem to suggest optimized aliases for your frequently used Unix commands. It looks at your command history to do that.

Seen via this Hacker News post which is interesting too:

What are your top 100 unix commands? (for science) :

https://news.ycombinator.com/item?id=5733426

- Vasudev Ram
dancingbison.com

Saturday, May 18, 2013

Python's inspect module is powerful

27.13. inspect — Inspect live objects — Python v2.7.5 documentation

The inspect module comes as part of the standard library of Python. It allows you to inspect live objects at run time by using its methods.

Here is an example:

import inspect
class Bar( object):
    def foo( self ):
        print "in Bar.foo 4"
        self .a = 1
        self .di = { 'b' : 2, 'c' : 3 }
        self .li = [  4, 5, 6 ]

bar = Bar()
bar.foo()
for member in inspect.getmembers(bar):
    print member

Running the above code gives this as (partial) output:

in Bar.foo 4

('__dict__', {'a': 1, 'li': [4, 5, 6], 'di': {'c': 3, 'b': 2}})
('__doc__', None)
('a', 1)
('di', {'c': 3, 'b': 2})
('foo', bound method Bar.foo of __main__.Bar object at 0x4035bfac)
('li', [4, 5, 6])

This shows both the bound methods and the member variables of the instance bar.

The inspect module can do a lot of other things too. Check the docs for it, linked at the top of this post.

You can also modify and run the above code snippet at this codepad.org URL:

http://codepad.org/dMLmkhQ6

It may not last there for too long, though, since they probably delete pastes to make room for new ones.

- Vasudev Ram
dancingbison.com