Popular recipes tagged "meta:loc=1"http://code.activestate.com/recipes/tags/meta:loc=1/2016-07-29T01:52:11-07:00ActiveState Code Recipestic (Python) 2016-07-29T01:52:11-07:00YasGonhttp://code.activestate.com/recipes/users/4194509/http://code.activestate.com/recipes/580693-tic/ <p style="color: grey"> Python recipe 580693 by <a href="/recipes/users/4194509/">YasGon</a> . Revision 2. </p> <p>toe</p> Python one-liner to compare two files (Python) 2016-03-28T21:36:31-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580632-python-one-liner-to-compare-two-files/ <p style="color: grey"> Python recipe 580632 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>As the title says ...</p> <p>It prints True if the files compared are the same, and False if they differ (either in size or in content).</p> Get external IP & geolocation in bash. (Bash) 2014-11-30T00:46:28-08:00manuhttp://code.activestate.com/recipes/users/4191225/http://code.activestate.com/recipes/578972-get-external-ip-geolocation-in-bash/ <p style="color: grey"> Bash recipe 578972 by <a href="/recipes/users/4191225/">manu</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/geocoding/">geocoding</a>, <a href="/recipes/tags/geolocation/">geolocation</a>). Revision 2. </p> <p>Very simple way to get external IP and geolocation uysing dig and geoiplookup.</p> <p><code>dig</code> is cool to obtain my external IP and I use <code>geoiplookup</code> to convert IP to location. You need geoip-bin and, geoip-database (and/or geoip-database-contrib and geoip-database-extra). In Debian, database seems update monthly.</p> <p>It's just a tip.</p> PPM (Django HTML Template) 2014-03-15T14:38:40-07:00Ruel Printhttp://code.activestate.com/recipes/users/4189448/http://code.activestate.com/recipes/578850-ppm/ <p style="color: grey"> Django HTML Template recipe 578850 by <a href="/recipes/users/4189448/">Ruel Print</a> . </p> <p>&lt;head&gt; &lt;title&gt;My Website&lt;/title&gt; &lt;/head&gt;</p> <p>&lt;body&gt;</p> <p>&lt;p&gt;Welcome to my website! I plan on using PHP and MySQL to generate these pages sometime, however I don't know much about PHP. A friend suggested I start by looking up PHP's php_info and mysql_info methods.&lt;/p&gt;</p> <p>&lt;!-- no frogs in here --&gt;</p> <p>&lt;/body&gt; &lt;/html&gt;</p> XML to PDF book with ElementTree and xtopdf (Python) 2013-06-16T19:14:58-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578561-xml-to-pdf-book-with-elementtree-and-xtopdf/ <p style="color: grey"> Python recipe 578561 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/ebooks/">ebooks</a>, <a href="/recipes/tags/elementtree/">elementtree</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/publishing/">publishing</a>, <a href="/recipes/tags/xml/">xml</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create a PDF book from XML text content. It requires my xtopdf toolkit, the ElementTree module (from Python's standard library) and the open source version of the ReportLab toolkit.</p> <p>Create an XML template file like this:</p> <p>&lt;?xml version="1.0"?&gt; &lt;book&gt; &lt;chapter&gt; Chapter 1 content here. &lt;/chapter&gt;</p> <pre class="prettyprint"><code> &lt;chapter&gt; Chapter 2 content here. &lt;/chapter&gt; </code></pre> <p>&lt;/book&gt;</p> <p>Then populate the chapter elements with the text of each of the chapters of your book, as text. Call that file, your_book.xml, say.</p> <p>Then run:</p> <p>python XMLtoPDFBook.py your_book.xml your_book.pdf</p> <p>Now the contents of your book will be in your_book.pdf</p> <p>More details and the full code here:</p> <p><a href="http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html" rel="nofollow">http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html</a></p> <ul> <li>Vasudev Ram <a href="http://dancingbison.com" rel="nofollow">dancingbison.com</a></li> </ul> Word count and length with map and lambda (Python) 2013-02-26T18:49:38-08:00Michael Thammhttp://code.activestate.com/recipes/users/4179483/http://code.activestate.com/recipes/578474-word-count-and-length-with-map-and-lambda/ <p style="color: grey"> Python recipe 578474 by <a href="/recipes/users/4179483/">Michael Thamm</a> (<a href="/recipes/tags/word_count/">word_count</a>). </p> <p>I was looking at some word count code and thought a more functional approach would be better and more fun to code. </p> ADMIN PLEASE REMOVE THIS RECIPE (Python) 2013-08-11T08:29:57-07:00jayhttp://code.activestate.com/recipes/users/4186699/http://code.activestate.com/recipes/578538-admin-please-remove-this-recipe/ <p style="color: grey"> Python recipe 578538 by <a href="/recipes/users/4186699/">jay</a> . Revision 3. </p> <p>code i would like removed</p> ADMIN PLEASE REMOVE THIS RECIPE (Python) 2013-08-11T08:27:14-07:00jayhttp://code.activestate.com/recipes/users/4186699/http://code.activestate.com/recipes/578541-admin-please-remove-this-recipe/ <p style="color: grey"> Python recipe 578541 by <a href="/recipes/users/4186699/">jay</a> . Revision 4. </p> <p>code i would like removed.</p> One-liner to show the caller of the current function. (Python) 2013-02-12T13:13:16-08:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578422-one-liner-to-show-the-caller-of-the-current-functi/ <p style="color: grey"> Python recipe 578422 by <a href="/recipes/users/2033964/">Oren Tirosh</a> (<a href="/recipes/tags/_getframe/">_getframe</a>). </p> <p>This is a quick one-liner to produce the filename and line number of the caller of the current function.</p> One-liner to show the caller of the current function. (Python) 2013-02-28T04:11:18-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578475-one-liner-to-show-the-caller-of-the-current-functi/ <p style="color: grey"> Python recipe 578475 by <a href="/recipes/users/4183429/">Deepak</a> (<a href="/recipes/tags/_getframe/">_getframe</a>). </p> <p>This is a quick one-liner to produce the filename and line number of the caller of the current function.</p> Find Multiple Elements In a List (Python) 2011-11-05T23:40:41-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577943-find-multiple-elements-in-a-list/ <p style="color: grey"> Python recipe 577943 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/enumerate/">enumerate</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/search_list/">search_list</a>). </p> <p>This algorithm searches for more than one element in a list. The input is a list that you want to search through and a list of elements that you want to search for. The output is a multidimensional list with the positions of the elements you are searching for in the search list in the order that you listed them. </p> Get multiple elements from a list (Python) 2011-11-21T06:41:57-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577953-get-multiple-elements-from-a-list/ <p style="color: grey"> Python recipe 577953 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/get/">get</a>, <a href="/recipes/tags/getvar/">getvar</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/retrieve/">retrieve</a>, <a href="/recipes/tags/retrieving/">retrieving</a>). </p> <p>This code lets you retrieve multiple elements from a list at one time</p> primeList (Python) 2011-11-05T23:42:37-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577935-primelist/ <p style="color: grey"> Python recipe 577935 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primelist/">primelist</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/theory/">theory</a>). Revision 3. </p> <p>This module returns all the prime numbers strictly less than n. For this code to print out all of the primes n inclusive, in the range, n+1 must be substituted for n.</p> Import modules in lambda functions (Python) 2010-06-16T20:13:15-07:00roopeshvhttp://code.activestate.com/recipes/users/4174204/http://code.activestate.com/recipes/577269-import-modules-in-lambda-functions/ <p style="color: grey"> Python recipe 577269 by <a href="/recipes/users/4174204/">roopeshv</a> . </p> <p>I am not sure how many know that we can import modules inside lambda functions. So I am writing this to make the feature standout.</p> <p>Instead of having the following function, which joins the paths</p> <pre class="prettyprint"><code>import os relative_to_current = lambda *x: os.path.join(os.path.dirname(__file__), *x) # current directory is suppose /home/user/ (on linux) OR C:\Users (on Windows) &gt;&gt;&gt; relative_to_current('Desktop') '/home/user/Desktop' # on linux 'C:\\Users\\Desktop' </code></pre> <p>Here is same thing without having to import os in the module.</p> null (C) 2013-05-26T10:55:59-07:00Joe Smithhttp://code.activestate.com/recipes/users/4168055/http://code.activestate.com/recipes/577239-null/ <p style="color: grey"> C recipe 577239 by <a href="/recipes/users/4168055/">Joe Smith</a> (<a href="/recipes/tags/null/">null</a>). Revision 2. </p> <p>null null</p> null null (Python) 2013-05-26T10:55:07-07:00Joe Smithhttp://code.activestate.com/recipes/users/4168055/http://code.activestate.com/recipes/577240-null-null/ <p style="color: grey"> Python recipe 577240 by <a href="/recipes/users/4168055/">Joe Smith</a> (<a href="/recipes/tags/null/">null</a>). Revision 4. </p> <p>null null null</p> null null (C) 2013-05-26T10:59:13-07:00Joe Smithhttp://code.activestate.com/recipes/users/4168055/http://code.activestate.com/recipes/577019-null-null/ <p style="color: grey"> C recipe 577019 by <a href="/recipes/users/4168055/">Joe Smith</a> (<a href="/recipes/tags/null/">null</a>). Revision 2. </p> <p>null null</p> Primes from 1 to 100 (Python) 2009-11-13T09:47:53-08:00Adam M Prosthttp://code.activestate.com/recipes/users/4172124/http://code.activestate.com/recipes/576956-primes-from-1-to-100/ <p style="color: grey"> Python recipe 576956 by <a href="/recipes/users/4172124/">Adam M Prost</a> (<a href="/recipes/tags/prime/">prime</a>). Revision 2. </p> <p>Get the primes from 1 to 100 or really any range you choose.</p> Pastebin Upload (Python) 2013-05-26T10:54:25-07:00Joe Smithhttp://code.activestate.com/recipes/users/4168055/http://code.activestate.com/recipes/576805-pastebin-upload/ <p style="color: grey"> Python recipe 576805 by <a href="/recipes/users/4168055/">Joe Smith</a> (<a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/post/">post</a>, <a href="/recipes/tags/source/">source</a>, <a href="/recipes/tags/urllib2/">urllib2</a>). Revision 2. </p> <p>A little script I made for some buddies and I. We are constantly collaborating on code. This scrips takes a source code file as it's parameter and uploads it to <a href="http://pastebin.com" rel="nofollow">pastebin.com</a> or any sub domain of pastebin. I integrated it with the righ click window in windows. Without that integration the script wouldn't be as cool! Hope others find it useful.</p> a more reliable DOCUMENT_ROOT (PHP) 2008-12-25T18:55:33-08:00Gui Rhttp://code.activestate.com/recipes/users/4166241/http://code.activestate.com/recipes/576595-a-more-reliable-document_root/ <p style="color: grey"> PHP recipe 576595 by <a href="/recipes/users/4166241/">Gui R</a> (<a href="/recipes/tags/web/">web</a>). </p> <p>$_SERVER['DOCUMENT_ROOT'] has been known to be broken on some servers. This is a bit of logic to retrieve the document root more reliably.</p>