Popular recipes tagged "meta:loc=46"http://code.activestate.com/recipes/tags/meta:loc=46/2016-01-13T00:46:40-08:00ActiveState Code Recipesadd password masking ability to getpass.getpass() (Python)
2016-01-13T00:46:40-08:00KingMakhttp://code.activestate.com/recipes/users/4193393/http://code.activestate.com/recipes/579148-add-password-masking-ability-to-getpassgetpass/
<p style="color: grey">
Python
recipe 579148
by <a href="/recipes/users/4193393/">KingMak</a>
(<a href="/recipes/tags/character/">character</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/getpass/">getpass</a>, <a href="/recipes/tags/hiding/">hiding</a>, <a href="/recipes/tags/masking/">masking</a>, <a href="/recipes/tags/msvcrt/">msvcrt</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>adding the ability to display a password masking character of the programmer's choice</p>
Python: Determine Name and Directory of the Top Level Running Script (Python)
2015-02-03T01:37:09-08:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/579018-python-determine-name-and-directory-of-the-top-lev/
<p style="color: grey">
Python
recipe 579018
by <a href="/recipes/users/4191581/">Harald Lieder</a>
.
</p>
<p>Yet another way to provide this information.
I wanted to get the right answers in ANY situation: Python 2 or 3, compiled or interpreted (interactive or batch).
The following code has been tested under Windows, Python 2.7, Python 3.4, IDLE, IPython (sh and Qt), PyInstaller, cx_Freeze, py2exe.</p>
Setting up a listbox filter in Tkinter(python 2.7) (Python)
2014-04-10T10:25:38-07:00Wyklephhttp://code.activestate.com/recipes/users/4189735/http://code.activestate.com/recipes/578860-setting-up-a-listbox-filter-in-tkinterpython-27/
<p style="color: grey">
Python
recipe 578860
by <a href="/recipes/users/4189735/">Wykleph</a>
(<a href="/recipes/tags/filter/">filter</a>, <a href="/recipes/tags/listbox/">listbox</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/searchbar/">searchbar</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>If you have a listbox and need to filter the contents of the listbox based on the contents of an entry field, this will help you! Shoutout to Nikola-K for the revision. It's much simpler now :D</p>
A basic WSGI PDF server (Python)
2013-12-26T18:45:35-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578798-a-basic-wsgi-pdf-server/
<p style="color: grey">
Python
recipe 578798
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/wsgi/">wsgi</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to create a rudimentary Python WSGI server that can serve PDF. I had seen a post on the Python Reddit about how to create 'a basic WSGI server (aka "enough to make a website without using a framework")'. Thought of modifying it to serve PDF content (hard-ccded, though, not dynamic content, just as a basic example). This is the result. It's meant for learning, as was the original from which it was adapted, not for production use. It requires my xtopdf toolkit and the Reportlab toolkit, v1.21</p>
Bell permutations using Even's nonrecursive algorithm (Python)
2013-12-23T02:44:43-08:00Chris Smithhttp://code.activestate.com/recipes/users/2725752/http://code.activestate.com/recipes/578792-bell-permutations-using-evens-nonrecursive-algorit/
<p style="color: grey">
Python
recipe 578792
by <a href="/recipes/users/2725752/">Chris Smith</a>
(<a href="/recipes/tags/bell/">bell</a>, <a href="/recipes/tags/johnson/">johnson</a>, <a href="/recipes/tags/permutations/">permutations</a>, <a href="/recipes/tags/steinhaus/">steinhaus</a>, <a href="/recipes/tags/trotter/">trotter</a>).
Revision 2.
</p>
<p>The "bell" permutations are those in which only a single inversion of neighbors occurs to generate the next permutation.</p>
Download file (Batch)
2013-10-10T16:31:50-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578680-download-file/
<p style="color: grey">
Batch
recipe 578680
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/download/">download</a>).
</p>
<p>Download file from internet without third party tools.</p>
Create a temporary mailbox (Python)
2013-04-29T14:04:20-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/578514-create-a-temporary-mailbox/
<p style="color: grey">
Python
recipe 578514
by <a href="/recipes/users/4173873/">Noufal Ibrahim</a>
(<a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/mbox/">mbox</a>).
</p>
<p>Generates a mailbox with lots of messages.</p>
Recursive find and replace in all files in directory with regex (Python)
2013-03-21T12:33:44-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/578312-recursive-find-and-replace-in-all-files-in-directo/
<p style="color: grey">
Python
recipe 578312
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/recursion/">recursion</a>, <a href="/recipes/tags/regular_expressions/">regular_expressions</a>, <a href="/recipes/tags/replace/">replace</a>).
</p>
<p>Search and replace files recursively in a given directory. Accepts regular expressions as search and replacement patterns.</p>
<p><strong>Example usage</strong>:</p>
<pre class="prettyprint"><code>python find_replace_regex.py ".", "<span[^>]*>", "<div>", "*.html" backup
</code></pre>
<p><strong>Note</strong>:
On win32 the <code><</code> and <code>></code> symbols are interpreted by the shell as input/output redirection even when they are surrounded with single or double quotes, and therefore need to be escaped with the caret character <code>^</code>.</p>
Bound Method Weakref (Python)
2013-07-29T05:35:55-07:00Esteban Castro Borsanihttp://code.activestate.com/recipes/users/4184010/http://code.activestate.com/recipes/578298-bound-method-weakref/
<p style="color: grey">
Python
recipe 578298
by <a href="/recipes/users/4184010/">Esteban Castro Borsani</a>
(<a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/weakref/">weakref</a>).
Revision 4.
</p>
<p>This is a workaorund for weak reference bound methods. It may be useful for observer patterns.</p>
Amplitude Modulation - Tremolo, Was:- An Audio/Sound Snippet For Linux... ;o) (Python)
2012-01-21T14:18:28-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578013-amplitude-modulation-tremolo-was-an-audiosound-sni/
<p style="color: grey">
Python
recipe 578013
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amplitude/">amplitude</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/mod/">mod</a>, <a href="/recipes/tags/modulation/">modulation</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/tremolo/">tremolo</a>).
Revision 2.
</p>
<p>This IS for the big guns as well as the amatuer...</p>
<p>I am always being told that too many comments inside any code is bad and that professional coders are clever enough to work out what a program does without comments...</p>
<p>So here goes! This snippet of code hits /dev/dsp in Linux and has no comments as to what it does.
Make sure that /dev/dsp is available in your Linux install - if not then install oss.compat from your repository.</p>
<p>It needs Python 2.6 minimum, but may well work on a much earlier version</p>
<p>Don't run the code first but have a go at working out what it does and see if you are correct... ;o)</p>
<p>You can email me if you think you are/were correct:- <a href="http://wisecracker_at_tesco.net" rel="nofollow">wisecracker_at_tesco.net</a></p>
<p>Bear in mind I don't think this has ever been done before by hitting the /dev/dsp __directly__.</p>
<p>NOTE:- NO imports are required at all!!!</p>
<p>It runs for about 7 seconds before exiting...</p>
<p>Another BIG PLUS for Linux.</p>
<p>(I have a feeling poeple on here might like this, possibly even vote it up. ;)</p>
<p>Answer now at the bottom of this page...</p>
<p>Enjoy...</p>
<p>Bazza, G0LCU...</p>
Send an HTML email with embedded image and plain text alternate (Python)
2011-06-12T18:38:14-07:00soham vaghelahttp://code.activestate.com/recipes/users/4178285/http://code.activestate.com/recipes/577751-send-an-html-email-with-embedded-image-and-plain-t/
<p style="color: grey">
Python
recipe 577751
by <a href="/recipes/users/4178285/">soham vaghela</a>
(<a href="/recipes/tags/network/">network</a>).
</p>
<p>HTML is the method of choice for those wishing to send emails with rich text, layout and graphics. Often it is desirable to embed the graphics within the message so recipients can display the message directly, without further downloads.</p>
<p>Some mail agents don't support HTML or their users prefer to receive plain text messages. Senders of HTML messages should include a plain text message as an alternate for these users.</p>
<p>This recipe sends a short HTML message with a single embedded image and an alternate plain text message.</p>
Speeding up computations using a lookup table part I (Python)
2011-07-02T15:14:33-07:00Kaushik Ghosehttp://code.activestate.com/recipes/users/4166965/http://code.activestate.com/recipes/577776-speeding-up-computations-using-a-lookup-table-part/
<p style="color: grey">
Python
recipe 577776
by <a href="/recipes/users/4166965/">Kaushik Ghose</a>
(<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/optimization/">optimization</a>).
</p>
<p>I needed to use the cumulative normal distribution and normal probability density functions repeatedly for some data analysis. I found that I could speed things up drastically by using a lookup table and matplotlib's builtin interpolation function.</p>
Send an HTML email with embedded image and plain text alternate (Python)
2011-06-12T18:38:47-07:00soham vaghelahttp://code.activestate.com/recipes/users/4178285/http://code.activestate.com/recipes/577752-send-an-html-email-with-embedded-image-and-plain-t/
<p style="color: grey">
Python
recipe 577752
by <a href="/recipes/users/4178285/">soham vaghela</a>
(<a href="/recipes/tags/network/">network</a>).
</p>
<p>HTML is the method of choice for those wishing to send emails with rich text, layout and graphics. Often it is desirable to embed the graphics within the message so recipients can display the message directly, without further downloads.</p>
<p>Some mail agents don't support HTML or their users prefer to receive plain text messages. Senders of HTML messages should include a plain text message as an alternate for these users.</p>
<p>This recipe sends a short HTML message with a single embedded image and an alternate plain text message.</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>
Record and Playbac using standard Python. (Python)
2011-02-25T19:33:59-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577587-record-and-playbac-using-standard-python/
<p style="color: grey">
Python
recipe 577587
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/playback/">playback</a>, <a href="/recipes/tags/record/">record</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>This very simple DEMO code records a few seconds of your voice from a microphone, (internal mic' on a laptop), and
replays your voice immedaiately after recording. It goes without saying that the RAW recording can be saved in
any extension of your choice and used as error reporting using the playback method.</p>
<p>There is the possibility of using it as a simple means of a single channel audio oscilloscope using the external
mic input and suitable Python GUI or with simple home built HW a seismometer recorder, plus other ideas.</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Read the code for more information...</p>
<p>73...</p>
<p>Bazza, G0LCU...</p>
<p>Team AMIGA...</p>
Send an HTML email with embedded image and plain text alternate (Python)
2006-01-29T18:40:36-08:00darrin massenahttp://code.activestate.com/recipes/users/1987292/http://code.activestate.com/recipes/473810-send-an-html-email-with-embedded-image-and-plain-t/
<p style="color: grey">
Python
recipe 473810
by <a href="/recipes/users/1987292/">darrin massena</a>
(<a href="/recipes/tags/network/">network</a>).
</p>
<p>HTML is the method of choice for those wishing to send emails with rich text, layout and graphics. Often it is desirable to embed the graphics within the message so recipients can display the message directly, without further downloads.</p>
<p>Some mail agents don't support HTML or their users prefer to receive plain text messages. Senders of HTML messages should include a plain text message as an alternate for these users.</p>
<p>This recipe sends a short HTML message with a single embedded image and an alternate plain text message.</p>
RSH with timeout (Python)
2010-09-13T06:49:35-07:00Shrinidhi Raohttp://code.activestate.com/recipes/users/4174946/http://code.activestate.com/recipes/577390-rsh-with-timeout/
<p style="color: grey">
Python
recipe 577390
by <a href="/recipes/users/4174946/">Shrinidhi Rao</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/execution/">execution</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/rsh/">rsh</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/timeout/">timeout</a>).
</p>
<p>RSH sometimes hangs if it cannot resolve to a given host. So here is a quick recipe in python </p>
RomanNumeral to Integers (viceversa) (Java)
2010-07-18T11:20:19-07:00st0lehttp://code.activestate.com/recipes/users/4174421/http://code.activestate.com/recipes/577313-romannumeral-to-integers-viceversa/
<p style="color: grey">
Java
recipe 577313
by <a href="/recipes/users/4174421/">st0le</a>
(<a href="/recipes/tags/conversions/">conversions</a>, <a href="/recipes/tags/java/">java</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/roman/">roman</a>).
</p>
<p>Converts Roman Symbols to Integers and back.</p>
NMEA sentence checksum (Python)
2009-06-02T02:37:28-07:00Alan Holthttp://code.activestate.com/recipes/users/4170480/http://code.activestate.com/recipes/576789-nmea-sentence-checksum/
<p style="color: grey">
Python
recipe 576789
by <a href="/recipes/users/4170480/">Alan Holt</a>
(<a href="/recipes/tags/checksum/">checksum</a>, <a href="/recipes/tags/gps/">gps</a>, <a href="/recipes/tags/nmea/">nmea</a>).
</p>
<p>Calculates the checksum of an NMEA sentence (GPS data).</p>
Twisted Public Deferred (Python)
2009-12-08T09:47:16-08:00Alan Franzonihttp://code.activestate.com/recipes/users/4169882/http://code.activestate.com/recipes/576978-twisted-public-deferred/
<p style="color: grey">
Python
recipe 576978
by <a href="/recipes/users/4169882/">Alan Franzoni</a>
(<a href="/recipes/tags/deferred/">deferred</a>, <a href="/recipes/tags/twisted/">twisted</a>).
Revision 5.
</p>
<p>This small piece of code helps separating the "public" and "private" interface parts of deferred objects in Twisted.</p>
<p>Although it might not be really useful in production code, it is great for newcomers who are still learning the framework.</p>