Popular recipes tagged "programs"http://code.activestate.com/recipes/tags/programs/2013-03-07T08:23:46-08:00ActiveState Code RecipesLinear equations solver in 3 lines (Python) 2013-03-07T07:33:09-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578481-linear-equations-solver-in-3-lines/ <p style="color: grey"> Python recipe 578481 by <a href="/recipes/users/4183429/">Deepak</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Just a little bit of hack: a linear equations solver using eval and built-in complex numbers:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; solve("x - 2*x + 5*x - 46*(235-24) = x + 2") 3236.0 </code></pre> First Class Enums in Python (Python) 2013-03-07T08:23:46-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578482-first-class-enums-in-python/ <p style="color: grey"> Python recipe 578482 by <a href="/recipes/users/4183429/">Deepak</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>True immutable symbolic enumeration with qualified value access.</p> Pants (Python) 2012-07-03T05:31:24-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578188-pants/ <p style="color: grey"> Python recipe 578188 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>According to memory this is a port of a shell script called pants that allows one to "start," "stop," "restart," and find the "status" of one's pants (the program itself). I am not sure what the silliness is about but must have found the idea interesting to rewrite in Python. This is committed for archival to be run under Python 2.5 or later versions.</p> Git Shell Script to enhance inline automation script... (Bash) 2010-11-01T00:43:03-07:00Patrick Riendeauhttp://code.activestate.com/recipes/users/4175653/http://code.activestate.com/recipes/577447-git-shell-script-to-enhance-inline-automation-scri/ <p style="color: grey"> Bash recipe 577447 by <a href="/recipes/users/4175653/">Patrick Riendeau</a> (<a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/git/">git</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/oriented/">oriented</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/property/">property</a>, <a href="/recipes/tags/property_creation/">property_creation</a>, <a href="/recipes/tags/repository/">repository</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/shelve/">shelve</a>). </p> <p>This tiny effort, depend from Fnct.D ActiveState no.577446 Core, also available from github <a href="http://github.com/priendeau/Fnct.d" rel="nofollow">http://github.com/priendeau/Fnct.d</a>, can develop basic methodology of implementing oriented program within uses of function re-declaration with function-parser to create both property-function to discover uses of getter-function and setter-function</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> 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> Pyscanlogger - Python Port scan detector (Python) 2010-03-17T07:27:15-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576690-pyscanlogger-python-port-scan-detector/ <p style="color: grey"> Python recipe 576690 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/security/">security</a>). Revision 5. </p> <p>A pure Python program to detect network port scanning attacks. Currently logs different TCP port scans. Can run in the background like a daemon and log attacks to a log file.</p> Utility Mill Test (Python) 2008-12-28T21:24:11-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/576598-utility-mill-test/ <p style="color: grey"> Python recipe 576598 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>After recently discovering the Utility Mill, I decided to create an automated tester that would check that the latest revision was still operating according to specifications. It checks the web site once a minute and displays status information as it runs. It is included here because it comes in three sections. The first section has several utility functions that you may find useful in your own applications. The actual test suite is located in the second section. The last section includes code that makes getting random text easy and fast (after an initial loading session). Hopefully, the first portion of the code may be of use to you.</p> List classes, methods and functions in a module (Python) 2008-10-22T08:15:26-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/553262-list-classes-methods-and-functions-in-a-module/ <p style="color: grey"> Python recipe 553262 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 5. </p> <p>The recipe provides a method "describe" which takes a module as argument and describes classes, methods and functions in the module. The method/function description provides information on the function/method arguments using the inspect module.</p> Deep rename (Python) 2008-10-13T07:01:53-07:00David Pokornyhttp://code.activestate.com/recipes/users/4166601/http://code.activestate.com/recipes/576537-deep-rename/ <p style="color: grey"> Python recipe 576537 by <a href="/recipes/users/4166601/">David Pokorny</a> (<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Rename an identifier in all source files in a directory tree.</p> prompt the user for confirmation (Python) 2008-01-02T08:35:30-08:00Raghuram Devarakondahttp://code.activestate.com/recipes/users/4084209/http://code.activestate.com/recipes/541096-prompt-the-user-for-confirmation/ <p style="color: grey"> Python recipe 541096 by <a href="/recipes/users/4084209/">Raghuram Devarakonda</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Displays a prompt and queries the user for positive or negative confirmation.</p> These Nasty Closures - Caveats for the Closure Enthusiast (Python) 2007-03-03T11:31:05-08:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/502271-these-nasty-closures-caveats-for-the-closure-enthu/ <p style="color: grey"> Python recipe 502271 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Closures are powerful. Closures are beautiful. But: Closures are TRICKY!</p> <p>This is an anti-recipe, a caveat about some obscure pitfalls with closures - or the way they are implemented in python.</p> <p>And now for the caveats: Two no-no's...</p> <ol> <li><p>Don't create more then one instance of the same closure per normal function!</p></li> <li><p>Don't create more then one instance of the same closure per generation cycle in a generator function!</p></li> </ol> <p>Here is why...</p> Use PEP 263 for metaprogramming (Python) 2008-02-22T11:19:08-08:00TJ Whttp://code.activestate.com/recipes/users/4127020/http://code.activestate.com/recipes/546539-use-pep-263-for-metaprogramming/ <p style="color: grey"> Python recipe 546539 by <a href="/recipes/users/4127020/">TJ W</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>Use PEP 263 to do source code transformation.</p> pypopper - Python POP3 Server (Python) 2007-10-24T18:52:39-07:00Daniel Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/534131-pypopper-python-pop3-server/ <p style="color: grey"> Python recipe 534131 by <a href="/recipes/users/4016391/">Daniel Miller</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>While developing &lt;a href="http://pieces.openpolitics.com/thunderbayes/"&gt;ThunderBayes&lt;/a&gt; (an extension for Thunderbird) I wrote this simple POP3 server to serve a message to my ThunderBayes test setup.</p> Create a restricted python function from a string (Python) 2008-08-05T22:15:18-07:00david decotignyhttp://code.activestate.com/recipes/users/4129454/http://code.activestate.com/recipes/550804-create-a-restricted-python-function-from-a-string/ <p style="color: grey"> Python recipe 550804 by <a href="/recipes/users/4129454/">david decotigny</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>The createFunction(sourceCode) below returns a python function that executes the given sourceCode (a string containing python code). The function, being a real python function, doesn't incur any overhead compared to any normal python function. And its environment is controlled: by default only safe operations are permitted (ie. map, reduce, filter, list, etc. ; others like import, open, close, eval, etc. are forbidden by default). But it is possible to extend this environment.</p> Mixing features of "tree" and of "md5sum" : tree_md5 :) (Python) 2008-03-29T09:12:09-07:00Guillaume Knispelhttp://code.activestate.com/recipes/users/4127202/http://code.activestate.com/recipes/552739-mixing-features-of-tree-and-of-md5sum-tree_md5/ <p style="color: grey"> Python recipe 552739 by <a href="/recipes/users/4127202/">Guillaume Knispel</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Have you ever wanted to describe a filesystem subtree with, as an extra bonus, the md5sum of each file ?</p> <p>I have.</p> <p>Here is a tiny Python script that mixes functions of "tree" and of "md5sum", just for your pleasure.</p> <p>I wrote it with Python 2.4 under Linux.</p> How __slots__ are implemented (Python) 2007-09-25T22:48:21-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/532903-how-__slots__-are-implemented/ <p style="color: grey"> Python recipe 532903 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Pure python equivalent of the __slots__ implementation using descriptors and a metaclass.</p> Generate a PDF Greeting Card (Python) 2007-12-06T04:06:04-08:00greg phttp://code.activestate.com/recipes/users/4047849/http://code.activestate.com/recipes/535155-generate-a-pdf-greeting-card/ <p style="color: grey"> Python recipe 535155 by <a href="/recipes/users/4047849/">greg p</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Code to generate a PDF greeting card using a user specified image, and text.</p> <p>You can try it out online here: <a href="http://utilitymill.com/utility/Greeting_Card_Generator" rel="nofollow">http://utilitymill.com/utility/Greeting_Card_Generator</a></p> Timing various python statements (Python) 2008-02-06T00:13:09-08:00Oliver Schoenbornhttp://code.activestate.com/recipes/users/1458241/http://code.activestate.com/recipes/544297-timing-various-python-statements/ <p style="color: grey"> Python recipe 544297 by <a href="/recipes/users/1458241/">Oliver Schoenborn</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>The timeit module (in Python standard library) is handy to find out how fast a statement takes to execute, but not very convenient to compare speed of several equivalent statements: too much typing, need to create a Timer object for each statement, etc, tedious. The timings module provides the times() function to make it super easy to compare several statements in one call.</p> Import of subpackages from different physical locations (Python) 2008-01-10T06:03:03-08:00Dirk Holtwickhttp://code.activestate.com/recipes/users/636691/http://code.activestate.com/recipes/542192-import-of-subpackages-from-different-physical-loca/ <p style="color: grey"> Python recipe 542192 by <a href="/recipes/users/636691/">Dirk Holtwick</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>If you want do distribute different modules in separate packages but under the same top directory that may be a problem when importing those modules. Since Python 2.5 the "pkgutil", described in the Python documentation under chapter 29.3, solves this problem.</p>