Popular recipes tagged "meta:loc=25"http://code.activestate.com/recipes/tags/meta:loc=25/2016-12-13T11:06:14-08:00ActiveState Code RecipesAccess PDF annotations (Python) 2016-12-13T11:06:14-08:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580732-access-pdf-annotations/ <p style="color: grey"> Python recipe 580732 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/annotation/">annotation</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/pdf/">pdf</a>). </p> <p>Version 1.10.0 of PyMuPDF supports PDF annotations. Among other things they can be extracted as images and also updated to some extent.</p> Simple Audio Capture For Windows... (Python) 2014-10-17T14:39:16-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578952-simple-audio-capture-for-windows/ <p style="color: grey"> Python recipe 578952 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/audio_capture/">audio_capture</a>, <a href="/recipes/tags/capture/">capture</a>, <a href="/recipes/tags/sample/">sample</a>, <a href="/recipes/tags/signal_capture/">signal_capture</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This snippet will capture from approximately 1 second to nearly 10000 hours of audio silently using Windows SoundRecorder.exe and save automatically to a file named SAMPLE.WAV in the C:\Windows\Temp\ folder/drawer/directory. It is 16 bit signed integer depth, stereo and sampled at 44100 Hz. This is for Python 2.0.1 to 3.3.2, (my latest version).</p> <p>Enjoy finding simple solutions to very difficult problems...</p> <p>(An OSX version is on its way too...)</p> <p>Bazza...</p> deprecate decorator which accepts arguments (Python) 2013-08-23T13:24:40-07:00tlatsashttp://code.activestate.com/recipes/users/4187618/http://code.activestate.com/recipes/578650-deprecate-decorator-which-accepts-arguments/ <p style="color: grey"> Python recipe 578650 by <a href="/recipes/users/4187618/">tlatsas</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/deprecated/">deprecated</a>). Revision 2. </p> <p>The deprecate decorator can be used to warn for future or current code deprecations. It accepts a message and an optional Warning class which will be passed to the warnings.warn() function.</p> Recursive string suffix (C) 2013-05-15T08:20:56-07:00Emilianhttp://code.activestate.com/recipes/users/4186515/http://code.activestate.com/recipes/578518-recursive-string-suffix/ <p style="color: grey"> C recipe 578518 by <a href="/recipes/users/4186515/">Emilian</a> . </p> <p>Saregard</p> Read text data from the network port (Python) 2012-12-04T20:17:59-08:00anatoly techtonikhttp://code.activestate.com/recipes/users/4168147/http://code.activestate.com/recipes/578355-read-text-data-from-the-network-port/ <p style="color: grey"> Python recipe 578355 by <a href="/recipes/users/4168147/">anatoly techtonik</a> (<a href="/recipes/tags/network/">network</a>). </p> <p>Here is a way to wait for incoming text on some port and print it to the screen. This is the best technique I could come up with.</p> Fibonacci numbers (Batch) 2012-11-14T19:03:11-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578326-fibonacci-numbers/ <p style="color: grey"> Batch recipe 578326 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/fibonacci/">fibonacci</a>). Revision 2. </p> <p>Using example: fibonacci.cmd 9 (returns 55).</p> One efficient way to print the first and last line of a text file in python (Python) 2012-04-04T20:25:29-07:00Dileep D Shttp://code.activestate.com/recipes/users/4181593/http://code.activestate.com/recipes/578095-one-efficient-way-to-print-the-first-and-last-line/ <p style="color: grey"> Python recipe 578095 by <a href="/recipes/users/4181593/">Dileep D S</a> . </p> <p>First line of the file may have the header information. Getting last line from the file is a common requirement in the case of log files. How we can do that without reading the entire file to memory and doing some operation on that. The script will take filename as argument where that file is placed in the same path of the script.</p> Benchmark code with the with statement (Python) 2011-10-08T09:53:06-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577896-benchmark-code-with-the-with-statement/ <p style="color: grey"> Python recipe 577896 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/benchmark/">benchmark</a>, <a href="/recipes/tags/speed/">speed</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/timer/">timer</a>). </p> <p>Inspired by <a href="http://preshing.com/20110924/timing-your-code-using-pythons-with-statement">this post</a> I wrote this context manager to benchmark code blocks or function calls.</p> <p>Usage is incredibly simple:</p> <pre class="prettyprint"><code>with Timer(): ... # code to benchmark goes here </code></pre> <p>The time taken (in seconds) will be printed when the code block completes. To capture the time taken programmatically is almost as easy:</p> <pre class="prettyprint"><code>t = Timer() with t: ... # code to benchmark goes here time_taken = t.interval </code></pre> <p>Due to the difficulties of timing small snippets of code <em>accurately</em>, you should only use this for timing code blocks or function calls which take a significant amount of time to process. For micro-benchmarks, you should use the <code>timeit</code> module.</p> Benchmark code with the with statement (Python) 2011-10-10T04:30:11-07:00vleonhttp://code.activestate.com/recipes/users/4179537/http://code.activestate.com/recipes/577900-benchmark-code-with-the-with-statement/ <p style="color: grey"> Python recipe 577900 by <a href="/recipes/users/4179537/">vleon</a> (<a href="/recipes/tags/benchmark/">benchmark</a>, <a href="/recipes/tags/speed/">speed</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/timer/">timer</a>). </p> <p>Inspired by <a href="http://preshing.com/20110924/timing-your-code-using-pythons-with-statement">this post</a> I wrote this context manager to benchmark code blocks or function calls.</p> <p>Usage is incredibly simple:</p> <pre class="prettyprint"><code>with Timer(): ... # code to benchmark goes here </code></pre> <p>The time taken (in seconds) will be printed when the code block completes. To capture the time taken programmatically is almost as easy:</p> <pre class="prettyprint"><code>t = Timer() with t: ... # code to benchmark goes here time_taken = t.interval </code></pre> <p>Due to the difficulties of timing small snippets of code <em>accurately</em>, you should only use this for timing code blocks or function calls which take a significant amount of time to process. For micro-benchmarks, you should use the <code>timeit</code> module.</p> Windows Event Log Viewer (Python) 2010-12-12T06:40:35-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577499-windows-event-log-viewer/ <p style="color: grey"> Python recipe 577499 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>Windows Event Log Viewer</p> A multithreaded, concurrent version of map() (Python) 2010-08-16T23:04:48-07:00Wai Yip Tunghttp://code.activestate.com/recipes/users/2382677/http://code.activestate.com/recipes/577360-a-multithreaded-concurrent-version-of-map/ <p style="color: grey"> Python recipe 577360 by <a href="/recipes/users/2382677/">Wai Yip Tung</a> (<a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/multithreading/">multithreading</a>, <a href="/recipes/tags/threads/">threads</a>). </p> <p>map() applies a function to a list of data sequentially. This is a variation to map that execute each function call concurrently in a thread.</p> Spawn command not found error (Tcl) 2010-09-24T16:07:59-07:00siva prasadhttp://code.activestate.com/recipes/users/4175066/http://code.activestate.com/recipes/577408-spawn-command-not-found-error/ <p style="color: grey"> Tcl recipe 577408 by <a href="/recipes/users/4175066/">siva prasad</a> . </p> <p>Installed ActiveTCL and executed the commands "teacup install --force Expect".</p> <p>I executed a script which will telnet to given ip.The following is the error.</p> <p>The system cannot find the file specified. while executing "spawn telnet $Machine".</p> <p>let me know,anything missed ?</p> <p>Thanks, Siva.</p> Singleton(subclass) with once initialization (Python) 2010-04-23T11:27:58-07:00Dmitryhttp://code.activestate.com/recipes/users/4173772/http://code.activestate.com/recipes/577208-singletonsubclass-with-once-initialization/ <p style="color: grey"> Python recipe 577208 by <a href="/recipes/users/4173772/">Dmitry</a> (<a href="/recipes/tags/initialization/">initialization</a>, <a href="/recipes/tags/singleton/">singleton</a>). </p> <p>Yet one singleton realization on Python without metaclass. Singleton may has __init__ method which will call only when first object create.</p> Yet again, one more enum for Python (Python) 2010-02-22T22:53:42-08:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/577063-yet-again-one-more-enum-for-python/ <p style="color: grey"> Python recipe 577063 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/enum/">enum</a>). </p> <p>This is a fork of recipe #577024 which describes an enum type for Python using __slots__ and read-only variables. Apart from the enum with default positional argument values, this one adds another enum type using keyword arguments.</p> Inverse modulo p (Python) 2013-01-31T23:41:21-08:00Justin Shawhttp://code.activestate.com/recipes/users/1523109/http://code.activestate.com/recipes/576737-inverse-modulo-p/ <p style="color: grey"> Python recipe 576737 by <a href="/recipes/users/1523109/">Justin Shaw</a> (<a href="/recipes/tags/mod/">mod</a>, <a href="/recipes/tags/modulo/">modulo</a>, <a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/theory/">theory</a>). Revision 4. </p> <p>Very rarely it is necessary to find the multiplicative inverse of a number in the ring of integers modulo p. Thie recipe handles those rare cases. That is, given x, an integer, and p the modulus, we seek a integer x^-1 such that x * x^-1 = 1 mod p. For example 38 is the inverse of 8 modulo 101 since 38 * 8 = 304 = 1 mod 101. The inverse only exists when a and p are relatively prime.</p> Determination of relatively frequency distribution (Python) 2009-10-01T21:56:52-07:00Donihttp://code.activestate.com/recipes/users/4171862/http://code.activestate.com/recipes/576920-determination-of-relatively-frequency-distribution/ <p style="color: grey"> Python recipe 576920 by <a href="/recipes/users/4171862/">Doni</a> . </p> <p>Determination of relatively frequency distribution</p> tarfile.extractall with read access (Python) 2009-06-04T15:48:17-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576797-tarfileextractall-with-read-access/ <p style="color: grey"> Python recipe 576797 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/tarfile/">tarfile</a>). </p> <p>Some tarballs have u-x set on directories .. this makes the program fail due to permissions. See <a href="http://bugs.python.org/issue6196" rel="nofollow">http://bugs.python.org/issue6196</a></p> Composable Functions (Python) 2008-07-12T06:08:55-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/574458-composable-functions/ <p style="color: grey"> Python recipe 574458 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/shortcuts/">shortcuts</a>). </p> <p>Decorator for the "f . g" style of function composition familiar to functional programmers.</p> Top-down, recursive pyparsing parsers without Forward() declarations (Python) 2007-09-07T14:11:38-07:00Kevin Atkinsonhttp://code.activestate.com/recipes/users/2965095/http://code.activestate.com/recipes/528934-top-down-recursive-pyparsing-parsers-without-forwa/ <p style="color: grey"> Python recipe 528934 by <a href="/recipes/users/2965095/">Kevin Atkinson</a> . Revision 5. </p> <p>Pyparsing with Yacc-like parser definitions (top-down, no Forward required, even in recursive rules).</p> BaseHTTPServer with socket timeout (Python) 2007-01-14T18:00:37-08:00Rogier Steehouderhttp://code.activestate.com/recipes/users/1381917/http://code.activestate.com/recipes/499376-basehttpserver-with-socket-timeout/ <p style="color: grey"> Python recipe 499376 by <a href="/recipes/users/1381917/">Rogier Steehouder</a> . Revision 2. </p> <p>BaseHTTPServer blocks while waiting for a connection. This means that a script will not respond to anything until it receives a network connection, which may never come. By adding a timeout to the listening socket, the script will regain control every so often.</p>