Popular recipes by Nicolas Lehuen http://code.activestate.com/recipes/users/1599156/2006-04-13T10:43:13-07:00ActiveState Code RecipesSorting big files the Python 2.4 way (Python)
2006-04-13T10:43:13-07:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/466302-sorting-big-files-the-python-24-way/
<p style="color: grey">
Python
recipe 466302
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/files/">files</a>).
Revision 6.
</p>
<p>This recipe can be used to sort big files (much bigger than the available RAM) according to a key. The sort is guaranteed to be stable on Python 2.3.</p>
Asynchronous port forwarding (Python)
2006-04-06T19:25:57-07:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/483732-asynchronous-port-forwarding/
<p style="color: grey">
Python
recipe 483732
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/network/">network</a>).
Revision 2.
</p>
<p>This forward the TCP traffic from your machine to another host, and back in the the other way. It uses asynchronous socket thanks to ye olde asyncore module, which was used by Zope up until recently (they integrated the Twisted reactor). As a consequence, it should be able to handle a great number of connections without crumbling under the weight of many threads.</p>
Read tabular data from Excel spreadsheets the fast and easy way (Python)
2005-12-14T20:36:30-08:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/440661-read-tabular-data-from-excel-spreadsheets-the-fast/
<p style="color: grey">
Python
recipe 440661
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/database/">database</a>).
Revision 3.
</p>
<p>Sometimes you get an Excel spreadsheet (say, from the marketing departement) and you want to read tabular data from it (i.e. a line with column headers and lines of data). There are many ways to do this (including ODBC + mxODBC), but the easiest way I've found is this one : provide a file name and a sheet name, and read the data !</p>
An interval mapping data structure (Python)
2006-01-18T08:09:18-08:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/457411-an-interval-mapping-data-structure/
<p style="color: grey">
Python
recipe 457411
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 3.
</p>
<p>This structure is a kind of dictionary which allows you to map data intervals to values. You can then query the structure for a given point, and it returns the value associated to the interval which contains the point. Boundary values don't need to be an integer ; indeed in the unit test I use a datetime object.</p>
Use frame inspection to simplify template usage (Python)
2005-10-12T06:34:40-07:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/440685-use-frame-inspection-to-simplify-template-usage/
<p style="color: grey">
Python
recipe 440685
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
Revision 2.
</p>
<p>Using string templates to separate views from models and controllers is fine, but passing data from controllers to views is often tiresome. Using frame inspection can make things a lot more straightforward, saving you the hassle of explicitely passing each and every bit of data the template needs through boring lines of code like {'name':name}. Here is a sample with a fake templating system.</p>
Thread-safe caching object with file and HTTP implementations (Python)
2006-02-08T10:04:16-08:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/302997-thread-safe-caching-object-with-file-and-http-impl/
<p style="color: grey">
Python
recipe 302997
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 9.
</p>
<p>Implementation of an abstract, thread-safe cache with minimal locking. Four concrete implementations : a validating file cache, a validating HTTP cache, an experimental Python module cache and a function cache. Plus, an abstract cache with weak references to its values.</p>
A native implementation of threading.Lock and threading.RLock using Pyrex (Python)
2004-10-19T13:37:44-07:00Nicolas Lehuenhttp://code.activestate.com/recipes/users/1599156/http://code.activestate.com/recipes/310792-a-native-implementation-of-threadinglock-and-threa/
<p style="color: grey">
Python
recipe 310792
by <a href="/recipes/users/1599156/">Nicolas Lehuen</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>Locks or mutexes are very basic primitives used to coordinate threads operations in multi-threaded programs. Unfortunately, even if Python provides a low-level implementation of locks in the thread module, the high level implementation of threading RLock is still in Python code, which is a bit worrying since locking is always a time critical task. This recipe implements both locks in Pyrex to get the speed of native code, and gives an example of how great Pyrex is.</p>