Popular recipes tagged "meta:loc=69"http://code.activestate.com/recipes/tags/meta:loc=69/popular/2017-07-10T16:07:51-07:00ActiveState Code RecipesHow to create a simple PDF Pie Chart using fitz / PyMuPDF (Python) 2017-07-10T16:07:51-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580810-how-to-create-a-simple-pdf-pie-chart-using-fitz-py/ <p style="color: grey"> Python recipe 580810 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>). </p> <p>PyMuPDF now supports drawing pie charts on a PDF page.</p> <p>Important parameters for the function are center of the circle, one of the two arc's end points and the angle of the circular sector. The function will draw the pie piece (in a variety of options) and return the arc's calculated other end point for any subsequent processing.</p> <p>This example creates a chart of the parliament seat distribution for political parties in the current German Bundestag.</p> Image background for tkinter (Python) 2017-04-12T19:37:06-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580782-image-background-for-tkinter/ <p style="color: grey"> Python recipe 580782 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/background/">background</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 3. </p> <p>This is only a proof of concept.</p> <p>In my first example, PIL is required. I use PIL also to draw the text over the background. I use the place geometry manager to position the entry.</p> <p>In my second example, I use a canvas widget to draw text over image. I also use the canvas to create other widgets over the background.</p> Data (A Class For Arbitrary Data) (Python) 2015-08-03T15:22:40-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/579092-data-a-class-for-arbitrary-data/ <p style="color: grey"> Python recipe 579092 by <a href="/recipes/users/4182236/">Alfe</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/lightweight/">lightweight</a>). </p> <p>A class which is designed to be easy to use when one needs a piece of data with a minimum of source required.</p> <p>Usage:</p> <pre class="prettyprint"><code>shop = Data(owner="Homer", address="down the street", ice=Data(flavor="vanilla", amount=3)) print shop Data: owner = 'Homer' ice = Data: amount = 3 flavor = 'vanilla' address = 'down the street' </code></pre> Yet another hex2dec (Batch) 2013-07-01T05:54:07-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578501-yet-another-hex2dec/ <p style="color: grey"> Batch recipe 578501 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/hex2dec/">hex2dec</a>). Revision 5. </p> <p>Script does not need <strong>0x</strong> or <strong>x</strong> in hex numbers which consists from both digits and letters. For example, command <strong>hex2dec.cmd ff</strong> returns 255.</p> Attempt to estimate a size of Python object (Python) 2013-02-02T12:09:23-08:00Andrewhttp://code.activestate.com/recipes/users/4185117/http://code.activestate.com/recipes/578447-attempt-to-estimate-a-size-of-python-object/ <p style="color: grey"> Python recipe 578447 by <a href="/recipes/users/4185117/">Andrew</a> (<a href="/recipes/tags/debug/">debug</a>). Revision 6. </p> <p>This function is built on assumption, that no custom types was implemented. Function traversing the tree of given object and summing sizes of pointers and basic-types objects got with sys.getsizeof() function. For example, for this two dicts {'key': 'shortstring'} and {'key': 'veryverylongandconsumingstring'} my function will return different sizes, while sys.getsizeof() will return same. TODO - make that calculation of size covers pointers of circular references which for now is just passed by</p> Find a unique name based on prefix + digit in log2(n) + log2(n/2) (Python) 2011-10-31T20:30:54-07:00Garel Alexhttp://code.activestate.com/recipes/users/2757636/http://code.activestate.com/recipes/577934-find-a-unique-name-based-on-prefix-digit-in-log2n-/ <p style="color: grey"> Python recipe 577934 by <a href="/recipes/users/2757636/">Garel Alex</a> (<a href="/recipes/tags/name/">name</a>, <a href="/recipes/tags/unique/">unique</a>). </p> <p>Find a unique name based on a prefix for a content in a container (eg. a file in a directory) adding a digit to the name</p> <p>Does it in log2(n) + log2(n/2) were n is the number of duplicates</p> <p>This would be used eg. in a CMS giving identifiers based on content title, or when shortening file names on a file system, etc.</p> Basic interface to Apache Solr (Python) 2011-10-17T12:46:55-07:00Graham Poulterhttp://code.activestate.com/recipes/users/4172291/http://code.activestate.com/recipes/577909-basic-interface-to-apache-solr/ <p style="color: grey"> Python recipe 577909 by <a href="/recipes/users/4172291/">Graham Poulter</a> (<a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/solr/">solr</a>). </p> <p>A basic model class representing Apache Solr. Abstracts the select, delete, update, and commit operations.</p> <p>Select operation returns Python object parsed from a JSON-formatted response.</p> Floyd-Steinberg dithering algorithm (Python) 2009-06-02T01:28:46-07:00Alan Holthttp://code.activestate.com/recipes/users/4170480/http://code.activestate.com/recipes/576788-floyd-steinberg-dithering-algorithm/ <p style="color: grey"> Python recipe 576788 by <a href="/recipes/users/4170480/">Alan Holt</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/dithering/">dithering</a>, <a href="/recipes/tags/floyd_steinberg/">floyd_steinberg</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/manipulation/">manipulation</a>). </p> <p>Floyd-Steinberg dithering is an image dithering algorithm (see <a href="http://en.wikipedia.org/wiki/Floyd-Steinberg" rel="nofollow">http://en.wikipedia.org/wiki/Floyd-Steinberg</a> for more details). While the algorithm is mainly for image manipulation, I use it to create random locations for sensor networt devices.</p> Subversion Directory Removal (Python) 2009-09-16T11:32:46-07:00Amos Andersonhttp://code.activestate.com/recipes/users/4171286/http://code.activestate.com/recipes/576903-subversion-directory-removal/ <p style="color: grey"> Python recipe 576903 by <a href="/recipes/users/4171286/">Amos Anderson</a> (<a href="/recipes/tags/directory_removal/">directory_removal</a>, <a href="/recipes/tags/non_empty_directory/">non_empty_directory</a>, <a href="/recipes/tags/remove_read_only/">remove_read_only</a>, <a href="/recipes/tags/subversion/">subversion</a>, <a href="/recipes/tags/_svn/">_svn</a>). Revision 9. </p> <p>This script removes all traces of subversion files from a directory tree.</p> Play wave audio (Python) 2009-08-04T05:45:46-07:00giuseppelobruttohttp://code.activestate.com/recipes/users/4171336/http://code.activestate.com/recipes/576866-play-wave-audio/ <p style="color: grey"> Python recipe 576866 by <a href="/recipes/users/4171336/">giuseppelobrutto</a> (<a href="/recipes/tags/multimedia/">multimedia</a>, <a href="/recipes/tags/ossaudiodev/">ossaudiodev</a>, <a href="/recipes/tags/wave/">wave</a>). </p> <p>Play wave audio</p> C function decorator (Python) 2009-04-29T23:55:03-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576731-c-function-decorator/ <p style="color: grey"> Python recipe 576731 by <a href="/recipes/users/4170000/">geremy condra</a> (<a href="/recipes/tags/cpp/">cpp</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/function/">function</a>). Revision 6. </p> <p>This recipe provides an easy-to-use, decorator-based solution to the problem of using functions from other languages, especially C, in Python. It takes advantage of Python's new annotations to provide simple type checking and automatic conversion. If you like it, you may also want to check out my <a href="http://code.activestate.com/recipes/576734/">C structure decorator</a></p> get a stock historical value from google finance (Python) 2008-09-07T12:03:11-07:00bussiere bussierehttp://code.activestate.com/recipes/users/4050557/http://code.activestate.com/recipes/576495-get-a-stock-historical-value-from-google-finance/ <p style="color: grey"> Python recipe 576495 by <a href="/recipes/users/4050557/">bussiere bussiere</a> (<a href="/recipes/tags/finance/">finance</a>, <a href="/recipes/tags/google/">google</a>, <a href="/recipes/tags/historical/">historical</a>, <a href="/recipes/tags/value/">value</a>). </p> <p>how to get a stock historical value from google finance</p> Generic block iterator (Python) 2008-01-17T03:55:45-08:00George Sakkishttp://code.activestate.com/recipes/users/2591466/http://code.activestate.com/recipes/521877-generic-block-iterator/ <p style="color: grey"> Python recipe 521877 by <a href="/recipes/users/2591466/">George Sakkis</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 4. </p> <p>A common task, especially in text processing, is to break some input sequence into chunks (lines, paragraphs, records, etc.) and process them one by one. The iterators of builtin strings and files can be considered such chunkers, breaking the object into characters and lines respectively. This recipe is a generic way to break any iterable into consecutive blocks, specified by a delimiter or a pair of (start,end) delimiters.</p> iterator wrapper, allowing 'pushback' and 'nonzero' test (Python) 2007-03-12T09:59:03-07:00Manuel Garciahttp://code.activestate.com/recipes/users/2827266/http://code.activestate.com/recipes/502304-iterator-wrapper-allowing-pushback-and-nonzero-tes/ <p style="color: grey"> Python recipe 502304 by <a href="/recipes/users/2827266/">Manuel Garcia</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Needed the ability to 'pushback' values back onto an iterator, and also was able to add a 'nonzero' test to the iterator at the same time.</p> zip_exc(), a lazy zip() that ensures that all iterables have the same length (Python) 2006-08-31T03:12:12-07:00Peter Ottenhttp://code.activestate.com/recipes/users/1780486/http://code.activestate.com/recipes/497006-zip_exc-a-lazy-zip-that-ensures-that-all-iterables/ <p style="color: grey"> Python recipe 497006 by <a href="/recipes/users/1780486/">Peter Otten</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Using zip(names, values) may inadvertently eat some of your data when there are, e. g., fewer values than names. This is easy to fix with assert len(names) == len(values) if the arguments' length is known, but not if they are arbitrary iterables. With zip_exc() no such glitches go unnoticed as list(zip_exc(names, values)) throws a LengthMismatch exception if the number of names and values differ.</p> Misspell words to avoid detection (Python) 2005-09-06T15:39:26-07:00Robert McDermotthttp://code.activestate.com/recipes/users/786815/http://code.activestate.com/recipes/440526-misspell-words-to-avoid-detection/ <p style="color: grey"> Python recipe 440526 by <a href="/recipes/users/786815/">Robert McDermott</a> (<a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>The misspell class takes a string and slightly mangles it by randomly transposing two adjacent characters while leaving the first and last characters intact. The resulting text is almost completely misspelled but still completely readable. Words less than four characters, numbers, email addresses and URLs are untouched. Each run will produce a message with a different signature (checksum).</p> Use wxPython/OpenGL to draw a sphere (Python) 2004-10-27T12:53:47-07:00Rick Mullerhttp://code.activestate.com/recipes/users/1461790/http://code.activestate.com/recipes/325392-use-wxpythonopengl-to-draw-a-sphere/ <p style="color: grey"> Python recipe 325392 by <a href="/recipes/users/1461790/">Rick Muller</a> (<a href="/recipes/tags/graphics/">graphics</a>). </p> <p>A simple wxPython/OpenGL application to draw a sphere.</p> Parsing the command line (Python) 2004-04-18T08:15:21-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/278844-parsing-the-command-line/ <p style="color: grey"> Python recipe 278844 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 2. </p> <p>The module optparse was a great addition to Python 2.3, since it is much more powerful and easier to use than getopt. Using optparse, writing command-line tools is a breeze. However, the power of optparse comes together with a certain verbosity. This recipe allows to use optparse with a minimum of boilerplate, trading flexibility for easy of use. Still, it covers 95% of my common needs, so I think it may be useful to others.</p> Generate java structure definitions for DB2 tables. (Tcl) 2003-06-18T01:33:12-07:00Patrick Finneganhttp://code.activestate.com/recipes/users/1220635/http://code.activestate.com/recipes/206126-generate-java-structure-definitions-for-db2-tables/ <p style="color: grey"> Tcl recipe 206126 by <a href="/recipes/users/1220635/">Patrick Finnegan</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>This tcl script, called from a windows bat file generates java structure definitions for DB2 tables using the db2 db2dclgn and describe utilities.</p> <p>Output is sent to two files.</p> <p>*.txt</p> <p>452 CHARACTER 1 ACCESS_STATUS 13 485 DECIMAL 8, 0 CUSTOMER 8</p> <p>*.java</p> <p>java.lang.String access_status; java.math.BigDecimal customer;</p> automatically upgrade class instances on reload() (Python) 2004-10-27T16:51:20-07:00Michael Hudsonhttp://code.activestate.com/recipes/users/597580/http://code.activestate.com/recipes/160164-automatically-upgrade-class-instances-on-reload/ <p style="color: grey"> Python recipe 160164 by <a href="/recipes/users/597580/">Michael Hudson</a> . Revision 3. </p> <p>Anyone who's used reload() on a module that defines a class in the interactive interpreter must have experienced the frustration of then running around and making sure that all instances are updated to be instances of the new rather than the old class.</p> <p>This metaclass tries to help with this.</p>