Popular recipes tagged "meta:license=gpl3" but not "mupdf"http://code.activestate.com/recipes/tags/meta:license=gpl3-mupdf/2016-09-28T12:03:59-07:00ActiveState Code RecipesExtract images of a PDF - optionally by page using PyMuPDF / fitz (Python) 2016-09-28T12:03:59-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580703-extract-images-of-a-pdf-optionally-by-page-using-p/ <p style="color: grey"> Python recipe 580703 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/png/">png</a>). </p> <p>Two small scripts to extract images contained in a PDF document as PNG files. (1) Script 1 extracts <strong>all</strong> images (2) Script 2 extracts only images that are referenced by a page</p> Decrypt a PDF using fitz / MuPDF (PyMuPDF) (Python) 2016-03-17T12:22:10-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580627-decrypt-a-pdf-using-fitz-mupdf-pymupdf/ <p style="color: grey"> Python recipe 580627 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/decompression/">decompression</a>, <a href="/recipes/tags/decryption/">decryption</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/repair/">repair</a>). </p> <p>It's more a code snippet. Shows how to dynamically check whether a PDF is password protected. If it is, decrypt it and save it back to disk un-encrypted.</p> PyOOCalc - Python Libre/Open Office Calc Interface API (UNO) (Python) 2016-01-10T13:12:53-08:00Yuriihttp://code.activestate.com/recipes/users/4193384/http://code.activestate.com/recipes/579147-pyoocalc-python-libreopen-office-calc-interface-ap/ <p style="color: grey"> Python recipe 579147 by <a href="/recipes/users/4193384/">Yurii</a> (<a href="/recipes/tags/openoffice/">openoffice</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>). </p> <p>Create Libre/Open Office Calc documents, reports on Python</p> PDF Joiner / Splitter using wxPython, PyMuPDF (fitz / MuPDF) (Python) 2016-03-15T19:07:35-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580622-pdf-joiner-splitter-using-wxpython-pymupdf-fitz-mu/ <p style="color: grey"> Python recipe 580622 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/join/">join</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/split/">split</a>). </p> <p>Full featured PDF joiner. Join several PDF files into one output PDF. Page ranges can be specified as well as page orientation for each output page range. Tables of contents are intelligently preserved for each page range (can also be switched off). Output PDF metadata editable.</p> nbitarray (Python) 2016-04-21T14:12:33-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/580649-nbitarray/ <p style="color: grey"> Python recipe 580649 by <a href="/recipes/users/4184815/">yota</a> . </p> <p>library to store n bits data (n &gt; 0) in a python array</p> Create Sierpinski Carpet (Fractal) FAST (Python) 2016-03-16T08:56:08-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580624-create-sierpinski-carpet-fractal-fast/ <p style="color: grey"> Python recipe 580624 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/sierpinski/">sierpinski</a>). </p> <p>Create a Sierpinski carpet using MuPDF's graphics library fitz (binding PyMuPDF) at high speed.</p> Add function to Python's __builtin__ module through C API (C) 2015-10-16T12:11:58-07:00airweenhttp://code.activestate.com/recipes/users/4192997/http://code.activestate.com/recipes/579110-add-function-to-pythons-__builtin__-module-through/ <p style="color: grey"> C recipe 579110 by <a href="/recipes/users/4192997/">airween</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/builtins/">builtins</a>, <a href="/recipes/tags/c/">c</a>, <a href="/recipes/tags/exten/">exten</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Add function to __builtin__ module through C API</p> <p>Sometimes it need to embedding a Python script to a C code, and it references to a function, which also provided by the same C code. Then you have to import the module, as you defined in your C code.</p> <p>But this import would be skipped, if you add your function to your __builtin__ module. In Python3 (3.5), there is the PyModule_AddFunctions() function, but in the previous versions, you can make it like this snippet.</p> <p>See these recipes:</p> <p>Makefile: <a href="https://code.activestate.com/recipes/579111-add-function-to-__builtin__-module-through-c-api-c/" rel="nofollow">https://code.activestate.com/recipes/579111-add-function-to-__builtin__-module-through-c-api-c/</a></p> <p>Python script: <a href="https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/" rel="nofollow">https://code.activestate.com/recipes/579112-add-function-to-__builtin__-module-through-c-api-c/</a></p> ed25519 (Python) 2015-09-21T12:58:34-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579102-ed25519/ <p style="color: grey"> Python recipe 579102 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/cryptography/">cryptography</a>). Revision 2. </p> <p>This is a re-implementation of the ed25519 signature algorithm as proposed on this page : <a href="http://ed25519.cr.yp.to/python/ed25519.py." rel="nofollow">http://ed25519.cr.yp.to/python/ed25519.py.</a></p> <p>Do not use for production, only for the eyes o_O</p> <p>Code is tab indented, space indentation kills kitten...</p> least square fitting (Python) 2015-10-03T15:32:28-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579106-least-square-fitting/ <p style="color: grey"> Python recipe 579106 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/fitting/">fitting</a>). Revision 2. </p> <p>a generic python code to fit points to a given curve, was made for a paraboloid, but can be easily expanded to many kind of curves</p> pick all combinations of items in buckets (Python) 2015-09-05T07:39:42-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579098-pick-all-combinations-of-items-in-buckets/ <p style="color: grey"> Python recipe 579098 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/combinatorics/">combinatorics</a>). </p> <p>Let be a number of buckets, containing each, a variable number of items. This function return all combinations possible of one item picked out of each bucket</p> <p>example, with three buckets {ba, be, bi}, {ka, ko, ku, ke} and {to, ty}, the function enumerate as such: </p> <pre class="prettyprint"><code> 0. ba-ka-to 1. ba-ka-ty 2. ba-ko-to 3. ba-ko-ty 4. ba-ku-to 5. ba-ku-ty 6. ba-ke-to 7. ba-ke-ty 8. be-ka-to 9. be-ka-ty 10. be-ko-to 11. be-ko-ty 12. be-ku-to 13. be-ku-ty 14. be-ke-to 15. be-ke-ty 16. bi-ka-to 17. bi-ka-ty 18. bi-ko-to 19. bi-ko-ty 20. bi-ku-to 21. bi-ku-ty 22. bi-ke-to 23. bi-ke-ty </code></pre> Simple video with ctypes and Xvid (Tkinter,pygame,...) (Python) 2015-06-29T13:59:38-07:00Jiri Justrahttp://code.activestate.com/recipes/users/4192188/http://code.activestate.com/recipes/579073-simple-video-with-ctypes-and-xvid-tkinterpygame/ <p style="color: grey"> Python recipe 579073 by <a href="/recipes/users/4192188/">Jiri Justra</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/video/">video</a>, <a href="/recipes/tags/xvid/">xvid</a>). </p> <p>This is simple library for playing avi video clips. Videos must be SOUNDLESS (and maybe Xvid encoded wont hurt), to work it properly. I am using it to play intro. It suites good to this purpose, since it can play one clip at a time only.</p> smart copy (Python) 2015-02-06T09:45:12-08:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/579020-smart-copy/ <p style="color: grey"> Python recipe 579020 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/shutil/">shutil</a>). </p> <p>take a glob expression, a source directory and a destination directory to copy each files matching the glob in the appropriate directory</p> <pre class="prettyprint"><code>glob = */*.txt src_dir = ./a/b dst_dir = /z/x/y </code></pre> <p>if the glob match a file <code>./a/b/c/foo.txt</code>, it will copy it in <code>/z/x/y/c/foo.txt</code> (and create the missing directory if needed)</p> <p>Require Python3.4, code tab indented</p> asskick.py (Python) 2014-09-20T08:16:57-07:00p@ntut$http://code.activestate.com/recipes/users/4183895/http://code.activestate.com/recipes/578940-asskickpy/ <p style="color: grey"> Python recipe 578940 by <a href="/recipes/users/4183895/">p@ntut$</a> (<a href="/recipes/tags/kickass/">kickass</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/torrents/">torrents</a>). </p> <p>URL: <a href="http://pantuts.com/2014/09/20/asskick-py-python-script-search-download-torrents-kickass/" rel="nofollow">http://pantuts.com/2014/09/20/asskick-py-python-script-search-download-torrents-kickass/</a></p> <p>Python script to search and download torrents from KickAss torrents.</p> Pasting python data into a spread sheet (Python) 2014-09-16T15:49:07-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578933-pasting-python-data-into-a-spread-sheet/ <p style="color: grey"> Python recipe 578933 by <a href="/recipes/users/4189558/">Tomas Nordin</a> (<a href="/recipes/tags/clipboard/">clipboard</a>, <a href="/recipes/tags/spreadsheet/">spreadsheet</a>). Revision 3. </p> <p>A smooth way to paste data you are working with in python into a spreadsheet. Put into the system clipboard, select a cell and do ctrl-v (at least with ms office and libre-office).</p> lru_timestamp - cache entry aging for functools.lru_cache (Python) 2014-02-02T21:28:25-08:00Peter Santorohttp://code.activestate.com/recipes/users/4189027/http://code.activestate.com/recipes/578817-lru_timestamp-cache-entry-aging-for-functoolslru_c/ <p style="color: grey"> Python recipe 578817 by <a href="/recipes/users/4189027/">Peter Santoro</a> (<a href="/recipes/tags/age/">age</a>, <a href="/recipes/tags/lru_cache/">lru_cache</a>). </p> <p>Return a timestamp string for @lru_cache decorated functions.</p> <p>The returned timestamp is used as the value of an extra parameter to @lru_cache decorated functions, allowing for more control over how often cache entries are refreshed. The lru_timestamp function should be called with the same refresh_interval value for a given @lru_cache decorated function. The returned timestamp is for the benefit of the @lru_cache decorator and is normally not used by the decorated function.</p> <p>Positional arguments: refresh_interval -- in minutes (default 60), values less than 1 are coerced to 1, values more than 1440 are coerced to 1440</p> NondurableLogger class for use with concurrent.futures.ProcessPoolExecutor's submit and map methods (Python) 2014-02-10T17:50:59-08:00Peter Santorohttp://code.activestate.com/recipes/users/4189027/http://code.activestate.com/recipes/578827-nondurablelogger-class-for-use-with-concurrentfutu/ <p style="color: grey"> Python recipe 578827 by <a href="/recipes/users/4189027/">Peter Santoro</a> (<a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>). Revision 2. </p> <p>I needed a simple logging solution that I could use with with concurrent.futures.ProcessPoolExecutor and this is my initial recipe.</p> Levenshtein, my love (Python) 2014-01-15T09:14:30-08:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/578810-levenshtein-my-love/ <p style="color: grey"> Python recipe 578810 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/text/">text</a>). Revision 3. </p> <p><em>be kind and comment, especially if you downvote</em></p> <p><strong>levenshtein_distance()</strong> is an implementation of the iterative algorithm for the levenshtein distance (cf. <a href="http://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_full_matrix%29" rel="nofollow">http://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_full_matrix)</a></p> <p><strong>levenshtein_sequence()</strong> is an attempt to retrieve one of the levenshtein paths (the one that give priority to substitution, deletion, insertion, in this order). The result is a list of tuples made of:</p> <ol> <li>the operation ( <code>=</code>, <code>-</code>, <code>+</code>, <code>*</code> for respectively keep, delete, insert, substitute)</li> <li>the coordinate in the first</li> <li>and in the second string.</li> </ol> <pre class="prettyprint"><code>&gt;&gt;&gt; levenshtein_sequence('saturday', 'sunday') [('=', 0, 0), ('-', 1, 0), ('-', 2, 0), ('=', 3, 1), ('*', 4, 2), ('=', 5, 3), ('=', 6, 4), ('=', 7, 5)] &gt;&gt;&gt; levenshtein_sequence('kitten', 'sitting') [('*', 0, 0), ('=', 1, 1), ('=', 2, 2), ('=', 3, 3), ('*', 4, 4), ('=', 5, 5), ('+', 5, 6)] </code></pre> <p>This code is part of foreplays, in a plan I have to improve difflib with alternative SequenceMatchers \o/</p> <p><em>/!\ tab indented, as usual.</em></p> dynamic mathjax demo page (HTML) 2015-02-12T13:10:17-08:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/578679-dynamic-mathjax-demo-page/ <p style="color: grey"> HTML recipe 578679 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/latex/">latex</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathjax/">mathjax</a>). Revision 7. </p> <p>Html web page to preview latex equations rendered by mathjax. <a href="http://jsfiddle.net/r82p49xx/5/">demo here</a></p> <p>Equations are updated when shift, space or enter keys are pressed, or when the Textarea lose focus.</p> <p>In the first block you can try inline-style math, in the second one, display-style math.</p> heap class (Python) 2015-09-17T12:41:15-07:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/578694-heap-class/ <p style="color: grey"> Python recipe 578694 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/heap/">heap</a>). Revision 2. </p> <p><em>heapq</em> is a nice python module, but the interface is not so clean. I found a one-liner on this <a href="http://metapython.blogspot.de/2010/10/creating-heap-class-in-one-python-line.html">blog</a>, it's as short as possible, but not really pythonic either :) Here is my contribution to a most readable heap class.</p> Bash script to create a header for Bash scripts (Bash) 2011-11-02T01:57:07-07:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/577862-bash-script-to-create-a-header-for-bash-scripts/ <p style="color: grey"> Bash recipe 577862 by <a href="/recipes/users/4179007/">userend</a> (<a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/gpl/">gpl</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/vim/">vim</a>). Revision 3. </p> <p>This will create a header for a Bash script. It is a nice way keep a track of what your script does and when it was created, the author of the script, etc.. </p> <p>It will open the script automatically with one of the two most popular editor out there, Vim or Emacs! It also checks to see if there is a script with the same name in the current working directory so it will not overwrite another file.</p> <p>v0.4: I had to kick this up a notch. I took the suggestion of "dev h" to add a chance for the user to select another name for the script.</p> <p>Please leave comments and suggestions.</p>