Popular recipes tagged "meta:loc=29"http://code.activestate.com/recipes/tags/meta:loc=29/2016-06-20T18:14:38-07:00ActiveState Code RecipesSimple PDF Bookmark / Table of Contents Maintenance (Python)
2016-06-20T18:14:38-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580684-simple-pdf-bookmark-table-of-contents-maintenance/
<p style="color: grey">
Python
recipe 580684
by <a href="/recipes/users/4193772/">Jorj X. McKie</a>
(<a href="/recipes/tags/bookmarks/">bookmarks</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/incremental/">incremental</a>, <a href="/recipes/tags/metadata/">metadata</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>).
</p>
<p>PyMuPDF now supports a simple interface for maintaining table of contents / bookmarks and metadata for PDF documents.
By manipulating ordinary, elementary lists and dictionaries you can add, delete, modify a PDF's metadata and table of contents.</p>
Batch priority queue (Batch)
2016-05-26T11:00:21-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/580666-batch-priority-queue/
<p style="color: grey">
Batch
recipe 580666
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/batch/">batch</a>).
</p>
<p>The fact the environment sorts itself by key allows us to implement a PQ using the prefix "queu" added to the priority value as a key</p>
Lecture 1: Applications of Python in Bioinformatics: Visualizing Protein (Python)
2015-04-29T07:09:33-07:00Devashish Dashttp://code.activestate.com/recipes/users/4192116/http://code.activestate.com/recipes/579050-lecture-1-applications-of-python-in-bioinformatics/
<p style="color: grey">
Python
recipe 579050
by <a href="/recipes/users/4192116/">Devashish Das</a>
(<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/bioinformatics/">bioinformatics</a>, <a href="/recipes/tags/plots/">plots</a>, <a href="/recipes/tags/protein/">protein</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This code reads 1qlz.pdb protein file can be downloaded from <a href="http://www.rcsb.org/pdb/files/1QLZ.pdb" rel="nofollow">http://www.rcsb.org/pdb/files/1QLZ.pdb</a> and plots a 3D graph using maplotlib library. For mystery write to me: <a href="mailto:devashish.das@educept.com">devashish.das@educept.com</a></p>
<pre class="prettyprint"><code>__author__ = Devashish Das
__contact__ = +91-9964218681
__email__ = <a href="mailto:deavshish.das@educept.com">deavshish.das@educept.com</a>
__website__ = <a href="http://www.educept.com">http://www.educept.com</a>
</code></pre>
A Function To Create A 1 Second Sinewave WAVE Beep File. (Python)
2014-11-23T19:24:46-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578971-a-function-to-create-a-1-second-sinewave-wave-beep/
<p style="color: grey">
Python
recipe 578971
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/beep/">beep</a>, <a href="/recipes/tags/error_beep/">error_beep</a>, <a href="/recipes/tags/error_sound/">error_sound</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/sinewave/">sinewave</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/wav/">wav</a>, <a href="/recipes/tags/wave/">wave</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>).
</p>
<p>sinebeep.py</p>
<p>Creating an audio file called...</p>
<p>beep.wav</p>
<p>...that can be played using almost ANY audio player available.</p>
<p>This simple snippet of code generates a 1 second sinewave WAVE file.
It IS saved inside the CURRENT drawer so that you can find it... ;o)</p>
<p>This works on:-
Classic stock AMIGA A1200, using Python 1.4.0.
WinUAE and E-UAE, AmigaOS 3.0.x using Python 1.4.0 to 2.0.1.
Windows, to at least 7, using Python 2.0.1 to 3.3.2.
Various Linux flavours using Python 2.4.6 to 3.2.2.
Apple OSX 10.7.x and above using Python 2.5.6 to 3.4.1.</p>
<p>The file size is 8044 bytes and _IF_ you need to it can be palyed directly
without a player on some Linux flavours that have the /dev/dsp device.
It is an 8 bit, unsigned integer, mono, 8000Hz sampling speed 8000 byte
RAW file with the WAVE header added.</p>
<p>It will still work with PulseAudio and OSS using...</p>
<p>cat /full/path/to/beep.wav > /dev/dsp</p>
<p>...but with a momenatry click due to the 44 header bytes; but hey it is
a beep alternative...</p>
<p>Enjoy finding simple solutions to often very difficult problems.</p>
<p>Bazza.</p>
Create simple PDF text calendars with xtopdf (Python)
2014-02-14T22:33:04-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578832-create-simple-pdf-text-calendars-with-xtopdf/
<p style="color: grey">
Python
recipe 578832
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/calendar/">calendar</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/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to create simple text calendars as PDF using xtopdf, a Python toolkit for PDF creation.</p>
Mandelbrot Fractal using Tkinter (Python)
2013-07-06T23:53:20-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578590-mandelbrot-fractal-using-tkinter/
<p style="color: grey">
Python
recipe 578590
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>Mandelbrot Fractal using Tkinter</p>
dynamically changing encoder (for json) with metaclass (class factory) (Python)
2013-10-24T11:31:44-07:00-http://code.activestate.com/recipes/users/4188267/http://code.activestate.com/recipes/578696-dynamically-changing-encoder-for-json-with-metacla/
<p style="color: grey">
Python
recipe 578696
by <a href="/recipes/users/4188267/">-</a>
(<a href="/recipes/tags/class_factory/">class_factory</a>, <a href="/recipes/tags/encode/">encode</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/metaclasses/">metaclasses</a>).
</p>
<p>The <em>json.dumps</em> need to be feed with some class (cls =someClass) but what if we want to change the class dynamically?
This example can be done by declaring the <em>listOfClasses</em> in class level of course, but the idea is to be changeable. This can be done by the class factory function <em>encoderFacory</em></p>
Bash style commands (Bash)
2013-08-22T13:05:29-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578648-bash-style-commands/
<p style="color: grey">
Bash
recipe 578648
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/cmd/">cmd</a>).
</p>
<p>This is just a concept. To import bash style commands use "script.cmd /bash", to get the list of imported commands use "script.cmd /map"</p>
Bash style commands (Batch)
2013-08-22T13:06:33-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578649-bash-style-commands/
<p style="color: grey">
Batch
recipe 578649
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/cmd/">cmd</a>).
</p>
<p>This is just a concept. To import bash style commands use "script.cmd /bash", to get the list of imported commands use "script.cmd /map"</p>
Verify html form with JavaScript (JavaScript)
2013-07-15T12:19:53-07:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578606-verify-html-form-with-javascript/
<p style="color: grey">
JavaScript
recipe 578606
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/form/">form</a>, <a href="/recipes/tags/javascript/">javascript</a>).
</p>
<p>I wrote this for a <a href="http://thelivingpearl.com/2013/07/15/the-guest-book-problem/">php Guest Book</a> app I wrote. </p>
Russian Multiplication in Python (Python)
2013-06-18T15:25:02-07:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578567-russian-multiplication-in-python/
<p style="color: grey">
Python
recipe 578567
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/multiplication/">multiplication</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Here is a very simple program in Python to multiply 2 numbers. This version follows the Russian Multiplication Algorithm. I worte for my blog <a href="http://thelivingpearl.com/basic-multiplication-in-python/">Captain DeadBones Chronicles</a></p>
Trimming strings (JavaScript)
2013-07-09T14:31:18-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578597-trimming-strings/
<p style="color: grey">
JavaScript
recipe 578597
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/trim/">trim</a>).
</p>
<p>I do not like jQuery that's why I wrote own implementation for trimming strings. There are two ways how to do it.</p>
Truth Value Aware Iterable (Python)
2013-06-11T08:00:25-07:00Alan Franzonihttp://code.activestate.com/recipes/users/4169882/http://code.activestate.com/recipes/578549-truth-value-aware-iterable/
<p style="color: grey">
Python
recipe 578549
by <a href="/recipes/users/4169882/">Alan Franzoni</a>
(<a href="/recipes/tags/boolean/">boolean</a>, <a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/truth/">truth</a>).
</p>
<p>This small recipe enables truth value testing on iterables.</p>
<p>It is quite common to do things like:</p>
<pre class="prettyprint"><code>if somesequence:
...
else:
...
</code></pre>
<p>Such constructs, that enter the if block if the sequence's got one or more elements and the else block if it's empty, work fine on non-lazy builtin sequences (lists, strings, tuples) and dictionaries as well, but doesn't necessarily work on generic iterables - most of them are always true regardless of their contents, since they're some kind of object. A classical example is generators, but such behaviour can be extended to any object implementing the Iterable interface.</p>
<p>Just wrap your iterable with this decorator and you'll get a truth-aware iterable which supports proper truth testing by doing a small first element prefetching and can then be used just like the original iterable.</p>
Bilinear Interpolation (Python)
2013-02-23T04:00:52-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578469-bilinear-interpolation/
<p style="color: grey">
Python
recipe 578469
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>).
</p>
<p>Creates a surface from a grid of random numbers using Bilinear Interpolation.</p>
Performance boost with metaclasses (Python)
2013-02-17T10:58:13-08:00Martin Schoepfhttp://code.activestate.com/recipes/users/4185283/http://code.activestate.com/recipes/578460-performance-boost-with-metaclasses/
<p style="color: grey">
Python
recipe 578460
by <a href="/recipes/users/4185283/">Martin Schoepf</a>
(<a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/performance/">performance</a>).
</p>
<p>Consider a highly dynamic system where a lot of objects are created and destroyed. If the objects are complex and have a lot of default values the following recipe may improve the performance. The more default values you have the more you will gain from it. </p>
Hamming Neighbors (Python)
2013-01-17T20:50:21-08:00Yong Shinhttp://code.activestate.com/recipes/users/4184933/http://code.activestate.com/recipes/578423-hamming-neighbors/
<p style="color: grey">
Python
recipe 578423
by <a href="/recipes/users/4184933/">Yong Shin</a>
(<a href="/recipes/tags/distance/">distance</a>, <a href="/recipes/tags/dynamic/">dynamic</a>, <a href="/recipes/tags/hamming/">hamming</a>, <a href="/recipes/tags/programming/">programming</a>).
</p>
<p>HammingNeighbors returns all integers that are k number of bits away (i.e. k Hamming distance away) from an integer. <br />
The algorithm uses dynamic programming.</p>
"Effcient" Prime Number Generator in Python (Python)
2013-01-19T03:58:05-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578402-effcient-prime-number-generator-in-python/
<p style="color: grey">
Python
recipe 578402
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>).
</p>
<p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a></p>
<p>Please Note. This is only efficient per the article discussing this code in the link above. See comments for a better library to generate prime numbers.</p>
Morse Code Generator in Python (Python)
2013-01-08T18:04:34-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578408-morse-code-generator-in-python/
<p style="color: grey">
Python
recipe 578408
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/morse_code/">morse_code</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is a slightly better version. It has the ability to translate sentences into Morse Code. I wrote this code for an article <a href="http://thelivingpearl.com/2013/01/08/morse-code-and-dictionaries-in-python-with-sound/">Morse Code and Dictionaries in Python</a></p>
Slightly Diffrent Morse Code Translator (Python)
2013-01-08T18:06:27-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578409-slightly-diffrent-morse-code-translator/
<p style="color: grey">
Python
recipe 578409
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/morse_code/">morse_code</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This Morse Code Generator will generate a word on each line. It was written for <a href="http://thelivingpearl.com/2013/01/08/morse-code-and-dictionaries-in-python-with-sound/">Morse Code and Dictionaries in Python</a></p>
Immutable class decorator (Python)
2012-08-05T08:30:41-07:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578233-immutable-class-decorator/
<p style="color: grey">
Python
recipe 578233
by <a href="/recipes/users/2033964/">Oren Tirosh</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/immutable/">immutable</a>).
</p>
<p>Apply this decorator to a class with __slots__. Members will be mutable during the execution of __init__ but read-only afterwards.</p>