Popular recipes tagged "meta:loc=36"http://code.activestate.com/recipes/tags/meta:loc=36/2016-06-01T19:36:28-07:00ActiveState Code RecipesThe many uses of randomness - Part 1 (Python)
2016-06-01T19:36:28-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580674-the-many-uses-of-randomness-part-1/
<p style="color: grey">
Python
recipe 580674
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/random_number/">random_number</a>).
</p>
<p>This recipe shows some of the many uses of random numbers, using the random function from the random module from Python's standard library. A subsequent recipe or two will show other uses, both of other functions from the module, and for other purposes.</p>
<p>The uses shown in this recipe have to do with using random float values, and scaling them and offsetting them, and also how to get a repeated/predictable series of random numbers.</p>
Angosso (Perl)
2015-07-29T21:21:56-07:00Roger Mbiama Assogohttp://code.activestate.com/recipes/users/4182949/http://code.activestate.com/recipes/579087-angosso/
<p style="color: grey">
Perl
recipe 579087
by <a href="/recipes/users/4182949/">Roger Mbiama Assogo</a>
(<a href="/recipes/tags/i18n/">i18n</a>).
</p>
<p>PPM management utility for ActivePerl
The http_proxy Environment Variable
Setting http_proxy
Using the CPAN shell</p>
Spread sheet style column enumeration letter to number (Python)
2014-09-20T18:45:09-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578941-spread-sheet-style-column-enumeration-letter-to-nu/
<p style="color: grey">
Python
recipe 578941
by <a href="/recipes/users/4189558/">Tomas Nordin</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/excel/">excel</a>, <a href="/recipes/tags/libreoffice/">libreoffice</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/spreadsheet/">spreadsheet</a>).
</p>
<p>A post-it suggestion on how to convert "Excel style" notation of columns to a number.</p>
Sticky window (Python)
2013-12-16T17:10:25-08:00winandhttp://code.activestate.com/recipes/users/4188769/http://code.activestate.com/recipes/578789-sticky-window/
<p style="color: grey">
Python
recipe 578789
by <a href="/recipes/users/4188769/">winand</a>
(<a href="/recipes/tags/windows/">windows</a>).
</p>
<p>Create a window which sticks to screen edges using PyQt4 under Windows.</p>
Worley Noise Generator (Python)
2013-02-16T21:11:05-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578459-worley-noise-generator/
<p style="color: grey">
Python
recipe 578459
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>Worley Noise is a type of parametric texture used for water, rock, leaf etc. textures in computer graphics. </p>
<p>The algorithm is a slightly modified version of Voronoi Diagram. </p>
Use rot13 to en/decrypt clear text (Python)
2012-11-07T09:17:51-08:00Eric.sunhttp://code.activestate.com/recipes/users/4183602/http://code.activestate.com/recipes/578322-use-rot13-to-endecrypt-clear-text/
<p style="color: grey">
Python
recipe 578322
by <a href="/recipes/users/4183602/">Eric.sun</a>
(<a href="/recipes/tags/encrypt/">encrypt</a>, <a href="/recipes/tags/python3/">python3</a>).
</p>
<p>Encryption.Using your solution to the previous problem, and create a "rot13" translator.
"rot13" is an old and fairly simplistic encryption routine where by each letter of the alphabet is
rotated 13 characters. Letters in the first half of the alphabet will be rotated to the equivalent
letter in the second half and vice versa, retaining case. For example, 'a' goes to 'n' and 'X' goes
to 'K'. Obviously, numbers and symbols are immune from translation.</p>
Promot & Verify Encrypted User Password (Python)
2013-01-19T04:10:13-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578431-promot-verify-encrypted-user-password/
<p style="color: grey">
Python
recipe 578431
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This snippet of code was written as part of an article - <a href="http://thelivingpearl.com/2013/01/18/password-protecting-your-python-application/">Password Protecting You Python Application</a>. The code requires a file with an encrypted password. The script to generate an encrypted file is <a href="http://code.activestate.com/recipes/578430-code-to-store-encrypted-password-in-a-file/">Code To Store Encrypted Password in a File</a>.</p>
Genreate x digits prime number in python, version 1 (Python)
2013-01-06T20:25:20-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578404-genreate-x-digits-prime-number-in-python-version-1/
<p style="color: grey">
Python
recipe 578404
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>).
</p>
<p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>. The script will generate a prime number of x digits for small numbers, less than 10. </p>
Random Sound FX Using WAV File (Python)
2012-07-01T19:54:17-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578180-random-sound-fx-using-wav-file/
<p style="color: grey">
Python
recipe 578180
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>It generates random sound effects using AM and FM.</p>
Pants (Python)
2012-07-03T05:31:24-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578188-pants/
<p style="color: grey">
Python
recipe 578188
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/shell/">shell</a>).
</p>
<p>According to memory this is a port of a shell script called pants that allows one to "start," "stop," "restart," and find the "status" of one's pants (the program itself). I am not sure what the silliness is about but must have found the idea interesting to rewrite in Python. This is committed for archival to be run under Python 2.5 or later versions.</p>
Rookie's Backup Program (Python)
2012-07-08T00:52:05-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578199-rookies-backup-program/
<p style="color: grey">
Python
recipe 578199
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/copy/">copy</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/utility/">utility</a>).
</p>
<p>A while back when still fairly new to Python, this simple program was developed to back directories of information. In reality, it is just a simple (and poorly written) file copier that could be greatly improved. This is committed for archival to be run under Python 2.5 or later versions.</p>
Find a line of text in another file (Python)
2012-06-15T15:45:18-07:00sami janhttp://code.activestate.com/recipes/users/4064232/http://code.activestate.com/recipes/578164-find-a-line-of-text-in-another-file/
<p style="color: grey">
Python
recipe 578164
by <a href="/recipes/users/4064232/">sami jan</a>
(<a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/search/">search</a>).
Revision 2.
</p>
<p>This is a simple recipe - it reads a line in file, removes the line-ending and attempts to search throughout another file for the same line, anywhere in the file</p>
<p>In case a line is missing, the line number is printed to stdout</p>
ProgressBar class (Python)
2011-10-27T06:16:29-07:00Petr Zizkahttp://code.activestate.com/recipes/users/4179733/http://code.activestate.com/recipes/577926-progressbar-class/
<p style="color: grey">
Python
recipe 577926
by <a href="/recipes/users/4179733/">Petr Zizka</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>Progress bars are popular when trying to
show how much of a job has been completed.
In my case, it was encrypting and decrypting
files. A GUI interface was written, but
something was lacking. How was the user of
the program supposed to know if the program
was doing its job? A progress bar seemed like
a good answer, so a simple GUI progress bar
was written using Tkinter.</p>
Decoding Binary Files (Python)
2011-03-15T00:11:10-07:00Yony Kochinskihttp://code.activestate.com/recipes/users/4175703/http://code.activestate.com/recipes/577610-decoding-binary-files/
<p style="color: grey">
Python
recipe 577610
by <a href="/recipes/users/4175703/">Yony Kochinski</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/decode/">decode</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/python/">python</a>).
Revision 2.
</p>
<p>One way to read files that contain binary fields is to use the <code>struct</code> module. However, to do this properly one must learn struct's format characters, which may look especially cryptic when sprinkled around the code. So instead, I use a wrapper object that presents a simple interface as well as type names that are more inline with many <a href="http://en.wikipedia.org/wiki/Interface_description_language">IDLs</a>.</p>
Method access counter proxy (Python)
2011-09-18T12:49:15-07:00Yaşar Arabacıhttp://code.activestate.com/recipes/users/4178739/http://code.activestate.com/recipes/577869-method-access-counter-proxy/
<p style="color: grey">
Python
recipe 577869
by <a href="/recipes/users/4178739/">Yaşar Arabacı</a>
(<a href="/recipes/tags/proxy/">proxy</a>).
Revision 4.
</p>
<p>This function creates a proxy for a class so that you can count how many times each method called. It only works for mutable types.</p>
Experiment with Kaprekar's routine (Python)
2011-06-12T03:29:01-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577749-experiment-with-kaprekars-routine/
<p style="color: grey">
Python
recipe 577749
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/6174/">6174</a>, <a href="/recipes/tags/dot/">dot</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/kaprekar/">kaprekar</a>).
Revision 2.
</p>
<p>Explore the story behind the mysterious number 6174. Generate all possible chains leading to 6174, show their length and their patterns of convergence.</p>
Synchronized Chaos using Lorenz Attractor (Python)
2011-08-02T03:53:03-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577816-synchronized-chaos-using-lorenz-attractor/
<p style="color: grey">
Python
recipe 577816
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>2 chaotic Lorenz dynamical systems get synchronized with time.
(Notice 2 y and 2 z values start differently but approach each other later.)</p>
<p>I used the x variable as the synchronization signal but y or z can also be used.</p>
jpg2pdf (Python)
2011-07-17T19:49:58-07:00Sundar Srinivasanhttp://code.activestate.com/recipes/users/4177884/http://code.activestate.com/recipes/577798-jpg2pdf/
<p style="color: grey">
Python
recipe 577798
by <a href="/recipes/users/4177884/">Sundar Srinivasan</a>
(<a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/reportlab/">reportlab</a>).
</p>
<p>Program to convert JPEG to PDF. Technically it just embeds the JPEG in a landscape US letter size PDF page.
When you might need it?: When you have to scan a document and do not have scanner handy, you can take a photograph of the document with webcam, and embed the JPEG into PDF - effectively works as a scanner.</p>
ActiveState recipe statistics (Python)
2011-06-02T14:52:50-07:00Kaan Ozturkhttp://code.activestate.com/recipes/users/4178179/http://code.activestate.com/recipes/577732-activestate-recipe-statistics/
<p style="color: grey">
Python
recipe 577732
by <a href="/recipes/users/4178179/">Kaan Ozturk</a>
(<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/regular_expressions/">regular_expressions</a>, <a href="/recipes/tags/statistics/">statistics</a>, <a href="/recipes/tags/urllib2/">urllib2</a>, <a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>Downloads "All Recipe Authors" pages in ActiveState, uses regular expressions to parse author name and number of their recipes on each page. Finally, it displays the recipe submission distribution (the count of how many authors have submitted how many recipes each).</p>
Composition of classes instead of multiple inheritance (Python)
2011-04-16T03:40:19-07:00Ethan Furmanhttp://code.activestate.com/recipes/users/4177684/http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/
<p style="color: grey">
Python
recipe 577658
by <a href="/recipes/users/4177684/">Ethan Furman</a>
(<a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/composition/">composition</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple_inheritance/">multiple_inheritance</a>).
</p>
<p>MI can be difficult and confusing, and if the base classes don't cooperate -- well, cooperative MI won't work.</p>
<p>One way around this is to use composition instead. This class decorator will combine the source classes with the target class, ensuring that no duplications occur (raises a TypeError if there are any).</p>