Popular recipes by Przemyslaw Podczasi http://code.activestate.com/recipes/users/4179716/2016-09-22T12:25:30-07:00ActiveState Code RecipesSimple Matlab/Ocave like arrays conversion to numpy.arrays in python interpreter (Python) 2016-09-22T12:25:30-07:00Przemyslaw Podczasihttp://code.activestate.com/recipes/users/4179716/http://code.activestate.com/recipes/580700-simple-matlabocave-like-arrays-conversion-to-numpy/ <p style="color: grey"> Python recipe 580700 by <a href="/recipes/users/4179716/">Przemyslaw Podczasi</a> (<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/interpreter/">interpreter</a>, <a href="/recipes/tags/matlab/">matlab</a>). </p> <p>Matlab/Octave syntax for 1D/2D arrays is more packed and doesn't require putting extra ',' and extra '[', ']' between dimensions. For this I wrote a parser that intercepts python interpreter and using numpy functionality parses Matlab's style arrays 1D and 2D into numpy.arrays.</p> partial with out of order arguments (Python) 2011-10-27T16:54:26-07:00Przemyslaw Podczasihttp://code.activestate.com/recipes/users/4179716/http://code.activestate.com/recipes/577922-partial-with-out-of-order-arguments/ <p style="color: grey"> Python recipe 577922 by <a href="/recipes/users/4179716/">Przemyslaw Podczasi</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/partial/">partial</a>). Revision 2. </p> <p>Working with Windows API which usually takes like a zillion for each function can be a little bit frustrating and if I want to only change two in the middle for each call I had to wrap everything into lambda functions which change arguments to the order that I need to use with partial.</p> <p>So finally I added kinda dangerous decorator which inserts keywords into right position if detected and was about to use it but ctypes functions don't accept keyword arguments :D so just ended up with decorator :)</p> indefinite currying decorator with greedy call and up front args checking (Python) 2011-10-28T22:05:55-07:00Przemyslaw Podczasihttp://code.activestate.com/recipes/users/4179716/http://code.activestate.com/recipes/577928-indefinite-currying-decorator-with-greedy-call-and/ <p style="color: grey"> Python recipe 577928 by <a href="/recipes/users/4179716/">Przemyslaw Podczasi</a> (<a href="/recipes/tags/curry/">curry</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/functional/">functional</a>). Revision 2. </p> <p>Decorator makes function currying as long as there are more correct arguments to take and fires it as soon as there is enough to call, also checks arguments up front for errors.</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>