Popular recipes tagged "meta:loc=71"http://code.activestate.com/recipes/tags/meta:loc=71/2015-01-15T16:09:27-08:00ActiveState Code RecipesPublish databases to PDF with PyDAL (a Python DB library) and xtopdf (Python)
2015-01-15T16:09:27-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579004-publish-databases-to-pdf-with-pydal-a-python-db-li/
<p style="color: grey">
Python
recipe 579004
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pydal/">pydal</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python_developer_tools/">python_developer_tools</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/web2py/">web2py</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to use the PyDAL database library for Python, together with xtopdf, a PDF creation library for Python, to publish database data to PDF. PyDAL was earlier a part of the web2py Python web framework, and then was split out into a separate library that does not need to be used with web2py. It supports access to many popular relational databases, both open source and proprietary.</p>
ascii anamation module (Python)
2013-08-22T16:20:58-07:00Andrew Wayne Teesdale Jr.http://code.activestate.com/recipes/users/4187305/http://code.activestate.com/recipes/578622-ascii-anamation-module/
<p style="color: grey">
Python
recipe 578622
by <a href="/recipes/users/4187305/">Andrew Wayne Teesdale Jr.</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/text_anamation/">text_anamation</a>).
Revision 2.
</p>
<p>module to anamate text using a simple hack
def clear():
print "\n"*1000</p>
Compare algorithms for heapq.smallest (Python)
2011-12-25T23:41:23-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577573-compare-algorithms-for-heapqsmallest/
<p style="color: grey">
Python
recipe 577573
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/benchmark/">benchmark</a>, <a href="/recipes/tags/heaps/">heaps</a>, <a href="/recipes/tags/performance/">performance</a>).
Revision 3.
</p>
<p>General purpose technique for counting comparisons in various searching and sorting applications.</p>
Lattice Multiplication (Python)
2011-07-07T07:07:59-07:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/577782-lattice-multiplication/
<p style="color: grey">
Python
recipe 577782
by <a href="/recipes/users/4174477/">Thomas Lehmann</a>
(<a href="/recipes/tags/lattice/">lattice</a>, <a href="/recipes/tags/multiplication/">multiplication</a>).
</p>
<p>The documentation in the function explains the algorithm but there are additional pages which provide additional visual help:</p>
<ul>
<li><a href="http://mathforum.org/library/drmath/view/52468.html" rel="nofollow">http://mathforum.org/library/drmath/view/52468.html</a></li>
<li><a href="http://en.wikipedia.org/wiki/Multiplication_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Multiplication_algorithm</a></li>
</ul>
<p>The function can handle a string as well as a sequence of digits. The test function is just to have a basic verification.</p>
Running 2Balls in Vpython by Flip-Flopping. (Python)
2011-07-17T16:50:01-07:00Dominic Innocenthttp://code.activestate.com/recipes/users/4178543/http://code.activestate.com/recipes/577797-running-2balls-in-vpython-by-flip-flopping/
<p style="color: grey">
Python
recipe 577797
by <a href="/recipes/users/4178543/">Dominic Innocent</a>
(<a href="/recipes/tags/vpython/">vpython</a>).
</p>
<p>Getting Vpython to run 2 moving objects is tricky as it tends to focus on only one. The answer I have used is to 'Flip-Flop' between the 2 blocks of code running each object; Set up 2 values for the flip-flop K & P. At the end of each nested 'While' P will be incramented (p=p+1). K is the remainder of P/2 (k=p%2). If k = 0 Flip! If k != 0 Flop!. I haven't got it to recognise a 'collision' event yet; & that is very Frustrating!</p>
OrderedSet (Python)
2011-08-12T14:15:20-07:00Jonathan Blakeshttp://code.activestate.com/recipes/users/4177368/http://code.activestate.com/recipes/577624-orderedset/
<p style="color: grey">
Python
recipe 577624
by <a href="/recipes/users/4177368/">Jonathan Blakes</a>
.
Revision 2.
</p>
<p>Set that remembers original insertion order.</p>
Minimalistic PostgreSQL console shell (Python)
2011-11-30T13:43:28-08:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/577468-minimalistic-postgresql-console-shell/
<p style="color: grey">
Python
recipe 577468
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/postgres/">postgres</a>, <a href="/recipes/tags/postgresql/">postgresql</a>, <a href="/recipes/tags/sql/">sql</a>).
Revision 17.
</p>
<p>Primitive shell for running PostgreSQL quieries from console. Make sure you set the right connection settings in the script.</p>
<p>All queries are executed in autocommit mode.</p>
<p>Example command line usage:</p>
<pre class="prettyprint"><code>pg.py select * from mytable where oidh=1
</code></pre>
<p>The script recognizes a number of magic keywords:</p>
<pre class="prettyprint"><code>pg.py show databases
pg.py show schemas
pg.py describe <table_name>
</code></pre>
Recoursive File Moving (Python)
2010-09-28T19:01:24-07:00shawnhttp://code.activestate.com/recipes/users/4175099/http://code.activestate.com/recipes/577411-recoursive-file-moving/
<p style="color: grey">
Python
recipe 577411
by <a href="/recipes/users/4175099/">shawn</a>
(<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/recursion/">recursion</a>).
Revision 3.
</p>
<p>This script is placed in a location then run. All files underneath the root will be propagated to the top level, while deleting any old directory's.</p>
<p>Problems: If you have large files in nested folders you will be copying them multiple times.</p>
<p>p.s. shoulda used walk() but i'm newb</p>
PHP 'Struct' port (PHP)
2010-03-28T01:22:31-07:00Jeff Griffithshttp://code.activestate.com/recipes/users/835605/http://code.activestate.com/recipes/577160-php-struct-port/
<p style="color: grey">
PHP
recipe 577160
by <a href="/recipes/users/835605/">Jeff Griffiths</a>
(<a href="/recipes/tags/iterator/">iterator</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/oop/">oop</a>).
Revision 2.
</p>
<p>In Ruby, the <a href="http://ruby-doc.org/core/classes/Struct.html">Struct class</a> is a convenient way to create a hash-like object on the fly and use it for your nefarious purposes. PHP 5+ can be convinced to do this type of things as well, it just doesn't have it out of the box. Here is a simple class that implements iterator and allows you to populate the internal data structure similar to how Ruby's Struct works. Syntactic sugar? Probably.</p>
<p>Note: I haven't bothered to implement the Ruby Struct API per se, Instead I just got something similar by implementing the Iterator interface and keeping things very PHP-like.</p>
Using proxy connection for QWebView (Python)
2009-10-02T02:32:51-07:00Keisuke URAGOhttp://code.activestate.com/recipes/users/668964/http://code.activestate.com/recipes/576921-using-proxy-connection-for-qwebview/
<p style="color: grey">
Python
recipe 576921
by <a href="/recipes/users/668964/">Keisuke URAGO</a>
(<a href="/recipes/tags/browser/">browser</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/pyqt/">pyqt</a>, <a href="/recipes/tags/qt4/">qt4</a>, <a href="/recipes/tags/web/">web</a>).
Revision 4.
</p>
<p>QWebView is powerful web browser. This script can use a http-proxy host.
Log file name is minibrowser.log in same directory.</p>
pyGTK threading (Python)
2009-04-01T07:07:56-07:00oohay_email2004http://code.activestate.com/recipes/users/4169723/http://code.activestate.com/recipes/576705-pygtk-threading/
<p style="color: grey">
Python
recipe 576705
by <a href="/recipes/users/4169723/">oohay_email2004</a>
(<a href="/recipes/tags/pygtk/">pygtk</a>, <a href="/recipes/tags/threading/">threading</a>).
Revision 2.
</p>
<p>This is my first successful attempt at threading in pyGTK.</p>
<p>Suggestions please.</p>
Converting MySQL database to an Amazon Simple DB database (Python)
2008-10-31T11:55:16-07:00Chris McAvoyhttp://code.activestate.com/recipes/users/4167739/http://code.activestate.com/recipes/576548-converting-mysql-database-to-an-amazon-simple-db-d/
<p style="color: grey">
Python
recipe 576548
by <a href="/recipes/users/4167739/">Chris McAvoy</a>
(<a href="/recipes/tags/amazon/">amazon</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/mysql/">mysql</a>, <a href="/recipes/tags/simpledb/">simpledb</a>).
</p>
<p>This script will take all the tables from a given MySQL database and upload them to Amazon SimpleDB as Domains. The 'name' of each uploaded record is the value of the first primary key found in the table.</p>
<p>This was written to scratch a particular itch, I've tested it against a 500mb database of my own, but didn't try overly hard to make it an all purpose general tool.</p>
Changing shortcut on a usb key V2 (Python)
2008-08-22T13:34:57-07:00bussiere bussierehttp://code.activestate.com/recipes/users/4050557/http://code.activestate.com/recipes/576437-changing-shortcut-on-a-usb-key-v2/
<p style="color: grey">
Python
recipe 576437
by <a href="/recipes/users/4050557/">bussiere bussiere</a>
(<a href="/recipes/tags/key/">key</a>, <a href="/recipes/tags/raccourcis/">raccourcis</a>, <a href="/recipes/tags/shortcut/">shortcut</a>, <a href="/recipes/tags/usb/">usb</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 2.
</p>
<p>i've made some shortcut on my usb key for launchy and i had always to change them if on one pc the usb drive was i: on an other it was k: it was such a pain each time.
Now it change all the shortcut automatically.</p>
Simplest Registry I/O (Python)
2007-08-24T12:38:48-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/528896-simplest-registry-io/
<p style="color: grey">
Python
recipe 528896
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>Most of the time I just want to either read or write one value to the registry. Here are two functions: ReadRegistryValue and WriteRegistryValue plus a few helpers.</p>
pipe convenience function for doing pipes as in bash (Python)
2006-03-24T00:38:28-08:00George Benkohttp://code.activestate.com/recipes/users/2826167/http://code.activestate.com/recipes/475171-pipe-convenience-function-for-doing-pipes-as-in-ba/
<p style="color: grey">
Python
recipe 475171
by <a href="/recipes/users/2826167/">George Benko</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>Allows arbitrary number of commands to be strung together with each one feeding into the next ones input. Syntax is simple: x=pipe("cmd1", "cmd2", "cmd3").read() is equivalent to bash command x=<code>cmd1 | cmd2 | cmd3</code>.</p>
<p>Works under python 2.4.2</p>
Exposing a COM component as a web service via XMLRPC with CherryPy (windows-specific) (Python)
2004-11-23T10:36:18-08:00gian paolo cicerihttp://code.activestate.com/recipes/users/631476/http://code.activestate.com/recipes/347209-exposing-a-com-component-as-a-web-service-via-xmlr/
<p style="color: grey">
Python
recipe 347209
by <a href="/recipes/users/631476/">gian paolo ciceri</a>
(<a href="/recipes/tags/distributed/">distributed</a>).
Revision 5.
</p>
<p>This recipe shows how to build an xmlrpc multithread server that exposes a COM component as a web service.</p>
Single parameters style for DB API modules (Python)
2004-04-16T05:32:06-07:00Denis Otkidachhttp://code.activestate.com/recipes/users/1732285/http://code.activestate.com/recipes/278612-single-parameters-style-for-db-api-modules/
<p style="color: grey">
Python
recipe 278612
by <a href="/recipes/users/1732285/">Denis Otkidach</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>This recipe allows to code SQL queries the same way independent on paramstyle of used DB module.</p>
python metakit example for safe reading and writing (Python)
2003-12-04T08:50:29-08:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/252494-python-metakit-example-for-safe-reading-and-writin/
<p style="color: grey">
Python
recipe 252494
by <a href="/recipes/users/135654/">John Nielsen</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>Metakit is a reliable/lightweight/fast database library that python can use.
Metakit has an extend mode that enables many simultaneous readers and one writer w/out needing a database server to synchronize things. Here is an example showing how to use that cool feature.</p>
Filtering out elements/attributes from a given namespace (Python)
2002-09-11T10:36:35-07:00A.M. Kuchlinghttp://code.activestate.com/recipes/users/681412/http://code.activestate.com/recipes/149284-filtering-out-elementsattributes-from-a-given-name/
<p style="color: grey">
Python
recipe 149284
by <a href="/recipes/users/681412/">A.M. Kuchling</a>
(<a href="/recipes/tags/xml/">xml</a>).
</p>
<p>This recipe shows a simple way to filter out elements and attributes
belonging to a particular namespace.</p>
installing source distributions on windows (Python)
2002-04-10T20:04:47-07:00Thomas Hellerhttp://code.activestate.com/recipes/users/98141/http://code.activestate.com/recipes/117248-installing-source-distributions-on-windows/
<p style="color: grey">
Python
recipe 117248
by <a href="/recipes/users/98141/">Thomas Heller</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
Revision 5.
</p>
<p>Distutil's bdist_wininst installers offer uninstallation support for Python extensions, many developers however only distribute sources in zip or tar.gz format. The typical steps to install such a distribution are:
- download the file
- unpack with winzip into a temporary directory
- open a command prompt and type 'python setup.py install'
- remove the temporary directory</p>
<p>This script unpacks a source distribution into a temporary directory, builds a windows installer on the fly, executes it, and cleans everything up afterward.</p>