Popular recipes tagged "meta:loc=89"http://code.activestate.com/recipes/tags/meta:loc=89/2016-04-07T18:19:35-07:00ActiveState Code RecipesA binary file split utility in Python (Python) 2016-04-07T18:19:35-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580637-a-binary-file-split-utility-in-python/ <p style="color: grey"> Python recipe 580637 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe shows how to create a simple binary file split utility in Python.</p> <p>It takes two command line arguments: 1) the name of the input file to split , 2) the number of bytes per file into which to split the input.</p> Manga Downloader (Python) 2013-07-16T21:44:47-07:00AJay Kumarhttp://code.activestate.com/recipes/users/4187119/http://code.activestate.com/recipes/578609-manga-downloader/ <p style="color: grey"> Python recipe 578609 by <a href="/recipes/users/4187119/">AJay Kumar</a> (<a href="/recipes/tags/scraping/">scraping</a>). </p> <p>Downloads Manga (Japanese Comics) It will get the images based on search and url There's an exe available @ Sourceforge Modules: 1.bs4 2.easygui</p> Dynamical Billiards Simulation (Python) 2013-06-20T06:57:57-07:00Steve Wadleyhttp://code.activestate.com/recipes/users/4186942/http://code.activestate.com/recipes/578572-dynamical-billiards-simulation/ <p style="color: grey"> Python recipe 578572 by <a href="/recipes/users/4186942/">Steve Wadley</a> (<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/random/">random</a>). </p> <p>It simulates reflections of a ball on a billiards table that has one or more circular obstacles. (This can also be thought as a 2d ray-tracing.)</p> <p>Most of the time the path of the ball would be chaotic (meaning, if another ball started from any slightly different location or direction then its path would be very different after a short while). </p> <p>See Wikipedia for more info: <a href="http://en.wikipedia.org/wiki/Dynamical_billiards" rel="nofollow">http://en.wikipedia.org/wiki/Dynamical_billiards</a></p> Colour Bar And Greyscale Generator For Standard Text Mode Python. (Python) 2013-01-18T21:08:21-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578425-colour-bar-and-greyscale-generator-for-standard-te/ <p style="color: grey"> Python recipe 578425 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bar/">bar</a>, <a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/colour/">colour</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/gray/">gray</a>, <a href="/recipes/tags/grey/">grey</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/scale/">scale</a>). </p> <p>This is just a simple colour bar and combined greyscale generator for standard text mode Python...</p> <p>It relies on the _magic_ of the ANSI Escape sequences to work and does mess with the terminal colours but restores the colours back to the defaults...</p> <p>See the code for the machines tested on. It might need the colours adjusting for some terminals but I am sure that is not beyond the average coder...</p> <p>Written so that anyone can see how it works.</p> <p>To hide the cursor the command "tput" is assumed to be available, if not, try "setterm -cursor off" and "setterm -cursor on" instead...</p> <p>Enjoy...</p> <p>Bazza, G0LCU...</p> Media File Renamer (Python) 2012-12-05T21:04:38-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578359-media-file-renamer/ <p style="color: grey"> Python recipe 578359 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>). </p> <p>Have you ever been annoyed with the names digital cameras give to their pictures? After considering the problem and wanting to standardize filenames, the following program was written to give files in their respective directories similar names according to a convention. For those who may be just starting out with programming and have a similar objective, this recipe may help show some of what may be involved in the process.</p> Recipe With No Name Yet (Python) 2012-08-22T17:57:12-07:00Cyrilhttp://code.activestate.com/recipes/users/4182937/http://code.activestate.com/recipes/578221-recipe-with-no-name-yet/ <p style="color: grey"> Python recipe 578221 by <a href="/recipes/users/4182937/">Cyril</a> (<a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/wrapper/">wrapper</a>). Revision 9. </p> <p>Not a very new recipe, but a short one and (I hope) useful :</p> <ul> <li>wrapping any function "f" with two decorators "enter_event" and "exit_event" that will trigger calling of user functions when, ... hum ... evidently, <strong>just before entering and just after exiting the "f" function</strong>.</li> </ul> <p>Typical usages :</p> <ul> <li>debugging on a function by function basis : <ul> <li>emit a trace in log file to see when functions are called and check sequences correctness (very usefull when programming by events)</li> <li>feed a profile analyzer (by fine tuning which functions are enabled)</li> <li>feed a code coverage analyzer ( " )</li> </ul></li> <li>kind of validator on function calling : <ul> <li>implement programming by contracts : <ul> <li>check that parameters values of "f" function will not have an unexpected value or be of an unexpected type</li> <li>this allow to increase code robustness by narrowing </li> </ul></li> <li>implement invariants (eg. check that returned value is always in the excepted range, ...)</li> <li>insure that a function follow specifications by meta-checking that has always predictable results (eg. return the fixed expected value for each possible input value, ...)</li> </ul></li> <li>minimum modification of existing code</li> <li><strong>in the same thinking line as the "monkey patching" concept</strong></li> </ul> <p>Notes on usage :</p> <ul> <li>recipe works on functions and any kind of methods (methods, class methods, and static methods)</li> <li>the usage order of "@enter_event" and "@exit_event" decorators doesn't matter : the result will be the same</li> </ul> <ul> <li><em>PLEASE VOTE FOR THIS RECIPE if you like it !</em></li> </ul> Hill Climbing Template Method (Python) 2013-12-07T23:24:29-08:00Filippo Squillacehttp://code.activestate.com/recipes/users/4174931/http://code.activestate.com/recipes/578157-hill-climbing-template-method/ <p style="color: grey"> Python recipe 578157 by <a href="/recipes/users/4174931/">Filippo Squillace</a> . Revision 3. </p> <p>This is a template method for the hill climbing algorithm. It doesn't guarantee that it will return the optimal solution. If the probability of success for a given initial random configuration is p the number of repetitions of the Hill Climbing algorithm should be at least 1/p. Note: generate_configuration() is not implemented yet but is quite easy to understand what it does.</p> Lazy Load Object Proxying (Python) 2012-01-13T07:56:29-08:00Cory Virokhttp://code.activestate.com/recipes/users/4180495/http://code.activestate.com/recipes/578014-lazy-load-object-proxying/ <p style="color: grey"> Python recipe 578014 by <a href="/recipes/users/4180495/">Cory Virok</a> (<a href="/recipes/tags/extending/">extending</a>). </p> <p>A very slight modification on Tomer Filiba's original Proxy class to use a factory function instead of an instance to create an object proxy the first time it is required. The only other modification is to add an instance variable to LazyLoadProxy to store data specific to the proxy and not the delegated instance. </p> Backwards Compatibility part 3... (Python) 2011-09-29T21:48:24-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577884-backwards-compatibility-part-3/ <p style="color: grey"> Python recipe 577884 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/all_versions/">all_versions</a>, <a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/backwards_compatibility/">backwards_compatibility</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>Some example lines to add to any test code you write that work from Python 1.4.0 to 3.2.2 on various platforms.</p> <p>It is all Public Domain and you can do with it as you please...</p> <p>I really don't care how you vote and/or rate this as I try to write Python code for my usage to work on the platforms and versions inside the code.</p> <p>Some people will know this but MANY won't and there will be more to come that involve platform and version compatibility...</p> <p>Enjoy finding simple solutions to often VERY difficult problems...</p> <p>(Watch out for wordwrapping, etc...)</p> <p>Bazza, G0LCU...</p> Persistent dict with multiple standard file formats (Python) 2011-09-06T20:01:46-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/576642-persistent-dict-with-multiple-standard-file-format/ <p style="color: grey"> Python recipe 576642 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/dbm/">dbm</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/persistent/">persistent</a>, <a href="/recipes/tags/shelve/">shelve</a>). Revision 10. </p> <p>dbdict: a dbm based on a dict subclass.</p> <p>On open, loads full file into memory. On close, writes full dict to disk (atomically). Supported output file formats: csv, json, and pickle. Input file format automatically discovered.</p> <p>Usable by the shelve module for fast access.</p> Dynamical Billiards Simulation (Python) 2010-10-30T06:22:28-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577445-dynamical-billiards-simulation/ <p style="color: grey"> Python recipe 577445 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/random/">random</a>). </p> <p>It simulates reflections of a ball on a billiards table that has one or more circular obstacles. (This can also be thought as a 2d ray-tracing.)</p> <p>Most of the time the path of the ball would be chaotic (meaning, if another ball started from any slightly different location or direction then its path would be very different after a short while). </p> <p>See Wikipedia for more info: <a href="http://en.wikipedia.org/wiki/Dynamical_billiards" rel="nofollow">http://en.wikipedia.org/wiki/Dynamical_billiards</a></p> Binary BCD clock using curses (Python) 2010-10-19T10:40:36-07:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/577430-binary-bcd-clock-using-curses/ <p style="color: grey"> Python recipe 577430 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/curses/">curses</a>, <a href="/recipes/tags/time/">time</a>). </p> <p>Converts actual time to vertical BCD digits. So actual time, 12:37:51 looks like:</p> <pre class="prettyprint"><code>...... ...**. .***.. *.**** </code></pre> Minimal Dependency Injection Container (Python) 2010-06-05T13:50:03-07:00Alan Franzonihttp://code.activestate.com/recipes/users/4169882/http://code.activestate.com/recipes/577254-minimal-dependency-injection-container/ <p style="color: grey"> Python recipe 577254 by <a href="/recipes/users/4169882/">Alan Franzoni</a> (<a href="/recipes/tags/container/">container</a>, <a href="/recipes/tags/control/">control</a>, <a href="/recipes/tags/dependency/">dependency</a>, <a href="/recipes/tags/di/">di</a>, <a href="/recipes/tags/dic/">dic</a>, <a href="/recipes/tags/injection/">injection</a>, <a href="/recipes/tags/inversion/">inversion</a>, <a href="/recipes/tags/ioc/">ioc</a>, <a href="/recipes/tags/iocc/">iocc</a>). </p> <p>An example of a minimal dependency injection ( aka Inversion of Control ) container for Python.</p> make subdirs (C) 2009-06-16T19:47:31-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576813-make-subdirs/ <p style="color: grey"> C recipe 576813 by <a href="/recipes/users/4170398/">J Y</a> (<a href="/recipes/tags/mkdir/">mkdir</a>). </p> <p>make subdirs recursively</p> Media Renamer (Python) 2012-07-04T01:23:12-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/510389-media-renamer/ <p style="color: grey"> Python recipe 510389 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>This program can rename lots of files that it recognizes for indexing purposes.</p> Download and rename RIDGE radar images (Python) 2007-01-03T07:51:18-08:00Chad Cooperhttp://code.activestate.com/recipes/users/4023200/http://code.activestate.com/recipes/499352-download-and-rename-ridge-radar-images/ <p style="color: grey"> Python recipe 499352 by <a href="/recipes/users/4023200/">Chad Cooper</a> (<a href="/recipes/tags/files/">files</a>). </p> <p>This script downloads RIDGE radar images from the RIDGE site (<a href="http://www.srh.noaa.gov/ridge/" rel="nofollow">http://www.srh.noaa.gov/ridge/</a>) to a local disk, then renames them with a timestamp. In the case below, the One-Hour Precipitation total image and associated world file for the Little Rock, AR station (LZK) are downloaded.</p> Sync the system clock to the naval time server (Python) 2006-08-26T20:38:42-07:00Jason Letbetterhttp://code.activestate.com/recipes/users/2137344/http://code.activestate.com/recipes/496992-sync-the-system-clock-to-the-naval-time-server/ <p style="color: grey"> Python recipe 496992 by <a href="/recipes/users/2137344/">Jason Letbetter</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 2. </p> <p>This software gets the date from a naval time server and updates the system clock for posix OS supporting the "date" command. It also requires an internet connection.</p> <p>WARNING: It will not work if your system clock is already off by more than 1 month.</p> <p>TIP: Use kcron to schedule this script on a periodic basis.</p> Encoding A String (Python) 2005-10-02T19:02:00-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440627-encoding-a-string/ <p style="color: grey"> Python recipe 440627 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>The main purpose of these functions are to allow encoding a string from base 256 to a special base 255. The function view the strings as numbers and simply change what base they are written in. This is not recommended for very long strings; otherwise, the encoding and deconding process can take a very long time to complete.</p> Buffered Stream with Multiple Forward-Only Readers (Python) 2005-03-18T07:40:04-08:00Dominic Foxhttp://code.activestate.com/recipes/users/1951506/http://code.activestate.com/recipes/392150-buffered-stream-with-multiple-forward-only-readers/ <p style="color: grey"> Python recipe 392150 by <a href="/recipes/users/1951506/">Dominic Fox</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>This recipe provides a buffered stream that supports multiple forward-only readers. The buffer enables readers that are behind the front-runner to access values that have already been read from the stream. Values that are no longer accessible by any reader are cleared from the buffer.</p> PackagePath (Python) 2005-01-19T18:40:54-08:00Shannon -jj Behrenshttp://code.activestate.com/recipes/users/2269827/http://code.activestate.com/recipes/363781-packagepath/ <p style="color: grey"> Python recipe 363781 by <a href="/recipes/users/2269827/">Shannon -jj Behrens</a> (<a href="/recipes/tags/oop/">oop</a>). Revision 2. </p> <p>If you have a hierarchy of packages in a library, permit the user of your library to have his own hierarchy of packages that "overlays" yours. That means he can even have classes named the same as your classes, and have his classes "shadow" yours. It also means that a project can be broken up into several top-level directories, all of which have the same package hierarchy within.</p>