Popular recipes tagged "meta:loc=108"http://code.activestate.com/recipes/tags/meta:loc=108/2015-03-14T01:25:49-07:00ActiveState Code Recipesstart and end date given the year and week (Python) 2015-03-14T01:25:49-07:00Fernando Peraltahttp://code.activestate.com/recipes/users/4191815/http://code.activestate.com/recipes/579034-start-and-end-date-given-the-year-and-week/ <p style="color: grey"> Python recipe 579034 by <a href="/recipes/users/4191815/">Fernando Peralta</a> (<a href="/recipes/tags/and/">and</a>, <a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/end/">end</a>, <a href="/recipes/tags/given/">given</a>, <a href="/recipes/tags/start/">start</a>, <a href="/recipes/tags/week/">week</a>, <a href="/recipes/tags/year/">year</a>). </p> <p>Determines the starting and ending date when the year and week are specified for a by-weekly report.</p> Forwards Compatibility; Generating A Function On The Fly... (Python) 2012-06-06T17:16:27-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578160-forwards-compatibility-generating-a-function-on-th/ <p style="color: grey"> Python recipe 578160 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/function/">function</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>This code auto-generates a function that converts a string to bytes only in Python Versions 3.x.x. The function will NOT be generated in Python Versions 1.4.0 to 2.7.x. See the code for all the versions tested on. Inside the code are commented-out lines to show a practical usage for this and WILL be used in future /dev/audio or /dev/dsp access that I may develop...</p> <p>See the notes right at the bottom and read all the notes inside the code...</p> <p>This is NOT Public Domain like all my other stuff but is MIT licenced...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza, G0LCU...</p> Caching decorator with timeout, selective invalidation (Python) 2005-11-05T05:47:03-08:00Greg Steffensenhttp://code.activestate.com/recipes/users/2649990/http://code.activestate.com/recipes/442513-caching-decorator-with-timeout-selective-invalidat/ <p style="color: grey"> Python recipe 442513 by <a href="/recipes/users/2649990/">Greg Steffensen</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 5. </p> <p>A caching decorator that garbage collects in a separate thread (for performance), allows each cached function to (optionally) set a custom maximum age for entries, and allows individual cache entries to be selectively invalidated.</p> A Protocol for Making Objects Immutable (Python) 2011-10-07T03:59:45-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577895-a-protocol-for-making-objects-immutable/ <p style="color: grey"> Python recipe 577895 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/freeze/">freeze</a>, <a href="/recipes/tags/immutable/">immutable</a>, <a href="/recipes/tags/mutable/">mutable</a>, <a href="/recipes/tags/unfreeze/">unfreeze</a>). </p> <p>Python already provides immutable versions of many of the mutable built-in types. Dict is the notable exception. Regardless, here is a protocol that objects may implement that facilitates turning immutable object mutable and vice-versa.</p> Simple White Noise Generator Using Standard Python In Linux. (Python) 2011-03-10T18:03:55-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577604-simple-white-noise-generator-using-standard-python/ <p style="color: grey"> Python recipe 577604 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/audio/">audio</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/noise/">noise</a>, <a href="/recipes/tags/program/">program</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/source/">source</a>). </p> <p>Simple White Noise Generator Using Standard Python In Linux - noise.py</p> <p>This code is a stand alone program to generate a signal, at the earphone sockets, of white noise.</p> <p>It needs /dev/dsp to work; if you haven't got it then install oss-compat from your distro's repository. (NOTE:- /dev/audio could also be used but I decided to use /dev/dsp to show that this was within easy reach of standard Python too.)</p> <p>Ensure the audio system is NOT in use for this to work and all the levels are set up for your normal requirements. In my case root level WAS NOT required but that does not mean that root level IS NOT required - so be aware.</p> <p>All that is required to make this a piece of audio test equipment is a cable plugged into to the earphone socket. The output level is fully controllable inside the code and the noise is generated in about 10 second bursts</p> <p>Assuming it is copied into the module(s) drawer just type:-</p> <pre class="prettyprint"><code>&gt;&gt;&gt; import noise[RETURN/ENTER] </code></pre> <p>And away you go...</p> <p>This is Public Domain and you may do with it as you like.</p> <p>Read the program for more information. (There will be more to come in the future... :)</p> <p>Enjoy finding simple solutions to often very difficult problems... ;o)</p> <p>73...</p> <p>Bazza, G0LCU...</p> <p>Team AMIGA...</p> Backtracking template method (Python) 2011-07-03T20:56:37-07:00Filippo Squillacehttp://code.activestate.com/recipes/users/4174931/http://code.activestate.com/recipes/577777-backtracking-template-method/ <p style="color: grey"> Python recipe 577777 by <a href="/recipes/users/4174931/">Filippo Squillace</a> (<a href="/recipes/tags/backtracking/">backtracking</a>, <a href="/recipes/tags/python/">python</a>). Revision 2. </p> <p>It's a faster pythonic solution for backtracking. It combine a list of choice points with a list of choices according to a function that define when a choice is assignable to a choice point. As you see, it's easy to formulate a 8 queens and 4 colors problems.</p> Context manager for low-level redirection of stdout/stderr (Python) 2012-01-26T02:14:25-08:00Greg Haskinshttp://code.activestate.com/recipes/users/4176881/http://code.activestate.com/recipes/577564-context-manager-for-low-level-redirection-of-stdou/ <p style="color: grey"> Python recipe 577564 by <a href="/recipes/users/4176881/">Greg Haskins</a> (<a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/context_manager/">context_manager</a>, <a href="/recipes/tags/f2py/">f2py</a>, <a href="/recipes/tags/fortran/">fortran</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/redirect/">redirect</a>, <a href="/recipes/tags/stdout/">stdout</a>). Revision 3. </p> <p>This context manager provides a convenient, Pythonic way to temporarily replace the file descriptors of <code>stdout</code> and <code>stderr</code>, redirecting to either <code>os.devnull</code> or files of your choosing. Swapping the C-level file descriptors is required when suppressing output from compiled extension modules, such as those built using F2PY. It functions equally well for pure-Python code. <em>UPDATE:</em> (see below).</p> Oracle Database String Search using cx_Oracle (Python) 2013-07-26T21:58:30-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577302-oracle-database-string-search-using-cx_oracle/ <p style="color: grey"> Python recipe 577302 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>). Revision 2. </p> <p>Finds all database rows in all tables that contain a given search string and outputs a CSV file for each table that has any match.</p> Pollard Rho Prime Factorization (Python) 2010-02-10T10:02:51-08:00Mukesh Tiwarihttp://code.activestate.com/recipes/users/4172899/http://code.activestate.com/recipes/577037-pollard-rho-prime-factorization/ <p style="color: grey"> Python recipe 577037 by <a href="/recipes/users/4172899/">Mukesh Tiwari</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>). Revision 4. </p> <p>This code is implementation of Pollard Rho prime factorization. As i am a bit new in python so further improvement is appreciated.Also added Brent variant.</p> Moving Plasma Fractal Applet (Java) 2010-03-26T01:28:58-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577146-moving-plasma-fractal-applet/ <p style="color: grey"> Java recipe 577146 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>). </p> <p>Moving Plasma Fractal Applet.</p> Python Syntax Highlighting in OpenOffice Impress (Python) 2009-06-04T12:24:04-07:00Bryan Colehttp://code.activestate.com/recipes/users/4170610/http://code.activestate.com/recipes/576796-python-syntax-highlighting-in-openoffice-impress/ <p style="color: grey"> Python recipe 576796 by <a href="/recipes/users/4170610/">Bryan Cole</a> (<a href="/recipes/tags/highlighting/">highlighting</a>, <a href="/recipes/tags/impress/">impress</a>, <a href="/recipes/tags/openoffice/">openoffice</a>, <a href="/recipes/tags/syntax/">syntax</a>). </p> <p>Applies python syntax highlighting to all the TextShapes (i.e. text boxes) in an OpenOffice document with the "code" graphic style applied. Typical usage is for highlighting code snippets in an Impress presentation. I have the "HighlightPython" function assigned to a menu item in my Tools menu for easy access. </p> what's the time of next seconds? (C) 2009-05-20T18:17:08-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576771-whats-the-time-of-next-seconds/ <p style="color: grey"> C recipe 576771 by <a href="/recipes/users/4170398/">J Y</a> . </p> <p>format the time of next seconds</p> Weighted choice (Python) 2006-10-30T13:48:55-08:00bearophile -http://code.activestate.com/recipes/users/2403049/http://code.activestate.com/recipes/498229-weighted-choice/ <p style="color: grey"> Python recipe 498229 by <a href="/recipes/users/2403049/">bearophile -</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). </p> <p>To choose among a list of objects using a specified frequency distribution.</p> Live Object Browser (Python) 2004-08-18T16:22:16-07:00Simon Burtonhttp://code.activestate.com/recipes/users/1214028/http://code.activestate.com/recipes/300304-live-object-browser/ <p style="color: grey"> Python recipe 300304 by <a href="/recipes/users/1214028/">Simon Burton</a> (<a href="/recipes/tags/debugging/">debugging</a>). </p> <p>Given an object, this tool throws up a gtk tree widget that maps all the references found. It dynamically builds the tree, which means it can handle large amounts of data and circular references.</p> Use jython to access an LDAP server (Python) 2003-10-23T13:42:31-07:00Zabil CMhttp://code.activestate.com/recipes/users/1414956/http://code.activestate.com/recipes/230342-use-jython-to-access-an-ldap-server/ <p style="color: grey"> Python recipe 230342 by <a href="/recipes/users/1414956/">Zabil CM</a> (<a href="/recipes/tags/jython/">jython</a>). Revision 2. </p> <p>This snippet shows how to use of jython to create an interactive environment for querying an LDAP database, searching a user/group and listing the attributes of that User/Group.</p> Yet Another Python Templating Utility (YAPTU) (Python) 2001-08-31T15:17:32-07:00Alex Martellihttp://code.activestate.com/recipes/users/97991/http://code.activestate.com/recipes/52305-yet-another-python-templating-utility-yaptu/ <p style="color: grey"> Python recipe 52305 by <a href="/recipes/users/97991/">Alex Martelli</a> (<a href="/recipes/tags/text/">text</a>). Revision 6. </p> <p>"Templating" (copying an input file to output, on the fly inserting Python expressions and statements) is a frequent need, and YAPTU is a small but complete Python module for that; expressions and statements are identified by arbitrary user-chosen regular-rexpressions.</p> Password generator (Python) 2001-06-17T00:33:26-07:00boshttp://code.activestate.com/recipes/users/99112/http://code.activestate.com/recipes/65217-password-generator/ <p style="color: grey"> Python recipe 65217 by <a href="/recipes/users/99112/">bos</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>This class generates passwords, either random or from a dictionary.</p>