Most viewed recipes tagged "meta:loc=4"http://code.activestate.com/recipes/tags/meta:loc=4/views/2017-07-17T05:53:45-07:00ActiveState Code RecipesShoelace Formula for polygonal area (Python) 2017-07-17T05:53:45-07:00Paddy McCarthyhttp://code.activestate.com/recipes/users/398009/http://code.activestate.com/recipes/580812-shoelace-formula-for-polygonal-area/ <p style="color: grey"> Python recipe 580812 by <a href="/recipes/users/398009/">Paddy McCarthy</a> (<a href="/recipes/tags/2d/">2d</a>, <a href="/recipes/tags/area/">area</a>). </p> <p>Copied, by author from "Paddy3118 Go deh!: Python investigation of the Shoelace Formula for polygonal area <a href="http://paddy3118.blogspot.com/2017/07/python-investigation-of-shoelace.html#ixzz4n43Dqhaa" rel="nofollow">http://paddy3118.blogspot.com/2017/07/python-investigation-of-shoelace.html#ixzz4n43Dqhaa</a> " Where there is more meat on the bone (under a different license though).</p> Linear equations solver in 3 lines (Python) 2005-01-31T22:06:30-08:00Maxim Krikunhttp://code.activestate.com/recipes/users/1085177/http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ <p style="color: grey"> Python recipe 365013 by <a href="/recipes/users/1085177/">Maxim Krikun</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>Just a little bit of hack: a linear equations solver using eval and built-in complex numbers:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; solve("x - 2*x + 5*x - 46*(235-24) = x + 2") 3236.0 </code></pre> Grab a document from the web (Python) 2001-02-23T19:15:17-08:00Gisle Aashttp://code.activestate.com/recipes/users/98047/http://code.activestate.com/recipes/52199-grab-a-document-from-the-web/ <p style="color: grey"> Python recipe 52199 by <a href="/recipes/users/98047/">Gisle Aas</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>This recipe shows how you can grab a document from the web using urllib.py.</p> Accessing cursors by field name (Python) 2010-04-09T22:50:04-07:00Ricardo Araozhttp://code.activestate.com/recipes/users/4173628/http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/ <p style="color: grey"> Python recipe 577186 by <a href="/recipes/users/4173628/">Ricardo Araoz</a> (<a href="/recipes/tags/cursor/">cursor</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/datastructures/">datastructures</a>, <a href="/recipes/tags/field/">field</a>, <a href="/recipes/tags/name/">name</a>). </p> <p>This class allows you to access the rows of a cursor by field name.</p> Grabbing text between HTML tags (Python) 2003-08-20T09:46:47-07:00Brendan Barryhttp://code.activestate.com/recipes/users/1326592/http://code.activestate.com/recipes/217019-grabbing-text-between-html-tags/ <p style="color: grey"> Python recipe 217019 by <a href="/recipes/users/1326592/">Brendan Barry</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>Just a snippet. I needed to grab the data between &lt;LI&gt; list item &lt;/LI&gt; tags. Highly annoying that I couldn't find it anywhere else.</p> Get a list from a ConfigParser option (Python) 2011-05-13T13:53:56-07:00Georges Martinhttp://code.activestate.com/recipes/users/4177973/http://code.activestate.com/recipes/577694-get-a-list-from-a-configparser-option/ <p style="color: grey"> Python recipe 577694 by <a href="/recipes/users/4177973/">Georges Martin</a> (<a href="/recipes/tags/configparser/">configparser</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/option/">option</a>). Revision 2. </p> <p>Return a list from a ConfigParser option. By default, split on a comma and strip whitespaces.</p> How to read millions of hexadecimal numbers into a numpy array quickly (Python) 2012-06-27T06:03:40-07:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578177-how-to-read-millions-of-hexadecimal-numbers-into-a/ <p style="color: grey"> Python recipe 578177 by <a href="/recipes/users/2033964/">Oren Tirosh</a> (<a href="/recipes/tags/numpy/">numpy</a>). </p> <p>The numpy.fromfile() function supports binary formats or decimal text. How do you read millions of hexadecimal numbers quickly?</p> Linear equations solver in 3 lines (Python) 2013-03-07T07:33:09-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578481-linear-equations-solver-in-3-lines/ <p style="color: grey"> Python recipe 578481 by <a href="/recipes/users/4183429/">Deepak</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>Just a little bit of hack: a linear equations solver using eval and built-in complex numbers:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; solve("x - 2*x + 5*x - 46*(235-24) = x + 2") 3236.0 </code></pre> Generating a list of prime numbers in one statement (Python) 2002-11-14T03:43:47-08:00Pierre Denishttp://code.activestate.com/recipes/users/112275/http://code.activestate.com/recipes/162479-generating-a-list-of-prime-numbers-in-one-statemen/ <p style="color: grey"> Python recipe 162479 by <a href="/recipes/users/112275/">Pierre Denis</a> . </p> <p>The following expression generates the list of prime numbers strictly inferior to a given positive integer N.</p> Generator for splitting a string on parts of equal size (Python) 2004-08-26T03:05:46-07:00Dmitry Vasilievhttp://code.activestate.com/recipes/users/1571302/http://code.activestate.com/recipes/302069-generator-for-splitting-a-string-on-parts-of-equal/ <p style="color: grey"> Python recipe 302069 by <a href="/recipes/users/1571302/">Dmitry Vasiliev</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). </p> <p>Example: &lt;pre&gt;</p> <pre class="prettyprint"><code>&gt;&gt;&gt; list(splitIterator("102030405", 2)) ['10', '20', '30', '40', '5'] &lt;/pre&gt; </code></pre> Add support for the "in" operator to the attributes map of minidom elements (Python) 2006-06-23T18:54:14-07:00Walker Halehttp://code.activestate.com/recipes/users/2928779/http://code.activestate.com/recipes/496817-add-support-for-the-in-operator-to-the-attributes-/ <p style="color: grey"> Python recipe 496817 by <a href="/recipes/users/2928779/">Walker Hale</a> (<a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>When you parse XML using minidom, you can get a map of attributes for any element. The problem is that using the "in" operator on this map will raise an exception. These three lines of code will fix that.</p> Prevent star imports (Python) 2010-05-21T16:22:08-07:00Mike Grahamhttp://code.activestate.com/recipes/users/4174015/http://code.activestate.com/recipes/577237-prevent-star-imports/ <p style="color: grey"> Python recipe 577237 by <a href="/recipes/users/4174015/">Mike Graham</a> (<a href="/recipes/tags/import/">import</a>). </p> <p>Use this code in your module to prevent people using the "from foo import *" syntax with your module.</p> Add Commas to a Number (Tcl) 2001-09-09T21:21:34-07:00Keith Vetterhttp://code.activestate.com/recipes/users/130056/http://code.activestate.com/recipes/68381-add-commas-to-a-number/ <p style="color: grey"> Tcl recipe 68381 by <a href="/recipes/users/130056/">Keith Vetter</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>Takes a number and inserts a comma (or separator of your choice) between every third digit.</p> Recursive defaultdict (Python) 2012-03-01T19:00:04-08:00thom nealehttp://code.activestate.com/recipes/users/4176069/http://code.activestate.com/recipes/578057-recursive-defaultdict/ <p style="color: grey"> Python recipe 578057 by <a href="/recipes/users/4176069/">thom neale</a> (<a href="/recipes/tags/defaultdict/">defaultdict</a>). </p> <p>A defaultdict that yields a defaultdict that yields a defaultdict, etc...</p> fibonacci (Python) 2002-04-04T08:08:41-08:00anurag uniyalhttp://code.activestate.com/recipes/users/127639/http://code.activestate.com/recipes/67677-fibonacci/ <p style="color: grey"> Python recipe 67677 by <a href="/recipes/users/127639/">anurag uniyal</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 2. </p> <p>One Liner fibonacci series generator</p> pseudo-random string (Python) 2009-04-21T18:56:01-07:00Patrick Ramseyhttp://code.activestate.com/recipes/users/4169944/http://code.activestate.com/recipes/576722-pseudo-random-string/ <p style="color: grey"> Python recipe 576722 by <a href="/recipes/users/4169944/">Patrick Ramsey</a> (<a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/string/">string</a>). Revision 3. </p> <p>Returns a random, password-suitable string with the specified number of characters. base64 stores 6 bits in each (8-bit) output character, hence the coefficient.</p> An IPv4 class (Python) 2012-11-05T02:46:36-08:00Keith Darthttp://code.activestate.com/recipes/users/121917/http://code.activestate.com/recipes/66420-an-ipv4-class/ <p style="color: grey"> Python recipe 66420 by <a href="/recipes/users/121917/">Keith Dart</a> (<a href="/recipes/tags/network/">network</a>). Revision 3. </p> <p>Complete IPv4 class that can represent a host or network, and iterate over networks. Supports slash notation, stringifying, and range generation (among other things).</p> Self Counter (Python) 2013-08-02T03:15:12-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578621-self-counter/ <p style="color: grey"> Python recipe 578621 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/counter/">counter</a>). </p> <p>This script was written as a revision of <a href="http://code.activestate.com/recipes/577456/">recipe 577456</a> as a variation on a theme.</p> Komodo JS Macro - use vertical editor tabs positioned to the right (JavaScript) 2010-09-10T02:53:33-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577386-komodo-js-macro-use-vertical-editor-tabs-positione/ <p style="color: grey"> JavaScript recipe 577386 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/layout/">layout</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/tab/">tab</a>). </p> <p>A <a href="http://www.activestate.com/komodo-ide">Komodo</a> JavaScript macro that can be used to position the editor tabs on the right side and shown vertically.</p> <p>Additional layouts (left, right, up, down, vertical, horizontal) can be made with different combinations, see here for the Mozilla tabbox positioning documentation: <a href="https://developer.mozilla.org/en/XUL_Tutorial/Tabboxes#Position_of_the_tabs" rel="nofollow">https://developer.mozilla.org/en/XUL_Tutorial/Tabboxes#Position_of_the_tabs</a></p> Short Enum Recipe (Python) 2013-01-31T14:16:06-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577021-short-enum-recipe/ <p style="color: grey"> Python recipe 577021 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/enum/">enum</a>, <a href="/recipes/tags/quick/">quick</a>, <a href="/recipes/tags/short/">short</a>). Revision 9. </p> <p>If you want a small code snippet for enumerations in Python and the following code is sufficient for your needs, please go ahead and use it! Running the code is as simple as this: <code>STATE = enum('GET_QUIZ, GET_VERSE, TEACH')</code></p> <p>This recipe was edited and adapted after the author was inspired by seeing other, better enum recipes lying around.</p>