Popular recipes tagged "meta:loc=73"http://code.activestate.com/recipes/tags/meta:loc=73/2017-04-07T12:40:46-07:00ActiveState Code RecipesReload Tkinter application like a browser (Python)
2017-04-07T12:40:46-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580707-reload-tkinter-application-like-a-browser/
<p style="color: grey">
Python
recipe 580707
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/reload/">reload</a>, <a href="/recipes/tags/reloading/">reloading</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 6.
</p>
<p><em>run_with_reloader:</em> Binding some hotkeys, for example control-r and control-R, the application is reloaded. It's the same behaviour than a browser. This code is useful for debugging.</p>
<p>Some applications use a similar approach for easy development. For example flask and django reloads the application every time they observe a change in a file.</p>
Not Quite So Simple QuickTime Player, Python Audio Capture. (Python)
2014-11-08T19:10:58-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578960-not-quite-so-simple-quicktime-player-python-audio-/
<p style="color: grey">
Python
recipe 578960
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/audio_capture/">audio_capture</a>, <a href="/recipes/tags/capture/">capture</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/maccbook_pro/">maccbook_pro</a>, <a href="/recipes/tags/sample/">sample</a>, <a href="/recipes/tags/signal_capture/">signal_capture</a>).
</p>
<p>Not Quite So Simple QuickTime Player, Python Audio Capture.</p>
<p>This DEMO code captures a function to generate a user 5 second Audio sample in Apple *.aifc format.
It is then converted to DC quailty *.WAV format.</p>
<p>It uses default shell system files to do the task.</p>
<p>An AppleScript is created to do the sample but due to the limitations of QT Player there is a 1.5 second delay to allow QuickTine Player to start up.
It is not entirely quiet but unobtrusive enough as to be like quiet mode...</p>
<p>This is again a means a signal capture for an AudioScope without the need for special tools or installs.</p>
<p>Read the code for more information.</p>
<p>IMPORTANT!!! This DEMO WILL delete all *.aifc files inside the default $HOME/Movies directory, so be aware.</p>
<p>A simple ALSA one is on its way too...</p>
<p>It actually works on Python 3.4.1 but I have no idea if it works below Python 2.5.6...</p>
<p>Bazza...</p>
String templates with adaptive indenting (Python)
2014-02-19T12:53:03-08:00Sander Evershttp://code.activestate.com/recipes/users/4173111/http://code.activestate.com/recipes/578835-string-templates-with-adaptive-indenting/
<p style="color: grey">
Python
recipe 578835
by <a href="/recipes/users/4173111/">Sander Evers</a>
(<a href="/recipes/tags/formatter/">formatter</a>, <a href="/recipes/tags/indent/">indent</a>, <a href="/recipes/tags/templating/">templating</a>).
</p>
<p>An extension of Python's <code>'Hello {fieldname}!'.format(fieldname='world')</code> functionality for multi-line strings. When <code>{fieldname}</code> is indented, all the lines in the inserted <code>fieldvalue</code> are indented to the same amount.</p>
Factory pattern (Python)
2013-02-04T21:12:27-08:00Ilya Pashchenkohttp://code.activestate.com/recipes/users/4185152/http://code.activestate.com/recipes/578450-factory-pattern/
<p style="color: grey">
Python
recipe 578450
by <a href="/recipes/users/4185152/">Ilya Pashchenko</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>In the factory pattern you have an object that creates other objects.</p>
First Script.....Anagram Solver (Python)
2013-01-20T13:40:53-08:00Garenhttp://code.activestate.com/recipes/users/4184964/http://code.activestate.com/recipes/578432-first-scriptanagram-solver/
<p style="color: grey">
Python
recipe 578432
by <a href="/recipes/users/4184964/">Garen</a>
(<a href="/recipes/tags/anagram/">anagram</a>, <a href="/recipes/tags/solver/">solver</a>).
</p>
<p>I made this for a programming challenge over on a site called hackthissite. This is my first attempt at python, please if you do take a look at my code, please show me where i could improve my code so i can get better at this language. Thanks and hope it works for you like it is supposed to</p>
@unittest.skip_others decorator (Python)
2012-08-06T02:20:19-07:00Giampaolo Rodolàhttp://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/578234-unittestskip_others-decorator/
<p style="color: grey">
Python
recipe 578234
by <a href="/recipes/users/4178764/">Giampaolo Rodolà</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/skip/">skip</a>, <a href="/recipes/tags/unittest/">unittest</a>).
Revision 3.
</p>
<p>Decorator which skips all tests except the one decorated with it.
Based on original proposal on python-ideas:
<a href="http://mail.python.org/pipermail/python-ideas/2010-August/007992.html" rel="nofollow">http://mail.python.org/pipermail/python-ideas/2010-August/007992.html</a></p>
Metronome For Beginner Musicians... (Python)
2012-05-18T19:30:04-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578139-metronome-for-beginner-musicians/
<p style="color: grey">
Python
recipe 578139
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/metronome/">metronome</a>, <a href="/recipes/tags/music_accessory/">music_accessory</a>, <a href="/recipes/tags/sound/">sound</a>).
Revision 2.
</p>
<p>This DEMO code is a simple metronome for the Linux platform. It is for newcomers to playing musical instruments as a timing unit for practicing with.</p>
<p>It is issued as Public Domain and you may do with it as you please...</p>
<p>The device /dev/dsp IS required for this to work. If your machine lacks this then install oss-compat from you distro's repository.</p>
<p>It exploits a flaw in the default /dev/dsp device inside linux...</p>
<p>The part of the code the uses Ctrl-C to exit a loop has a flaw. This is not a bug. I will let the big guns explain what is happening if they want to in the comments section.</p>
<p>Enjoy finding simple solutions to often very difficult pronblems...</p>
<p>Bazza, G0LCU...</p>
Dynamically modifying class attributes at runtime (Python)
2011-03-31T20:07:18-07:00Nabil Stendardohttp://code.activestate.com/recipes/users/4177507/http://code.activestate.com/recipes/577628-dynamically-modifying-class-attributes-at-runtime/
<p style="color: grey">
Python
recipe 577628
by <a href="/recipes/users/4177507/">Nabil Stendardo</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/modification/">modification</a>, <a href="/recipes/tags/monkeypatching/">monkeypatching</a>, <a href="/recipes/tags/open/">open</a>).
</p>
<p>However considered bad programming, Ruby/JavaScript-like open classes (i.e. classes which can be modified at runtime) actually can be a programming pattern when developing plug-in architectures. And, guess what, Python has that functionality too. This code allows to add attributes (typically methods) to classes, even when already instantiated.</p>
Perpetual calendar (Python)
2011-04-15T20:44:54-07:00sundanceriddlehttp://code.activestate.com/recipes/users/4177681/http://code.activestate.com/recipes/577657-perpetual-calendar/
<p style="color: grey">
Python
recipe 577657
by <a href="/recipes/users/4177681/">sundanceriddle</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/calendar/">calendar</a>).
</p>
<p>Represents the so-called "perpetual clock" ( <a href="http://www.evilmadscientist.com/article.php/perpetualcalendar" rel="nofollow">http://www.evilmadscientist.com/article.php/perpetualcalendar</a> ) with numbers instead of pennies. Thinking about making a simple window with heads/tails images.</p>
Arduino Diecimila Board Access Inside Linux DEMO. (Python)
2011-04-03T22:04:02-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577631-arduino-diecimila-board-access-inside-linux-demo/
<p style="color: grey">
Python
recipe 577631
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/arduino/">arduino</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/linux/">linux</a>).
</p>
<p>Arduino-Linux2x.py</p>
<p>This is a simple Python example of accessing a(n) Arduino Diecimila Board using Standard Python 2.x.x.</p>
<p>This code requires NO PySerial to work, just standard Linux(/Unix?) commands and a Standard Python install.</p>
<p>The only prerequisite is that a root terminal is needed to start Python in.</p>
<p>This code is released as Public Domain and you can do with it as you please.</p>
<p>To get more values displayed it is best to use a potentiometer wired as one end to +5V, the other end to Gnd
and the wiper to ANALOG IN 0. This has been tested on various Linux Distros and kept as simple as possible so
that anyone can understand it.</p>
<p>The required ?.pde file for the Arduino Board can be found here:-</p>
<p><a href="http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/?in=lang-python" rel="nofollow">http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/?in=lang-python</a></p>
<p>Similar assumptions are made as in the URL above.</p>
<p>Enjoy finding simple solutions to often very difficult problems... ;o)</p>
Pomodoro timer (Python)
2010-08-14T11:48:18-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577358-pomodoro-timer/
<p style="color: grey">
Python
recipe 577358
by <a href="/recipes/users/4173873/">Noufal Ibrahim</a>
(<a href="/recipes/tags/gtd/">gtd</a>, <a href="/recipes/tags/pomodoro/">pomodoro</a>, <a href="/recipes/tags/timer/">timer</a>).
</p>
<p>A simple script that works as a pomodoro timer. Useful to enhance ones focus while working on something.
The Pomodoro technique is described at <a href="http://www.pomodorotechnique.com/" rel="nofollow">http://www.pomodorotechnique.com/</a></p>
<p>This script is an offline version of <a href="http://www.focusboosterapp.com/live.cfm" rel="nofollow">http://www.focusboosterapp.com/live.cfm</a></p>
<p>It requires the <a href="http://www.mpg123.de/">Mpg123</a> program to play the audio and I obtained the ticking sounds from <a href="http://www.soundjay.com/clock-sounds-1.html" rel="nofollow">http://www.soundjay.com/clock-sounds-1.html</a></p>
Query CSV file (Python)
2010-10-12T00:08:22-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577419-query-csv-file/
<p style="color: grey">
Python
recipe 577419
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>).
Revision 4.
</p>
<p>The user can define a query expression for (almost) any CSV file.
(The first row assumed to contain column headers.)
Then the code outputs all data rows matching to the given query expression.</p>
Sierpinski Triangle Fractal using HTML5 Canvas (JavaScript)
2010-07-07T15:07:30-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577294-sierpinski-triangle-fractal-using-html5-canvas/
<p style="color: grey">
JavaScript
recipe 577294
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>).
</p>
<p>Sierpinski Triangle Fractal using Line Automaton (1D CA).
The 1D CA rule used is actually Pascal's Triangle Mod 2.
Tested only using Firefox 3.5.</p>
Union-Find (Python)
2010-05-10T20:32:15-07:00Ahmed El Deebhttp://code.activestate.com/recipes/users/4173897/http://code.activestate.com/recipes/577225-union-find/
<p style="color: grey">
Python
recipe 577225
by <a href="/recipes/users/4173897/">Ahmed El Deeb</a>
(<a href="/recipes/tags/disjoint/">disjoint</a>, <a href="/recipes/tags/forests/">forests</a>, <a href="/recipes/tags/set/">set</a>, <a href="/recipes/tags/unionfind/">unionfind</a>).
</p>
<p>A.k.a. Disjoint set forests. Minimalistic implementation. Directly ported from pseudo code on the Wikipedia page:
<a href="http://en.wikipedia.org/wiki/Disjoint-set_data_structure">http://en.wikipedia.org/wiki/Disjoint-set_data_structure</a></p>
<p>Employs path compression and union by rank as described in the link above.</p>
ReadOnlyPrivateSingletonImplicitThisMetaClass (Python)
2010-05-10T08:34:32-07:00Chris Joneshttp://code.activestate.com/recipes/users/4171447/http://code.activestate.com/recipes/577221-readonlyprivatesingletonimplicitthismetaclass/
<p style="color: grey">
Python
recipe 577221
by <a href="/recipes/users/4171447/">Chris Jones</a>
(<a href="/recipes/tags/enterprise/">enterprise</a>, <a href="/recipes/tags/implicit/">implicit</a>, <a href="/recipes/tags/private/">private</a>, <a href="/recipes/tags/readonly/">readonly</a>, <a href="/recipes/tags/self/">self</a>, <a href="/recipes/tags/singleton/">singleton</a>).
Revision 3.
</p>
<p>Are you a totally agile rock star developer? Turn your code into a rock concert with this handy metaclass that makes your classes suitable for production deployment!</p>
Easy Property Creation in Python (Python)
2009-05-06T11:59:16-07:00runsun panhttp://code.activestate.com/recipes/users/2638612/http://code.activestate.com/recipes/576742-easy-property-creation-in-python/
<p style="color: grey">
Python
recipe 576742
by <a href="/recipes/users/2638612/">runsun pan</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/property/">property</a>, <a href="/recipes/tags/property_creation/">property_creation</a>).
Revision 4.
</p>
<p>Presented in this recipe is a function <strong>prop</strong>, with that a property <em>myprop</em> can be created as simple as:</p>
<pre class="prettyprint"><code>@prop
def myprop(): pass
</code></pre>
<p>It has only 7 lines of code, easy to understand, easy to customize, will make the code look much netter and will save you a lot of typing.</p>
<p>See discussion and the doc test string for more complicated usages.</p>
<p>Note: This is a recipe created with python v.2.5.2.</p>
Lightweight Unittester (Python)
2009-04-07T19:47:08-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/572194-lightweight-unittester/
<p style="color: grey">
Python
recipe 572194
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/debugging/">debugging</a>).
Revision 4.
</p>
<p>Inspired by py.test, the unittester is a single, simple function that is easily customized. The main virtue is that tests are much clearer than with the unittest.py.</p>
Lightweight Unittester (Python)
2010-07-20T14:28:25-07:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/572204-lightweight-unittester/
<p style="color: grey">
Python
recipe 572204
by <a href="/recipes/users/4035877/">Louis RIVIERE</a>
(<a href="/recipes/tags/debugging/">debugging</a>).
Revision 3.
</p>
<p>This is <a href="http://code.activestate.com/recipes/572194/">recipe 572194</a> from Raymond HETTINGER with a little decorator to get timings on tested functions</p>
Extention Editor (Python)
2007-03-20T18:20:30-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/510388-extention-editor/
<p style="color: grey">
Python
recipe 510388
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>This program raises or lowers the case of your file's extention.</p>
Calculate the distance matrix for n-dimensional point array (Python)
2006-11-11T22:56:49-08:00Willi Richerthttp://code.activestate.com/recipes/users/4003859/http://code.activestate.com/recipes/498246-calculate-the-distance-matrix-for-n-dimensional-po/
<p style="color: grey">
Python
recipe 498246
by <a href="/recipes/users/4003859/">Willi Richert</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 3.
</p>
<p>Three ways to calculate a distance matrix out of a list of n-dimensional points using scipy.</p>