Popular recipes tagged "meta:loc=116"http://code.activestate.com/recipes/tags/meta:loc=116/2017-04-10T11:27:05-07:00ActiveState Code RecipesTkinter Animated GIF (Python)
2017-04-10T11:27:05-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580708-tkinter-animated-gif/
<p style="color: grey">
Python
recipe 580708
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/gif/">gif</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 10.
</p>
<p>Tkinter GIF in motion. It uses the "after" command of Tcl and PIL.</p>
<p>Add path to GIF to make the example working.</p>
Simple FIFO trading model for pnl (Python)
2015-02-10T13:34:48-08:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/579024-simple-fifo-trading-model-for-pnl/
<p style="color: grey">
Python
recipe 579024
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/pnl/">pnl</a>, <a href="/recipes/tags/trading/">trading</a>).
Revision 2.
</p>
<p>Simple approach to calculating FIFO pnl.</p>
Stopwatch with laps in Tkinter (Python)
2013-09-19T18:42:10-07:00Fredericohttp://code.activestate.com/recipes/users/4187878/http://code.activestate.com/recipes/578666-stopwatch-with-laps-in-tkinter/
<p style="color: grey">
Python
recipe 578666
by <a href="/recipes/users/4187878/">Frederico</a>
(<a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>This is a small implementation of a stopwatch widget in Tkinter. The widget displays a label with minutes:seconds:1/100-seconds. The label is updated every 50 ms, but that can easily be changed. Methods are availble for starting, stopping and resetting the stopwatch. A simple program demonstrates the widget.</p>
Python Exception Chains (or Trees) (Python)
2013-02-04T15:15:22-08:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/578252-python-exception-chains-or-trees/
<p style="color: grey">
Python
recipe 578252
by <a href="/recipes/users/4182236/">Alfe</a>
(<a href="/recipes/tags/cause/">cause</a>, <a href="/recipes/tags/chain/">chain</a>, <a href="/recipes/tags/exception/">exception</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reason/">reason</a>, <a href="/recipes/tags/reraise/">reraise</a>, <a href="/recipes/tags/tree/">tree</a>).
Revision 2.
</p>
<p>I have here an approach for chaining exceptions in case a lower layer (<em>library</em>) raises an exception which is caught in an upper layer (<em>application</em>) and later given as <em>cause</em> when a different exception is raised. Passing this <em>cause</em> exception is meant to offer access to the stack trace of the inner exception for debugging.</p>
<p>This approach is implemented in Python 3 and in Java, so it definitely makes sense; you also quickly find questions on <a href="http://stackoverflow.com">Stackoverflow</a> concerning it.</p>
<p>I even extended this feature by not only using chains of exceptions but also trees. Trees, why trees? Because I had situations in which my application layer tried various approaches using the library layer. If all failed (raised an exception), my application layer also raised an exception; this is the case in which I wanted to pass more than one cause exception into my own exception (hence the tree of causes).</p>
<p>My approach uses a special Exception class from which all my exceptions will inherit; standard exception must be wrapped (directly after catching, to preserve the exception stack trace). Please see the examples contained in the code below. The exception itself is rather small.</p>
<p>I'd be happy to hear any comments regarding memory leaks (I didn't find any but one never knows), usability, enhancements or similar.</p>
Sending non-ASCII emails from Python 3 (Python)
2012-09-16T07:50:17-07:00Krystian Rosińskihttp://code.activestate.com/recipes/users/4182314/http://code.activestate.com/recipes/578150-sending-non-ascii-emails-from-python-3/
<p style="color: grey">
Python
recipe 578150
by <a href="/recipes/users/4182314/">Krystian Rosiński</a>
(<a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/smtp/">smtp</a>).
Revision 17.
</p>
<p>Simple Python 3 module for sending emails with attachments through an SMTP server.</p>
<p>The module supports non-ASCII characters in sender name, subject, message and file names.</p>
Generic way to create a daemonized process in python (Python)
2012-03-26T14:56:17-07:00ajaymenon.khttp://code.activestate.com/recipes/users/4181225/http://code.activestate.com/recipes/578072-generic-way-to-create-a-daemonized-process-in-pyth/
<p style="color: grey">
Python
recipe 578072
by <a href="/recipes/users/4181225/">ajaymenon.k</a>
(<a href="/recipes/tags/daemon/">daemon</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/threads/">threads</a>).
Revision 4.
</p>
<p>A simple daemon that will constantly keep track the size of your inbox and when it exceeds a certain size, will send you a reminder email.</p>
Simple enum mechanism (Python)
2012-01-15T12:30:31-08:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/578015-simple-enum-mechanism/
<p style="color: grey">
Python
recipe 578015
by <a href="/recipes/users/4174477/">Thomas Lehmann</a>
(<a href="/recipes/tags/enum/">enum</a>).
</p>
<p><strong>Here are the basic ideas (orientation: C++)</strong>:</p>
<ul>
<li>You are responsible to find names for constants and this code provides a way to give values which differ from each other</li>
<li>The context is to allow different enums with values starting by 0</li>
<li>If you like to use constants like here: "Orientation.TOP" then place those constants in the relating class</li>
<li>You still can assign your own values</li>
</ul>
<p><strong>About the code</strong>:</p>
<ul>
<li>It's not much code also it might look like (implementation + documentation + unittests)</li>
<li>The __docformat__ is for epydoc. Temporarily remove the "@singleton" when trying to generate the HTML documentation (can not yet be handled by epydoc).</li>
</ul>
<p><strong>Example(s)</strong>:
Have a look at the unittests please.</p>
Representing a set in a compact way (Python)
2011-04-24T10:55:45-07:00jimmy2timeshttp://code.activestate.com/recipes/users/4177690/http://code.activestate.com/recipes/577660-representing-a-set-in-a-compact-way/
<p style="color: grey">
Python
recipe 577660
by <a href="/recipes/users/4177690/">jimmy2times</a>
(<a href="/recipes/tags/compact/">compact</a>, <a href="/recipes/tags/compressed/">compressed</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/set/">set</a>, <a href="/recipes/tags/structure/">structure</a>).
Revision 5.
</p>
<p>Implements a data structure for sets of natural numbers, represented by a single integer. The interface is similar to the built-in structure 'set'.</p>
Redate source files using SVN info from $Id:$ (Python)
2010-07-30T10:00:25-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/577341-redate-source-files-using-svn-info-from-id/
<p style="color: grey">
Python
recipe 577341
by <a href="/recipes/users/186902/">Michal Niklas</a>
(<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/svn/">svn</a>).
</p>
<p>Iterates through a directory, reading the data from svn info that looks like:</p>
<pre class="prettyprint"><code>$Id: svn_redater.py 747 2010-07-30 09:56:08Z mn $
</code></pre>
<p>from source files.</p>
<p>Parses the datetime from svn info and if it differs from file
modification datetime then changes file datetime</p>
Coldfusion 8 + TSQL SQL Server 2005 > backup database (Text)
2009-05-06T02:38:40-07:00dimitris siskopouloshttp://code.activestate.com/recipes/users/4170125/http://code.activestate.com/recipes/576740-coldfusion-8-tsql-sql-server-2005-backup-database/
<p style="color: grey">
Text
recipe 576740
by <a href="/recipes/users/4170125/">dimitris siskopoulos</a>
(<a href="/recipes/tags/coldfusion/">coldfusion</a>, <a href="/recipes/tags/sql_server_2005/">sql_server_2005</a>).
</p>
<p>Code and Stored Procedure for database backup, zip and links to download and delete backup files.</p>
schizoid (Python)
2007-11-02T21:57:15-07:00photon thughttp://code.activestate.com/recipes/users/4096917/http://code.activestate.com/recipes/534146-schizoid/
<p style="color: grey">
Python
recipe 534146
by <a href="/recipes/users/4096917/">photon thug</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>a (useful???) curiosity inspired by monty python, guido's multimethods demo,
and schizophrenia.</p>
<p>comments to: photon DOT thug AT gmail DOT com</p>
Generating an HTML report listing all crontabs from several hosts (Python)
2006-04-12T10:11:01-07:00Walter Dörwaldhttp://code.activestate.com/recipes/users/776207/http://code.activestate.com/recipes/483759-generating-an-html-report-listing-all-crontabs-fro/
<p style="color: grey">
Python
recipe 483759
by <a href="/recipes/users/776207/">Walter Dörwald</a>
.
</p>
<p>If you're administering a number of machines and each account on these machines has a number of cronjobs this recipe can be used to generate an HTML report listing all crontabs on all your machines. You can use this script in a cronjob to regenerate this report periodically.</p>
War Game (Version 2) (Python)
2005-10-02T17:45:49-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440622-war-game-version-2/
<p style="color: grey">
Python
recipe 440622
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>And here is my second interpretation of the card game known as "WAR." If you are wondering how it works, you should look at "Version 1" of this program (it is another program that I submitted). There is no documentation whatsoever of this program (as you can see), but it follows just about the same logic of the first game. This game is just easier to win at IMHO.</p>
An easy password generator using standard Python modules (Python)
2006-11-12T11:54:30-08:00hemanth sethuramhttp://code.activestate.com/recipes/users/2187507/http://code.activestate.com/recipes/440564-an-easy-password-generator-using-standard-python-m/
<p style="color: grey">
Python
recipe 440564
by <a href="/recipes/users/2187507/">hemanth sethuram</a>
.
Revision 4.
</p>
<p>This recipe generates a password of any length using the standard library modules of Python. The password generated is a function of an identifier and a master password.</p>
<p>I liked the idea behind the PasswordMaker browser plugin (<a href="http://passwordmaker.org/" rel="nofollow">http://passwordmaker.org/</a>). But I wanted to have a portable command line version which I wanted to carry around without having the need to install an application or needing a web browser. Additionally I wanted to use only the pre-installed modules.
I haven't looked into the PasswordMaker's algorithms but I have borrowed the main idea that you have a single master password. To that you add a site address or your account name and take a cryptographic hash (MD5, SHA-1, etc.) of this string. Your password will be a function of this generated hash.
I have broken each of the above steps into separate functions so that one can replace the actual implementation with their own algorithms.
Note on Security: I am not a security expert; so I am not qualified to comment on how secure this approach is. I welcome others' comments on the vulnerabilities.</p>
Fractal tree (Python)
2005-05-01T10:54:00-07:00Alexander Pletzerhttp://code.activestate.com/recipes/users/98107/http://code.activestate.com/recipes/410158-fractal-tree/
<p style="color: grey">
Python
recipe 410158
by <a href="/recipes/users/98107/">Alexander Pletzer</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
Revision 4.
</p>
<p>This simple program can be used to compute and display a 2D fractal tree.</p>
deque collection class (Python)
2007-07-14T11:53:06-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/259179-deque-collection-class/
<p style="color: grey">
Python
recipe 259179
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 8.
</p>
<p>Pure python drop in replacement for collections.deque() from Py2.4. See documentation at: <a href="http://www.python.org/dev/doc/devel/lib/module-collections.html" rel="nofollow">http://www.python.org/dev/doc/devel/lib/module-collections.html</a>
<br>
Uses a dictionary as the underlying data structure for the deque (pronounced "deck", short for "double-ended queue", a generalization of stacks and queues) which provides O(1) performance for appends and pops from either end.
<br>
Runs on PyPy, Jython, and older Pythons.</p>