Popular recipes tagged "meta:loc=53"http://code.activestate.com/recipes/tags/meta:loc=53/2016-09-19T13:24:37-07:00ActiveState Code RecipesA simple raw hexdumper. (Python) 2016-09-19T13:24:37-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/580697-a-simple-raw-hexdumper/ <p style="color: grey"> Python recipe 580697 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/fs_uae/">fs_uae</a>, <a href="/recipes/tags/hex/">hex</a>, <a href="/recipes/tags/hexdump/">hexdump</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/raw_hexdump/">raw_hexdump</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>This is not a hexreader. This code creates a raw hexdump of a binary file that is whitespace, optional, delimited. The dump is saved into the current directory with a ".hex" extension.</p> <p>It works on just about any current platform but is designed around a stock Amiga A1200(HD) with Python 1.4.0. It also works on the current stable version 3.5.2.</p> <p>I needed a hexdump some years ago for banging the Amiga hardware, and decided to modify recently for another usage but it had to still work on version 1.4.0 for the classic A1200.</p> <p>Enjoy...</p> Dependency resolution (Python) 2016-04-14T12:58:40-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/580642-dependency-resolution/ <p style="color: grey"> Python recipe 580642 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/dependency/">dependency</a>, <a href="/recipes/tags/sort/">sort</a>, <a href="/recipes/tags/sorting/">sorting</a>). </p> <p>This recipe shows how to take a list of objects, each with their own list of dependencies, and resolve them to proper order. It includes some poor mans circular dependency detection (very poor mans).</p> Search for oranges with the wikipedia Python library (Python) 2015-11-03T18:52:55-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579121-search-for-oranges-with-the-wikipedia-python-libra/ <p style="color: grey"> Python recipe 579121 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/library/">library</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/retrieving/">retrieving</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/wikipedia/">wikipedia</a>). </p> <p>The wikipedia Python library (available on PyPI) is a wrapper for the official Wikipedia API. The library is higher level and easier to use than the API, though for limited functionality of the API. It can be used to easily do basic access of Wikipedia pages, which could be useful for many educational, reference and other purposes. This recipe shows the basic use of the wikipedia library, by using it to search for information about oranges.</p> How to execute x86 64-bit assembly code directly from Python on Linux (requires Nasm) (Python) 2015-03-24T18:23:19-07:00Simon Harrisonhttp://code.activestate.com/recipes/users/4191738/http://code.activestate.com/recipes/579037-how-to-execute-x86-64-bit-assembly-code-directly-f/ <p style="color: grey"> Python recipe 579037 by <a href="/recipes/users/4191738/">Simon Harrison</a> (<a href="/recipes/tags/nasm/">nasm</a>). Revision 4. </p> <p>This particular example pertains to running 64-bit assembly code under 64-bit Python, however if you are fortunate enough to be running on a 32-bit Linux platform you may get away with doing a lot less. Since the introduction of DEP you can no longer just shove some code in a buffer and execute it. You must first allow execute permission. Further, you cannot change memory protection settings for anything other than an entire page, so I've padded the memory allocated to include a page before and a page after, so I can seek back to the start of page for the start of my assembler, then change memory protection from there secure in the knowledge that I won't change protection for anything beyond the end of my allocated region. I could probably have used valloc() instead.</p> <p>After that it's simply a matter of changing protection. There is some doubt over whether you can leave this memory read/writable after you set the execute bit, I haven't played with that.</p> <p>Finally, it's important to reset the memory protection before the memory gets freed/reused by Python because Python has no knowledge of the hackery you've just been up to.</p> <p>For a Windows version, use VirtualProtect() to achieve similar results. I could have conditionally added this and made the code portable, however I rarely do any assembler on Windows, so it's left as an exercise for the reader.</p> Pseudo-Random Experiment: Coin Toss (Python) 2014-03-31T18:51:15-07:00Fabian Mayerhttp://code.activestate.com/recipes/users/4189629/http://code.activestate.com/recipes/578859-pseudo-random-experiment-coin-toss/ <p style="color: grey"> Python recipe 578859 by <a href="/recipes/users/4189629/">Fabian Mayer</a> (<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/toss/">toss</a>). </p> <p>This Python Script flips a coin a user defined number of times and returns the frequency and relative frequency for heads and tails.</p> A Complete Morse Code Generator in Python with Sound (Python) 2013-01-08T18:13:33-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578411-a-complete-morse-code-generator-in-python-with-sou/ <p style="color: grey"> Python recipe 578411 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/morse_code/">morse_code</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This is a complete Morse Code Generator with sound. You can <a href="http://temp3.net/thelivingpearl_downloads/morse_sound_files.zip">download the sound files (ogg) for Morse Code</a>. For more information checkout the article <a href="http://thelivingpearl.com/2013/01/08/morse-code-and-dictionaries-in-python-with-sound/">Morse Code and Dictionaries in Python</a></p> A Class Decorator that Adds a copy() Method (Python) 2013-02-14T20:43:20-08:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/578457-a-class-decorator-that-adds-a-copy-method/ <p style="color: grey"> Python recipe 578457 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/metaprogramming/">metaprogramming</a>). </p> <p>Here's a class decorator that adds a rudimentary copy() method onto the decorated class. Use it like this:</p> <pre class="prettyprint"><code>@copiable class SomethingDifferent: def __init__(self, a, b, c): self.a = a self.b = b self.c = c </code></pre> <p>or like this:</p> <pre class="prettyprint"><code>@copiable("a b c") class SomethingDifferent: def __init__(self, a, b, c): self.a = a self.b = b self.c = c s = SomethingDifferent(1,2,3) sc = s.copy() assert vars(s) == vars(sc) </code></pre> <p>(Python 3.3)</p> Print an object only a limited number of times (Python) 2012-12-09T19:41:20-08:00Filippo Squillacehttp://code.activestate.com/recipes/users/4174931/http://code.activestate.com/recipes/578374-print-an-object-only-a-limited-number-of-times/ <p style="color: grey"> Python recipe 578374 by <a href="/recipes/users/4174931/">Filippo Squillace</a> . </p> <p>The psome function detects the position into the source files where the function itself is called. It prints the object according a counter variable. Therefore, whenever the psome function is called inside a loop the object will be printed only a limited number of times. This can useful for debugging code in particular when the data structure we want to scan is quite big and we want to print only the first elements of it.</p> Use PIL to make a "contact sheet" montage of images (Python) 2012-09-21T11:06:58-07:00Hugohttp://code.activestate.com/recipes/users/4183663/http://code.activestate.com/recipes/578267-use-pil-to-make-a-contact-sheet-montage-of-images/ <p style="color: grey"> Python recipe 578267 by <a href="/recipes/users/4183663/">Hugo</a> (<a href="/recipes/tags/graphics/">graphics</a>). Revision 2. </p> <p>The Python Imaging Library (PIL) makes many tasks easy in digital photography. This recipe shows how to make a "contact sheet" of images, a single image with thumbnails of many different pictures. It's limited in that it will only work with pictures of the same shape, but you can make some really fun images.</p> Find Path to Object (Python) 2012-02-05T07:07:33-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578033-find-path-to-object/ <p style="color: grey"> Python recipe 578033 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/search/">search</a>). </p> <p>After wondering what the easiest what to access one object from another was, the following functions were written to automatically discover the shortest path possible. The <code>find</code> function takes the item to find and the object to find it from and tries finding out the best access path. The optional arguments control the search depth, memory usage, et cetera. The <code>nth</code> function is a helper function for accessing data containers that cannot be indexed into. As a final note, line thirteen (<code>while candidates:</code>) will probably never evaluate to false.</p> Temperature Calculator (Python) 2011-12-19T19:06:17-08:00Sabbib Chowdhuryhttp://code.activestate.com/recipes/users/4180311/http://code.activestate.com/recipes/577991-temperature-calculator/ <p style="color: grey"> Python recipe 577991 by <a href="/recipes/users/4180311/">Sabbib Chowdhury</a> (<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3_1/">python3_1</a>). </p> <p>A little tool that calculates temperature with a little user-friendly(ness) added to it.</p> IOPS calculator (Python) 2011-09-20T09:31:09-07:00Slava Yansonhttp://code.activestate.com/recipes/users/4176967/http://code.activestate.com/recipes/577873-iops-calculator/ <p style="color: grey"> Python recipe 577873 by <a href="/recipes/users/4176967/">Slava Yanson</a> (<a href="/recipes/tags/iops/">iops</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/performance/">performance</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Calculates IOPS for all disks in Linux/Unix system</p> Set executable mode where needed: directories, ELF files and scripts (Python) 2011-08-19T20:38:20-07:00Hector Rivashttp://code.activestate.com/recipes/users/4179015/http://code.activestate.com/recipes/577848-set-executable-mode-where-needed-directories-elf-f/ <p style="color: grey"> Python recipe 577848 by <a href="/recipes/users/4179015/">Hector Rivas</a> . Revision 4. </p> <p>If you make a mess (like I did) and you removed all the executable permissions of a directory (or you set executable permissions to everything) this can help.</p> <p>It will walk through a tree of files setting or unsetting the executable mode of files or directories. </p> <p>NOTE: Will autodetect executables if they contain the word ELF at the beggining, so it won't work in platforms that does not use ELF (windows, AIX, etc).</p> Python Thread Pool (Python) 2010-04-12T22:27:32-07:00Emilio Montihttp://code.activestate.com/recipes/users/4173642/http://code.activestate.com/recipes/577187-python-thread-pool/ <p style="color: grey"> Python recipe 577187 by <a href="/recipes/users/4173642/">Emilio Monti</a> (<a href="/recipes/tags/pool/">pool</a>, <a href="/recipes/tags/thread/">thread</a>). Revision 9. </p> <p>A simple Python ThreadPool based on the standard library's <a href="http://docs.python.org/library/queue.html">Queue</a> object.</p> Maclaurin's_series_tanh-1(x) (Python) 2010-09-28T11:50:45-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577399-maclaurins_series_tanh-1x/ <p style="color: grey"> Python recipe 577399 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p> <p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p> <p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p> <p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor's series. </p> <p>Natural logarithms are used to compute inverse hyperbolic functions.</p> Revisiting "Revenge of the auto-wrap": Another toggle-macro (JavaScript) 2010-10-04T23:51:41-07:00Eric Promislowhttp://code.activestate.com/recipes/users/4166930/http://code.activestate.com/recipes/577417-revisiting-revenge-of-the-auto-wrap-another-toggle/ <p style="color: grey"> JavaScript recipe 577417 by <a href="/recipes/users/4166930/">Eric Promislow</a> (<a href="/recipes/tags/autowrap/">autowrap</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/togglemacro/">togglemacro</a>). Revision 2. </p> <p>Komodo doesn't automatically wrap lines when they reach a certain length, which is a good trait to have in a code editor. However, for those times where you're editing non-code, it can be helpful to have newlines inserted automatically. Troy Topnik addressed this problem a couple of years ago, in his post <a href="http://www.activestate.com/blog/2008/11/revenge-auto-wrap-type-type-type-ding" rel="nofollow">http://www.activestate.com/blog/2008/11/revenge-auto-wrap-type-type-type-ding</a> . As Komodo 6 heads out the door, I've been writing blog posts, and found this feature useful. But his solution used two macros. I put my coding hat back on, and reimplemented it as a "toggle macro".</p> IP address and CIDR mask conversion to network and broadcast (Python) 2010-08-25T21:37:16-07:00Rafael Zanellahttp://code.activestate.com/recipes/users/4165925/http://code.activestate.com/recipes/577375-ip-address-and-cidr-mask-conversion-to-network-and/ <p style="color: grey"> Python recipe 577375 by <a href="/recipes/users/4165925/">Rafael Zanella</a> (<a href="/recipes/tags/cidr/">cidr</a>, <a href="/recipes/tags/ipv4/">ipv4</a>, <a href="/recipes/tags/mask/">mask</a>, <a href="/recipes/tags/network/">network</a>). Revision 2. </p> <p>Convert dotted-quad IPv4 addresses along with CIDR mask to host-byte-order long integer ip, network and broadcast, along with their dotted-quad IPv4 representation.</p> Sudoku Solver (Bruteforce) (Java) 2010-07-18T11:31:10-07:00st0lehttp://code.activestate.com/recipes/users/4174421/http://code.activestate.com/recipes/577314-sudoku-solver-bruteforce/ <p style="color: grey"> Java recipe 577314 by <a href="/recipes/users/4174421/">st0le</a> (<a href="/recipes/tags/java/">java</a>, <a href="/recipes/tags/sudoku/">sudoku</a>). </p> <p>A simple Sudoku Solver, use 0 for blank cells.</p> Python Wrapper for Google AJAX Language API (Python) 2009-08-22T12:59:38-07:00Ashish Yadavhttp://code.activestate.com/recipes/users/4171522/http://code.activestate.com/recipes/576890-python-wrapper-for-google-ajax-language-api/ <p style="color: grey"> Python recipe 576890 by <a href="/recipes/users/4171522/">Ashish Yadav</a> (<a href="/recipes/tags/google_ajax_api/">google_ajax_api</a>, <a href="/recipes/tags/language_translation/">language_translation</a>, <a href="/recipes/tags/wrapper/">wrapper</a>). Revision 3. </p> <p>A Python Wrapper for Google AJAX Language API, Uses Google Language Detection, in cases source language is not provided with the source text, Splits up text if it's longer then 4500 characters, as a limit put up by the API. Working fine for me, please let me know if i missed something.</p> Generation of captcha without using any fonts (Python) 2009-03-21T14:29:30-07:00Agnius Vasiliauskashttp://code.activestate.com/recipes/users/4169134/http://code.activestate.com/recipes/576695-generation-of-captcha-without-using-any-fonts/ <p style="color: grey"> Python recipe 576695 by <a href="/recipes/users/4169134/">Agnius Vasiliauskas</a> (<a href="/recipes/tags/captcha/">captcha</a>, <a href="/recipes/tags/reverse_turing_test/">reverse_turing_test</a>). Revision 3. </p> <p>Generation of captcha image composed of numbers without using any fonts. As such it adds more variability to symbols (because every symbol is generated using random noise). And because of this - should be more secure than known set of fonts.</p>