Popular recipes by Anand http://code.activestate.com/recipes/users/760763/2010-03-17T07:27:15-07:00ActiveState Code RecipesYet again, one more enum for Python (Python)
2010-02-22T22:53:42-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/577063-yet-again-one-more-enum-for-python/
<p style="color: grey">
Python
recipe 577063
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/enum/">enum</a>).
</p>
<p>This is a fork of recipe #577024 which describes an enum type for Python using __slots__ and read-only variables. Apart from the enum with default positional argument values, this one adds another enum type using keyword arguments.</p>
Pyscanlogger - Python Port scan detector (Python)
2010-03-17T07:27:15-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576690-pyscanlogger-python-port-scan-detector/
<p style="color: grey">
Python
recipe 576690
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/security/">security</a>).
Revision 5.
</p>
<p>A pure Python program to detect network port scanning attacks. Currently logs different TCP port scans. Can run in the background like a daemon and log attacks to a log file.</p>
TwitterCmd - Interactive console for twittering (Python)
2009-10-08T02:15:19-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576923-twittercmd-interactive-console-for-twittering/
<p style="color: grey">
Python
recipe 576923
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/microblogging/">microblogging</a>, <a href="/recipes/tags/shortcuts/">shortcuts</a>, <a href="/recipes/tags/twitter/">twitter</a>).
Revision 4.
</p>
<p>TwitterCmd is an interactive console for twitter built on top of python-twitter library. It provides short, easy to remember commands for most twitter actions and provides a one-way interaction with the Python interpreter, exposing its objects to further inspection by the python-twitter API.</p>
Pretty-print XML (Python)
2009-05-13T07:47:45-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576750-pretty-print-xml/
<p style="color: grey">
Python
recipe 576750
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/xml/">xml</a>).
</p>
<p>One-liner to pretty print an XML file using xml.dom.minidom.</p>
Chat server & client using select.select (Python)
2007-09-28T08:57:53-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/531824-chat-server-client-using-selectselect/
<p style="color: grey">
Python
recipe 531824
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/network/">network</a>).
Revision 3.
</p>
<p>This recipe demos how to write a simple command line chat server & client using multiplexing using select.select. The server uses select call to multiplex multiple clients and the client uses it to multiplex command line & socket I/O.</p>
List classes, methods and functions in a module (Python)
2008-10-22T08:15:26-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/553262-list-classes-methods-and-functions-in-a-module/
<p style="color: grey">
Python
recipe 553262
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/programs/">programs</a>).
Revision 5.
</p>
<p>The recipe provides a method "describe" which takes a module as argument and describes classes, methods and functions in the module. The method/function description provides information on the function/method arguments using the inspect module.</p>
Multithreaded FIFO Gate (Python)
2008-09-08T08:29:14-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576418-multithreaded-fifo-gate/
<p style="color: grey">
Python
recipe 576418
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/semaphores/">semaphores</a>, <a href="/recipes/tags/synchronization/">synchronization</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/threading/">threading</a>).
Revision 5.
</p>
<p>While programming with multiple threads, sometimes one needs a construct which allows to suspend the execution of a set of running threads. This is normally required by an outside thread which wants to suspend the running threads for performing a specific action. The threads need to resume after the action in the same order in which they got suspended. </p>
<p>A thread gate (or gateway) allows you to do this. It acts like a gate through which only one thread can pass at a time. By default the gate is open, allowing all threads to "enter" the gate. When a thread calls "close", the gate is closed, blocking any threads which make a further call to "enter", till the gate is re-opened by the owner, whence the threads resume the order in which they got blocked.</p>
<p>The real-life parallel for this is a human operated level cross, which allows only one vehicle to pass at a time.</p>
Spin Cursor (Python)
2007-10-31T13:22:40-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/534142-spin-cursor/
<p style="color: grey">
Python
recipe 534142
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>A class providing a threaded spin cursor on the console.</p>
Text to PDF Converter (rewrite) (Python)
2007-09-26T13:32:30-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/532908-text-to-pdf-converter-rewrite/
<p style="color: grey">
Python
recipe 532908
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 3.
</p>
<p>This is a rewrite of my text2pdf converter posted as recipe #189858, which can be used to convert pure text files to PDF.</p>
Twisted XML RPC server with basic HTTP authentication (Python)
2007-08-09T09:48:48-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/526625-twisted-xml-rpc-server-with-basic-http-authenticat/
<p style="color: grey">
Python
recipe 526625
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 3.
</p>
<p>This recipe illustrates an XML RPC server using twisted with support for HTTP basic client authentication.</p>
Synchronization classes using decorators (Python)
2007-10-08T19:15:42-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/533135-synchronization-classes-using-decorators/
<p style="color: grey">
Python
recipe 533135
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/threads/">threads</a>).
Revision 2.
</p>
<p>This recipe provides decorator classes that can be used to transparently provide synchronization and access control to your resources.</p>
Bitsort algorithm (Python)
2007-09-11T01:47:23-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/528942-bitsort-algorithm/
<p style="color: grey">
Python
recipe 528942
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>The recipe illustrates a Python implementation of the bitsort algorithm. This algorithm is illustrated in the book "Programming Pearls" by Jon Bentley. The bitsort algorithm provides a very efficient way to sort large numbers in disk files.</p>
A python replacement for java.util.Properties (Python)
2006-07-28T08:52:19-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/496795-a-python-replacement-for-javautilproperties/
<p style="color: grey">
Python
recipe 496795
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/files/">files</a>).
Revision 5.
</p>
<p>This recipe provides a quick and easy way to process Java properties files using pure Python. Of course, Jython can always be used, but in situations where Jython cannot be used, this recipe provides a sure-fire drop-in replacement. The Properties class is modelled to duplicate the behaviour of the original as closely as possible.</p>
Composite design-pattern using dictionaries (Python)
2006-11-07T08:39:25-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/498249-composite-design-pattern-using-dictionaries/
<p style="color: grey">
Python
recipe 498249
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/oop/">oop</a>).
Revision 2.
</p>
<p>The recipe illustrates the composite design pattern by using hierarchical dictionaries. It can be used to process hierarchical, tree-based data structures using Python dictionaries.</p>
Mini-commands using subprocess (Python)
2006-09-26T07:38:58-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/498137-mini-commands-using-subprocess/
<p style="color: grey">
Python
recipe 498137
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
Revision 2.
</p>
<p>A set of template classes which allows to develop custom "mini-command"
classes which allow to execute any system command and customize the
execution using template strings.</p>
Amaze - An object-oriented maze generator/solver in Python (Python)
2006-07-26T15:04:50-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/496884-amaze-an-object-oriented-maze-generatorsolver-in-p/
<p style="color: grey">
Python
recipe 496884
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 10.
</p>
<p>This is a simple maze generator & solver written in Python. It is written as a game, consisting of classes which can read mazes from STDIN or a file. It provides a a random maze generator game, which can generate mazes of any dimension and solve it. Use it for fun and learning.</p>
A basic time profiler (Python)
2006-08-03T20:39:37-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/496938-a-basic-time-profiler/
<p style="color: grey">
Python
recipe 496938
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
</p>
<p>This recipe provides a very simple time profiling module which helps you to
measure actual execution time for blocks of Python code without peppering your
code with many time.time() statements.</p>
YARW - Yet Another Registry Wrapper (Python)
2006-04-05T07:13:16-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/476229-yarw-yet-another-registry-wrapper/
<p style="color: grey">
Python
recipe 476229
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
Revision 3.
</p>
<p>This recipe provides "Registry", a Windows registry wrapper class that makes it easy to work with the Windows registry. The class works with an inner class named "RegistryKey", which wraps up a Windows registry key and provides methods to access and manipulate the key information. The class provides easy to remember substitutes for long method names of _winreg.</p>
Simple XML serlializer/de-serializer using Python dictionaries and marshalling (Python)
2005-06-07T09:13:40-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/415983-simple-xml-serlializerde-serializer-using-python-d/
<p style="color: grey">
Python
recipe 415983
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/xml/">xml</a>).
Revision 2.
</p>
<p>This recipe presents a way of serializing & de-serializing XML using
the marshal module. The XML is converted to an equivalent Python
dictionary first, which is marshaled to serialize it. De-serialization
first unmarshals the dictionary from the file, and constructs the
original XML.</p>
'Zip walker' - Zip file tree generator (Python)
2005-06-16T02:54:02-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/425840-zip-walker-zip-file-tree-generator/
<p style="color: grey">
Python
recipe 425840
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>A generator which provides a quick way to 'walk' a zip file archive.
The generator can process multiple zip archives, i.e zip files which
contain zip files. Inspired by the os.walk function.</p>