Top-rated recipes tagged "meta:loc=12"http://code.activestate.com/recipes/tags/meta:loc=12/top/2017-07-11T18:57:54-07:00ActiveState Code RecipesHow to handle PDF embedded files with PyMuPDF (Python) 2017-07-11T18:57:54-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580796-how-to-handle-pdf-embedded-files-with-pymupdf/ <p style="color: grey"> Python recipe 580796 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/embedded_files/">embedded_files</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 3. </p> <p>Version 1.11.0 (based on MuPDF v1.11) allows exporting, importing and interrogating files embedded in a PDF.</p> <p>PDF "/EmbeddedFiles" are similar to ZIP archives (or the Microsoft OLE technique), allowing arbitrary data to be incorporated in a PDF and benefit from its unique features.</p> First n primes numbers (Python) 2014-09-20T19:33:41-07:00juanhttp://code.activestate.com/recipes/users/4190606/http://code.activestate.com/recipes/578923-first-n-primes-numbers/ <p style="color: grey"> Python recipe 578923 by <a href="/recipes/users/4190606/">juan</a> . Revision 6. </p> <p>Using the Sieve of Eratosthenes find the first n primes numbers.</p> Quick Test If Strings Are Identifiers (Python) 2005-05-08T10:42:59-07:00Zoran Isailovskihttp://code.activestate.com/recipes/users/2400454/http://code.activestate.com/recipes/413487-quick-test-if-strings-are-identifiers/ <p style="color: grey"> Python recipe 413487 by <a href="/recipes/users/2400454/">Zoran Isailovski</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 3. </p> <p>Sometimes you need strings to be true identifiers, for ex. to represent symbolic names. Smalltalk offers the type 'Symbol' for this purpose. In python, you need to test this explicitly. Here is a quick way.</p> Dicts from lists (Python) 2003-11-28T03:09:30-08:00Richard Philipshttp://code.activestate.com/recipes/users/98125/http://code.activestate.com/recipes/252176-dicts-from-lists/ <p style="color: grey"> Python recipe 252176 by <a href="/recipes/users/98125/">Richard Philips</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>Simple oneliner to built a dictionary from a list</p> Primes (Python) 2012-06-05T05:16:42-07:00wycao2khttp://code.activestate.com/recipes/users/4182318/http://code.activestate.com/recipes/578155-primes/ <p style="color: grey"> Python recipe 578155 by <a href="/recipes/users/4182318/">wycao2k</a> . </p> <p>This program is to produce prime numbers less than and equal to n.</p> User List Subclass (Python) 2008-08-18T09:26:07-07:00nosklohttp://code.activestate.com/recipes/users/4166478/http://code.activestate.com/recipes/576428-user-list-subclass/ <p style="color: grey"> Python recipe 576428 by <a href="/recipes/users/4166478/">nosklo</a> (<a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/slices/">slices</a>, <a href="/recipes/tags/subclass/">subclass</a>, <a href="/recipes/tags/__getitem__/">__getitem__</a>). Revision 2. </p> <p>As subclassing list has a problem when using __getitem__, __delitem__ and __setitem__ methods with slices (they don't get called because parent implements __getslice__, __delslice__ and __setslice__ respectively), I've coded this UserList class that is a subclass of list, but overwrites these methods. By subclassing this class, you can overwrite __getitem__ and it will be called correctly for slices.</p> PyGoogle (Python) 2008-06-06T16:46:38-07:00Erik Andersonhttp://code.activestate.com/recipes/users/4155471/http://code.activestate.com/recipes/573447-pygoogle/ <p style="color: grey"> Python recipe 573447 by <a href="/recipes/users/4155471/">Erik Anderson</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). </p> <p>PyGoogle searches google. The google search engine uses 'http://www.google.com/search?hl=en&amp;q=' plus whatever you are searching and replaces the spaces with '+' signs.</p> Class with default method handler (Python) 2004-10-08T06:21:21-07:00mark andrewhttp://code.activestate.com/recipes/users/2085251/http://code.activestate.com/recipes/307618-class-with-default-method-handler/ <p style="color: grey"> Python recipe 307618 by <a href="/recipes/users/2085251/">mark andrew</a> (<a href="/recipes/tags/oop/">oop</a>). </p> <p>A class whose objects can handle undefined method calls, passing them on to a default handler.</p> sample with replacement (Python) 2004-03-08T00:21:23-08:00Sean Rosshttp://code.activestate.com/recipes/users/761068/http://code.activestate.com/recipes/273085-sample-with-replacement/ <p style="color: grey"> Python recipe 273085 by <a href="/recipes/users/761068/">Sean Ross</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 3. </p> <p>For taking k random samples (with replacement) from a population, where k may be greater than len(population).</p> Getting a value from a dictionary (Python) 2001-05-29T09:51:54-07:00andy mckayhttp://code.activestate.com/recipes/users/92886/http://code.activestate.com/recipes/59866-getting-a-value-from-a-dictionary/ <p style="color: grey"> Python recipe 59866 by <a href="/recipes/users/92886/">andy mckay</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). </p> <p>Want to get a value from a dictionary but want to make sure that the value exists in the dictionary? Then use the incredibly useful get method.</p> Number of bits needed to store an integer, and its binary representation (Python) 2017-03-12T23:10:48-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580762-number-of-bits-needed-to-store-an-integer-and-its-/ <p style="color: grey"> Python recipe 580762 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/integers/">integers</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/type/">type</a>). </p> <p>This recipe shows how to find, via Python code, the number of bits needed to store an integer, and how to generate its binary representation. It does this for integers from 0 to 256.</p> <p>More details and full output here:</p> <p><a href="https://jugad2.blogspot.in/2017/03/find-number-of-bits-needed-to-store.html" rel="nofollow">https://jugad2.blogspot.in/2017/03/find-number-of-bits-needed-to-store.html</a></p> Installed Modules (Perl) 2015-07-17T04:18:15-07:00Roger Mbiama Assogohttp://code.activestate.com/recipes/users/4178746/http://code.activestate.com/recipes/579084-installed-modules/ <p style="color: grey"> Perl recipe 579084 by <a href="/recipes/users/4178746/">Roger Mbiama Assogo</a> (<a href="/recipes/tags/application/">application</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/network/">network</a>). </p> <p>Additional Perl modules are installed on the server (aside from the standard libraries) run from a web broswer.</p> Draw a diamond with asterisks using recursion (Python) 2014-11-07T17:51:32-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578959-draw-a-diamond-with-asterisks-using-recursion/ <p style="color: grey"> Python recipe 578959 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/drawing/">drawing</a>). </p> <p>Given the following function header:</p> <pre class="prettyprint"><code>def triangles(n): </code></pre> <p>If n for example is 5, then the drawing would be like this:</p> <pre class="prettyprint"><code> * * * * * * * * * * * * * </code></pre> Name a lambda (Python) 2014-07-02T20:54:01-07:00David Weilhttp://code.activestate.com/recipes/users/1296670/http://code.activestate.com/recipes/578902-name-a-lambda/ <p style="color: grey"> Python recipe 578902 by <a href="/recipes/users/1296670/">David Weil</a> (<a href="/recipes/tags/func_name/">func_name</a>, <a href="/recipes/tags/introspection/">introspection</a>, <a href="/recipes/tags/lambda/">lambda</a>, <a href="/recipes/tags/name/">name</a>, <a href="/recipes/tags/naming/">naming</a>). </p> <p>A very simple recipe to allow you <em>easily</em> name lambda-objects (or other kind of objects, callable, for example, partial objects) you create, with little overhead and friendly syntax.</p> php backwards compatibility porting tips (PHP) 2013-02-10T00:40:26-08:00imam feriantohttp://code.activestate.com/recipes/users/633541/http://code.activestate.com/recipes/578452-php-backwards-compatibility-porting-tips/ <p style="color: grey"> PHP recipe 578452 by <a href="/recipes/users/633541/">imam ferianto</a> (<a href="/recipes/tags/backwards/">backwards</a>, <a href="/recipes/tags/compatibility/">compatibility</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/php4/">php4</a>, <a href="/recipes/tags/php5/">php5</a>). </p> <p>Hello again, on december 2012, I was porting my old php code (php4) to new php 5.4.3. There are to many errors within code, especially for session, eregi, global variables and others. This some pieces step for compatibility porting:</p> <ol> <li><p>add global variable definiton on some function that need outside variable &lt;code&gt; function getuser(){ global $loginid,$password; } &lt;/code&gt;</p></li> <li><p>replace eregi(/find/,str) with preg_match(//,str)</p></li> <li><p>add function exists for function that not exists in php5.4.3. for example: &lt;code&gt; if(!function_exists("session_is_registered")){ function session_is_registered($var){ return isset($_SESSION[$var]); } } if(!function_exists("session_register")){ function session_register($var){ $_SESSION[$var]=$_GLOBALS[$var]; } } &lt;/code&gt;</p></li> </ol> <p>Ok there is my tips, how about you? </p> Traverse dotted attribute of an object using built-in function reduce (Python) 2013-01-05T05:49:27-08:00Chaobin Tang (唐超斌)http://code.activestate.com/recipes/users/4174076/http://code.activestate.com/recipes/578398-traverse-dotted-attribute-of-an-object-using-built/ <p style="color: grey"> Python recipe 578398 by <a href="/recipes/users/4174076/">Chaobin Tang (唐超斌)</a> (<a href="/recipes/tags/attributes/">attributes</a>, <a href="/recipes/tags/bif/">bif</a>, <a href="/recipes/tags/recursive/">recursive</a>, <a href="/recipes/tags/reduce/">reduce</a>). </p> <p>Making good use of reduce() to traverse dotted attribute of an object.</p> General decorators decorator (Python) 2012-11-13T09:44:07-08:00Hans Zauberhttp://code.activestate.com/recipes/users/4184246/http://code.activestate.com/recipes/578325-general-decorators-decorator/ <p style="color: grey"> Python recipe 578325 by <a href="/recipes/users/4184246/">Hans Zauber</a> (<a href="/recipes/tags/decorators/">decorators</a>). </p> <p>A general decorator aimed to decorate decorators, letting them keep (some of) the original attributes of the functions they decorate.</p> List of datasets in SPSS (Python) 2011-10-27T06:12:13-07:00Petr Zizkahttp://code.activestate.com/recipes/users/4179733/http://code.activestate.com/recipes/577925-list-of-datasets-in-spss/ <p style="color: grey"> Python recipe 577925 by <a href="/recipes/users/4179733/">Petr Zizka</a> (<a href="/recipes/tags/dataset/">dataset</a>, <a href="/recipes/tags/spss/">spss</a>). </p> <p>Return list with opened datasets</p> using `from somename.api import *` when somename is a single module (Python) 2011-08-12T20:24:11-07:00Ethan Furmanhttp://code.activestate.com/recipes/users/4177684/http://code.activestate.com/recipes/577839-using-from-somenameapi-import-when-somename-is-a-s/ <p style="color: grey"> Python recipe 577839 by <a href="/recipes/users/4177684/">Ethan Furman</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/__all__/">__all__</a>). </p> <p>Allow a module to export a subset of __all__, so a user can do <code>from module.api import *</code></p> sleep_min: Sleep for a minimum number of seconds (Python) 2011-02-08T16:44:36-08:00Drew Vogelhttp://code.activestate.com/recipes/users/4176907/http://code.activestate.com/recipes/577568-sleep_min-sleep-for-a-minimum-number-of-seconds/ <p style="color: grey"> Python recipe 577568 by <a href="/recipes/users/4176907/">Drew Vogel</a> (<a href="/recipes/tags/sleep/">sleep</a>, <a href="/recipes/tags/time/">time</a>). </p> <p><code>time.sleep(delay)</code> will sleep for, at most, <code>delay</code> seconds. This function will sleep for at least <code>delay</code> seconds.</p>