Top-rated recipes by Jack Trainor http://code.activestate.com/recipes/users/4076953/top/2016-03-11T03:39:32-08:00ActiveState Code RecipesPathCatcher - Windows utility for right-click capture of file or folder path (Python) 2008-04-19T17:14:18-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/528893-pathcatcher-windows-utility-for-right-click-captur/ <p style="color: grey"> Python recipe 528893 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 3. </p> <p>PathCatcher is a Windows utility that allows one to right-click on a file or a folder or a group of files and folders in Explorer and save its path to the clipboard.</p> <p>To install, save the code as PathCatcher.py, then double-click the PathCatcher.py file. Afterwards, PathCatcher will appear in the Explorer right-click menu.</p> "More Sex is Safer Sex" Paradox (Python) 2010-09-22T02:56:37-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577403-more-sex-is-safer-sex-paradox/ <p style="color: grey"> Python recipe 577403 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/simulation/">simulation</a>). </p> <p>In his book, "More Sex Is Safer Sex: The Unconventional Wisdom of Economics, " Steven Landsburg argues that if sexual conservatives took more sexual partners it would improve everyone's chances of finding low-risk partners, thereby reducing the spread of STDs for all. </p> <p>See <a href="http://www.nytimes.com/2007/07/08/books/chapters/0708-1st-land.html?_r=1&amp;pagewanted=print" rel="nofollow">http://www.nytimes.com/2007/07/08/books/chapters/0708-1st-land.html?_r=1&amp;pagewanted=print</a> .</p> <p>This recipe attempts to simulate the scenario which Landsburg describes and test his claim that "More sex is safer sex."</p> Attribute-based Framework 1: Basics (Python) 2010-07-21T21:40:54-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577327-attribute-based-framework-1-basics/ <p style="color: grey"> Python recipe 577327 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/framework/">framework</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/simulation/">simulation</a>). Revision 2. </p> <p>I am adapting Prof. David Cheriton's OO software methodology to Python. It's an approach for building industrial-strength code with a disciplined architecture, consistent naming conventions, and a rigorous division of interface from implementation. I'll be adding more of his techniques in further recipes. These recipes are based on Cheriton's CS249a course at Stanford.</p> BigDirs - Where's my disk space gone? (Python) 2010-07-18T02:52:18-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577301-bigdirs-wheres-my-disk-space-gone/ <p style="color: grey"> Python recipe 577301 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/administration/">administration</a>, <a href="/recipes/tags/shortcut/">shortcut</a>). Revision 2. </p> <p>BigDirs locates directories taking up the most disk space in files at that directory level, not in the nested directories below it. In my experience this is the easiest way to find where my disk space got chewed up.</p> <p>Set DEFAULT_DIR for the root directory you wish to check. Set DEFAULT_THRESHOLD for the minimum size of the directories you wish to see in the output.</p> Consolidate group of modules into one recipe (Python) 2010-07-21T21:22:46-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577297-consolidate-group-of-modules-into-one-recipe/ <p style="color: grey"> Python recipe 577297 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/recipe/">recipe</a>, <a href="/recipes/tags/shortcut/">shortcut</a>). Revision 4. </p> <p>Packs all python source files from current directory into a single recipe file that can be later run to recreate packed files. Skips files whose names begin with underscore or contain "recipe".</p> CommentEditor: HTML editor for online comments (Python) 2009-06-17T12:10:55-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/576814-commenteditor-html-editor-for-online-comments/ <p style="color: grey"> Python recipe 576814 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/wxwidgets/">wxwidgets</a>). Revision 3. </p> <p>Edit online comments with easy addition of HTML tags for bold, italics, underlining, blockquote and anchored links. Then check your work with the preview feature.</p> <p>Requires wxWidgets.</p> Convert text/enriched MIME to text/html (Python) 2009-06-09T15:08:40-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/576800-convert-textenriched-mime-to-texthtml/ <p style="color: grey"> Python recipe 576800 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/mime/">mime</a>, <a href="/recipes/tags/text_enriched/">text_enriched</a>). </p> <p>Converts text stream in text/enriched MIME format from file or stdin to text/html output to file or stdout.</p> State Machine for Text Processing (Python) 2009-01-21T14:01:23-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/576624-state-machine-for-text-processing/ <p style="color: grey"> Python recipe 576624 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/state_machine/">state_machine</a>, <a href="/recipes/tags/text_processing/">text_processing</a>). </p> <p>General state machine mechanism plus a specialized version, LineStateMachine, for processing text files based by using regular expressions to determine state transitions.</p> Line Oriented State Machine (Python) 2008-06-30T05:13:27-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/574430-line-oriented-state-machine/ <p style="color: grey"> Python recipe 574430 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/text/">text</a>). Revision 4. </p> <p>State machine for processing text files on a line-by-line basis using regular expressions to determine transition to next state.</p> <p>Developed from sample code from "Text Processing in Python" by David Mertz,pp. 274-280.</p> Unicode String Hex Dump (Python) 2008-05-03T01:12:27-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/572181-unicode-string-hex-dump/ <p style="color: grey"> Python recipe 572181 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/debugging/">debugging</a>). Revision 3. </p> <p>Simple routine for dumping any kind of string, ascii, encoded, or unicode, to a standard hex dump. Plus read/write of unicode and encoded strings.</p> Simplest Registry I/O (Python) 2007-08-24T12:38:48-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/528896-simplest-registry-io/ <p style="color: grey"> Python recipe 528896 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Most of the time I just want to either read or write one value to the registry. Here are two functions: ReadRegistryValue and WriteRegistryValue plus a few helpers.</p> Simple calls to Python functions from command line or shortcut (Python) 2008-07-22T02:17:06-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/528891-simple-calls-to-python-functions-from-command-line/ <p style="color: grey"> Python recipe 528891 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). Revision 3. </p> <p>This module allows one to create a command to call a Python function from the command line, and to call that function with arguments from the command line without using getopt or optparse</p> Catalog multiple drives (Python) 2016-03-11T03:39:32-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/580619-catalog-multiple-drives/ <p style="color: grey"> Python recipe 580619 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/drives/">drives</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>As one accumulates multiple drives, hard and flash, containing, thousands even millions of files, it becomes useful to have a text file containing an alphabetized catalog list of all files and their locations by drive and directory.</p> <p>The list can be searched by eye or by an editor to locate particular files.</p> <p>The list can also be loaded into a script to be filtered programmatically as desired.</p> FileSpec: Set it, forget it, reuse it (Python) 2016-03-08T05:49:16-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/580618-filespec-set-it-forget-it-reuse-it/ <p style="color: grey"> Python recipe 580618 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/filename/">filename</a>, <a href="/recipes/tags/utilities/">utilities</a>). </p> <p>Python provides good utilities for transforming filenames, but they are tedious to use and clutter up the source code.</p> <p>FileSpec offers one-stop shopping to convert a file path to every component you might want to know, reuse, or transform.</p> MicroXml: Stand-alone library for basic XML features (C++) 2016-02-18T19:33:07-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/580612-microxml-stand-alone-library-for-basic-xml-feature/ <p style="color: grey"> C++ recipe 580612 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>MicroXml provides stand-alone support for the basic, most-used features of XML -- tags, attributes, and element values. It produces a DOM tree of XML nodes. MicroXml does not support DTDs, CDATAs and other advanced XML features.</p> <p>MicroXml is easy to use and provides easy access to view/navigate its nodes in a debugger.</p> Mandelbrot Set made simple (Python) 2015-12-28T17:56:08-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579143-mandelbrot-set-made-simple/ <p style="color: grey"> Python recipe 579143 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/mandelbrot/">mandelbrot</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). Revision 2. </p> <p>This is a mini-framework for exploring the Mandelbrot Set.</p> <p>It outputs to a Tkinter window or to a PNG file (Pillow package required). It includes a disk caching mechanism for saving and later retrieving Mandelbrot calculations to avoid recalculating the Set on each run.</p> <p>See module documentation for further information. Compatible with Python 2 and 3.</p> Simple breadth-first, depth-first tree traversal (Python) 2015-12-18T18:15:18-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579138-simple-breadth-first-depth-first-tree-traversal/ <p style="color: grey"> Python recipe 579138 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/tree/">tree</a>). </p> <p>When you want to avoid recursion with a tree, you read the tree nodes into a stack, which is organized either breadth-first or depth-first.</p> <p>Here are two dead simple routines for doing so. Most of the recipe is just a test bed for those functions.</p> Roll your own Postscript code from scratch (Python) 2015-12-09T23:30:13-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579136-roll-your-own-postscript-code-from-scratch/ <p style="color: grey"> Python recipe 579136 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/ghostscript/">ghostscript</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/postscript/">postscript</a>, <a href="/recipes/tags/ps/">ps</a>). </p> <p>This recipe provides a mini-framework for creating custom Postscript PS and PDF files from scratch. It includes sample code for a personalized business index card.</p> <p>Recipe does not use any Python PDF libraries. However, Ghostscript and a PDF viewer are useful for displaying/debugging output.</p> <p>It's easier than you might think to roll your own Postscript code!</p> MicroXml: Stand-alone library for basic XML features (Python) 2015-12-04T22:36:56-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579133-microxml-stand-alone-library-for-basic-xml-feature/ <p style="color: grey"> Python recipe 579133 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>MicroXml provides stand-alone support for the basic, most-used features of XML -- tags, attributes, and element values. It produces a DOM tree of XML nodes. It's compatible with Python 2.7 and Python 3. MicroXml does not support DTDs, CDATAs and other advanced XML features.</p> <p>MicroXml is easy to use and easy to view/navigate its nodes in a debugger. It also includes a minimal XPath-like implementation.</p> TRAC Interpreter -- Sixties programming language (Python) 2010-08-22T19:05:09-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577366-trac-interpreter-sixties-programming-language/ <p style="color: grey"> Python recipe 577366 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/interpreter/">interpreter</a>, <a href="/recipes/tags/language/">language</a>, <a href="/recipes/tags/trac/">trac</a>). </p> <p>A Python implementation of an interpreter for the TRAC programming language developed by Calvin Mooers in the early 1960s. This implementation reconstructs Mooers' original algorithm in Python and supports only a limited number of TRAC primitives for demonstration purposes.</p>