Top-rated recipes by Anand http://code.activestate.com/recipes/users/760763/top/2010-03-17T07:27:15-07:00ActiveState Code RecipesList 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>
Timeit module wrapper (Python)
2005-02-28T09:34:34-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/389767-timeit-module-wrapper/
<p style="color: grey">
Python
recipe 389767
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 4.
</p>
<p>A simple, easy to use wrapper function for doing quick tests
of your functions using the timeit module.</p>
Simple File Splitter/Combiner module (Python)
2003-11-06T07:14:42-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/224800-simple-file-splittercombiner-module/
<p style="color: grey">
Python
recipe 224800
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/files/">files</a>).
Revision 4.
</p>
<p>This module can be used to split any file, text or binary
to equal sized chunks. It can also combine the chunks back
to recreate the original file.</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>
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>
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>
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>
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>
Basic Exception handling idiom using decorators (Python)
2005-04-06T04:25:10-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/408937-basic-exception-handling-idiom-using-decorators/
<p style="color: grey">
Python
recipe 408937
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
Revision 2.
</p>
<p>A basic exception handling idiom using decorators which allows you to
re-use the exception handler for different functions, while customizing your
handlers using arguments passed to an exception handling "decorator".</p>
Backup your files (Python)
2008-04-08T10:16:26-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/191017-backup-your-files/
<p style="color: grey">
Python
recipe 191017
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/files/">files</a>).
Revision 5.
</p>
<p>Makes backup versions of files</p>
Python text to pdf converter (Python)
2004-02-25T11:45:48-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/189858-python-text-to-pdf-converter/
<p style="color: grey">
Python
recipe 189858
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 8.
</p>
<p>Python port of a very popular implementation of
text2pdf in the C programming language. I ported this
to python because it could be used as a script instead
of executable which is the case with the original program.
Most of the options remain the same.</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>
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>
wxPython Graphics - Drawing rubberbands over a canvas (Python)
2003-12-30T05:43:10-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/189744-wxpython-graphics-drawing-rubberbands-over-a-canva/
<p style="color: grey">
Python
recipe 189744
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
Revision 2.
</p>
<p>This recipe talks about how to implement rubberbanding code for canvas
objects in a wxPython application. Canvas classes in wxPython include
wxPanel, wxStaticBitmap, wxGlCanvas etc.</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>
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>
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>
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>