Popular recipes tagged "meta:loc=65"http://code.activestate.com/recipes/tags/meta:loc=65/2015-03-29T20:45:57-07:00ActiveState Code RecipesShortcut Utility (Python)
2015-03-29T20:45:57-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579041-shortcut-utility/
<p style="color: grey">
Python
recipe 579041
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/desktop/">desktop</a>, <a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/ui/">ui</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>).
</p>
<p>I dislike filling my desktop with shortcut icons in Windows.
This code enables creating shortcuts in a CSV file.</p>
Humanize decorator (Python)
2013-07-31T16:04:13-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/578619-humanize-decorator/
<p style="color: grey">
Python
recipe 578619
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/objects/">objects</a>, <a href="/recipes/tags/pretty/">pretty</a>, <a href="/recipes/tags/print/">print</a>).
</p>
<p>When you need to inspect Python objects in a human-readable way, you're usually required to implement a custom <code>__str__</code> or <code>__repr__</code> which are just boilerplate (e.g., <code>return "Foo(%r, %r, %r)" % (self.bar, self.spam, self.eggs)</code>. You may implement <code>__str__</code> and <code>__repr__</code> by a base-class, but it's hard to call it <em>inheritance</em> and moreover, you may wish to remove it when you're done debugging.</p>
<p>This simple (yet complete) recipe is a class decorator that injects <code>__str__</code> and <code>__repr__</code> into the class being printed. It handles nesting and even cycle detection, allowing you to just plug it into existing classes to get them pretty-printed and perhaps remove it later.</p>
Create .CAB or .ZIP with batch (Batch)
2012-11-01T18:33:32-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578315-create-cab-or-zip-with-batch/
<p style="color: grey">
Batch
recipe 578315
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/cab/">cab</a>, <a href="/recipes/tags/cscript/">cscript</a>, <a href="/recipes/tags/zip/">zip</a>).
</p>
<p>Naturally, commnad language hasn't native methods to create archives but there is no obstacle to use JScript inside a batch. By the way, this do not need creation temporary files. OK, how does it work? Maybe you heard about conditional compilation in JScript, so you must be familiar with this trick. Take a look at this:</p>
actorish decorator for making async code look more like sync one and a less blocking (Python)
2011-10-30T19:59:44-07:00Przemyslaw Podczasihttp://code.activestate.com/recipes/users/4179716/http://code.activestate.com/recipes/577931-actorish-decorator-for-making-async-code-look-more/
<p style="color: grey">
Python
recipe 577931
by <a href="/recipes/users/4179716/">Przemyslaw Podczasi</a>
(<a href="/recipes/tags/actor/">actor</a>, <a href="/recipes/tags/threading/">threading</a>).
</p>
<p>I like how gevent is making async code to look like sync but non blocking without all the ugly callbacks.
I tried doing that with threads and object proxy (I found great one at: <a href="http://pypi.python.org/pypi/ProxyTypes" rel="nofollow">http://pypi.python.org/pypi/ProxyTypes</a> written by Phillip J. Eby, and this is where the actual magic happens).</p>
<p>For every function that is decorated it returns a proxy and the io call (or anything else) won't block until the value is actually needed.
(should be some pools and args pickling there, to make it more like message passing but I didn't want to fuzzy the example)
To use it as actor model, I guess it would require to queue requests to decorated object's methods and create a single thread to process them an in LazyProxy callback set q.get() instead of t.join()</p>
Filling command line arguments with a file (Python)
2011-10-24T13:13:04-07:00obernard78+activestatehttp://code.activestate.com/recipes/users/4179024/http://code.activestate.com/recipes/577918-filling-command-line-arguments-with-a-file/
<p style="color: grey">
Python
recipe 577918
by <a href="/recipes/users/4179024/">obernard78+activestate</a>
(<a href="/recipes/tags/argparse/">argparse</a>).
</p>
<p>This is a recipe to populate command line args with the content of a file.</p>
<p>It is also an example of how to use the Action class from the argparse module.</p>
<p>I use this script in order to put frequently used options (such as for the scripts I write in config files.
I created an abstract class in order to inherit from it to implement several file formats.
Choice has been taken not to keep the file name in parsed args, but it can be done by adding:
setattr(namespace, self.dest, values)
at the end of the <code>__call__</code> method.</p>
<p>Test functions at the end (even if the ugliest I've ever written and seen) explains the way it works.</p>
PRNG Test (Python)
2010-12-04T18:51:04-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577484-prng-test/
<p style="color: grey">
Python
recipe 577484
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/random/">random</a>).
Revision 2.
</p>
<p>This is a pseudo-random number generator test.</p>
<p>(There are many known tests for pseudo-random generators
but I came up w/ this one on my own. I don't know
if it is an already known method or not.)</p>
<p>Idea is this:
Imagine if you generate a 1000-bit binary number using any
PRNG (as 1-bit at a time) what is the probability that
all bits will be 0 in the number?</p>
<p>If you had a true number generator then there is a real
probability (=1/(2**1000)) but if you use a PRNG then I would say the
probability is really 0!</p>
<p>If you had generated 2**1000 1000-bit numbers using a hypothetical
True-Random Number Generator, assuming perfectly uniform probability
distribution, then TRNG would generate 1 number that contains 1000 zeros.
That is C(1000, 1000) = 1</p>
<p>Assuming perfectly uniform probability distribution,
C(n,k) gives you how many n-digit binary numbers would contain k zeros.</p>
<p>This code generates 2**n n-bit binary numbers (one bit at a time)
using the given PRNG and compares the actual distribution to the perfect
distribution of a hypothetical True-Random Number Generator.</p>
<p>(I used n=20 in the code because the calculation takes too long.)</p>
Maclaurin's_series_ln(1+x) (Python)
2010-07-07T12:28:36-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577290-maclaurins_series_ln1x/
<p style="color: grey">
Python
recipe 577290
by <a href="/recipes/users/4155345/">Fouad Teniou</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 series. </p>
<p>The Maclaurin's series for ln(1+x) could be used to approximate the natural logarithm ln(x).</p>
Numerical Inversion of the Laplace Transform using the Talbot method. (Python)
2009-10-27T04:53:30-07:00Fernando Nieuwveldthttp://code.activestate.com/recipes/users/4172088/http://code.activestate.com/recipes/576934-numerical-inversion-of-the-laplace-transform-using/
<p style="color: grey">
Python
recipe 576934
by <a href="/recipes/users/4172088/">Fernando Nieuwveldt</a>
(<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/laplace/">laplace</a>, <a href="/recipes/tags/numerical/">numerical</a>).
Revision 5.
</p>
<p>This is a fast and highly accurate numerical method for the inversion of the Laplace transform</p>
ZipScript: Build a directly executable zipped Python script set (Python)
2010-02-11T15:32:38-08:00Glennhttp://code.activestate.com/recipes/users/4171639/http://code.activestate.com/recipes/577042-zipscript-build-a-directly-executable-zipped-pytho/
<p style="color: grey">
Python
recipe 577042
by <a href="/recipes/users/4171639/">Glenn</a>
(<a href="/recipes/tags/package/">package</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/zip/">zip</a>).
Revision 2.
</p>
<p>This function will package a python script and additional python modules, in either source or compiled form. Either are directly executable by Python 2.7/3.1 or newer.</p>
<p>Uses make-like logic to only rebuild if something is newer than the previous build.</p>
State Capitals Quiz (Python)
2009-05-28T07:45:06-07:00joedaviscpahttp://code.activestate.com/recipes/users/4170361/http://code.activestate.com/recipes/576783-state-capitals-quiz/
<p style="color: grey">
Python
recipe 576783
by <a href="/recipes/users/4170361/">joedaviscpa</a>
(<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/random/">random</a>).
</p>
<p>The program loops through all 50 states asking for the state capital. </p>
scan db to login the ssh servers (Bash)
2010-03-16T13:11:17-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576877-scan-db-to-login-the-ssh-servers/
<p style="color: grey">
Bash
recipe 576877
by <a href="/recipes/users/4170398/">J Y</a>
(<a href="/recipes/tags/awk/">awk</a>, <a href="/recipes/tags/bash/">bash</a>).
Revision 2.
</p>
<p>awk with parameters passed from bash</p>
Printing with Python and pyGTK (Python)
2009-06-25T13:54:34-07:00Mark Muzenhardthttp://code.activestate.com/recipes/users/4170846/http://code.activestate.com/recipes/576820-printing-with-python-and-pygtk/
<p style="color: grey">
Python
recipe 576820
by <a href="/recipes/users/4170846/">Mark Muzenhardt</a>
(<a href="/recipes/tags/drawingarea/">drawingarea</a>, <a href="/recipes/tags/gtk/">gtk</a>, <a href="/recipes/tags/print/">print</a>, <a href="/recipes/tags/pygtk/">pygtk</a>).
Revision 2.
</p>
<p>PyGTK is a very powerful GUI-Toolkit. Nearly everything is well documented, except how to print. I messed around for hours just to solve this problem so I decided to share this cool piece of code!</p>
a list (C)
2009-05-20T18:19:52-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576772-a-list/
<p style="color: grey">
C
recipe 576772
by <a href="/recipes/users/4170398/">J Y</a>
(<a href="/recipes/tags/list/">list</a>).
</p>
<p>what am i doing?</p>
Dependency resolver (Python)
2008-11-23T07:43:01-08:00Florian Mayerhttp://code.activestate.com/recipes/users/4165843/http://code.activestate.com/recipes/576569-dependency-resolver/
<p style="color: grey">
Python
recipe 576569
by <a href="/recipes/users/4165843/">Florian Mayer</a>
(<a href="/recipes/tags/dependecy/">dependecy</a>, <a href="/recipes/tags/resolver/">resolver</a>).
Revision 6.
</p>
<p>Resolve dependencies of tasks.</p>
Color Module (for Windows only) (Python)
2008-06-01T10:11:47-07:00Drew Buckleyhttp://code.activestate.com/recipes/users/4154108/http://code.activestate.com/recipes/573439-color-module-for-windows-only/
<p style="color: grey">
Python
recipe 573439
by <a href="/recipes/users/4154108/">Drew Buckley</a>
.
</p>
<p>This module makes it easy to set color schemes: preset and custom.
Comes with 10 preset color schemes as well as an on-the-spot function to 'set' what ever scheme you want.
Applies only to Windows CMD (Command Prompt)</p>
N-way merge sort (Python)
2007-05-01T18:58:46-07:00Mike Klaashttp://code.activestate.com/recipes/users/4052999/http://code.activestate.com/recipes/511509-n-way-merge-sort/
<p style="color: grey">
Python
recipe 511509
by <a href="/recipes/users/4052999/">Mike Klaas</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>Merge sorted iterables with stability and built-in DSO</p>
Firefox MOD (Python)
2007-03-28T14:45:50-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/511430-firefox-mod/
<p style="color: grey">
Python
recipe 511430
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/search/">search</a>).
</p>
<p>This program fixes a file for Firefox for use on
certain intranets and demonstrates automated
file searching and editing. It was written for
use at a university of several thousand computers.</p>
Ping Technocrati with your blog URL (Python)
2006-10-31T07:42:07-08:00Mayuresh Phadkehttp://code.activestate.com/recipes/users/4009783/http://code.activestate.com/recipes/498232-ping-technocrati-with-your-blog-url/
<p style="color: grey">
Python
recipe 498232
by <a href="/recipes/users/4009783/">Mayuresh Phadke</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>Technocrati (<a href="http://www.technorati.com/" rel="nofollow">http://www.technorati.com/</a>) maintains a list of blogs tagged with user specified tags. People can submit their blogs for inclusion in Technocrati by using their RPC ping service at <a href="http://www.technorati.com/ping" rel="nofollow">http://www.technorati.com/ping</a>. This piece of code allows you ping Technocrati with blog details through a script.</p>
Sized Dictionary (Python)
2006-07-02T06:22:29-07:00James Kassemihttp://code.activestate.com/recipes/users/2916378/http://code.activestate.com/recipes/496842-sized-dictionary/
<p style="color: grey">
Python
recipe 496842
by <a href="/recipes/users/2916378/">James Kassemi</a>
(<a href="/recipes/tags/extending/">extending</a>).
Revision 2.
</p>
<p>Good demonstration of inheriting python default object types. Define a maximum size (items, not bytes) to limit to and use as a normal dictionary (be careful to have KeyError exception handling, or use the dictionary's get method with a default value).</p>
UrlAppServer (Python)
2006-02-27T13:25:24-08:00Maciej Obarskihttp://code.activestate.com/recipes/users/2559120/http://code.activestate.com/recipes/474094-urlappserver/
<p style="color: grey">
Python
recipe 474094
by <a href="/recipes/users/2559120/">Maciej Obarski</a>
(<a href="/recipes/tags/network/">network</a>).
</p>
<p>Very simple way to interact with python via http.</p>