Popular recipes tagged "meta:loc=27"http://code.activestate.com/recipes/tags/meta:loc=27/2014-12-17T19:03:15-08:00ActiveState Code RecipesClear Only Project Modules (Python)
2014-12-17T19:03:15-08:00Cornelius Jatniel Prinsloohttp://code.activestate.com/recipes/users/4191358/http://code.activestate.com/recipes/578982-clear-only-project-modules/
<p style="color: grey">
Python
recipe 578982
by <a href="/recipes/users/4191358/">Cornelius Jatniel Prinsloo</a>
(<a href="/recipes/tags/clear/">clear</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/project/">project</a>, <a href="/recipes/tags/reload/">reload</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/startup/">startup</a>).
</p>
<p>Useful for python sessions that have a long startup time
because of external dependancies
[In my case that would be pygame and pymunk]
I've got a slow computer so it takes a while to startup
this is the solution I came up with</p>
<p>import this before any other of your project imports
example:
import reloading # The modules in your project folder get cleared
then load the rest of your project modules</p>
<p>make sure that the reloading script is in your project folder, or else it won't work</p>
<p>You might be able to extend this by changing line</p>
hex2dec (Bash)
2013-07-01T05:59:06-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578588-hex2dec/
<p style="color: grey">
Bash
recipe 578588
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/hex2dec/">hex2dec</a>).
</p>
<p>Experimental </p>
DEMO - Generate A Crude 1KHz Sinewave Using A BASH Script. (Bash)
2013-03-01T19:41:47-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578477-demo-generate-a-crude-1khz-sinewave-using-a-bash-s/
<p style="color: grey">
Bash
recipe 578477
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/sinewave/">sinewave</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>A very simple crude sinewave generator using a BASH script inside a Linux Terminal.</p>
<p>The file required is generated inside the code and requires /dev/audio to work.</p>
<p>Ensure you have this device, if not the download oss-compat from your OS's repository...</p>
<p>It lasts for about 8 seconds before exiting and saves a 65536 byte file to your working directory/drawer/folder as sinewave.raw.</p>
<p>Use an oscilloscope to check the waveform generated...</p>
<p>It is entirely Public Domain and you may do with it as you please...</p>
<p>Enjoy finding simple solutions to often very difficult problems... ;o)</p>
<p>Bazza, G0LCU...</p>
Bisection Method in Python (Python)
2013-01-16T16:37:33-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578417-bisection-method-in-python/
<p style="color: grey">
Python
recipe 578417
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/bisect/">bisect</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is a quick way to do bisection method in python. I wrote his code as part of an article, <a href="http://thelivingpearl.com/2013/01/15/the-easy-way-to-solve-equations-in-python/">How to solve equations using python</a></p>
Storing a Single Username and Encrypted Password to a File (Python)
2013-01-31T02:07:25-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578443-storing-a-single-username-and-encrypted-password-t/
<p style="color: grey">
Python
recipe 578443
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This script was written for an article I wrote to check user passwords. It stores data using SHA one-way function. For more information <a href="http://thelivingpearl.com/2013/01/29/authentication-of-users-and-passwords-in-python/">Authentication Of Users And Passwords In Python</a></p>
Code To Store Encrypted Password in a File (Python)
2013-01-19T04:07:50-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578430-code-to-store-encrypted-password-in-a-file/
<p style="color: grey">
Python
recipe 578430
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></p>
Find the nth prime in python (Python)
2013-01-06T20:23:21-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578403-find-the-nth-prime-in-python/
<p style="color: grey">
Python
recipe 578403
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>).
</p>
<p>This is a nth 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></p>
Finding the limits (C)
2012-03-16T10:46:32-07:00Boubakrhttp://code.activestate.com/recipes/users/4176416/http://code.activestate.com/recipes/578077-finding-the-limits/
<p style="color: grey">
C
recipe 578077
by <a href="/recipes/users/4176416/">Boubakr</a>
.
</p>
<p>a simple program to output the values corresponding to the symbols defined in the header files.</p>
Fuzzy Logic Fractal (Python)
2011-08-14T23:09:08-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577841-fuzzy-logic-fractal/
<p style="color: grey">
Python
recipe 577841
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>This fractal created by converting logic statements into equations using fuzzy logic operators:</p>
<p>X: X is as true as Y is true</p>
<p>Y: Y is as true as X is false</p>
<p>See: Scientific American Magazine, February 1993, "A Partly True Story"</p>
Universal eval to string function (Python)
2011-02-24T10:17:32-08:00Jakub Jankiewiczhttp://code.activestate.com/recipes/users/4028109/http://code.activestate.com/recipes/577585-universal-eval-to-string-function/
<p style="color: grey">
Python
recipe 577585
by <a href="/recipes/users/4028109/">Jakub Jankiewicz</a>
(<a href="/recipes/tags/evaluation/">evaluation</a>, <a href="/recipes/tags/exec/">exec</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python_scripts/">python_scripts</a>).
</p>
<p>This is a function that evaluate all expressions and statements and return the result as a string. It also return Exceptions as strings. It is used in <a href="http://trypython.jcubic.pl">trypython.jcubic.pl</a></p>
Remove ID3 tags from MP3 files (Python)
2010-03-29T10:55:27-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/577139-remove-id3-tags-from-mp3-files/
<p style="color: grey">
Python
recipe 577139
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/id3/">id3</a>, <a href="/recipes/tags/mp3/">mp3</a>, <a href="/recipes/tags/mutagen/">mutagen</a>).
Revision 3.
</p>
<p>Remove ID3 tags from all files in the current directory</p>
Eight Queens With out Permutations (Python)
2010-07-21T10:11:20-07:00Narayana Chikkamhttp://code.activestate.com/recipes/users/4174427/http://code.activestate.com/recipes/577325-eight-queens-with-out-permutations/
<p style="color: grey">
Python
recipe 577325
by <a href="/recipes/users/4174427/">Narayana Chikkam</a>
(<a href="/recipes/tags/eight/">eight</a>, <a href="/recipes/tags/queens/">queens</a>).
</p>
<p>Eight Queens is one of the popular algorithms in backtracking. The solution given below uses simple math to reduce the processing. The logic is keep placing the coins on the board with below rules:</p>
<ol>
<li>Don't place the coin if there is another coin present in the same row</li>
<li>Don't place the coin if there is another coin present in the same col</li>
<li>Don't place the coin if there is another coin present in any of the diagonal lines.</li>
</ol>
<p>Keep repeating the above 3 rules recursively until we keep all the coins.
Problem Definition:
<a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle" rel="nofollow">http://en.wikipedia.org/wiki/Eight_queens_puzzle</a></p>
Simple primes generator (Python)
2009-11-04T06:52:06-08:00Maxime Fontenierhttp://code.activestate.com/recipes/users/4172150/http://code.activestate.com/recipes/576948-simple-primes-generator/
<p style="color: grey">
Python
recipe 576948
by <a href="/recipes/users/4172150/">Maxime Fontenier</a>
(<a href="/recipes/tags/any/">any</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/primes/">primes</a>).
</p>
<p>Simple prime generator. </p>
<p>I write it as a sample usage of the any function.</p>
Simple reverse converter of unicode code points string (Python)
2009-09-22T20:02:32-07:00Ryanhttp://code.activestate.com/recipes/users/4171767/http://code.activestate.com/recipes/576909-simple-reverse-converter-of-unicode-code-points-st/
<p style="color: grey">
Python
recipe 576909
by <a href="/recipes/users/4171767/">Ryan</a>
(<a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/points/">points</a>, <a href="/recipes/tags/prefix/">prefix</a>, <a href="/recipes/tags/reverse/">reverse</a>, <a href="/recipes/tags/str/">str</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/u/">u</a>, <a href="/recipes/tags/unicode/">unicode</a>).
Revision 4.
</p>
<p>It's a simple recipe to convert a str type string with pure unicode code point (e.g string = <strong>"\u5982\u679c\u7231"</strong> ) to an unicode type string.
Actually, this method has the same effect with <strong>'u'</strong> prefix. But differently, it allows you to pass a variable of code points string as well as a constant one.</p>
Packet monitoring with pcap and dpkt (Python)
2011-09-13T06:56:36-07:00Victor Yanghttp://code.activestate.com/recipes/users/627255/http://code.activestate.com/recipes/576678-packet-monitoring-with-pcap-and-dpkt/
<p style="color: grey">
Python
recipe 576678
by <a href="/recipes/users/627255/">Victor Yang</a>
(<a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/sniff/">sniff</a>).
Revision 3.
</p>
<p>This recipe shows how to use pypcap and dpkt to monitor network traffic and grep with regular expression. Python 2.3 up required
pypcap: <a href="http://code.google.com/p/pypcap/" rel="nofollow">http://code.google.com/p/pypcap/</a>
dpkt: <a href="http://code.google.com/p/dpkt/" rel="nofollow">http://code.google.com/p/dpkt/</a> </p>
Subclass function (Python)
2009-03-23T00:48:54-07:00Peter Russellhttp://code.activestate.com/recipes/users/4166045/http://code.activestate.com/recipes/576697-subclass-function/
<p style="color: grey">
Python
recipe 576697
by <a href="/recipes/users/4166045/">Peter Russell</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/metaprogramming/">metaprogramming</a>, <a href="/recipes/tags/subclass/">subclass</a>).
Revision 4.
</p>
<p><strong>Do not use this function - instead use the built in type(name, bases, dict) constructor</strong> This is a function that builds a subclass of some base classes. I wrote it while unaware that type could be used as a constructor.</p>
Romantic love poem in Python (Python)
2014-09-04T09:34:16-07:00Damian Parniewiczhttp://code.activestate.com/recipes/users/2913290/http://code.activestate.com/recipes/496781-romantic-love-poem-in-python/
<p style="color: grey">
Python
recipe 496781
by <a href="/recipes/users/2913290/">Damian Parniewicz</a>
(<a href="/recipes/tags/ui/">ui</a>).
Revision 3.
</p>
<p>This recipe was written for my beautiful girl...however signification of this code is universal</p>
@replier using tweet-sauce (Python)
2009-01-12T17:01:40-08:00Zach Seiftshttp://code.activestate.com/recipes/users/4168562/http://code.activestate.com/recipes/576610-replier-using-tweet-sauce/
<p style="color: grey">
Python
recipe 576610
by <a href="/recipes/users/4168562/">Zach Seifts</a>
(<a href="/recipes/tags/sauce/">sauce</a>, <a href="/recipes/tags/tweet_sauce/">tweet_sauce</a>, <a href="/recipes/tags/twitter/">twitter</a>).
</p>
<p>Requires: <a href="http://code.google.com/p/tweet-sauce/">tweet-sauce</a></p>
<p>Replies to anyone who @replies the logged user. </p>
Efficient generation of permutations (Python)
2008-12-22T06:11:55-08:00nnarulahttp://code.activestate.com/recipes/users/4168533/http://code.activestate.com/recipes/576593-efficient-generation-of-permutations/
<p style="color: grey">
Python
recipe 576593
by <a href="/recipes/users/4168533/">nnarula</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/permutations/">permutations</a>).
</p>
<p>This code builds an iterator on the fly that will successfully return unique permutations of n integers, m at a time (nPm). It does not use recursion, so stack size is not a problem.
Sample usage
it= build(n,p) <br />
it.next() # returns permutation</p>
<p>it=build(n) is the same as build(n,n) do it will generate n! unique permuatations.</p>
<p>I worte it over the weekend and have tested it reasonably for n upto 30 and p from 1 to 30 </p>
Spherical Polar Coordinates (Python)
2008-08-26T08:49:39-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576457-spherical-polar-coordinates/
<p style="color: grey">
Python
recipe 576457
by <a href="/recipes/users/4166679/">alexander baker</a>
(<a href="/recipes/tags/mechanics/">mechanics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/polar/">polar</a>, <a href="/recipes/tags/quantum/">quantum</a>).
</p>
<p>Spherical Polar Coordinates
<a href="http://www.alexfb.com/cgi-bin/twiki/view/PtPhysics/Spherical-Polar-Coordinates-Python" rel="nofollow">http://www.alexfb.com/cgi-bin/twiki/view/PtPhysics/Spherical-Polar-Coordinates-Python</a></p>