Popular recipes by Ori Peleg http://code.activestate.com/recipes/users/2056315/2006-10-07T20:55:12-07:00ActiveState Code Recipesexpand_tabs.py - expand tabs in files in-place (Python) 2006-10-07T20:55:12-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/498179-expand_tabspy-expand-tabs-in-files-in-place/ <p style="color: grey"> Python recipe 498179 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>expand_tabs.py - Similar to Unix's expand(1) command, but can edit the files in-place.</p> Extending the 'logging' module (Python) 2006-02-27T00:57:54-08:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/474089-extending-the-logging-module/ <p style="color: grey"> Python recipe 474089 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/debugging/">debugging</a>). Revision 2. </p> <p>Adding new format specifiers to the logging module. In this example, it's for the user name and the name of the function that logged the message.</p> Count commits to a Subversion repository (Python) 2006-08-31T13:53:36-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/497011-count-commits-to-a-subversion-repository/ <p style="color: grey"> Python recipe 497011 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Who's the most prolific committer in town? Use this script to find out!</p> <p>This script uses pysvn, <a href="http://pysvn.tigris.org" rel="nofollow">http://pysvn.tigris.org</a></p> clear the screen (Python) 2006-09-04T14:52:58-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/498064-clear-the-screen/ <p style="color: grey"> Python recipe 498064 by <a href="/recipes/users/2056315/">Ori Peleg</a> . </p> <p>Clear the screen on unix terminals, uses terminfo.</p> <p>terminfo inspiration courtesy of <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475116" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475116</a></p> "safely" defining __setattr__ (Python) 2006-09-01T08:06:29-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/497009-safely-defining-__setattr__/ <p style="color: grey"> Python recipe 497009 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 2. </p> <p>Overriding __setattr__ in classes requires care when setting attributes yourself. Here's an idea for safely setting attributes in __init__.</p> <p>Update: this idea doesn't work. See Mike Foord's recipe for one that does:</p> <p><a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/389916" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/389916</a></p> Finding out an argument default (Python) 2006-04-19T14:41:46-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/491272-finding-out-an-argument-default/ <p style="color: grey"> Python recipe 491272 by <a href="/recipes/users/2056315/">Ori Peleg</a> . </p> <p>Simple recipe for finding out a function argument's default value.</p> <p>Can be used as a poor-man's function attribute, see the examples.</p> has_colors(stream): Does an output stream support colors? (Python) 2006-03-26T14:26:42-08:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/475186-has_colorsstream-does-an-output-stream-support-col/ <p style="color: grey"> Python recipe 475186 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Great for deciding automatically whether to use colors.</p> <p>Based on <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475116" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475116</a></p> Randomize an iterator (Python) 2006-01-08T07:01:55-08:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/466177-randomize-an-iterator/ <p style="color: grey"> Python recipe 466177 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Extremely simple/straightforward implementation.</p> <p>Posted mainly to receive comments on alternative implementations.</p> "once" decorator (Python) 2005-06-19T00:15:03-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/425445-once-decorator/ <p style="color: grey"> Python recipe 425445 by <a href="/recipes/users/2056315/">Ori Peleg</a> . Revision 3. </p> <p>This decorator runs a function or method once and caches the result.</p> <p>It offers minimal memory use and high speed (only one extra function call). It is _not_ a memoization implementation, the result is cached for all future arguments as well.</p> <p>This code is used in the TestOOB testing framework (<a href="http://testoob.sourceforge.net%29." rel="nofollow">http://testoob.sourceforge.net).</a></p> Automatic fields pickling (Python) 2005-11-20T23:28:34-08:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/456363-automatic-fields-pickling/ <p style="color: grey"> Python recipe 456363 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 3. </p> <p>A 'fields' class is a class that acts like a struct full of fields, e.g.:</p> <p>&lt;pre&gt; class Titles: def __init__(self, name): self.name = name def dr(self): return "Dr. " + self.name def mr(self): return "Mr. " + self.name &lt;/pre&gt;</p> <p>Once an instance is constructed, the return value of x.dr() or x.mr() doesn't change.</p> <p>I sometimes have 'fields' classes that I need to pickle (e.g. they go over a wire) but they contain unpickleable members, like file objects or tracebacks.</p> <p>This code adds picklers to such classes that automatically 'flattens' the instances on pickling, saving the return values and making the unpickled instance return the saved values.</p> Normalizing newlines between windows/unix/macs (Python) 2005-07-02T14:28:58-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/435882-normalizing-newlines-between-windowsunixmacs/ <p style="color: grey"> Python recipe 435882 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>When comparing text generated on different platforms, the newlines are different. This recipe normalizes any string to use unix-style newlines.</p> <p>This code is used in the TestOOB unit testing framework (<a href="http://testoob.sourceforge.net%29." rel="nofollow">http://testoob.sourceforge.net).</a></p> ObserverProxy (Python) 2005-05-10T09:26:05-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/413701-observerproxy/ <p style="color: grey"> Python recipe 413701 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/ui/">ui</a>). Revision 2. </p> <p>Create an proxy that forwards methods to a group of observers</p> Pseudo-random string to float conversion (Python) 2005-03-11T15:46:51-08:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/391413-pseudo-random-string-to-float-conversion/ <p style="color: grey"> Python recipe 391413 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Convert strings to floats in the range [0, 1), using a hash function</p> Threaded test suite running and other goodies (Python) 2005-07-14T21:45:54-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/391414-threaded-test-suite-running-and-other-goodies/ <p style="color: grey"> Python recipe 391414 by <a href="/recipes/users/2056315/">Ori Peleg</a> (<a href="/recipes/tags/threads/">threads</a>). Revision 3. </p> <p>Note: This recipe is superceded by TestOOB, a Python unit testing framework that extends unittest and provides many new features - including running tests in threads! <a href="http://testoob.sourceforge.net" rel="nofollow">http://testoob.sourceforge.net</a></p> <p>Trying to extend unittest to provide extra features wasn't easy. This scheme allows easy extensions for running existing test suites.</p> Generating a RSS feed from CVS commits (Python) 2004-10-16T14:27:11-07:00Ori Peleghttp://code.activestate.com/recipes/users/2056315/http://code.activestate.com/recipes/310322-generating-a-rss-feed-from-cvs-commits/ <p style="color: grey"> Python recipe 310322 by <a href="/recipes/users/2056315/">Ori Peleg</a> . Revision 2. </p> <p>Track commits to CVS repositories as RSS feeds.</p>