Popular recipes by Michael Palmer http://code.activestate.com/recipes/users/1827292/2009-04-03T13:38:39-07:00ActiveState Code RecipesTransparently execute SQL queries as prepared statements with Postgresql (Python) 2009-03-23T07:30:07-07:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/576698-transparently-execute-sql-queries-as-prepared-stat/ <p style="color: grey"> Python recipe 576698 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/postgresql/">postgresql</a>, <a href="/recipes/tags/prepared_statements/">prepared_statements</a>, <a href="/recipes/tags/sql/">sql</a>). Revision 4. </p> <p>This recipe defines a mixin class for DBAPI cursors that gives them an 'executeps' method. This method transparently converts any SQL query into a prepared statement, which gets cached and executed instead of the original query.</p> Multi-Regex: Single pass replace of multiple regexes (Python) 2009-04-03T13:38:39-07:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/576710-multi-regex-single-pass-replace-of-multiple-regexe/ <p style="color: grey"> Python recipe 576710 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/regular_expressions/">regular_expressions</a>, <a href="/recipes/tags/string_substitution/">string_substitution</a>). Revision 5. </p> <p>Not really - all regexes first get combined into a single big disjunction. Then, for each match, the matching sub-regex is determined from a group name and the match object dispatched to a corresponding method, or simply replaced by a string. </p> Thread pool mixin class for use with SocketServer.TCPServer (Python) 2008-07-10T18:52:58-07:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/574454-thread-pool-mixin-class-for-use-with-socketservert/ <p style="color: grey"> Python recipe 574454 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/threads/">threads</a>). Revision 2. </p> <p>This is intended as a drop-in replacement for the ThreadingMixIn class in module SocketServer of the standard lib. Instead of spawning a new thread for each request, requests are processed by of pool of reusable threads.</p> A self-cleaning dict-like container which limits the number and lifetime of its items (Python) 2006-11-15T23:51:50-08:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/498266-a-self-cleaning-dict-like-container-which-limits-t/ <p style="color: grey"> Python recipe 498266 by <a href="/recipes/users/1827292/">Michael Palmer</a> . Revision 2. </p> <p>This container stores its items both in a dict (for direct access) and in a bi-directionally linked list, which enables it to update itself in essentially O(1) time. No iteration over the entire list is ever needed, no separate thread is required for cleaning either. Should be useful e.g. for session storage in web servers.</p> Server side JavaScript dependency resolution (Python) 2006-11-15T09:53:45-08:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/498265-server-side-javascript-dependency-resolution/ <p style="color: grey"> Python recipe 498265 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>Purpose: Easing maintenance of JavaScript files and their inclusions in web pages by server-side dependency resolution. If at the top of a.js you include the comment</p> <p>// requireScript b.js</p> <p>and at the top of b.js you say</p> <p>// requireScript c.js</p> <p>then JSResolver's method .asTags('a.js') will give you e.g.</p> <p>&lt;script language="javascript" src="c.js"&gt;&lt;/script&gt; &lt;script language="javascript" src="b.js"&gt;&lt;/script&gt; &lt;script language="javascript" src="a.js"&gt;&lt;/script&gt;</p> <p>which you can then stick straight into your web page.</p> <p>Circular dependencies between JS files are forbidden and raise an exception.</p> JavaScript code compression (Python) 2008-05-04T01:08:24-07:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/496882-javascript-code-compression/ <p style="color: grey"> Python recipe 496882 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/web/">web</a>). Revision 8. </p> <p>A regex-based JavaScript compression kludge.</p> <p>The current version has been tested against mochikit and json.js, which indeed tripped up the previous version (see comments).</p> Simple exception logging (Python) 2006-01-22T08:48:00-08:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/466332-simple-exception-logging/ <p style="color: grey"> Python recipe 466332 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>If you want to log exceptions, here is a simple way to do so without having to explicitly repetitiously call the logger in each try-except clause.</p> Yaptoo (Yaptu outrageously obfuscated) - or yet yet another templating utility (Python) 2006-11-15T16:58:11-08:00Michael Palmerhttp://code.activestate.com/recipes/users/1827292/http://code.activestate.com/recipes/465508-yaptoo-yaptu-outrageously-obfuscated-or-yet-yet-an/ <p style="color: grey"> Python recipe 465508 by <a href="/recipes/users/1827292/">Michael Palmer</a> (<a href="/recipes/tags/web/">web</a>). Revision 10. </p> <p>An enhanced version of yaptu, with the following changes - separated parsing from execution - added caching of parsed templates - added some error reporting - added a choice of template syntaxes - added comment syntax - added Cheetah-style variable substitution with optional caching of the equivalent Python expression - limited flow control to 'for' and 'if' Reasonably small, no external dependencies, pretty fast.</p>