Popular recipes tagged "meta:loc=74"http://code.activestate.com/recipes/tags/meta:loc=74/2016-10-26T17:49:00-07:00ActiveState Code RecipesRead CSV with D and write it to PDF with Python (Python) 2016-10-26T17:49:00-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580710-read-csv-with-d-and-write-it-to-pdf-with-python/ <p style="color: grey"> Python recipe 580710 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to read data from a CSV file with a D program and write that data to a PDF file with a Python program - all in a single command-line invocation (after writing the individual programs, of course).</p> <p>It requires the xtopdf toolkit, which you can get from:</p> <p><a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p> <p>Instructions for installing xtopdf:</p> <p><a href="http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html" rel="nofollow">http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html</a></p> <p>xtopdf in turn requires the open source version of the ReportLab toolkit, which you can get from:</p> <p><a href="http://www.reportlab.com/ftp" rel="nofollow">http://www.reportlab.com/ftp</a> (<a href="http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz%29" rel="nofollow">http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz)</a></p> <p>It also requires the DMD compiler to compile the D program - this was the version used:</p> <p>DMD32 D Compiler v2.071.2</p> Create tabular PDF reports with xtopdf and tablib in Python (Python) 2014-12-25T17:48:53-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578991-create-tabular-pdf-reports-with-xtopdf-and-tablib-/ <p style="color: grey"> Python recipe 578991 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/reportgeneration/">reportgeneration</a>, <a href="/recipes/tags/reporting/">reporting</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/tablib/">tablib</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create tabular PDF reports, i.e. PDF reports containing tabular data - rows and columns, using Python, xtopdf (a PDF creation library) and tablib (a Python library for manipulating tabular data). </p> Garden Requirements Calculator (Python) 2014-09-17T22:04:36-07:00Ethan Hannhttp://code.activestate.com/recipes/users/4190746/http://code.activestate.com/recipes/578935-garden-requirements-calculator/ <p style="color: grey"> Python recipe 578935 by <a href="/recipes/users/4190746/">Ethan Hann</a> (<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/garden/">garden</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>This program takes input from the user and determines the amount of gardening materials needed for a garden. The garden is a perfect square. The four outer flowerbeds are congruent semicircles and the central flowerbed is a perfect circle. Everything else inside the garden is considered fill: stone, mulch, or other fill material.</p> List MySql databases in a Gtk.TreeView (Python) 2013-11-27T14:03:21-08:00Anonimistahttp://code.activestate.com/recipes/users/4188571/http://code.activestate.com/recipes/578774-list-mysql-databases-in-a-gtktreeview/ <p style="color: grey"> Python recipe 578774 by <a href="/recipes/users/4188571/">Anonimista</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/gtk/">gtk</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/mysqldb/">mysqldb</a>, <a href="/recipes/tags/user_interface/">user_interface</a>). </p> <p>List MySql databases in a Gtk.TreeView</p> emingoo - Extract emails from google search results (Python) 2014-07-30T07:23:36-07:00p@ntut$http://code.activestate.com/recipes/users/4183895/http://code.activestate.com/recipes/578498-emingoo-extract-emails-from-google-search-results/ <p style="color: grey"> Python recipe 578498 by <a href="/recipes/users/4183895/">p@ntut$</a> (<a href="/recipes/tags/python3/">python3</a>). Revision 2. </p> <p>This is a quick and dirty script that does not use google REST api so use this with warning. It extracts emails from google search results. <a href="http://pantuts.com/2013/03/20/emingoo-extract-emails-from-google-search-results/" rel="nofollow">http://pantuts.com/2013/03/20/emingoo-extract-emails-from-google-search-results/</a></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> Script that compares various Interest Rate term structure models. (Python) 2012-09-10T08:02:34-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578256-script-that-compares-various-interest-rate-term-st/ <p style="color: grey"> Python recipe 578256 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/finance/">finance</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>A common model used in the financial industry for modelling the short rate (think overnight rate, but actually an infinitesimally short amount of time) is the Vasicek model. # Although it is unlikely to perfectly fit the yield curve, it has some nice properties that make it a good model to work with. The dynamics of the Vasicek model are describe below.</p> <p>In this model, the parameters are constants, and the random motion is generated by the Q measure Brownian motion . An important property of the Vasicek model is that the interest rate is mean reverting to , and the tendency to revert is controlled by . Also, this process is a diffusion process, hence Markovian, which will lead to some nice closed form formulas. Finally, the future value of the interest rate is normally distributed with the distribution .</p> to change instance to immutable (Python) 2011-08-08T05:52:18-07:00KATO Kanryuhttp://code.activestate.com/recipes/users/4178894/http://code.activestate.com/recipes/577831-to-change-instance-to-immutable/ <p style="color: grey"> Python recipe 577831 by <a href="/recipes/users/4178894/">KATO Kanryu</a> (<a href="/recipes/tags/immutable/">immutable</a>, <a href="/recipes/tags/instance/">instance</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>make a class instance to immutable one. we can call fields, methods, and properties. This airms to make easier to develop multi thread object-oriented programming.</p> "tail -f" with inode monitor (Python) 2010-09-21T07:37:38-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577398-tail-f-with-inode-monitor/ <p style="color: grey"> Python recipe 577398 by <a href="/recipes/users/57155/">Denis Barmenkov</a> (<a href="/recipes/tags/inode/">inode</a>, <a href="/recipes/tags/monitor/">monitor</a>, <a href="/recipes/tags/tail/">tail</a>). Revision 3. </p> <p>Sometimes tail -f launched for log file miss the point when program recreates log file. Script in this recipe monitors inode changes for specified file and restarts tail if needed.</p> BigDirs - Where's my disk space gone? (Python) 2010-07-18T02:52:18-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577301-bigdirs-wheres-my-disk-space-gone/ <p style="color: grey"> Python recipe 577301 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/administration/">administration</a>, <a href="/recipes/tags/shortcut/">shortcut</a>). Revision 2. </p> <p>BigDirs locates directories taking up the most disk space in files at that directory level, not in the nested directories below it. In my experience this is the easiest way to find where my disk space got chewed up.</p> <p>Set DEFAULT_DIR for the root directory you wish to check. Set DEFAULT_THRESHOLD for the minimum size of the directories you wish to see in the output.</p> Pricing Asian options using mpmath (Python) 2009-11-13T01:28:24-08:00Fernando Nieuwveldthttp://code.activestate.com/recipes/users/4172088/http://code.activestate.com/recipes/576954-pricing-asian-options-using-mpmath/ <p style="color: grey"> Python recipe 576954 by <a href="/recipes/users/4172088/">Fernando Nieuwveldt</a> (<a href="/recipes/tags/computational_finance/">computational_finance</a>, <a href="/recipes/tags/laplace/">laplace</a>, <a href="/recipes/tags/mpmath/">mpmath</a>). </p> <p>I present a numerical method for pricing Asian options. The method is based on the numerical inversion of the Laplace transform. The inversion method that is used is based on Talbot contours. It is known that Geman and Yor's formula is computational expensive for low volatility cases. By using Talbots method we can reduce the timing for the low volatility cases, at least to \sigma ~ 0.05. Afterwards the method start to converge slowly. In the literature for \sigma = 0.1 the Geman and Yor formula converges slowly.</p> send a multipart email via gmail's SMTP server (Python) 2009-12-21T14:29:41-08:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/576824-send-a-multipart-email-via-gmails-smtp-server/ <p style="color: grey"> Python recipe 576824 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/gmail/">gmail</a>, <a href="/recipes/tags/smtp/">smtp</a>). Revision 3. </p> <p>This is a Python function to send an email (a) with optional text and html alternative parts and (b) via gmail's SMTP server using your gmail account.</p> Unicode String Hex Dump (Python) 2008-05-03T01:12:27-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/572181-unicode-string-hex-dump/ <p style="color: grey"> Python recipe 572181 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/debugging/">debugging</a>). Revision 3. </p> <p>Simple routine for dumping any kind of string, ascii, encoded, or unicode, to a standard hex dump. Plus read/write of unicode and encoded strings.</p> Parse patch details from a darcs inventory file (Python) 2007-06-07T14:43:18-07:00Jonathan Buchananhttp://code.activestate.com/recipes/users/4060582/http://code.activestate.com/recipes/521889-parse-patch-details-from-a-darcs-inventory-file/ <p style="color: grey"> Python recipe 521889 by <a href="/recipes/users/4060582/">Jonathan Buchanan</a> (<a href="/recipes/tags/text/">text</a>). Revision 5. </p> <p>Uses a multiline regular expression to retrieve patch details from a darcs (<a href="http://www.darcs.net" rel="nofollow">http://www.darcs.net</a>) inventory file.</p> <p>The regular expression is defined in verbose format for sanity's sake.</p> Boost.Bind in Python (a variation of Curry technique, partial function application) (Python) 2005-09-22T04:47:28-07:00Maxim Khesinhttp://code.activestate.com/recipes/users/2591465/http://code.activestate.com/recipes/440557-boostbind-in-python-a-variation-of-curry-technique/ <p style="color: grey"> Python recipe 440557 by <a href="/recipes/users/2591465/">Maxim Khesin</a> . Revision 5. </p> <p>The Boost.Bind library <a href="http://www.boost.org/libs/bind/bind.html" rel="nofollow">http://www.boost.org/libs/bind/bind.html</a> , which I use a lot in C++, has a very nice implementation of the Curry technique. The main innovation of the library is usage of 'placeholders', which allows 'currying' arbitrary parameters in the arg list (please see discussion section). I missed this library in Python, and reimplementing it in a dynamic language was a piece of cake (and I did not have to yell at my compiler to get it done ;). Enjoy!</p> List comprehensions for database requests (Python) 2005-10-04T12:44:32-07:00Pierre Quentelhttp://code.activestate.com/recipes/users/1552957/http://code.activestate.com/recipes/440653-list-comprehensions-for-database-requests/ <p style="color: grey"> Python recipe 440653 by <a href="/recipes/users/1552957/">Pierre Quentel</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>The usual way to make a request to a database is to write a string with the SQL syntax, then execute this request and get the result as a list with cursor.fetchall() or cursor.fetchone()</p> <p>Python has list comprehensions to select items in an iterable if a certain condition is true ; this is very similar to database requests</p> <p>This recipe wraps a table of a DB-API compliant database in a class that implements the iteration protocol, so that you can use the for ... in ... if ... syntax</p> Show installed MQ Queues. (Tcl) 2005-10-18T01:07:27-07:00Patrick Finneganhttp://code.activestate.com/recipes/users/1220635/http://code.activestate.com/recipes/442424-show-installed-mq-queues/ <p style="color: grey"> Tcl recipe 442424 by <a href="/recipes/users/1220635/">Patrick Finnegan</a> (<a href="/recipes/tags/websphere/">websphere</a>). </p> <p>Show installed MQ Queues.</p> Using the logging module (Python) 2005-05-04T05:41:45-07:00Christopher Dunnhttp://code.activestate.com/recipes/users/1683375/http://code.activestate.com/recipes/412552-using-the-logging-module/ <p style="color: grey"> Python recipe 412552 by <a href="/recipes/users/1683375/">Christopher Dunn</a> (<a href="/recipes/tags/debugging/">debugging</a>). Revision 7. </p> <p>This amazingly powerful module is a mystery to novices. Once you figure it out, you'll use it everywhere.</p> <p>In addition to examples, here are a couple of useful filters.</p> Authenticate users through a third party POP-server (Python) 2003-06-03T15:51:09-07:00Magnus Lyckåhttp://code.activestate.com/recipes/users/729822/http://code.activestate.com/recipes/203610-authenticate-users-through-a-third-party-pop-serve/ <p style="color: grey"> Python recipe 203610 by <a href="/recipes/users/729822/">Magnus Lyckå</a> (<a href="/recipes/tags/network/">network</a>). </p> <p>Here's an example of how an existing POP-mail account can be used to provide authentication to a python application.</p> <p>The user doesn't have to remember yet another password, and the administrator doesn't have to handle users who forgot... Instead, we associate all our users to some external POP-mail account. When they want to log in to our system, we ask them for the password to their email account.</p> <p>If we can log in to the pop server using their password, and just get a status from their mailbox (we don't peek of course) we decide that the user has authenticated himself.</p> Tkinter : moving geometry methods (Python) 2003-06-16T21:34:05-07:00Pedro Werneckhttp://code.activestate.com/recipes/users/1161684/http://code.activestate.com/recipes/202052-tkinter-moving-geometry-methods/ <p style="color: grey"> Python recipe 202052 by <a href="/recipes/users/1161684/">Pedro Werneck</a> (<a href="/recipes/tags/ui/">ui</a>). Revision 3. </p> <p>A common way to create new compound widgets is to inherit Frame, create everything you need inside it and pack this base Frame on your application. Here's an alternative to this method, that sets geometry methods and options from a wiget to another...</p>