Popular recipes tagged "meta:license=psf"http://code.activestate.com/recipes/tags/meta:license=psf/2016-09-18T20:39:20-07:00ActiveState Code RecipesDBF reader and writer -- selective fields and nullreplace (Python)
2016-09-18T20:39:20-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/580696-dbf-reader-and-writer-selective-fields-and-nullrep/
<p style="color: grey">
Python
recipe 580696
by <a href="/recipes/users/4189558/">Tomas Nordin</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>This fork assumes a desire for limited selection of field names. With
huge files this might be necessary on some machines.</p>
<p>Also, assuming that the meaning of null in a dbf file means zero might
be a mistake, so the fork adds an argument nullreplace as way to
choose what to replace null with. Null is sometimes used to mean
missing value. This change is decoupled from the selective names
feature.</p>
Persistent Queue (Python)
2015-11-12T06:45:12-08:00zhangkaizhaohttp://code.activestate.com/recipes/users/4189594/http://code.activestate.com/recipes/579124-persistent-queue/
<p style="color: grey">
Python
recipe 579124
by <a href="/recipes/users/4189594/">zhangkaizhao</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>A class for persistent queues.</p>
Print Hook (Python)
2015-12-04T02:51:42-08:00kauliehttp://code.activestate.com/recipes/users/4193226/http://code.activestate.com/recipes/579132-print-hook/
<p style="color: grey">
Python
recipe 579132
by <a href="/recipes/users/4193226/">kaulie</a>
(<a href="/recipes/tags/debugging/">debugging</a>).
</p>
<p>Hook on stdout and stderr so that we can handle
printing of text,error differently
e.g in GUI base application divert text to a log window.</p>
getch()-like unbuffered character reading from stdin on both Windows and Unix (Python)
2015-08-19T04:45:51-07:00jwhite88http://code.activestate.com/recipes/users/4192711/http://code.activestate.com/recipes/579095-getch-like-unbuffered-character-reading-from-stdin/
<p style="color: grey">
Python
recipe 579095
by <a href="/recipes/users/4192711/">jwhite88</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>A small utility class to read single characters from standard input, on both Windows and UNIX systems. It provides a getch() function-like instance.</p>
<p>This extends the original script by adding a timeout necessary for another project.</p>
edge-coloring of a bipartite graph (Python)
2015-07-30T13:40:41-07:00Praveenhttp://code.activestate.com/recipes/users/4192603/http://code.activestate.com/recipes/579088-edge-coloring-of-a-bipartite-graph/
<p style="color: grey">
Python
recipe 579088
by <a href="/recipes/users/4192603/">Praveen</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>Konig's theorem tells us that every bipartite graph with maximum vertex-degree d can be edge-colored with just d colors.
This recipe relies on a previous recipe by D.Eppstein (123641) : "Hopcroft-Karp bipartite matching".</p>
start 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>
Python ADO Database Interface for MS SQL Server - Python 3 version 1.0 (Python)
2014-08-27T16:04:04-07:00Jorge Besadahttp://code.activestate.com/recipes/users/100038/http://code.activestate.com/recipes/578913-python-ado-database-interface-for-ms-sql-server-py/
<p style="color: grey">
Python
recipe 578913
by <a href="/recipes/users/100038/">Jorge Besada</a>
(<a href="/recipes/tags/ado/">ado</a>, <a href="/recipes/tags/database/">database</a>).
Revision 3.
</p>
<p>This DBI implements the Cursor and Connection objects. You can create connections, cursors, do fetchone, fetchall. It uses ADO. Will add more features later </p>
Creating a single instance application (Python)
2014-11-20T11:59:46-08:00Matteo Bertinihttp://code.activestate.com/recipes/users/4191156/http://code.activestate.com/recipes/578966-creating-a-single-instance-application/
<p style="color: grey">
Python
recipe 578966
by <a href="/recipes/users/4191156/">Matteo Bertini</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>Sometimes it is necessary to ensure that only one instance of application is running. This quite simple solution uses mutex to achieve this, and will run only on Windows platform.</p>
Python Database Interface for MS SQL Server - Python 3 version (Python)
2014-07-11T19:25:48-07:00Jorge Besadahttp://code.activestate.com/recipes/users/100038/http://code.activestate.com/recipes/578906-python-database-interface-for-ms-sql-server-python/
<p style="color: grey">
Python
recipe 578906
by <a href="/recipes/users/100038/">Jorge Besada</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>This DBI implements the Cursor and Connection objects. It is functional: you can create connections, cursors, do fetchone, fetchall, get rowcount, etc. It uses osql or sqlcmd instead of ODBC or ADO. There is a good sized section with examples to get you started. </p>
Convert Wordpress Export File to multiple html files (Python)
2014-06-15T03:17:19-07:00rrebotohttp://code.activestate.com/recipes/users/4190203/http://code.activestate.com/recipes/578892-convert-wordpress-export-file-to-multiple-html-fil/
<p style="color: grey">
Python
recipe 578892
by <a href="/recipes/users/4190203/">rreboto</a>
(<a href="/recipes/tags/xml/">xml</a>).
</p>
<p>Converts Wordpress Export Files (XML) to multiple html files and optionally uses tags and authors to create a directory structure.</p>
The Secret Name of List Comprehensions (Python)
2014-04-21T20:09:43-07:00He Guhttp://code.activestate.com/recipes/users/4189822/http://code.activestate.com/recipes/578865-the-secret-name-of-list-comprehensions/
<p style="color: grey">
Python
recipe 578865
by <a href="/recipes/users/4189822/">He Gu</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
</p>
<p>Sometimes you want to have a list comprehension refer to itself, but you can't because it isn't bound to a name until after it is fully constructed. However, the interpreter creates a secret name that only exists while the list is being built. That name is (usually) "_[1]", and it refers to the bound method "append" of the list. This is our back door to get at the list object itself.</p>
MultiListbox Tkinter widget (Python)
2014-01-03T19:23:48-08:00Juan Ramirezhttp://code.activestate.com/recipes/users/4174026/http://code.activestate.com/recipes/578805-multilistbox-tkinter-widget/
<p style="color: grey">
Python
recipe 578805
by <a href="/recipes/users/4174026/">Juan Ramirez</a>
(<a href="/recipes/tags/ui/">ui</a>).
</p>
<p>This is a compound widget that gangs multiple Tk Listboxes to a single
scrollbar to achieve a simple multi-column scrolled listbox. Most of
the Listbox API is mirrored to make it act like the normal Listbox
but with multiple values per row.</p>
Stopwatch with laps in Tkinter (Python)
2013-09-19T18:42:10-07:00Fredericohttp://code.activestate.com/recipes/users/4187878/http://code.activestate.com/recipes/578666-stopwatch-with-laps-in-tkinter/
<p style="color: grey">
Python
recipe 578666
by <a href="/recipes/users/4187878/">Frederico</a>
(<a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>This is a small implementation of a stopwatch widget in Tkinter. The widget displays a label with minutes:seconds:1/100-seconds. The label is updated every 50 ms, but that can easily be changed. Methods are availble for starting, stopping and resetting the stopwatch. A simple program demonstrates the widget.</p>
Wrap a a file-like object in another that calls a user callback whenever read() is called on it. (Python)
2013-09-25T01:54:53-07:00Martin Millerhttp://code.activestate.com/recipes/users/155538/http://code.activestate.com/recipes/578674-wrap-a-a-file-like-object-in-another-that-calls-a-/
<p style="color: grey">
Python
recipe 578674
by <a href="/recipes/users/155538/">Martin Miller</a>
(<a href="/recipes/tags/callback/">callback</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/progress/">progress</a>, <a href="/recipes/tags/upload/">upload</a>).
</p>
<p>Wraps a file-like object in another, but also calls a user callback with the number of bytes read whenever its <code>read()</code> method is called. Used for tracking upload progress, for example for a progress bar in a UI application.</p>
pack multiple images of different sizes into one image (Python)
2013-06-27T14:50:37-07:00Hugohttp://code.activestate.com/recipes/users/4183663/http://code.activestate.com/recipes/578585-pack-multiple-images-of-different-sizes-into-one-i/
<p style="color: grey">
Python
recipe 578585
by <a href="/recipes/users/4183663/">Hugo</a>
(<a href="/recipes/tags/graphics/">graphics</a>).
</p>
<p>Packing images of different sizes into one image is often required in order to efficiently use hardware accelerated texture mapping functions of 3D video cards.</p>
Observer Pattern (Python)
2013-03-09T10:03:10-08:00Mauro B. Bianchttp://code.activestate.com/recipes/users/4185493/http://code.activestate.com/recipes/578484-observer-pattern/
<p style="color: grey">
Python
recipe 578484
by <a href="/recipes/users/4185493/">Mauro B. Bianc</a>
(<a href="/recipes/tags/cascade/">cascade</a>, <a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/pattern/">pattern</a>, <a href="/recipes/tags/patterns/">patterns</a>, <a href="/recipes/tags/setattr/">setattr</a>, <a href="/recipes/tags/__setattr__/">__setattr__</a>).
Revision 2.
</p>
<p>This is a Python implementation of the observer pattern described by Gamma et. al.
It defines a one-to many dependency between objects so that when one object changes state,
all its dependents (i.e. observers) are notified and updated automatically.</p>
<p>My adaptation gets rid of the need to use specific functions to set the data (and to call Notify)
and allows you to be notified for ANY attribute you set.
It is possible to specify a list of attributes which should not trigger a notification.
In case you need the opposite, it is very easy to invert the behavior of the code.</p>
<p>The example should output:
Creating data1 without notification for attrs name & surname <br />
Creating data2 without notification for attr age <br />
Setting data1.name=Heather - Notification unnecessary <br />
Setting data1.num=333 - Notification expected <br />
Observer1: Subject Heather has updated attr num to 333 <br />
Setting data2.name=Molly - Notification expected <br />
Observer2: Subject Molly has updated attr name to Molly <br />
Setting data2.age=28 - Notification unnecessary <br />
Setting data2.eyecolor=blue - Notification expected <br />
Observer2: Subject Molly has updated attr eyecolor to blue </p>
Linear equations solver in 3 lines (Python)
2013-03-07T07:33:09-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578481-linear-equations-solver-in-3-lines/
<p style="color: grey">
Python
recipe 578481
by <a href="/recipes/users/4183429/">Deepak</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>Just a little bit of hack: a linear equations solver using eval and built-in complex numbers:</p>
<pre class="prettyprint"><code>>>> solve("x - 2*x + 5*x - 46*(235-24) = x + 2")
3236.0
</code></pre>
First Class Enums in Python (Python)
2013-03-07T08:23:46-08:00Deepakhttp://code.activestate.com/recipes/users/4183429/http://code.activestate.com/recipes/578482-first-class-enums-in-python/
<p style="color: grey">
Python
recipe 578482
by <a href="/recipes/users/4183429/">Deepak</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>True immutable symbolic enumeration with qualified value access.</p>
Observer Pattern (Python)
2013-02-04T20:55:10-08:00Ilya Pashchenkohttp://code.activestate.com/recipes/users/4185152/http://code.activestate.com/recipes/578449-observer-pattern/
<p style="color: grey">
Python
recipe 578449
by <a href="/recipes/users/4185152/">Ilya Pashchenko</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>This is a Python implementation of the observer pattern described by Gamma et. al. It defines a one-to many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.</p>
<p>The example should output:
Setting Data 1 = 10
DecimalViewer: Subject Data 1 has data 10
HexViewer: Subject Data 1 has data 0xa
Setting Data 2 = 15
HexViewer: Subject Data 2 has data 0xf
DecimalViewer: Subject Data 2 has data 15
Setting Data 1 = 3
DecimalViewer: Subject Data 1 has data 3
HexViewer: Subject Data 1 has data 0x3
Setting Data 2 = 5
HexViewer: Subject Data 2 has data 0x5
DecimalViewer: Subject Data 2 has data 5
Detach HexViewer from data1 and data2.
Setting Data 1 = 10
DecimalViewer: Subject Data 1 has data 10
Setting Data 2 = 15
DecimalViewer: Subject Data 2 has data 15</p>
Factory pattern (Python)
2013-02-04T21:12:27-08:00Ilya Pashchenkohttp://code.activestate.com/recipes/users/4185152/http://code.activestate.com/recipes/578450-factory-pattern/
<p style="color: grey">
Python
recipe 578450
by <a href="/recipes/users/4185152/">Ilya Pashchenko</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>In the factory pattern you have an object that creates other objects.</p>