Most viewed recipes tagged "meta:loc=30"http://code.activestate.com/recipes/tags/meta:loc=30/views/2016-03-17T12:22:10-07:00ActiveState Code RecipesPass Javascript arrays to PHP (PHP)
2005-05-16T11:45:33-07:00Noah Spurrierhttp://code.activestate.com/recipes/users/103276/http://code.activestate.com/recipes/414334-pass-javascript-arrays-to-php/
<p style="color: grey">
PHP
recipe 414334
by <a href="/recipes/users/103276/">Noah Spurrier</a>
(<a href="/recipes/tags/session/">session</a>).
</p>
<p>This is a Javascript function that will convert a Javascript array to a string in PHP serialized format. You can pass this string to a PHP script and easily unserialize it to a PHP array.</p>
Basic threaded Python TCP server (Python)
2012-09-19T17:59:01-07:00Luis Martin Gilhttp://code.activestate.com/recipes/users/4183220/http://code.activestate.com/recipes/578247-basic-threaded-python-tcp-server/
<p style="color: grey">
Python
recipe 578247
by <a href="/recipes/users/4183220/">Luis Martin Gil</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/server/">server</a>, <a href="/recipes/tags/tcp/">tcp</a>, <a href="/recipes/tags/thread/">thread</a>).
Revision 3.
</p>
<p>TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer. Sometimes you need a quick deployment of a TCP server and here I bring to you a Python 2.* snippet of a threaded Python server.</p>
Convert Microsot Excel (XLSX) to PDF with Python and xtopdf (Python)
2015-11-22T22:15:25-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579128-convert-microsot-excel-xlsx-to-pdf-with-python-and/
<p style="color: grey">
Python
recipe 579128
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/excel/">excel</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/openpyxl/">openpyxl</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xlsx/">xlsx</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how the basics of to convert the text data in a Microsoft Excel file (XLSX format) to PDF (Portable Document Format). It uses openpyxl to read the XLSX file and xtopdf to generate the PDF file.</p>
Run a task every few seconds (Python)
2001-06-18T04:31:57-07:00Itamar Shtull-Trauringhttp://code.activestate.com/recipes/users/98053/http://code.activestate.com/recipes/65222-run-a-task-every-few-seconds/
<p style="color: grey">
Python
recipe 65222
by <a href="/recipes/users/98053/">Itamar Shtull-Trauring</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>The TaskThread class allows you to create threads that execute a specific action at a specified interval, by subclassing - just override the task() method. You can also shutdown a TaskThread without having to wait for it to finish "sleeping" (due to the use of threading.Event objects as an alternative to time.sleep()).</p>
Groupby (Python)
2004-02-12T07:05:02-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/259173-groupby/
<p style="color: grey">
Python
recipe 259173
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 5.
</p>
<p>Guido inspired SQL-like GROUPBY class that also encapsulates the logic in a Unix-like "sort | uniq".</p>
thread2 -- killable threads (Python)
2012-08-09T20:14:33-07:00tomer filibahttp://code.activestate.com/recipes/users/2520014/http://code.activestate.com/recipes/496960-thread2-killable-threads/
<p style="color: grey">
Python
recipe 496960
by <a href="/recipes/users/2520014/">tomer filiba</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>A little module that extends the threading's module functionality -- allows one thread to raise exceptions in the context of another thread. By raising SystemExit, you can finally kill python threads :)</p>
custom django login_required decorator (Python)
2006-10-24T08:54:07-07:00Jian Ding Chenhttp://code.activestate.com/recipes/users/2927458/http://code.activestate.com/recipes/498217-custom-django-login_required-decorator/
<p style="color: grey">
Python
recipe 498217
by <a href="/recipes/users/2927458/">Jian Ding Chen</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>I found django's auth module is too complex for my needs, instead I wrote a relative simple one, but I miss the login_required decorator in django auth module, so I decide to write a new one.</p>
Automatic delegation as an alternative to inheritance (Python)
2001-04-08T21:03:15-07:00Alex Martellihttp://code.activestate.com/recipes/users/97991/http://code.activestate.com/recipes/52295-automatic-delegation-as-an-alternative-to-inherita/
<p style="color: grey">
Python
recipe 52295
by <a href="/recipes/users/97991/">Alex Martelli</a>
(<a href="/recipes/tags/oop/">oop</a>).
Revision 2.
</p>
<p>Python classes cannot inherit from any type, just from other classes. However, automatic delegation (via __getattr__ and __setattr__) can provide pretty much the same functionality as inheritance (without such limits, and with finer-grained control).</p>
Remove diatrical marks (including accents) from strings using latin alphabets (Python)
2009-02-11T11:40:55-08:00Sylvain Fourmanoithttp://code.activestate.com/recipes/users/4150902/http://code.activestate.com/recipes/576648-remove-diatrical-marks-including-accents-from-stri/
<p style="color: grey">
Python
recipe 576648
by <a href="/recipes/users/4150902/">Sylvain Fourmanoit</a>
(<a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_processing/">text_processing</a>).
Revision 7.
</p>
<p>Many written languages using latin alphabets employ <a href="http://en.wikipedia.org/wiki/Diacritic">diacritical marks</a>. Even today, it is still pretty common to encounter situations where it would be desirable to get rid of them: files naming, creation of easy to read URIs, indexing schemes, etc. </p>
<p>An easy way has always been to simply filter out any "decorated characters"; unfortunately, this does not preserve the base, undecorated glyphs. But thanks to Unicode support in Python, it is now straightforward to perform such a transliteration.</p>
<p>(This recipe was completely rewritten based on a comment by Mathieu Clabaut: many thanks to him!)</p>
To 'return None' from your Python-callable C function (Python)
2001-03-26T12:02:44-08:00Alex Martellihttp://code.activestate.com/recipes/users/97991/http://code.activestate.com/recipes/52309-to-return-none-from-your-python-callable-c-functio/
<p style="color: grey">
Python
recipe 52309
by <a href="/recipes/users/97991/">Alex Martelli</a>
(<a href="/recipes/tags/extending/">extending</a>).
</p>
<p>Often a function written in C for Python needs to return nothing in particular -- a "return None" in Python terms; but _don't_ just "return Py_None" from C, as that will mess up reference counts!</p>
Summary reports using itertools.groupby (Python)
2004-09-10T13:20:37-07:00Paul Moorehttp://code.activestate.com/recipes/users/1826654/http://code.activestate.com/recipes/304162-summary-reports-using-itertoolsgroupby/
<p style="color: grey">
Python
recipe 304162
by <a href="/recipes/users/1826654/">Paul Moore</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 2.
</p>
<p>Lists of data grouped by a key value are common - obvious examples are spreadsheets or other tabular arrangements of information. In many cases, the new itertools groupby function introduced in Python 2.4 can provide a means of easily generating summaries of such information.</p>
Keyword Argument Injection with Python Decorators (Python)
2010-09-05T17:06:04-07:00Ahmet Emre Aladağhttp://code.activestate.com/recipes/users/4174877/http://code.activestate.com/recipes/577382-keyword-argument-injection-with-python-decorators/
<p style="color: grey">
Python
recipe 577382
by <a href="/recipes/users/4174877/">Ahmet Emre Aladağ</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/injection/">injection</a>, <a href="/recipes/tags/variable/">variable</a>).
Revision 2.
</p>
<p>In most of the object oriented codes we write, we need to set class attributes to the given argument values and this is a very line-consuming thing. To get over these redundant lines, I found a solution using decorators. </p>
Create an ODBC data source (Python)
2005-05-22T16:48:29-07:00Mark Reeshttp://code.activestate.com/recipes/users/98082/http://code.activestate.com/recipes/414879-create-an-odbc-data-source/
<p style="color: grey">
Python
recipe 414879
by <a href="/recipes/users/98082/">Mark Rees</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>When installing database applications that use ODBC, I wanted to create the required ODBC data sources from my python install script. With the help of the ctypes module, it's simple.</p>
Logging to console .. without surprises (Python)
2009-06-25T13:12:55-07:00Sridhar Ratnakumarhttp://code.activestate.com/recipes/users/4169511/http://code.activestate.com/recipes/576819-logging-to-console-without-surprises/
<p style="color: grey">
Python
recipe 576819
by <a href="/recipes/users/4169511/">Sridhar Ratnakumar</a>
(<a href="/recipes/tags/logging/">logging</a>).
Revision 3.
</p>
<p><code>logging.StreamHandler</code> is not the best way to log to console .. as it prints everything to <code>sys.stderr</code> by default. You can configure it to log to <code>sys.stdout</code> .. but that means even error/exception will be printed to <code>sys.stdout</code>.</p>
Copy huge files on Windows avoiding system cache misbehaviour (Python)
2006-05-10T18:06:55-07:00Christos Georgiouhttp://code.activestate.com/recipes/users/418040/http://code.activestate.com/recipes/496694-copy-huge-files-on-windows-avoiding-system-cache-m/
<p style="color: grey">
Python
recipe 496694
by <a href="/recipes/users/418040/">Christos Georgiou</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>This recipe uses pywin32 in order to copy files making use of the win32file.FILE_FLAG_SEQUENTIAL_SCAN, which makes much more efficient use of the system cache (only a few megabytes are consumed instead of caching the whole file).</p>
inline java code into jython (Python)
2004-12-27T12:35:17-08:00Ferdinand Jamitzkyhttp://code.activestate.com/recipes/users/98863/http://code.activestate.com/recipes/360875-inline-java-code-into-jython/
<p style="color: grey">
Python
recipe 360875
by <a href="/recipes/users/98863/">Ferdinand Jamitzky</a>
(<a href="/recipes/tags/jython/">jython</a>).
</p>
<p>This recipe shows how to insert java code into a jython program. The java code is automatically compiled and the resulting class is imported and returned. Compilation only occurs after a change of the java source.</p>
edge-coloring of a bipartite graph (Python)
2006-09-13T01:29:41-07:00Alain Pointdexterhttp://code.activestate.com/recipes/users/612654/http://code.activestate.com/recipes/498092-edge-coloring-of-a-bipartite-graph/
<p style="color: grey">
Python
recipe 498092
by <a href="/recipes/users/612654/">Alain Pointdexter</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>
Extending socket.socketpair() to work on Windows (Python)
2007-07-22T22:36:21-07:00Bob Ziuchkovskihttp://code.activestate.com/recipes/users/4070023/http://code.activestate.com/recipes/525487-extending-socketsocketpair-to-work-on-windows/
<p style="color: grey">
Python
recipe 525487
by <a href="/recipes/users/4070023/">Bob Ziuchkovski</a>
(<a href="/recipes/tags/network/">network</a>).
</p>
<p>This recipe wraps socketpair() to provide a standard socket pair on POSIX systems or a pair of connected sockets using ephemeral ports on Windows.</p>
progress_bar.py (Python)
2006-04-30T20:33:49-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/492230-progress_barpy/
<p style="color: grey">
Python
recipe 492230
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>Progress bars are popular when trying to
show how much of a job has been completed.
In my case, it was encrypting and decrypting
files. A GUI interface was written, but
something was lacking. How was the user of
the program supposed to know if the program
was doing its job? A progress bar seemed like
a good answer, so a simple GUI progress bar
was written using Tkinter.</p>
Decrypt a PDF using fitz / MuPDF (PyMuPDF) (Python)
2016-03-17T12:22:10-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580627-decrypt-a-pdf-using-fitz-mupdf-pymupdf/
<p style="color: grey">
Python
recipe 580627
by <a href="/recipes/users/4191581/">Harald Lieder</a>
(<a href="/recipes/tags/decompression/">decompression</a>, <a href="/recipes/tags/decryption/">decryption</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/repair/">repair</a>).
</p>
<p>It's more a code snippet. Shows how to dynamically check whether a PDF is password protected. If it is, decrypt it and save it back to disk un-encrypted.</p>