Latest recipes tagged "meta:loc=8"http://code.activestate.com/recipes/tags/meta:loc=8/new/2017-05-17T21:10:26-07:00ActiveState Code RecipesInserting Images on PDF Pages (Python) 2017-05-17T21:10:26-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580803-inserting-images-on-pdf-pages/ <p style="color: grey"> Python recipe 580803 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>Version 1.11.0 of PyMuPDF allows putting an image on an existing PDF page. The following example puts the same image on every page of a given PDF - like a thumbnail.</p> groupby() For Unsorted Input (Python) 2017-05-12T10:40:58-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/580800-groupby-for-unsorted-input/ <p style="color: grey"> Python recipe 580800 by <a href="/recipes/users/4182236/">Alfe</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/datastructures/">datastructures</a>, <a href="/recipes/tags/generators/">generators</a>, <a href="/recipes/tags/grouping/">grouping</a>, <a href="/recipes/tags/lazy/">lazy</a>). </p> <p>We all know the <code>groupby()</code> which is available in the <code>itertools</code> standard module. This one yields groups of consecutive elements in the input which are meant to be together in one group. For non-consecutive elements this will yield more than one group for the same key.</p> <p>So effectively, <code>groupby()</code> only reformats a flat list into bunches of elements from that list without reordering anything. In practice this means that for input sorted by key this works perfect, but for unsorted input it might yield several groups for the same key (with groups for other keys in between). Typically needed, though, is a grouping with reordering if necessary.</p> <p>I implemented a likewise lazy function (yielding generators) which also accepts ungrouped input.</p> Hivemind (Python) 2015-07-15T12:37:13-07:00Oscar Byrnehttp://code.activestate.com/recipes/users/4192487/http://code.activestate.com/recipes/579082-hivemind/ <p style="color: grey"> Python recipe 579082 by <a href="/recipes/users/4192487/">Oscar Byrne</a> (<a href="/recipes/tags/borg/">borg</a>, <a href="/recipes/tags/defaultdict/">defaultdict</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/hashing/">hashing</a>, <a href="/recipes/tags/hivemind/">hivemind</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/singleton/">singleton</a>, <a href="/recipes/tags/state/">state</a>). </p> <p>Inspired by the ever-popular Borg pattern, objects inheriting from Hivemind share state if initialised with the same arguments</p> list all locale (Python) 2014-04-19T13:41:38-07:00Shane Wanghttp://code.activestate.com/recipes/users/4171830/http://code.activestate.com/recipes/578863-list-all-locale/ <p style="color: grey"> Python recipe 578863 by <a href="/recipes/users/4171830/">Shane Wang</a> . </p> <p>list all locales via Python</p> mac address from ip address (Python) 2013-07-07T17:34:06-07:00judyhttp://code.activestate.com/recipes/users/4186659/http://code.activestate.com/recipes/578593-mac-address-from-ip-address/ <p style="color: grey"> Python recipe 578593 by <a href="/recipes/users/4186659/">judy</a> (<a href="/recipes/tags/address/">address</a>, <a href="/recipes/tags/adress/">adress</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/mac/">mac</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>get the mac address from ip address work only in linux system</p> Generating Balanced Parenthesis (Python) 2013-02-14T22:00:22-08:00bartenderhttp://code.activestate.com/recipes/users/4185259/http://code.activestate.com/recipes/578458-generating-balanced-parenthesis/ <p style="color: grey"> Python recipe 578458 by <a href="/recipes/users/4185259/">bartender</a> (<a href="/recipes/tags/algorithm/">algorithm</a>). </p> <p>The python code generates balanced parenthesis recursively. Example for depth=3 i.e. 3 opening brackets and 3 closing brackets,the sample output should be:</p> <p>((())) (()()) (())() ()(()) ()()()</p> <p>The number of such output ( 5 in above case) is a Catalan Number.</p> Counting TCP\UDP endpoints (Batch) 2013-10-10T16:26:33-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578335-counting-tcpudp-endpoints/ <p style="color: grey"> Batch recipe 578335 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/endpoint/">endpoint</a>, <a href="/recipes/tags/tcp/">tcp</a>, <a href="/recipes/tags/udp/">udp</a>). Revision 2. </p> <p>Needs just for statistic, no further.</p> Checking letters for drives that already using (Batch) 2012-11-19T08:32:33-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578334-checking-letters-for-drives-that-already-using/ <p style="color: grey"> Batch recipe 578334 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/disk/">disk</a>). </p> <p>For keeping order drive naming with active <strong>diskpart</strong> using.</p> 2D polygon area (Python) 2012-10-01T16:22:13-07:00Jamie Bullhttp://code.activestate.com/recipes/users/4183059/http://code.activestate.com/recipes/578275-2d-polygon-area/ <p style="color: grey"> Python recipe 578275 by <a href="/recipes/users/4183059/">Jamie Bull</a> (<a href="/recipes/tags/2d/">2d</a>, <a href="/recipes/tags/area/">area</a>, <a href="/recipes/tags/geometry/">geometry</a>, <a href="/recipes/tags/polygon/">polygon</a>). </p> <p>Function for finding the area of a polygon in a 2D co-ordinate system.</p> Zcgi Test (Python) 2012-07-02T22:44:58-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578185-zcgi-test/ <p style="color: grey"> Python recipe 578185 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/test/">test</a>). </p> <p>While trying to implement a bare-bones CGI module with little support for the then-new-to-me concept, the <code>Zcgi</code> module was written, and this experiment was designed to test what it could do. This is committed for archival to be run under Python 2.5 or later versions.</p> Minimalistic Word Wrap using Regex (Python) 2012-06-07T14:31:44-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/578162-minimalistic-word-wrap-using-regex/ <p style="color: grey"> Python recipe 578162 by <a href="/recipes/users/4182236/">Alfe</a> (<a href="/recipes/tags/minimalistic/">minimalistic</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/word/">word</a>, <a href="/recipes/tags/wrap/">wrap</a>). </p> <p>I know there is the module textwrap and other recipes like <a href="http://code.activestate.com/recipes/148061-one-liner-word-wrap-function/" rel="nofollow">http://code.activestate.com/recipes/148061-one-liner-word-wrap-function/</a></p> <p>But in some constellations my recipe for a very simple word wrap might come in handy nevertheless.</p> Komodo JS Macro: move tabs (JavaScript) 2012-04-10T17:39:47-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/578093-komodo-js-macro-move-tabs/ <p style="color: grey"> JavaScript recipe 578093 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/position/">position</a>, <a href="/recipes/tags/tabs/">tabs</a>, <a href="/recipes/tags/toddw/">toddw</a>). </p> <p>This Komodo macro is an example to show how to programmatically re-position a Komodo editor tab. This macro moves the currently selected tab to the start of the tab list.</p> Base64 encode-decode Five Liner (Python) 2013-04-26T09:37:21-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/577626-base64-encode-decode-five-liner/ <p style="color: grey"> Python recipe 577626 by <a href="/recipes/users/4170754/">ccpizza</a> (<a href="/recipes/tags/base64/">base64</a>). Revision 2. </p> <p>Encodes or decodes base64-encoded files. If the input or output file(s) are ommited standard input/output will be used.</p> <p>The encoding direction is detected from the file name: for decoding save the script e.g. as encode64.py. For decoding create a symlink with <code>decode</code> in the name.</p> Flattening lists (Python) 2010-12-21T16:04:38-08:00Michael Pucketthttp://code.activestate.com/recipes/users/4176295/http://code.activestate.com/recipes/577509-flattening-lists/ <p style="color: grey"> Python recipe 577509 by <a href="/recipes/users/4176295/">Michael Puckett</a> (<a href="/recipes/tags/flatten/">flatten</a>, <a href="/recipes/tags/list/">list</a>). </p> <p>Classic / frequently asked, <em>'How to flatten a list, regardless the nesting.'</em></p> hexadecimal CSS colors, convert the six-digit to the three-digit notation (Bash) 2010-10-02T14:07:23-07:00Romain Dartigueshttp://code.activestate.com/recipes/users/4167472/http://code.activestate.com/recipes/577416-hexadecimal-css-colors-convert-the-six-digit-to-th/ <p style="color: grey"> Bash recipe 577416 by <a href="/recipes/users/4167472/">Romain Dartigues</a> (<a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/css/">css</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/rgb/">rgb</a>, <a href="/recipes/tags/sed/">sed</a>, <a href="/recipes/tags/shortening/">shortening</a>). </p> <p>Want to replace all six-digit RGB notation (#rrggbb) to the short (three-digit #rgb) form? Or the opposite?</p> node.js quicklog method to log to a file (JavaScript) 2010-08-11T05:08:57-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577351-nodejs-quicklog-method-to-log-to-a-file/ <p style="color: grey"> JavaScript recipe 577351 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/nodejs/">nodejs</a>). </p> <p>I tend to have a "quicklog" method for a few of the languages I'm working in to do logging when stdout/stderr isn't necessarily available (GUI app) or convenient (lots of other output on stdout, etc.). My usage with <a href="http://nodejs.org">nodejs</a> was while working on the node REPL. Log output to stdout interfered with the REPL.</p> Flatten a list (or list of lists, etc.) (Python) 2011-03-01T03:46:26-08:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577255-flatten-a-list-or-list-of-lists-etc/ <p style="color: grey"> Python recipe 577255 by <a href="/recipes/users/4174115/">Sunjay Varma</a> (<a href="/recipes/tags/extend/">extend</a>, <a href="/recipes/tags/flatten/">flatten</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/optimization/">optimization</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/smart/">smart</a>). Revision 2. </p> <p>I created this function sometime ago for my own purposes. It simply flattens a list.</p> <p>Check out the first comment for another version of someone else's design.</p> Countdown to screenshot (PIL). (Python) 2009-12-03T20:07:52-08:00me mehttp://code.activestate.com/recipes/users/4172371/http://code.activestate.com/recipes/576976-countdown-to-screenshot-pil/ <p style="color: grey"> Python recipe 576976 by <a href="/recipes/users/4172371/">me me</a> (<a href="/recipes/tags/countdown/">countdown</a>, <a href="/recipes/tags/screenshot/">screenshot</a>, <a href="/recipes/tags/time/">time</a>). Revision 2. </p> <p>Tested on Linux and Windows-XP, Python 2.6 ...</p> <p>Counts down to a number and takes a screenshot. I simplified one of my long lost screenshot taking codes for linux removing sound, graphics and all other unnecessary bits.</p> Self-Printing Program (C) 2009-06-05T01:19:17-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576798-self-printing-program/ <p style="color: grey"> C recipe 576798 by <a href="/recipes/users/4170398/">J Y</a> (<a href="/recipes/tags/tricky/">tricky</a>). </p> <p>The two key tricks here are using a string with an embedded %s specifier to allow the string to contain itself when printed, and to use the %c format specifier to allow printing out special characters like newlines, which could not otherwise be embedded in the output string. </p> Energy Distrubution of Black Body (Python) 2009-05-19T05:17:03-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576761-energy-distrubution-of-black-body/ <p style="color: grey"> Python recipe 576761 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/black/">black</a>, <a href="/recipes/tags/body/">body</a>, <a href="/recipes/tags/energy/">energy</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/pylab/">pylab</a>, <a href="/recipes/tags/scipy/">scipy</a>). </p> <p>Energy Distrubution of Black Body</p>