Most viewed recipes tagged "meta:license=gpl3"http://code.activestate.com/recipes/tags/meta:license=gpl3/views/2017-06-18T17:43:47-07:00ActiveState Code RecipesBash 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> Create Calendars on PDF with a few lines (Python) 2017-06-13T10:57:34-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580805-create-calendars-on-pdf-with-a-few-lines/ <p style="color: grey"> Python recipe 580805 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/calendar/">calendar</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>). Revision 2. </p> <p>PyMuPDF (fitz) provides easy to use ways to create PDF documents out of simple texts.</p> <p>An example is the text output of Python's calendar module. Here we take a starting year as script parameter and output a 3-page (A4 landscape) document with calendars for this and the following two years - in less than 20 lines of code.</p> 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> Python script to create a header for Python scripts (Python) 2011-10-02T15:45:11-07:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/577846-python-script-to-create-a-header-for-python-script/ <p style="color: grey"> Python recipe 577846 by <a href="/recipes/users/4179007/">userend</a> (<a href="/recipes/tags/2/">2</a>, <a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/vim/">vim</a>). Revision 5. </p> <p>This will create a header for a Python 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>Update: Now, it will automatically open with one of the two most popular editors, Vim or Emacs! This script has been updated from the second version to replace spaces with underscores in the title, to convert uppercase to lowercase. 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. Please leave comments and suggestions.</p> How to Create a PDF with a Caustic Drawing (Python) 2017-06-18T17:43:47-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580806-how-to-create-a-pdf-with-a-caustic-drawing/ <p style="color: grey"> Python recipe 580806 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>). </p> <p>Just a little demo on how to create simple drawings with PyMuPDF.</p> <p>This script simulates what you see looking into your coffee mug, early in the morning after a long night of programming ...</p> String to Binary (Python) 2014-07-30T07:20:22-07:00p@ntut$http://code.activestate.com/recipes/users/4183895/http://code.activestate.com/recipes/578291-string-to-binary/ <p style="color: grey"> Python recipe 578291 by <a href="/recipes/users/4183895/">p@ntut$</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/to/">to</a>). Revision 2. </p> <p>String to binary snippet, python3+</p> Multiplication table (Python) 2011-04-21T09:12:26-07:00Boubakrhttp://code.activestate.com/recipes/users/4176416/http://code.activestate.com/recipes/577672-multiplication-table/ <p style="color: grey"> Python recipe 577672 by <a href="/recipes/users/4176416/">Boubakr</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/multiplication/">multiplication</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/table/">table</a>). </p> <p>Multiplication table (Python)</p> TCP Port Checker (Python) 2011-06-24T09:53:28-07:00Boubakrhttp://code.activestate.com/recipes/users/4176416/http://code.activestate.com/recipes/577769-tcp-port-checker/ <p style="color: grey"> Python recipe 577769 by <a href="/recipes/users/4176416/">Boubakr</a> (<a href="/recipes/tags/checker/">checker</a>, <a href="/recipes/tags/port/">port</a>, <a href="/recipes/tags/tcp/">tcp</a>). </p> <p>a simple TCP Port Checker using socket !</p> PDF Text Extraction using fitz / MuPDF (PyMuPDF) (Python) 2016-03-17T12:00:06-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580626-pdf-text-extraction-using-fitz-mupdf-pymupdf/ <p style="color: grey"> Python recipe 580626 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/openxps/">openxps</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/text_extraction/">text_extraction</a>, <a href="/recipes/tags/xps/">xps</a>). </p> <p>Extract all the text of a PDF (or other supported container types) at very high speed. In general, text pieces of a PDF page are not arranged in natural reading order, but in the order they were entered during PDF creation. This script re-arranges text blocks according to their pixel coordinates to achieve a more readable output, i.e. top-down, left-right.</p> Python code minifier (Python) 2014-05-25T16:23:55-07:00Dan McDougallhttp://code.activestate.com/recipes/users/4169722/http://code.activestate.com/recipes/576704-python-code-minifier/ <p style="color: grey"> Python recipe 576704 by <a href="/recipes/users/4169722/">Dan McDougall</a> (<a href="/recipes/tags/bz2/">bz2</a>, <a href="/recipes/tags/bzip2/">bzip2</a>, <a href="/recipes/tags/comments/">comments</a>, <a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/docstring/">docstring</a>, <a href="/recipes/tags/embedded/">embedded</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/minify/">minify</a>, <a href="/recipes/tags/pack/">pack</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/zlib/">zlib</a>). Revision 16. </p> <p><strong>Update 05/25/2014:</strong> Pyminifier 2.0 has been released and now lives on Github: <a href="https://github.com/liftoff/pyminifier" rel="nofollow">https://github.com/liftoff/pyminifier</a> (docs are here: <a href="http://liftoff.github.io/pyminifier/" rel="nofollow">http://liftoff.github.io/pyminifier/</a>). The code below is very out-of-date but will be left alone for historical purposes.</p> <p>Python Minifier: Reduces the size of Python code for use on embedded platforms. Performs the following:</p> <ol> <li>Removes docstrings.</li> <li>Removes comments.</li> <li>Removes blank lines.</li> <li>Minimizes code indentation.</li> <li>Joins multiline pairs of parentheses, braces, and brackets (and removes extraneous whitespace within).</li> <li>Preserves shebangs and encoding info (e.g. "# -<em>- coding: utf-8 -</em>-")</li> <li><strong>NEW:</strong> Optionally, produces a bzip2 or gzip-compressed self-extracting python script containing the minified source for ultimate minification.</li> </ol> <p><strong>Update 09/23/2010:</strong> Version 1.4.1: Fixed an indentation bug when operators such as @ and open parens started a line.</p> <p><strong>Update 09/18/2010:</strong> Version 1.4:</p> <ul> <li>Added some command line options to save the result to an output file.</li> <li>Added the ability to save the result as a bzip2 or gzip-compressed self-extracting python script (which is kinda neat--try it!).</li> <li>Updated some of the docstrings to provide more examples of what each function does.</li> </ul> <p><strong>Update 06/02/2010:</strong> Version 1.3: Rewrote several functions to use Python's built-in tokenizer module (which I just discovered despite being in Python since version 2.2). This negated the requirement for pyparsing and improved performance by an order of magnitude. It also fixed some pretty serious bugs with dedent() and reduce_operators().</p> <p>PLEASE POST A COMMENT IF YOU ENCOUNTER A BUG!</p> Pyscanlogger - Python Port scan detector (Python) 2010-03-17T07:27:15-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576690-pyscanlogger-python-port-scan-detector/ <p style="color: grey"> Python recipe 576690 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/security/">security</a>). Revision 5. </p> <p>A pure Python program to detect network port scanning attacks. Currently logs different TCP port scans. Can run in the background like a daemon and log attacks to a log file.</p> Extract 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> 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> Decorator to expose local variables of a function after execution (Python) 2010-07-07T22:01:23-07:00Pietro Berkeshttp://code.activestate.com/recipes/users/4174299/http://code.activestate.com/recipes/577283-decorator-to-expose-local-variables-of-a-function-/ <p style="color: grey"> Python recipe 577283 by <a href="/recipes/users/4174299/">Pietro Berkes</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/function/">function</a>, <a href="/recipes/tags/inner/">inner</a>, <a href="/recipes/tags/local/">local</a>, <a href="/recipes/tags/scope/">scope</a>, <a href="/recipes/tags/variables/">variables</a>). Revision 2. </p> <p>Decorator to expose the local variables defined in the inner scope of a function. At the exit of the decorated function (regular exit or exceptions), the local dictionary is copied to a read-only property, <code>locals</code>.</p> <p>The main implementation is based on injecting bytecode into the original function, and requires the lightweight module <code>byteplay</code> (available <a href="http://code.google.com/p/byteplay/">here</a>). See below for an alternative implementation that only uses the standard library.</p> Keyword Argument Injection with Python Decorators (Python) 2010-09-05T17:06:04-07:00Ahmet Emre Aladağhttp://code.activestate.com/recipes/users/4174877/http://code.activestate.com/recipes/577382-keyword-argument-injection-with-python-decorators/ <p style="color: grey"> Python recipe 577382 by <a href="/recipes/users/4174877/">Ahmet Emre Aladağ</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/injection/">injection</a>, <a href="/recipes/tags/variable/">variable</a>). Revision 2. </p> <p>In most of the object oriented codes we write, we need to set class attributes to the given argument values and this is a very line-consuming thing. To get over these redundant lines, I found a solution using decorators. </p> How to parse a table in a PDF document (Python) 2016-04-10T22:43:57-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580635-how-to-parse-a-table-in-a-pdf-document/ <p style="color: grey"> Python recipe 580635 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/openxps/">openxps</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/xps/">xps</a>). Revision 4. </p> <p>A Python function that converts a table contained in a page of a PDF (or OpenXPS, EPUB, CBZ, XPS) document to a matrix-like Python object (list of lists of strings).</p> Object wrapper class (Python) 2011-01-28T12:40:58-08:00Nichita Utiuhttp://code.activestate.com/recipes/users/4176755/http://code.activestate.com/recipes/577555-object-wrapper-class/ <p style="color: grey"> Python recipe 577555 by <a href="/recipes/users/4176755/">Nichita Utiu</a> (<a href="/recipes/tags/wrapper/">wrapper</a>). </p> <p>This is a wrapper class which, it wraps an object which it then proxies unnhandled getattr calls to.</p> Find Prime Numbers in python (Python) 2010-06-12T08:22:40-07:00Giannis Fysakishttp://code.activestate.com/recipes/users/4174072/http://code.activestate.com/recipes/577259-find-prime-numbers-in-python/ <p style="color: grey"> Python recipe 577259 by <a href="/recipes/users/4174072/">Giannis Fysakis</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). Revision 2. </p> <p>The algorithm is based on the idea <br /> that the next larger prime after one prime is the sum of the two smaller previous minus three prime numbers back. For the first five prime numbers 2,3,5,7,11 this pattern is not true also it is not true if the number is a composite number (including of course if the number's square root is integer). </p> <p>Example trying to find the tenth prime</p> <p>so lets play with numbers 17(minus 3 from Next,position 7), 19(minus 2 from Next,position 8), 23(minus 1 from Next,position 9) and number Next at position 10 :</p> <p>hmmm ... if we add 19 and 23 we get 42, but 42 minus 17 equals 25 which isn't a prime :(</p> <p>In order to correct this we assume that 25 is the next prime number ( temporary holding the tenth position) finally to get the real Next prime number we take 23 + 25 = 48 , we subtract 19 and we get 29 which finally it takes the tenth position ( because it deserves it :P)</p> Running linux command inside your python script (Python) 2012-09-09T08:08:46-07:00Ahmed Kamelhttp://code.activestate.com/recipes/users/4183490/http://code.activestate.com/recipes/578254-running-linux-command-inside-your-python-script/ <p style="color: grey"> Python recipe 578254 by <a href="/recipes/users/4183490/">Ahmed Kamel</a> (<a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Running any linux command line inside your python script.</p> How to stream an mp3 file using vlc.py, with a simple TKinter GUI. (Python) 2013-06-09T12:52:30-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/578556-how-to-stream-an-mp3-file-using-vlcpy-with-a-simpl/ <p style="color: grey"> Python recipe 578556 by <a href="/recipes/users/2667360/">Anton Vredegoor</a> (<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/streaming/">streaming</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/vlc/">vlc</a>). </p> <p>This script can be used to stream an existing mp3 file to multiple computers. It has a simple Tkinter GUI with only one button to start/stop the stream, and a slider to indicate or change the position.</p>