Popular recipes by Mike Sweeney http://code.activestate.com/recipes/users/4177990/2013-12-01T02:21:14-08:00ActiveState Code RecipesEasy Bit Arrays using Long Integers (Python) 2013-12-01T02:21:14-08:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/578777-easy-bit-arrays-using-long-integers/ <p style="color: grey"> Python recipe 578777 by <a href="/recipes/users/4177990/">Mike Sweeney</a> (<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/bit/">bit</a>, <a href="/recipes/tags/bitwise/">bitwise</a>, <a href="/recipes/tags/integer/">integer</a>, <a href="/recipes/tags/long/">long</a>). </p> <p>Some simple techniques for working with long integers as bit arrays. Python support for long integers allows fast bitwise operations on large bit arrays. Bitwise operations on 100 million bit arrays happen in the blink of an eye. They are also fast and compact when saving and loading to disk. Unfortunately bit set, get, append, pop etc are slow so another bit array technique may be preferred.</p> A Simple Timing Function (Python) 2013-12-01T01:39:44-08:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/578776-a-simple-timing-function/ <p style="color: grey"> Python recipe 578776 by <a href="/recipes/users/4177990/">Mike Sweeney</a> (<a href="/recipes/tags/performance/">performance</a>, <a href="/recipes/tags/timing/">timing</a>). Revision 2. </p> <p>This function prints out a message with the elapsed time from the previous call. It works with most Python 2.x platforms. The function uses a simple trick to store a persistent variable (clock) without using a global variable.</p> Extracting structured text or code (Python) 2011-05-18T13:04:01-07:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/577700-extracting-structured-text-or-code/ <p style="color: grey"> Python recipe 577700 by <a href="/recipes/users/4177990/">Mike Sweeney</a> (<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/structured/">structured</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/token/">token</a>). Revision 2. </p> <p>This function uses the power of regular expressions to extract parts of a structured text string. It can build a token list from many types of code and data formats. It finds string types (with quotes) and nested structures that use parentheses, brackets, and braces. If you need to extract a different syntax, you can provide a custom token pattern in the function arguments.</p> A flexible state machine class (Python) 2011-05-18T15:17:02-07:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/577701-a-flexible-state-machine-class/ <p style="color: grey"> Python recipe 577701 by <a href="/recipes/users/4177990/">Mike Sweeney</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/state_machine/">state_machine</a>). Revision 2. </p> <p>The operation of the state machine is defined by transitions. The transitions control what value is returned and which new state to switch to, given an "event" input when in a certain current "state". State machines have many applications such as games, process controls, and language parsing.</p> Simple numeric database (Python) 2011-05-16T08:41:46-07:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/577697-simple-numeric-database/ <p style="color: grey"> Python recipe 577697 by <a href="/recipes/users/4177990/">Mike Sweeney</a> (<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/numeric/">numeric</a>). Revision 2. </p> <p>A simple in-memory numeric database for Python. Arrays are used to minimise memory consumption.</p>