Popular recipes by Gabriel Genellina http://code.activestate.com/recipes/users/924636/2010-04-01T04:54:16-07:00ActiveState Code RecipesLoggingWebMonitor - a central logging server and monitor. (Python) 2010-02-02T01:56:42-08:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/577025-loggingwebmonitor-a-central-logging-server-and-mon/ <p style="color: grey"> Python recipe 577025 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/client_server/">client_server</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/distributed/">distributed</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/web/">web</a>). Revision 3. </p> <p>LoggingWebMonitor listens for log records sent from other processes running in the same box or network. Collects and saves them concurrently in a log file. Shows a summary web page with the latest N records received.</p> Sets with a custom equality/uniqueness function (Python) 2009-10-29T21:08:22-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576932-sets-with-a-custom-equalityuniqueness-function/ <p style="color: grey"> Python recipe 576932 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/abstract_base_class/">abstract_base_class</a>, <a href="/recipes/tags/mutableset/">mutableset</a>, <a href="/recipes/tags/set/">set</a>, <a href="/recipes/tags/unique/">unique</a>). Revision 4. </p> <p>The builtin <code>set</code> and <code>frozenset</code> types are based on object equality; they call __eq__ to determine whether an object is a member of the set or not. But there are cases when one needs a set of objects that are compared by other means, apart from the default __eq__ function. There are several ways to achieve that; this recipe presents two classes, FrozenKeyedSet and KeyedSet, that take an additional function <code>key</code> which is used to determine membership and uniqueness. Given two objects which return the same value for <code>key</code>, only one of them will be in the set.</p> Yet another 'enum' for Python (Python) 2010-01-28T18:23:11-08:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/577024-yet-another-enum-for-python/ <p style="color: grey"> Python recipe 577024 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/enum/">enum</a>). Revision 5. </p> <p>There are quite a few 'enum' recipes already here. This one is short, cheap, and has neither bells nor whistles :)</p> Find all subclasses of a given class (Python) 2009-11-04T20:26:08-08:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576949-find-all-subclasses-of-a-given-class/ <p style="color: grey"> Python recipe 576949 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/extending/">extending</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/plugin/">plugin</a>, <a href="/recipes/tags/subclass/">subclass</a>, <a href="/recipes/tags/subclasses/">subclasses</a>, <a href="/recipes/tags/type/">type</a>). Revision 3. </p> <p>itersubclasses(cls) returns a generator over all subclasses of cls, in depth first order. cls must be a new-style class; old-style classes are <em>not</em> supported.</p> Merge multiple (potentially infinite) sorted inputs into a single sorted output (Python) 2010-04-01T04:54:16-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/577041-merge-multiple-potentially-infinite-sorted-inputs-/ <p style="color: grey"> Python recipe 577041 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/merge/">merge</a>, <a href="/recipes/tags/sort/">sort</a>). Revision 4. </p> <p>Merge a (possibly infinite) number of already sorted inputs (each of possibly infinite length) into a single sorted output.</p> <p>Similar to heapq.merge and sorted(itertools.chain(*iterables)).</p> <p>Like heapq.merge, returns a generator, does not pull the data into memory all at once, and assumes that each of the input iterables is already sorted (smallest to largest).</p> <p>Unlike heapq.merge, accepts an infinite number of input iterables, but requires all of them to come in ascending order (that is, their starting point must come in ascending order).</p> <p>In addition, accepts a <em>key</em> function (like <code>sorted</code>, <code>min</code>, <code>max</code>, etc.)</p> Detect when system is idle (Python) 2009-05-31T01:18:03-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576786-detect-when-system-is-idle/ <p style="color: grey"> Python recipe 576786 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/idle/">idle</a>, <a href="/recipes/tags/idle_time/">idle_time</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/user_input/">user_input</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>Detect when system is idle, globally. That is, the user is not moving the mouse nor typing anything, in any application (not just our program).</p> Decorator for BindingConstants at compile time (Python) 2009-09-15T00:34:37-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576904-decorator-for-bindingconstants-at-compile-time/ <p style="color: grey"> Python recipe 576904 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/optimisation/">optimisation</a>, <a href="/recipes/tags/optimization/">optimization</a>, <a href="/recipes/tags/programs/">programs</a>). </p> <p>Decorator for automatic code optimization. If a global is known at compile time, replace it with a constant. Fold tuples of constants into a single constant. Fold constant attribute lookups into a single constant.</p> <p>This is only an update of <a href="http://code.activestate.com/recipes/277940/">Recipe 277940</a>, making it compatible with Python 3. All credit must go to the original author, Raymond Hettinger.</p> Sorting big files the Python 2.6 way (Python) 2009-05-30T21:51:09-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576755-sorting-big-files-the-python-26-way/ <p style="color: grey"> Python recipe 576755 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/sort/">sort</a>, <a href="/recipes/tags/sorting/">sorting</a>, <a href="/recipes/tags/text/">text</a>). Revision 3. </p> <p>This is just a rewrite of <a href="http://code.activestate.com/recipes/466302/">Recipe 466302</a> "Sorting big files the Python 2.4 way", taking advantage of heapq.merge, context managers, and other niceties of newer Python versions. It can be used to sort very large files (millions of records) in Python. No record termination character is required, hence a record may contain embedded binary data, newlines, etc. You can specify how many temporary files to use and where they are located.</p> Gaussian integration with or without Log singularity (Python) 2009-09-09T21:03:10-07:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/576900-gaussian-integration-with-or-without-log-singulari/ <p style="color: grey"> Python recipe 576900 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/area/">area</a>, <a href="/recipes/tags/integration/">integration</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>The Gaussian quadrature is among the most accurate integration scheme for smooth integrands. It replaces a integral by a sum of sampled values of the integrand function times some weight factors.</p> <p>This is strictly a minor rewrite of <a href="http://code.activestate.com/recipes/52292/">recipe 52292</a>, just to make it compatible with Python 2.4 and above. 2to3 converts it perfectly to be used with Python 3.x</p> <p><em>All</em> credit is due to the original author, Alexander Pletzer.</p>