Popular recipes tagged "meta:loc=24"http://code.activestate.com/recipes/tags/meta:loc=24/2017-06-13T10:57:34-07:00ActiveState Code RecipesCreate Calendars on PDF with a few lines (Python) 2017-06-13T10:57:34-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580805-create-calendars-on-pdf-with-a-few-lines/ <p style="color: grey"> Python recipe 580805 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/calendar/">calendar</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>). Revision 2. </p> <p>PyMuPDF (fitz) provides easy to use ways to create PDF documents out of simple texts.</p> <p>An example is the text output of Python's calendar module. Here we take a starting year as script parameter and output a 3-page (A4 landscape) document with calendars for this and the following two years - in less than 20 lines of code.</p> Get names and types of all attributes of a Python module (Python) 2016-10-06T17:21:42-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580705-get-names-and-types-of-all-attributes-of-a-python-/ <p style="color: grey"> Python recipe 580705 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/documentation/">documentation</a>, <a href="/recipes/tags/introspection/">introspection</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/reflection/">reflection</a>, <a href="/recipes/tags/type/">type</a>). </p> <p>This recipe shows how to get the names and types of all the attributes of a Python module. This can be useful when exploring new modules (either built-in or third-party), because attributes are mostly a) data elements or b) functions or methods, and for either of those, you would like to know the type of the attribute, so that, if it is a data element, you can print it, and if it is a function or method, you can print its docstring to get brief help on its arguments, processsing and outputs or return values, as a way of learning how to use it.</p> <p>The code for the recipe includes an example call to it, at the end of the code. Note that you first have to import the modules that you want to introspect in this way.</p> Publish Firebird SQL data to PDF with xtopdf (Python) 2015-12-01T19:45:18-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579131-publish-firebird-sql-data-to-pdf-with-xtopdf/ <p style="color: grey"> Python recipe 579131 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/firebird/">firebird</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sql/">sql</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to publish data from the Firebird RDBMS to PDF, using the xtopdf toolkit and the fbd Python driver for Firebird. Firebird is a cross-platform, open source RDBMS based on the former Interbase RDBMS from Borland, which they used to bundle with some of their developmemt tools, such as Borland C++ and Borland Delphi.</p> <p>The recipe reads data from a Firebird table, using the fbd Python driver for Firebird, and writes it to PDF, using the xtopdf toolkit. See:</p> <p><a href="http://jugad2.blogspot.in/p/xtopdf-pdf-creation-library.html" rel="nofollow">http://jugad2.blogspot.in/p/xtopdf-pdf-creation-library.html</a></p> <p>for information on xtopdf.</p> <p>It assumes that a Firebird database called test.fdb exists under /temp/firebird (C:\temp\firebird, really - the test was done on Windows), and that it has a contacts table with the structure shown in the code of the recipe.</p> <p>More details and sample output are here:</p> <p><a href="http://jugad2.blogspot.in/2014/01/by-vasudev-ram-pdf-firebird-is-cross.html" rel="nofollow">http://jugad2.blogspot.in/2014/01/by-vasudev-ram-pdf-firebird-is-cross.html</a></p> Mandelbrot Fractal image output to ppm file (Python) 2015-01-17T19:21:47-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579006-mandelbrot-fractal-image-output-to-ppm-file/ <p style="color: grey"> Python recipe 579006 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>It creates image output without using any external library.</p> <p>PPM image files can be viewed and converted to other image file formats using many applications, GIMP or IrfanView for example.</p> A Bash Beep Command For OSX 10.7+... (Bash) 2014-02-27T19:36:17-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578837-a-bash-beep-command-for-osx-107/ <p style="color: grey"> Bash recipe 578837 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/beep/">beep</a>, <a href="/recipes/tags/error_beep/">error_beep</a>, <a href="/recipes/tags/error_sound/">error_sound</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/sound/">sound</a>). </p> <p>This small bash script generates an 8044 byte 1KHz sinewave wave file and immediately plays it. The file created is a _pure_ sinewave and lasts for 1 second. It uses the default "afplay" command to run the generated file.</p> <p>It was designed around an Apple Macbook Pro but using "aplay" it might even work on other *nix flavours from the command line. I have not bothered to try it as this was purely for my MB Pro.</p> <p>The wave file can be found as "/tmp/sinewave.wav" during the working session(s) and can be saved anywhere of your choice.</p> <p>Enjoy...</p> <p>(Watch for word wrapping etc...)</p> <p>Bazza.</p> Simple Text Mode Digital Oscilloscope Graphics DEMO. (Python) 2014-01-21T19:07:49-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578812-simple-text-mode-digital-oscilloscope-graphics-dem/ <p style="color: grey"> Python recipe 578812 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>). </p> <p>This is a DEMO to switch a *NIX terminal from text to _graphics_ mode on the fly.</p> <p>The graphics characters are limited to lowercase 'a' through 'z' and this DEMO just prints a small subset to see what a fun, kids level, 8 channel Logic-Analyser/Digital-Oscilloscope might look like.</p> <p>This may not work in every *NIX style terminal but does work on default terminals using bash on OSX 10.7.5, PCLinuxOS 2009 and Debian Linux 6.0.x.</p> <p>Tested on Python 2.5.x to 3.3.2 on the above platforms... (It might work on earlier versions of Python but untested.)</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza...</p> Printing list of ODBC data sources (Python) 2013-12-10T11:07:37-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/578782-printing-list-of-odbc-data-sources/ <p style="color: grey"> Python recipe 578782 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/odbc/">odbc</a>, <a href="/recipes/tags/sql/">sql</a>). </p> <p>This simple code shows ODBC data sources. It uses <code>odbc</code> module.</p> Pretty Print table in tabular format (Python) 2013-12-30T23:05:55-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578801-pretty-print-table-in-tabular-format/ <p style="color: grey"> Python recipe 578801 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/pretty_printer/">pretty_printer</a>, <a href="/recipes/tags/print/">print</a>, <a href="/recipes/tags/printer/">printer</a>, <a href="/recipes/tags/printf/">printf</a>, <a href="/recipes/tags/printing/">printing</a>). </p> <p>A simple function to Pretty Print a table in tabular format.</p> <p>Table maybe a list of lists or list of tuples.</p> <p>Justify and column width are optional parameters.</p> Using websocketd with Python for web-based system monitoring (Python) 2014-01-02T22:57:02-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578803-using-websocketd-with-python-for-web-based-system-/ <p style="color: grey"> Python recipe 578803 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/go/">go</a>, <a href="/recipes/tags/golang/">golang</a>, <a href="/recipes/tags/psutil/">psutil</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/websockets/">websockets</a>). </p> <p>This is the server side of a recipe that shows how the use websocket, a tool written in Go, that sort of daemonizes a program that reads from standard input and writes to standard output, thus making it into a WebSocket server.</p> CSS line with px value adds a new line with rem (JavaScript) 2013-11-20T21:15:22-08:00Magnus Axelssonhttp://code.activestate.com/recipes/users/4188509/http://code.activestate.com/recipes/578769-css-line-with-px-value-adds-a-new-line-with-rem/ <p style="color: grey"> JavaScript recipe 578769 by <a href="/recipes/users/4188509/">Magnus Axelsson</a> (<a href="/recipes/tags/convert/">convert</a>, <a href="/recipes/tags/css/">css</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>). </p> <p>Put your cursor on a CSS line that ends with a value in px (do not select any text). Run the script and it will insert a new line there the px value is converted to a rem value. </p> <p>You need to edit the code to modify your rem base matching the one you use in your own CSS. The default value is 16.</p> <p>Example: font-size: 12px; (run the script with the cursor in this line) font-size: 0.75rem (new line added by script) </p> Newton's Method to Solve Equations in Python (Python) 2013-01-16T16:40:55-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578419-newtons-method-to-solve-equations-in-python/ <p style="color: grey"> Python recipe 578419 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/newtons_method/">newtons_method</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This is how you would use Newton's method to solve equations. For more information about solving equations in python checkout <a href="http://thelivingpearl.com/2013/01/15/the-easy-way-to-solve-equations-in-python/">How to solve equations using python</a>.</p> Simple Prime Number Generator in Python (Python) 2013-01-06T20:18:38-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578400-simple-prime-number-generator-in-python/ <p style="color: grey"> Python recipe 578400 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a simple prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a>.</p> <p>Note: There are more efficient ways to do this. Please look at my other recipes. </p> Recursively print (nested) dictionaries (Python) 2012-04-04T15:20:42-07:00Mauricio Dada Fonseca de Freitashttp://code.activestate.com/recipes/users/4179701/http://code.activestate.com/recipes/578094-recursively-print-nested-dictionaries/ <p style="color: grey"> Python recipe 578094 by <a href="/recipes/users/4179701/">Mauricio Dada Fonseca de Freitas</a> (<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/print/">print</a>, <a href="/recipes/tags/recursion/">recursion</a>). </p> <p>Snippet of code that uses recursion to print nested dictionaries. It does not sort the entries!</p> IP Address (Python) 2012-07-02T22:34:13-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578182-ip-address/ <p style="color: grey"> Python recipe 578182 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/old/">old</a>). </p> <p>The following was a CGI experiment for finding out the IP address of a connecting client. This is committed for archival to be run under Python 2.5 or later versions.</p> Round number to specified number of significant digits (Python) 2012-04-26T20:15:48-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/578114-round-number-to-specified-number-of-significant-di/ <p style="color: grey"> Python recipe 578114 by <a href="/recipes/users/4170919/">Ben Hoyt</a> (<a href="/recipes/tags/decimalplaces/">decimalplaces</a>, <a href="/recipes/tags/round/">round</a>, <a href="/recipes/tags/rounding/">rounding</a>, <a href="/recipes/tags/significantfigures/">significantfigures</a>). </p> <p>This function rounds num to the specified number of significant digits (rather than decimal places). See doctests for more examples.</p> Simple Password Generator (Python) 2012-05-10T16:55:59-07:00Isendrak Skatasmidhttp://code.activestate.com/recipes/users/4182031/http://code.activestate.com/recipes/578125-simple-password-generator/ <p style="color: grey"> Python recipe 578125 by <a href="/recipes/users/4182031/">Isendrak Skatasmid</a> (<a href="/recipes/tags/security/">security</a>). </p> <p>A simple Password Generator in Python</p> A MutableMapping that Can Use Unhashable Objects as Keys (Python) 2012-04-04T20:36:59-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/578096-a-mutablemapping-that-can-use-unhashable-objects-a/ <p style="color: grey"> Python recipe 578096 by <a href="/recipes/users/4177816/">Eric Snow</a> . </p> <p>The catch is that the unhashable objects aren't actually stored in the mapping. Only their IDs are. Thus you must also store the actual objects somewhere else.</p> Komodo JS Macro: Real auto word-wrap (JavaScript) 2012-04-10T17:38:13-07:00Furlohttp://code.activestate.com/recipes/users/4180513/http://code.activestate.com/recipes/578099-komodo-js-macro-real-auto-word-wrap/ <p style="color: grey"> JavaScript recipe 578099 by <a href="/recipes/users/4180513/">Furlo</a> (<a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/word/">word</a>, <a href="/recipes/tags/wrap/">wrap</a>). </p> <p>This script will add real auto-wrap functionality to Komodo, ie. it will wrap text after reaching column 80 just in the same way as you would by pressing &lt;Enter&gt;.</p> <p>You can bind a keyboard shortcut to macro, or trigger it on Komodo startup, or both. Either way, repeated pressing of binded shortcut (or running the macro) will switch it off and on again.</p> <p>In fact, script only adds event listener, which fires a function (after each keypress), that checks if cursor position is not in column higher that 79 and, if needed, calls Komodo built-in function "Reflow paragraph" to reflow the paragraph.</p> <p>This recipe was not created by me from scratch. I have just read David Brewer's feature request at <a href="http://code.activestate.com/lists/komodo-discuss/4965/">komodo-discuss</a>, used <a href="http://www.openkomodo.com/blogs/troyt/revenge-auto-wrap-type-type-type-ding">troyt's original code</a> for autowrap and tweaked/simplified it a little.</p> PostgreSQL database backup script (Python) 2011-07-15T08:27:05-07:00Evgeniy.Khttp://code.activestate.com/recipes/users/4178635/http://code.activestate.com/recipes/577793-postgresql-database-backup-script/ <p style="color: grey"> Python recipe 577793 by <a href="/recipes/users/4178635/">Evgeniy.K</a> (<a href="/recipes/tags/backup/">backup</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/postgresql/">postgresql</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>). </p> <p>Simple script to backup some databases from PostgreSQL on unix\linux.</p> Object wrapper class (Python) 2011-01-28T12:40:58-08:00Nichita Utiuhttp://code.activestate.com/recipes/users/4176755/http://code.activestate.com/recipes/577555-object-wrapper-class/ <p style="color: grey"> Python recipe 577555 by <a href="/recipes/users/4176755/">Nichita Utiu</a> (<a href="/recipes/tags/wrapper/">wrapper</a>). </p> <p>This is a wrapper class which, it wraps an object which it then proxies unnhandled getattr calls to.</p>