Popular recipes tagged "meta:loc=45"http://code.activestate.com/recipes/tags/meta:loc=45/2016-09-25T21:24:12-07:00ActiveState Code RecipesImage to ASCII Art Converter (Python)
2016-09-25T21:24:12-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/580702-image-to-ascii-art-converter/
<p style="color: grey">
Python
recipe 580702
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/pil/">pil</a>).
</p>
<p>ASCII Art Generator (Image to ASCII Art Converter)</p>
<p>Input file maybe JPG, PNG, GIF etc.
Output file name maybe output.txt etc.</p>
generates a set of binary files by doing ASCII replacements on a master binary file, controlled by a csv file (Python)
2015-09-16T16:25:49-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579099-generates-a-set-of-binary-files-by-doing-ascii-rep/
<p style="color: grey">
Python
recipe 579099
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/replace/">replace</a>).
</p>
<p>A hack that saved me a lot of time. Well perhaps not so much, but it was funnier than to do it manually. </p>
Run OS command with timeout on a list of files using several threads (Python)
2015-05-19T19:31:59-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579056-run-os-command-with-timeout-on-a-list-of-files-usi/
<p style="color: grey">
Python
recipe 579056
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/threading/">threading</a>).
Revision 3.
</p>
<p>This hack runs a command sequentially on a list of files using two simultaneous threads. If one of the commands takes more than a set time, it's killed and the program goes for the next file. EDITED to add some exception handling.</p>
Safely (over)write a file (Python)
2014-05-12T20:26:20-07:00Pavel Krchttp://code.activestate.com/recipes/users/4177047/http://code.activestate.com/recipes/578877-safely-overwrite-a-file/
<p style="color: grey">
Python
recipe 578877
by <a href="/recipes/users/4177047/">Pavel Krc</a>
.
</p>
<p>Create a file or replace its content in an atomic way using tempfile.</p>
Mounted devices (Batch)
2013-08-13T14:32:51-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578639-mounted-devices/
<p style="color: grey">
Batch
recipe 578639
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/device/">device</a>, <a href="/recipes/tags/mount/">mount</a>).
Revision 2.
</p>
<p>Script reads data stored in HKLM\SYSTEM\MountedDevices key and shows it in user friendly format. It's still under development.</p>
Perlin Noise Generator (Python)
2013-02-23T05:23:24-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578470-perlin-noise-generator/
<p style="color: grey">
Python
recipe 578470
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>).
Revision 2.
</p>
<p>Perlin Noise Generator using Bilinear Interpolation.</p>
True-color Mandelbrot Fractal (Python)
2013-01-14T02:07:47-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578415-true-color-mandelbrot-fractal/
<p style="color: grey">
Python
recipe 578415
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>, <a href="/recipes/tags/pil/">pil</a>).
Revision 2.
</p>
<p>True-color Mandelbrot Fractal.
It uses |x|, |y|, |z|, |angle(z)| values of the final iteration point for coloring.</p>
Disk usage (Python)
2012-10-06T15:33:40-07:00Giampaolo RodolĂ http://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/577972-disk-usage/
<p style="color: grey">
Python
recipe 577972
by <a href="/recipes/users/4178764/">Giampaolo RodolĂ </a>
(<a href="/recipes/tags/disk/">disk</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/space/">space</a>, <a href="/recipes/tags/statistics/">statistics</a>, <a href="/recipes/tags/usage/">usage</a>).
Revision 6.
</p>
<p>Provides disk usage statistics (total, used and free disk space) about a given path.</p>
<p>This recipe was initially developed for psutil:</p>
<ul>
<li><a href="http://code.google.com/p/psutil/issues/detail?id=172" rel="nofollow">http://code.google.com/p/psutil/issues/detail?id=172</a></li>
</ul>
<p>...and then included into shutil module starting from Python 3.3:</p>
<ul>
<li><a href="http://mail.python.org/pipermail/python-ideas/2011-June/010480.html" rel="nofollow">http://mail.python.org/pipermail/python-ideas/2011-June/010480.html</a></li>
<li><a href="http://bugs.python.org/issue12442" rel="nofollow">http://bugs.python.org/issue12442</a></li>
<li><a href="http://docs.python.org/dev/library/shutil.html#shutil.disk_usage" rel="nofollow">http://docs.python.org/dev/library/shutil.html#shutil.disk_usage</a></li>
</ul>
<p>The recipe you see here is a modified version of the latter one in that the Windows implementation uses ctypes instead of a C extension module. As such it can be used with python >= 2.5.</p>
Dragon IFS Fractal (Python)
2012-01-07T05:22:54-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578001-dragon-ifs-fractal/
<p style="color: grey">
Python
recipe 578001
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>Dragon IFS Fractal</p>
Validating classes and objects against an Abstract Base Class (Python)
2011-05-21T19:14:19-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577711-validating-classes-and-objects-against-an-abstract/
<p style="color: grey">
Python
recipe 577711
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/abc/">abc</a>, <a href="/recipes/tags/validation/">validation</a>).
Revision 4.
</p>
<p>Abstract Bases Classes in Python provide great features for describing interfaces programmatically. By default a subclass is validated against all its ABC parents at instantiation time (in object.__new__). This recipe aims to provide for validation against an ABC of:</p>
<ul>
<li>any class at definition time (including subclasses and registered classes),</li>
<li>any object at any time.</li>
</ul>
<p>I have included an example of the reason I did all this. It allows you to implement an ABC in the instance rather than the class.</p>
<p>If the classes argument to validate is None then it tries to build the list of classes from the object's MRO. If the ABCMeta.register method facilitated an __implements__ list on classes, we could also use that to validate against the registered "base" classes.</p>
<p>The code I have provided is for Python 3, but it should work in 2.7 with a little modification.</p>
<p>This code borrows from Lib/abc.py and objects/typeobject.c</p>
Lorenz Attractor (Python)
2011-07-31T22:05:11-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577814-lorenz-attractor/
<p style="color: grey">
Python
recipe 577814
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>Lorenz Attractor</p>
nicerest: pretty-print JSON output (JavaScript)
2011-01-18T22:59:12-08:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577549-nicerest-pretty-print-json-output/
<p style="color: grey">
JavaScript
recipe 577549
by <a href="/recipes/users/4173505/">Trent Mick</a>
(<a href="/recipes/tags/curl/">curl</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/node/">node</a>, <a href="/recipes/tags/nodejs/">nodejs</a>, <a href="/recipes/tags/rest/">rest</a>).
Revision 3.
</p>
<p>Save this to "nicerest", <code>chmod +x</code>-it, and pipe your REST API <code>curl</code> calls through this for nicer output. It will notice HTTP headers (curl's <code>-i</code> option) and skips those before attempting to pretty-print the following JSON.</p>
<p>Note: This is currently using node 0.2. I should update for 0.3 changes (I think <code>process.openStdin</code> changed).</p>
Partitioning a sequence (Python)
2011-04-17T21:28:12-07:00Praveenhttp://code.activestate.com/recipes/users/4177693/http://code.activestate.com/recipes/577665-partitioning-a-sequence/
<p style="color: grey">
Python
recipe 577665
by <a href="/recipes/users/4177693/">Praveen</a>
.
</p>
<p>Distinct partitions of a sequence.</p>
My First Poem Written in Python (Python)
2011-04-06T18:09:48-07:00thermohttp://code.activestate.com/recipes/users/4177569/http://code.activestate.com/recipes/577641-my-first-poem-written-in-python/
<p style="color: grey">
Python
recipe 577641
by <a href="/recipes/users/4177569/">thermo</a>
(<a href="/recipes/tags/poem/">poem</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>My First Poem Written in Python</p>
Hex Dump (Python)
2010-05-24T14:16:45-07:00Bill Picketthttp://code.activestate.com/recipes/users/4174028/http://code.activestate.com/recipes/577243-hex-dump/
<p style="color: grey">
Python
recipe 577243
by <a href="/recipes/users/4174028/">Bill Pickett</a>
(<a href="/recipes/tags/hexadecimal/">hexadecimal</a>).
</p>
<p>Load a file and print formatted hexadecimal and ascii characters to the console.</p>
Partitioning a sequence (Python)
2009-06-03T20:57:42-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/576795-partitioning-a-sequence/
<p style="color: grey">
Python
recipe 576795
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
.
Revision 2.
</p>
<p>Distinct partitions of a sequence.</p>
how to implement kbhit() on Linux (Python)
2008-05-03T05:13:00-07:00Nelson Rushhttp://code.activestate.com/recipes/users/144881/http://code.activestate.com/recipes/572182-how-to-implement-kbhit-on-linux/
<p style="color: grey">
Python
recipe 572182
by <a href="/recipes/users/144881/">Nelson Rush</a>
.
Revision 2.
</p>
<p>kbhit on linux, the sample just prints dots until you press any key. I updated the sample to show how to implement unbuffered getch and getche safely.</p>
Sort sections and keys in .ini file (Python)
2008-12-19T05:46:05-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/576587-sort-sections-and-keys-in-ini-file/
<p style="color: grey">
Python
recipe 576587
by <a href="/recipes/users/186902/">Michal Niklas</a>
(<a href="/recipes/tags/config/">config</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/ini/">ini</a>, <a href="/recipes/tags/sort/">sort</a>).
Revision 3.
</p>
<p>I use this program when I want to make .ini file more readable or compare two .ini files</p>
Round to base (Python)
2009-01-28T09:48:13-08:00David Lamberthttp://code.activestate.com/recipes/users/4167420/http://code.activestate.com/recipes/576637-round-to-base/
<p style="color: grey">
Python
recipe 576637
by <a href="/recipes/users/4167420/">David Lambert</a>
.
</p>
<p>This python3 code generalizes rounding. It includes a "base" argument, which can be a float greater than 0. The "number of places" argument may also be a float. When the base is 10 Round uses builtins.round.</p>
XML to python dictionary of list (Python)
2008-04-16T15:17:30-07:00Vivek Khuranahttp://code.activestate.com/recipes/users/4125433/http://code.activestate.com/recipes/570085-xml-to-python-dictionary-of-list/
<p style="color: grey">
Python
recipe 570085
by <a href="/recipes/users/4125433/">Vivek Khurana</a>
(<a href="/recipes/tags/xml/">xml</a>).
Revision 4.
</p>
<p>Another recipe to convert xml file into a python dictionary. This recipe uses lxml</p>