Popular recipes tagged "meta:loc=8" but not "python"http://code.activestate.com/recipes/tags/meta:loc=8-python/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>
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>
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>
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>
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>
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>
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>
Eight queens. Six lines. (Python)
2009-02-10T14:59:07-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/576647-eight-queens-six-lines/
<p style="color: grey">
Python
recipe 576647
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
.
Revision 3.
</p>
<p>What six lines of Python can do</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>
safe print (Python)
2009-01-02T15:40:30-08:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/576602-safe-print/
<p style="color: grey">
Python
recipe 576602
by <a href="/recipes/users/4173505/">Trent Mick</a>
(<a href="/recipes/tags/encode/">encode</a>, <a href="/recipes/tags/safe/">safe</a>, <a href="/recipes/tags/unicode/">unicode</a>).
</p>
<p>A replacement for "print" that will safely handle unicode conversion.</p>
script for calculating simple interest (Python)
2008-10-09T07:51:39-07:00Mahmoud Hossamhttp://code.activestate.com/recipes/users/4167486/http://code.activestate.com/recipes/576533-script-for-calculating-simple-interest/
<p style="color: grey">
Python
recipe 576533
by <a href="/recipes/users/4167486/">Mahmoud Hossam</a>
(<a href="/recipes/tags/accounting/">accounting</a>, <a href="/recipes/tags/interest/">interest</a>).
</p>
<p>a script which can be used to calculate the amount of interest using the formula I=Pit</p>
<p>this is a very simple code,any suggestions are welcome</p>
Get a posix timestamp from a type 1 uuid (Python)
2008-08-13T18:56:29-07:00Kent Tenneyhttp://code.activestate.com/recipes/users/4166394/http://code.activestate.com/recipes/576420-get-a-posix-timestamp-from-a-type-1-uuid/
<p style="color: grey">
Python
recipe 576420
by <a href="/recipes/users/4166394/">Kent Tenney</a>
(<a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/timestamp/">timestamp</a>, <a href="/recipes/tags/uuid/">uuid</a>).
</p>
<p>The uuid timestamp is 60 bits, the number of 100 nanosecond increments since Oct. 15, 1582
This simple function returns a value which makes datetime.datetime.fromtimestamp() happy.</p>
<p>It simply rewinds the code in the standard library's uuid1 function:</p>
<pre class="prettyprint"><code>nanoseconds = int(time() * 1e9)
# 0x01b21dd213814000 is the number of 100-ns intervals between the
# UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
timestamp = int(nanoseconds/100) + 0x01b21dd213814000
</code></pre>