Popular recipes tagged "meta:loc=11"http://code.activestate.com/recipes/tags/meta:loc=11/2015-10-22T13:09:02-07:00ActiveState Code RecipesRecognizing speech (speech-to-text) with the Python speech module (Python) 2015-10-22T13:09:02-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579115-recognizing-speech-speech-to-text-with-the-python-/ <p style="color: grey"> Python recipe 579115 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/language_translation/">language_translation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/speech_recognition/">speech_recognition</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe shows how to use the 'speech' (or 'pyspeech' - it seems to have two names) Python library to make the computer recognize what you say and convert it to text. Note: This library did not always give correct results for me, so it may not be advisable to use it in production. Also, the pyspeech site says that the library is no longer being maintained. Use at your own risk.</p> Fluent API method decorator (Python) 2015-07-08T13:20:58-07:00Oscar Byrnehttp://code.activestate.com/recipes/users/4192487/http://code.activestate.com/recipes/579078-fluent-api-method-decorator/ <p style="color: grey"> Python recipe 579078 by <a href="/recipes/users/4192487/">Oscar Byrne</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/fluent/">fluent</a>, <a href="/recipes/tags/interface/">interface</a>). </p> <p>A decorator for producing robust fluent API interfaces by returning a copy of self</p> Send a message to remote syslog server (Perl) 2014-07-31T17:23:17-07:00Brett Carrollhttp://code.activestate.com/recipes/users/4174322/http://code.activestate.com/recipes/578916-send-a-message-to-remote-syslog-server/ <p style="color: grey"> Perl recipe 578916 by <a href="/recipes/users/4174322/">Brett Carroll</a> (<a href="/recipes/tags/perl/">perl</a>, <a href="/recipes/tags/syslog/">syslog</a>, <a href="/recipes/tags/unix/">unix</a>). Revision 2. </p> <p>This script allows sending syslog messages to a remote syslog server (UNIX).</p> String length (Batch) 2013-10-10T16:27:48-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578664-string-length/ <p style="color: grey"> Batch recipe 578664 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/length/">length</a>, <a href="/recipes/tags/string/">string</a>). Revision 2. </p> <p>A way for checking string length.</p> ascii2wide Translate printable non-whitespace ascii characters to wide characters (Python) 2013-06-20T20:23:09-07:00Gary Eakinshttp://code.activestate.com/recipes/users/470921/http://code.activestate.com/recipes/578577-ascii2wide-translate-printable-non-whitespace-asci/ <p style="color: grey"> Python recipe 578577 by <a href="/recipes/users/470921/">Gary Eakins</a> (<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/translate/">translate</a>, <a href="/recipes/tags/wide/">wide</a>). </p> <p>Translates ascii characters to wide characters.</p> Mixin for pickling objects with __slots__ (Python) 2013-01-21T08:55:57-08:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578433-mixin-for-pickling-objects-with-__slots__/ <p style="color: grey"> Python recipe 578433 by <a href="/recipes/users/2033964/">Oren Tirosh</a> (<a href="/recipes/tags/pickle/">pickle</a>, <a href="/recipes/tags/unpickle/">unpickle</a>, <a href="/recipes/tags/__slots__/">__slots__</a>). </p> <p>This mixin makes it possible to pickle/unpickle objects with __slots__ defined. </p> Reading all subvalues of key (Ruby) 2012-11-19T08:41:11-08:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578337-reading-all-subvalues-of-key/ <p style="color: grey"> Ruby recipe 578337 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/registry/">registry</a>). </p> <p>With Ruby you can make wonders ;) This snippet shows how to read all subvalues of a key at one time.</p> All [iter] is Instance of [class/type/tuple] (Python) 2012-07-26T18:09:30-07:00Jonathan Frerehttp://code.activestate.com/recipes/users/4182985/http://code.activestate.com/recipes/578226-all-iter-is-instance-of-classtypetuple/ <p style="color: grey"> Python recipe 578226 by <a href="/recipes/users/4182985/">Jonathan Frere</a> (<a href="/recipes/tags/function/">function</a>, <a href="/recipes/tags/instance/">instance</a>, <a href="/recipes/tags/isinstance/">isinstance</a>). Revision 2. </p> <p>So it turned out that I needed a way of ensuring that all members of an iterable are instances of a certain class. Here, therefore, is the <code>isallinstance()</code> function.</p> trifocal tensor from two camera matrices (Python) 2012-06-27T03:38:35-07:00J W Jhttp://code.activestate.com/recipes/users/4181154/http://code.activestate.com/recipes/578170-trifocal-tensor-from-two-camera-matrices/ <p style="color: grey"> Python recipe 578170 by <a href="/recipes/users/4181154/">J W J</a> (<a href="/recipes/tags/tensor/">tensor</a>, <a href="/recipes/tags/trifocal/">trifocal</a>). Revision 4. </p> <p>Get the 3x3x3 (27 element) trifocal tensor from two 3x4 camera matrices.</p> <pre class="prettyprint"><code>T[i,j,k] = A[j,i]*B[k,4] - A[j,4]*B[k,i] </code></pre> A Simple HTTP Web Server (Python) 2012-06-22T22:46:56-07:00Joe B. Lewishttp://code.activestate.com/recipes/users/4182556/http://code.activestate.com/recipes/578172-a-simple-http-web-server/ <p style="color: grey"> Python recipe 578172 by <a href="/recipes/users/4182556/">Joe B. Lewis</a> (<a href="/recipes/tags/httpserver/">httpserver</a>, <a href="/recipes/tags/webserver/">webserver</a>). </p> <p>A Simple python script that acts as a web server, and handles requests</p> METACLASS AND DEEPCOPY (Python) 2012-02-26T15:43:01-08:00thonpyhttp://code.activestate.com/recipes/users/4181053/http://code.activestate.com/recipes/578053-metaclass-and-deepcopy/ <p style="color: grey"> Python recipe 578053 by <a href="/recipes/users/4181053/">thonpy</a> (<a href="/recipes/tags/deepcopy/">deepcopy</a>, <a href="/recipes/tags/equal/">equal</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/sign/">sign</a>). </p> <p>I would like to solve this excercise: Traditionally object-oriented programming provides two different modes for cloning an instance or a structured data type: shallow and deep copy. The former has the effect to clone exclusively the external shell and not its content originating a quite fastidious aliasing effect. The latter, instead, copies the shell and its content recursively creating two completely separate copies of the instance.</p> <p>As you know, Python's programs suffer of the aliasing effect when you copy an instance of a class or a structured type (e.g., a list) with the = operator. As showed in the following example:</p> <p>l=[0,1,2] mylist=l mylist[2] = ’B’ mylist [1, 2, ’B’] l [1, 2, ’B’</p> <p>The exercise consists of defining a meta-class which implements the deep copy on the assignment operator and binding this to the standard class list. Such that the following behavior can be yielded</p> State FIPS Codes Dict (Python) 2011-07-01T17:22:36-07:00Zach Williamshttp://code.activestate.com/recipes/users/4178496/http://code.activestate.com/recipes/577775-state-fips-codes-dict/ <p style="color: grey"> Python recipe 577775 by <a href="/recipes/users/4178496/">Zach Williams</a> (<a href="/recipes/tags/fips/">fips</a>, <a href="/recipes/tags/fips_codes/">fips_codes</a>, <a href="/recipes/tags/state/">state</a>, <a href="/recipes/tags/states/">states</a>). </p> <p>Had to put state codes with their FIPS code into a dict, and took way longer than I expected. Thought someone else might benefit from this.</p> Make a Class Available in its Own Definition Body! (Python) 2011-09-15T05:36:36-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/577867-make-a-class-available-in-its-own-definition-body/ <p style="color: grey"> Python recipe 577867 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/metaclass/">metaclass</a>). </p> <p>This may sound too good to be true, but see for yourself. No time machines involved. Just plug in this metaclass and look for __newclass__ in your class body. It's not perfect, but the problematic corner cases are more bark than bite.</p> Wake On Lan for Python 3 (Text) 2011-03-14T16:31:14-07:00Jesús Gómezhttp://code.activestate.com/recipes/users/4172540/http://code.activestate.com/recipes/577609-wake-on-lan-for-python-3/ <p style="color: grey"> Text recipe 577609 by <a href="/recipes/users/4172540/">Jesús Gómez</a> (<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/wol/">wol</a>). </p> <p>patch to upgrade <a href="http://code.activestate.com/recipes/358449-wake-on-lan/">Wake On Lan Recipe</a> that "Switches on remote computers using WOL". </p> Safe unicode representation (Python) 2011-03-17T23:28:40-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/577614-safe-unicode-representation/ <p style="color: grey"> Python recipe 577614 by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a> (<a href="/recipes/tags/unicode/">unicode</a>). </p> <p>Safely convert any given string type (text or binary) to unicode. You won't get UnicodeDecodeError error, at the cost of ignoring those errors during conversion, which is useful for debugging and logging. This recipe requires the <a href="http://code.activestate.com/pypm/six/">six</a> package.</p> dealing with directory paths with ~ (Python) 2010-06-16T23:17:20-07:00roopeshvhttp://code.activestate.com/recipes/users/4174204/http://code.activestate.com/recipes/577270-dealing-with-directory-paths-with/ <p style="color: grey"> Python recipe 577270 by <a href="/recipes/users/4174204/">roopeshv</a> (<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/expanding/">expanding</a>, <a href="/recipes/tags/paths/">paths</a>). Revision 2. </p> <p>Dealing with directory paths which start with <code>~</code> which are passed as paramaters, to <code>os</code> module functions.</p> <p>Here is what I think python doesn't do for me:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; import os # suppose my home = curdir = /home/rv &gt;&gt;&gt; os.path.abspath('.') '/home/rv' </code></pre> <p>Now if I want to go to folder <code>/home/rv/test</code> if there is no folder by name /home/rv/~/test/</p> <pre class="prettyprint"><code># This is what happens by default. &gt;&gt;&gt; os.path.abspath('~/test') '/home/rv/~/test' &gt;&gt;&gt; os.chdir('/home/rv/some/dir') # doesn't matter if the resulting path exists or not. &gt;&gt;&gt; os.path.abspath('~/test') 'home/rv/some/dir/~/test' </code></pre> <p>This would be more sensible I guess:</p> <pre class="prettyprint"><code># if /home/rv/~/test doesn't exist &gt;&gt;&gt; os.path.abspath('~/test') '/home/rv/test' </code></pre> Komodo JS Macro - increase the number of code completion items shown (JavaScript) 2012-03-15T23:20:25-07:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577163-komodo-js-macro-increase-the-number-of-code-comple/ <p style="color: grey"> JavaScript recipe 577163 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/codeintel/">codeintel</a>, <a href="/recipes/tags/completions/">completions</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/toddw/">toddw</a>). Revision 2. </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can be used to set the number of code completion items shown in the list.</p> <p>If you set the macro to Trigger on the Komodo "After file open" event - then this setting will be always be applied to every file code completion list.</p> Find file in subdirectory (Python) 2010-02-02T11:35:53-08:00Daniel Cohnhttp://code.activestate.com/recipes/users/4172918/http://code.activestate.com/recipes/577027-find-file-in-subdirectory/ <p style="color: grey"> Python recipe 577027 by <a href="/recipes/users/4172918/">Daniel Cohn</a> (<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/subdirectory/">subdirectory</a>). Revision 2. </p> <p>Walks subdirectories to find a file and returns . Default start location is the current working directory. Optionally, a different directory can be set as the search's starting location.</p> Prime detect (Python) 2010-03-02T00:41:18-08:00mitnk kinghttp://code.activestate.com/recipes/users/4173201/http://code.activestate.com/recipes/577079-prime-detect/ <p style="color: grey"> Python recipe 577079 by <a href="/recipes/users/4173201/">mitnk king</a> . </p> <p>check a number out of prime.</p> Pretty-print XML (Python) 2009-05-13T07:47:45-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576750-pretty-print-xml/ <p style="color: grey"> Python recipe 576750 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>One-liner to pretty print an XML file using xml.dom.minidom.</p>