Popular recipes tagged "meta:loc=75"http://code.activestate.com/recipes/tags/meta:loc=75/2016-09-29T18:04:57-07:00ActiveState Code RecipesPut Peewee ORM data to PDF with xtopdf (Python)
2016-09-29T18:04:57-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580704-put-peewee-orm-data-to-pdf-with-xtopdf/
<p style="color: grey">
Python
recipe 580704
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/orm/">orm</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/peewee/">peewee</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how some basics of how to fetch data from database tables managed by the Peewee ORM (a lightweight expressive ORM for Python) and write that data, formatted, to a PDF file. The recipe uses Python, the Peewee ORM and the xtopdf toolkit for PDF creation.</p>
Unix-like split command in Python (simple version) (Python)
2016-03-14T22:35:05-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580620-unix-like-split-command-in-python-simple-version/
<p style="color: grey">
Python
recipe 580620
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/split/">split</a>, <a href="/recipes/tags/splitting/">splitting</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple version of the Unix split command in Python. The split command splits an input file into multiple smaller files, the size of each of which is specified by a command-line argument giving the number of lines per file. This is useful for multiple purposes, such as editing large files in pieces, backing up files to small capacity storage devices, sending files across the network, etc.</p>
Publish SQLite data to PDF using named tuples (Python)
2015-02-24T22:08:11-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579027-publish-sqlite-data-to-pdf-using-named-tuples/
<p style="color: grey">
Python
recipe 579027
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/sqlite3/">sqlite3</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to publish SQLite data to PDF, using named tuples from the collections module of Python, the sqlite3 library, and the xtopdf library for PDF generation.</p>
All in one Area Calculator (Python)
2014-07-03T09:16:14-07:00karimhttp://code.activestate.com/recipes/users/4190244/http://code.activestate.com/recipes/578901-all-in-one-area-calculator/
<p style="color: grey">
Python
recipe 578901
by <a href="/recipes/users/4190244/">karim</a>
(<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/circlearea/">circlearea</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/tranglearea/">tranglearea</a>, <a href="/recipes/tags/trianglearea/">trianglearea</a>).
Revision 2.
</p>
<p>Its a python 3 based All in one Area Calculator.you can calculate Area of Rectangle,Area of Triangle and Area of Circle</p>
Easy Bit Arrays using Long Integers (Python)
2013-12-01T02:21:14-08:00Mike Sweeneyhttp://code.activestate.com/recipes/users/4177990/http://code.activestate.com/recipes/578777-easy-bit-arrays-using-long-integers/
<p style="color: grey">
Python
recipe 578777
by <a href="/recipes/users/4177990/">Mike Sweeney</a>
(<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/bit/">bit</a>, <a href="/recipes/tags/bitwise/">bitwise</a>, <a href="/recipes/tags/integer/">integer</a>, <a href="/recipes/tags/long/">long</a>).
</p>
<p>Some simple techniques for working with long integers as bit arrays. Python support for long integers allows fast bitwise operations on large bit arrays. Bitwise operations on 100 million bit arrays happen in the blink of an eye. They are also fast and compact when saving and loading to disk. Unfortunately bit set, get, append, pop etc are slow so another bit array technique may be preferred.</p>
Send Messages to millions of facebook Users (Python)
2013-07-08T04:33:58-07:00AJay Kumarhttp://code.activestate.com/recipes/users/4187119/http://code.activestate.com/recipes/578594-send-messages-to-millions-of-facebook-users/
<p style="color: grey">
Python
recipe 578594
by <a href="/recipes/users/4187119/">AJay Kumar</a>
(<a href="/recipes/tags/facebook/">facebook</a>).
</p>
<p>This script will allow you to send Messages to people who have a username on facebook from an email id you specify in the script.Although message will not be sent to their inbox,if you're not a friend but it will be sent to other category.</p>
type Checking in Python using decorators (version 2.0) (Python)
2012-11-19T13:15:35-08:00LL Snarkhttp://code.activestate.com/recipes/users/4180463/http://code.activestate.com/recipes/578330-type-checking-in-python-using-decorators-version-2/
<p style="color: grey">
Python
recipe 578330
by <a href="/recipes/users/4180463/">LL Snark</a>
(<a href="/recipes/tags/checking/">checking</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/type/">type</a>).
Revision 2.
</p>
<p>The two decorators checkparams and checkreturn allow you to check (at execution time) that function parameters or a function return value are the right type.</p>
Control your mouse with the Microsoft Kinect using OpenKinect (Python)
2012-03-19T21:28:08-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578082-control-your-mouse-with-the-microsoft-kinect-using/
<p style="color: grey">
Python
recipe 578082
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/computer/">computer</a>, <a href="/recipes/tags/control/">control</a>, <a href="/recipes/tags/freenect/">freenect</a>, <a href="/recipes/tags/kinect/">kinect</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/microsoft/">microsoft</a>, <a href="/recipes/tags/mouse/">mouse</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/openkinect/">openkinect</a>, <a href="/recipes/tags/vision/">vision</a>, <a href="/recipes/tags/xlib/">xlib</a>).
</p>
<p>This is a simple code that uses the Kinect in order to simulate the mouse on the screen. In order for this code to work you must have a Linux machine, the freenect module from OpenKinect, NumPy, and Xlib. The last three can be downloaded and installed by running sudo apt-get install {PROGRAM NAME HERE}. Freenect needs to be downloaded and installed for python using the terminal and there are good instructions here how to do it <a href="http://openkinect.org/wiki/Getting_Started" rel="nofollow">http://openkinect.org/wiki/Getting_Started</a>. You will also need to install the python wrapper. This can be done by following the instructions on this site: <a href="http://openkinect.org/wiki/Python_Wrapper" rel="nofollow">http://openkinect.org/wiki/Python_Wrapper</a>. To run the code you must first cd into the directory in which the code resides and then in the terminal run the command sudo python {THE NAME YOU STORED THE CODE BELOW AS}.py. This should run the code. The code needs superuser privileges. Also if you wonder why the mouse will stop tracking your hand, there are two reasons. 1) This code is not super sophisticated, all it does is find the minimum point in the depth image and scales the coordinates to the size of the screen and moves the mouse there so if your stomach is the closest thing to the screen it will track it and place the mouse there. The other reason the mouse might stop tracking is because there is a counter in the that will only let it run 10000 iterations. This is just a safety precaution in case you are not able to control the mouse and the computer freaks out. The last thing you need to know to run this code is that the main_mouse() function takes to arguments, the first is the x dimension of your screen and the second is the y dimension. THE CODE WILL NOT FUNCTION PROPERLY ON MULTIDISPLAY COMPUTERS. Thank You</p>
Selective directory walking (Python)
2011-10-20T05:05:39-07:00Nick Coghlanhttp://code.activestate.com/recipes/users/2035254/http://code.activestate.com/recipes/577913-selective-directory-walking/
<p style="color: grey">
Python
recipe 577913
by <a href="/recipes/users/2035254/">Nick Coghlan</a>
(<a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/globbing/">globbing</a>).
Revision 2.
</p>
<p>Python's os.walk() standard library iterator is useful if you want to walk an entire directory tree, but you're on your own when it comes to implementing name filtering and recursive depth limiting on top of it.</p>
<p>This recipe supports these features with an interface that is just as convenient as the underlying os.walk() API, while being significantly more powerful.</p>
HTML template animation built on PyQuery (Python)
2011-12-13T18:49:46-08:00Graham Poulterhttp://code.activestate.com/recipes/users/4172291/http://code.activestate.com/recipes/577983-html-template-animation-built-on-pyquery/
<p style="color: grey">
Python
recipe 577983
by <a href="/recipes/users/4172291/">Graham Poulter</a>
(<a href="/recipes/tags/templating/">templating</a>).
Revision 2.
</p>
<p>The beginnings of a class for "animating" plain HTML to produce a dynamic HTML output as an alternative to a templating language. It's inspired by Ruby's hquery library, which describes itself as "unobtrusive server scripting".</p>
Web based Query Browser (PHP)
2011-06-15T03:54:02-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/577753-web-based-query-browser/
<p style="color: grey">
PHP
recipe 577753
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/based/">based</a>, <a href="/recipes/tags/browser/">browser</a>, <a href="/recipes/tags/php/">php</a>, <a href="/recipes/tags/query/">query</a>, <a href="/recipes/tags/web/">web</a>).
</p>
<p>Query browser works </p>
<p>add password to this part of the code if you require a password for mysql</p>
<p>Code =</p>
<p>// Connect to the database
$conn = mysql_connect('localhost', 'root' 'PASSWORD GOES HERE");</p>
A MSSQL XML importer for MySQL (Python)
2011-03-09T03:46:49-08:00Albert Perrien IIhttp://code.activestate.com/recipes/users/4177266/http://code.activestate.com/recipes/577601-a-mssql-xml-importer-for-mysql/
<p style="color: grey">
Python
recipe 577601
by <a href="/recipes/users/4177266/">Albert Perrien II</a>
(<a href="/recipes/tags/mysql/">mysql</a>, <a href="/recipes/tags/server/">server</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/xml/">xml</a>).
</p>
<p>This is a simple function that takes records exported to XML from SQL Server or Access and imports them into MySQL. </p>
Caching iterable wrapper (Python)
2009-11-06T11:38:43-08:00Ulrik Sverdruphttp://code.activestate.com/recipes/users/4172166/http://code.activestate.com/recipes/576941-caching-iterable-wrapper/
<p style="color: grey">
Python
recipe 576941
by <a href="/recipes/users/4172166/">Ulrik Sverdrup</a>
(<a href="/recipes/tags/cached/">cached</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/iterator/">iterator</a>).
Revision 8.
</p>
<p>This is a very simple wrapper of an iterator or iterable, such that the iterator can be iterated streamingly without generating all elements or any at all, but the object can still be iterated from the beginning as many times as wanted. In effect, it is a streamingly loaded list.</p>
Brute-force sudoku solver (Python)
2009-04-23T18:33:56-07:00Sylvain Fourmanoithttp://code.activestate.com/recipes/users/4150902/http://code.activestate.com/recipes/576725-brute-force-sudoku-solver/
<p style="color: grey">
Python
recipe 576725
by <a href="/recipes/users/4150902/">Sylvain Fourmanoit</a>
(<a href="/recipes/tags/sudoku/">sudoku</a>).
Revision 4.
</p>
<p>This is a very simple, short Sudoku solver using a classic brute-force approach.</p>
<p>What makes it nice is the purely arithmetic one-liner computing the constraint c (the sequence of already used digits on the same row, same column, same block of a given cell).</p>
ChangeDirectory context manager (Python)
2009-01-24T12:41:53-08:00Christophe Simonishttp://code.activestate.com/recipes/users/4166953/http://code.activestate.com/recipes/576620-changedirectory-context-manager/
<p style="color: grey">
Python
recipe 576620
by <a href="/recipes/users/4166953/">Christophe Simonis</a>
(<a href="/recipes/tags/change/">change</a>, <a href="/recipes/tags/chdir/">chdir</a>, <a href="/recipes/tags/context_manager/">context_manager</a>, <a href="/recipes/tags/directory/">directory</a>).
Revision 2.
</p>
<p>A context manager that handle a temporary change of the working directory</p>
Generating random numbers with arbitrary distribution (Python)
2008-11-05T07:52:39-08:00Kaushik Ghosehttp://code.activestate.com/recipes/users/4166965/http://code.activestate.com/recipes/576556-generating-random-numbers-with-arbitrary-distribut/
<p style="color: grey">
Python
recipe 576556
by <a href="/recipes/users/4166965/">Kaushik Ghose</a>
(<a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/random_number/">random_number</a>).
</p>
<p>This is a class that allows you to set up an arbitrary probability distribution function and generate random numbers that follow that arbitrary distribution.</p>
Gray Code Generator/Iterator (Python)
2009-01-01T09:25:13-08:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/576592-gray-code-generatoriterator/
<p style="color: grey">
Python
recipe 576592
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/gray_code/">gray_code</a>).
Revision 3.
</p>
<p>Please refer to: <a href="http://en.wikipedia.org/wiki/Gray_code" rel="nofollow">http://en.wikipedia.org/wiki/Gray_code</a></p>
<p>The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one digit.</p>
<p>The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems.</p>
<p>Example Gray Codes:
2-bit Gray code
00
01
11
10</p>
<p>3-bit Gray code
000
001
011
010
110
111
101
100</p>
<p>4-bit Gray code
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000</p>
Use PEP 263 for metaprogramming (Python)
2008-02-22T11:19:08-08:00TJ Whttp://code.activestate.com/recipes/users/4127020/http://code.activestate.com/recipes/546539-use-pep-263-for-metaprogramming/
<p style="color: grey">
Python
recipe 546539
by <a href="/recipes/users/4127020/">TJ W</a>
(<a href="/recipes/tags/programs/">programs</a>).
Revision 3.
</p>
<p>Use PEP 263 to do source code transformation.</p>
searching in list of maps (Python)
2007-08-19T11:24:51-07:00Pietro Bernardihttp://code.activestate.com/recipes/users/4076246/http://code.activestate.com/recipes/528889-searching-in-list-of-maps/
<p style="color: grey">
Python
recipe 528889
by <a href="/recipes/users/4076246/">Pietro Bernardi</a>
(<a href="/recipes/tags/search/">search</a>).
</p>
<p>Find all occurencies of given map in map list, yielding index of first match and
subsequently indexes of all other found.
All maps in list have the same structure, pattern for search can have the same structure or less keys.</p>
All k-subsets from an n-set. (Python)
2007-01-20T11:37:11-08:00Justin Shawhttp://code.activestate.com/recipes/users/1523109/http://code.activestate.com/recipes/500268-all-k-subsets-from-an-n-set/
<p style="color: grey">
Python
recipe 500268
by <a href="/recipes/users/1523109/">Justin Shaw</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>This recipe yields each subset of size k from a super set of size n. I thought I had seen a recipe that did this before, but when I needed it I couldn't find it. There are two methods. The first operates on sets of integers of the form range(n). The seconds operates on arbitrary sets or lists.</p>