Popular recipes tagged "meta:loc=51"http://code.activestate.com/recipes/tags/meta:loc=51/2016-12-06T20:37:30-08:00ActiveState Code RecipesConvert wildcard text files to PDF with xtopdf (e.g. report*.txt) (Python) 2016-12-06T20:37:30-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580727-convert-wildcard-text-files-to-pdf-with-xtopdf-eg-/ <p style="color: grey"> Python recipe 580727 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/globbing/">globbing</a>, <a href="/recipes/tags/patterns/">patterns</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/wildcard/">wildcard</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to convert all text files matching a filename wildcard to PDF, using the xtopdf PDF creation toolkit. For example, if you specify report<em>.txt as the wildcard, all files in the current directory that match report</em>.txt, will be converted to PDF, each in a separate PDF file. The original text files are not changed.</p> <p>Here is a guide to installing and using xtopdf:</p> <p><a href="http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html" rel="nofollow">http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html</a></p> <p>More details on running the program, and sample output, are available here:</p> <p><a href="http://jugad2.blogspot.in/2016/12/xtopdf-wildcard-text-files-to-pdf-with.html" rel="nofollow">http://jugad2.blogspot.in/2016/12/xtopdf-wildcard-text-files-to-pdf-with.html</a></p> A memoize decorator for instance methods (Python) 2010-11-04T20:23:35-07:00Daniel Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/ <p style="color: grey"> Python recipe 577452 by <a href="/recipes/users/4016391/">Daniel Miller</a> (<a href="/recipes/tags/cache/">cache</a>, <a href="/recipes/tags/functools/">functools</a>, <a href="/recipes/tags/memoize/">memoize</a>, <a href="/recipes/tags/partial/">partial</a>). </p> <p>A simple result-caching decorator for instance methods. NOTE: does not work with plain old non-instance-method functions. The cache is stored on the instance to prevent memory leaks caused by long-term caching beyond the life of the instance (almost all other recipes I found suffer from this problem when used with instance methods).</p> Fixed Lengh List (Python) 2014-01-24T15:27:25-08:00Hirohttp://code.activestate.com/recipes/users/4184239/http://code.activestate.com/recipes/578813-fixed-lengh-list/ <p style="color: grey"> Python recipe 578813 by <a href="/recipes/users/4184239/">Hiro</a> (<a href="/recipes/tags/length/">length</a>, <a href="/recipes/tags/list/">list</a>). Revision 2. </p> <p>In some applications, it's advantageous to be able to define a fixed length list.</p> <p>The class provides all features as python internal type: list</p> <p>The main focus of <strong>fixed length</strong> list is only keep certain number of items. "overflow" items will be discarded.</p> Dynamically format a comment block (Python) 2013-08-31T08:14:10-07:00Michael Swartzhttp://code.activestate.com/recipes/users/4187428/http://code.activestate.com/recipes/578624-dynamically-format-a-comment-block/ <p style="color: grey"> Python recipe 578624 by <a href="/recipes/users/4187428/">Michael Swartz</a> (<a href="/recipes/tags/comments/">comments</a>, <a href="/recipes/tags/for_loop/">for_loop</a>, <a href="/recipes/tags/list/">list</a>). Revision 3. </p> <p>Neatly format a comment block that is surrounded by #s and takes into account right side space padding.</p> Geometry class for Tkinter (Python) 2013-03-18T14:49:16-07:00David Cornehttp://code.activestate.com/recipes/users/4185735/http://code.activestate.com/recipes/578494-geometry-class-for-tkinter/ <p style="color: grey"> Python recipe 578494 by <a href="/recipes/users/4185735/">David Corne</a> (<a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/ui/">ui</a>). Revision 2. </p> <p>An easily extensible class, inheriting from Canvas, which can be used to define geometry in a more mathematical way. So rather than specify a circle from 2 points you give a radius and a centre. These could have colour as a keyword argument but personally I always want to specify the colour.</p> Mandelbulb Fractal (Python) 2012-07-08T00:10:25-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578198-mandelbulb-fractal/ <p style="color: grey"> Python recipe 578198 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>It draws a random 2D cross-section of Mandelbulb fractal.</p> Cached Class (Python) 2012-01-06T02:24:08-08:00Peter Donishttp://code.activestate.com/recipes/users/4180313/http://code.activestate.com/recipes/577998-cached-class/ <p style="color: grey"> Python recipe 577998 by <a href="/recipes/users/4180313/">Peter Donis</a> (<a href="/recipes/tags/cache/">cache</a>, <a href="/recipes/tags/decorators/">decorators</a>). Revision 5. </p> <p>A class decorator that ensures that only one instance of the class exists for each distinct set of constructor arguments.</p> <p>Note that if a decorated class is subclassed, each subclass is cached separately. (This is because each cached subclass is a different <code>cls</code> argument to the <code>__new__</code> method.)</p> Sleepsort with processes and pipes (Python) 2011-06-17T02:37:58-07:00Benjamin Petersonhttp://code.activestate.com/recipes/users/4170802/http://code.activestate.com/recipes/577758-sleepsort-with-processes-and-pipes/ <p style="color: grey"> Python recipe 577758 by <a href="/recipes/users/4170802/">Benjamin Peterson</a> (<a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/sorting/">sorting</a>, <a href="/recipes/tags/unix/">unix</a>). Revision 2. </p> <p>Sleepsort is a sorting algorithm that uses the system sleep syscall in a very creative fashion.</p> <p>This is the same algorithm as <a href="http://code.activestate.com/recipes/577756/">recipe 577756</a> but using *nix processes instead of threads.</p> Simple creation, configuration and installation of logging handlers (Python) 2011-06-01T19:05:40-07:00Hankhttp://code.activestate.com/recipes/users/4178168/http://code.activestate.com/recipes/577731-simple-creation-configuration-and-installation-of-/ <p style="color: grey"> Python recipe 577731 by <a href="/recipes/users/4178168/">Hank</a> (<a href="/recipes/tags/logging/">logging</a>). </p> <p>A helper class and function to make it easy to configure logging, and an example of using it to send <code>INFO</code> to <code>sys.stdout</code> and <code>WARNING</code> or above to <code>sys.stderr</code>.</p> <p>This is a simple port to Python 2 (I tested on 2.7) of <a href="http://code.activestate.com/recipes/577496-simple-creation-configuration-and-installation-of-/">Nick Coghlan's Python 3 recipe</a> for doing the same thing.</p> Archiving time series (Python) 2011-04-14T15:39:57-07:00Tyler Grosshueschhttp://code.activestate.com/recipes/users/4177659/http://code.activestate.com/recipes/577653-archiving-time-series/ <p style="color: grey"> Python recipe 577653 by <a href="/recipes/users/4177659/">Tyler Grosshuesch</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/backup/">backup</a>, <a href="/recipes/tags/timestamp/">timestamp</a>). </p> <p>Copies files and directories periodically to a time-stamaped directory. Used to create a running record of digital files to document change over time.</p> Display a git repository (Ruby) 2012-07-05T17:01:53-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577572-display-a-git-repository/ <p style="color: grey"> Ruby recipe 577572 by <a href="/recipes/users/4173873/">Noufal Ibrahim</a> (<a href="/recipes/tags/git/">git</a>, <a href="/recipes/tags/graphviz/">graphviz</a>, <a href="/recipes/tags/grit/">grit</a>, <a href="/recipes/tags/visualisation/">visualisation</a>). Revision 2. </p> <p>A tiny script to display the entire contents of a medium sized git repository. It will display tags, branches and commits with different shapes and colours and the commits messages in a dimmed colour. </p> <p>It relies on graphviz to do the plotting. Use it like so </p> <pre class="prettyprint"><code> ruby plotrepo.rb /path/to/repository | dot -Tpng | display -antialias </code></pre> Simple creation, configuration and installation of logging handlers (Python) 2011-06-01T12:13:21-07:00Nick Coghlanhttp://code.activestate.com/recipes/users/2035254/http://code.activestate.com/recipes/577496-simple-creation-configuration-and-installation-of-/ <p style="color: grey"> Python recipe 577496 by <a href="/recipes/users/2035254/">Nick Coghlan</a> (<a href="/recipes/tags/logging/">logging</a>). </p> <p>Creation of log message handler for the logging module is often a multi-step process, involving creation of the handler object, configuration of the message levels and formats, installation of any filters and then actual connection of the handler to the relevant logger object.</p> <p>This helper function allows all of these things to be specified up front in a single function call, which then takes care of configuring the handler object appropriately.</p> A Template for Crash-Resistant Toggle-Macros (JavaScript) 2010-10-07T00:51:42-07:00Eric Promislowhttp://code.activestate.com/recipes/users/4166930/http://code.activestate.com/recipes/577418-a-template-for-crash-resistant-toggle-macros/ <p style="color: grey"> JavaScript recipe 577418 by <a href="/recipes/users/4166930/">Eric Promislow</a> (<a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/snippet/">snippet</a>, <a href="/recipes/tags/template/">template</a>). </p> <p>If you've followed my postings here lately (<a href="http://code.activestate.com/recipes/users/4166930/" rel="nofollow">http://code.activestate.com/recipes/users/4166930/</a>), you'll see that I've been playing with what I call "toggle macros", macros that toggle a state on and off, with different behaviors for each state. Unfortunately I found that it was easy to get Komodo to crash on shutdown. Meanwhile I wanted to build a framework to make it easier to build these.</p> <p>This recipe accomplishes both. It looks like putting a listener on a view object can trigger this crash, but so can storing a method on a view object, even with a unique name. So while I wanted to use the "view.view_closing" event, I can't, and I notice no other core Komodo code is. The template instead uses a global hash, ko.extensions.togglers, to store the code objects. And now I'm not getting a crash.</p> Oracle Database Regex Search using cx_Oracle (Python) 2010-07-11T19:39:21-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577303-oracle-database-regex-search-using-cx_oracle/ <p style="color: grey"> Python recipe 577303 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>). </p> <p>Finds all database rows in all tables that contain any column which matches to given regex and outputs a CSV file for each table containing matches.</p> File read/write routines (Python) 2010-04-18T17:18:50-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577199-file-readwrite-routines/ <p style="color: grey"> Python recipe 577199 by <a href="/recipes/users/57155/">Denis Barmenkov</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/read/">read</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/write/">write</a>). Revision 2. </p> <p>For small dirty hacks in Perl has a module File::Slurp. I wrote two simple functions when I moving from Perl to Python - one for reading files and second for writing files. Valuable data is list of lines or blob (additionally specified argument binmode=1).</p> Generator Attributes (Python) 2010-02-18T17:23:59-08:00Longpokehttp://code.activestate.com/recipes/users/4173085/http://code.activestate.com/recipes/577057-generator-attributes/ <p style="color: grey"> Python recipe 577057 by <a href="/recipes/users/4173085/">Longpoke</a> (<a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/state/">state</a>). </p> <p>A decorator that creates a generator factory that creates generators that can have attributes set on them (like a normal python class).</p> Technique for cyclical iteration II (Python) 2010-01-20T03:54:15-08:00Jakub Wronieckihttp://code.activestate.com/recipes/users/4172837/http://code.activestate.com/recipes/577014-technique-for-cyclical-iteration-ii/ <p style="color: grey"> Python recipe 577014 by <a href="/recipes/users/4172837/">Jakub Wroniecki</a> (<a href="/recipes/tags/cyclic_iterator/">cyclic_iterator</a>, <a href="/recipes/tags/recursive_iterator/">recursive_iterator</a>). </p> <p>Inspired by this recipe: <a href="http://code.activestate.com/recipes/576961/" rel="nofollow">http://code.activestate.com/recipes/576961/</a>, I played a little with the code and came with a more general piece of code implementing recursive iterators.</p> Extending anydbm with marshal (Python) 2010-01-11T17:43:05-08:00Maurice Linghttp://code.activestate.com/recipes/users/4172778/http://code.activestate.com/recipes/577003-extending-anydbm-with-marshal/ <p style="color: grey"> Python recipe 577003 by <a href="/recipes/users/4172778/">Maurice Ling</a> (<a href="/recipes/tags/anydbm/">anydbm</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/marshal/">marshal</a>). </p> <p>Enables objects to be stored as values in an anydbm file.</p> firefox sqlite files cleaner (Python) 2009-07-18T21:41:13-07:00peekaahttp://code.activestate.com/recipes/users/2919471/http://code.activestate.com/recipes/576842-firefox-sqlite-files-cleaner/ <p style="color: grey"> Python recipe 576842 by <a href="/recipes/users/2919471/">peekaa</a> (<a href="/recipes/tags/firefox/">firefox</a>, <a href="/recipes/tags/sqlite/">sqlite</a>). Revision 7. </p> <p>Walks through the all the Firefox profiles in current user account and cleans all *.sqlite files with "vacuum". It makes firefox faster then often. Should work on Linux, too, when properly changed constants.</p> <p>For: python 2.6 (2.5+sqlite3), FF 3.5</p> firefox sqlite files cleaner (linux) (Python) 2009-07-15T12:15:20-07:00Vince Spicerhttp://code.activestate.com/recipes/users/4171124/http://code.activestate.com/recipes/576843-firefox-sqlite-files-cleaner-linux/ <p style="color: grey"> Python recipe 576843 by <a href="/recipes/users/4171124/">Vince Spicer</a> (<a href="/recipes/tags/firefox/">firefox</a>, <a href="/recipes/tags/sqlite/">sqlite</a>). Revision 3. </p> <p>Modified from <a href="http://code.activestate.com/recipes/576842/">Recipe 576842</a> to support linux</p> <p>Walks through the all the Firefox profiles in current user account and cleans all *.sqlite files with "vacuum". It makes firefox faster then often. </p> <p>tested on Ubuntu</p> <p>For: python 2.6 (2.5+sqlite3), FF 3.5</p>