Popular recipes tagged "meta:loc=176"http://code.activestate.com/recipes/tags/meta:loc=176/2012-05-07T13:21:30-07:00ActiveState Code RecipesKomodo JS Macro: Execute JavaScript (JavaScript)
2012-05-07T13:21:30-07:00Patrick Clokehttp://code.activestate.com/recipes/users/4180275/http://code.activestate.com/recipes/578120-komodo-js-macro-execute-javascript/
<p style="color: grey">
JavaScript
recipe 578120
by <a href="/recipes/users/4180275/">Patrick Cloke</a>
(<a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>).
</p>
<p>Executes a JavaScript file (or the selected text) and display the results in the command output window.</p>
Simple regex engine, elementary Python (Python)
2010-07-10T10:43:30-07:00Joost Behrendshttp://code.activestate.com/recipes/users/4174081/http://code.activestate.com/recipes/577251-simple-regex-engine-elementary-python/
<p style="color: grey">
Python
recipe 577251
by <a href="/recipes/users/4174081/">Joost Behrends</a>
(<a href="/recipes/tags/cached/">cached</a>, <a href="/recipes/tags/parse/">parse</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/recursion/">recursion</a>, <a href="/recipes/tags/regular_expressions/">regular_expressions</a>).
Revision 40.
</p>
<p>A short engine for testing against a regex, understanding the 3 common quantifiers
?,+,* (non-greedy) working on characters, ., [...], [^...], \s, \S, bracketed patterns and group designators \N. Accepts unicode objects and fixed-width encoded strings
(but problems with eventual comparisons of trailing bytes in multi-byte utf-letters).
Captures up to 10 groups ( (?:...) implemented), which can be used for back referencing and in xreplace(). Captured groups are accessible after the search in the global list xGroups. | is supported, but only in groups and needing nested=True. nested=False is making '(' and ')' common letters.</p>
<p>This is not about Python or for Python, there it has little use beside re. But regarding that re needs about 6,000 lines you might agree with the author, that these 176 lines are powerful. This was the reason to publish it as a recipe - as a kind of (fairly complete) minimal example of a regex tester and as an example for corresponding recursive structures in data (TokenListCache) and code.</p>
<p>Working on this improved the author's understanding of regular expressions - especially of their eventual "greed". "Greedy" quantifiers are a concept, which has to be explained seperately and is coming unexpected: Whoever is scanning a text for <code>'<.*>'</code>, s/he will search SGML tags, not the whole text. Even with the star's "greediness" the code has to take care, that <code>'.*'</code> doesn't eat the whole text finding no match for <code>'<.*>'</code> at all. Thus the standard syntax with greedy quantifiers cannot be simpler to implement than this with its mere 3 lines 101, 111 and 121 preventing any greed. Perhaps it is faster - otherwise it is difficult to understand, why the concept "greed" is existing at all.</p>
<p>This engine might be useful here and then under circumstances with nothing else available. Its brevity eases translation to other languages and it can work with arbitrary characters for STAR or PERHAPS (for example).</p>
Crop PDF File with pyPdf (Python)
2011-11-03T17:42:10-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/576837-crop-pdf-file-with-pypdf/
<p style="color: grey">
Python
recipe 576837
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pypdf/">pypdf</a>).
Revision 3.
</p>
<p>This recipe was originally posted by <code>sjvr767</code> on <a href="http://www.mobileread.com/forums/showthread.php?t=25565" rel="nofollow">http://www.mobileread.com/forums/showthread.php?t=25565</a> and I decided to also make it available here.</p>
<p>It uses pypdf (<a href="http://pybrary.net/pyPdf/%29" rel="nofollow">http://pybrary.net/pyPdf/)</a></p>
<p>The script is supposed to be run like this:</p>
<p><code>pdf_crop.py" -m "120 50 120 180" -i mypdf.pdf</code></p>
<p>where the margins are <code>left top right bottom</code></p>
<p>To install pyPdf try <code>easy_install pypdf</code>.</p>
Convert datetime.datetime objects to/from Boost.python posix time (Python)
2008-09-17T23:55:23-07:00david decotignyhttp://code.activestate.com/recipes/users/4129454/http://code.activestate.com/recipes/576395-convert-datetimedatetime-objects-tofrom-boostpytho/
<p style="color: grey">
Python
recipe 576395
by <a href="/recipes/users/4129454/">david decotigny</a>
(<a href="/recipes/tags/boost/">boost</a>).
Revision 10.
</p>
<p>This recipe allows to transparently convert python's datetime.datetime objects to and from boost's boost::posix_time::ptime objects.</p>
Simple Example demonstrating Ajax Implementation using Perl (Perl)
2007-03-11T07:37:16-07:00Rajkumar Jainhttp://code.activestate.com/recipes/users/4040865/http://code.activestate.com/recipes/502299-simple-example-demonstrating-ajax-implementation-u/
<p style="color: grey">
Perl
recipe 502299
by <a href="/recipes/users/4040865/">Rajkumar Jain</a>
.
</p>
<p>In the example below, we have a table containing Student names and Marks. Every row has an Edit button, by which user can edit the information for that row. We have used Microsoft Access as the Database to keep things very simple. In order to run the below example code you will have to create a table by the name “Student” in MS Access”. It should have the following columns.</p>
<p>Column Name Data type
Sl_No(Primary Key) Number
Name Text
Marks Number</p>
<p>Also you need to create a DSN by the name “mydsn” pointing to the Access DB.</p>
<p>The basic logic here used in the example is that we have two separate rows for View and Edit (for every Student). Initially we hide the Edit row (by using style="display:none") and display the View Row(by using style="display:block"). When the user clicks on the “Edit” button, the View row becomes hidden and the Edit row is displayed. We have used JavaScript to toggle between the rows. Below is the code snippet used in files (AjaxExample.pl and student.js).</p>
Pythologic -- Prolog syntax in Python (Python)
2004-09-01T21:11:14-07:00Shai Bergerhttp://code.activestate.com/recipes/users/2014324/http://code.activestate.com/recipes/303057-pythologic-prolog-syntax-in-python/
<p style="color: grey">
Python
recipe 303057
by <a href="/recipes/users/2014324/">Shai Berger</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>Some of Python's powerful meta-programming features are used to enable writing Python functions which include Prolog-like statements. Such functions load a Prolog-like database. When coupled with a suitable inference engine for logic databases, this is a way to add logical programming -- the last unsupported major paradigm -- to Python. Start at the bottom of the code for an example of the enabled syntax.</p>
SQL-like set operations with list comprehension one-liners. (Python)
2002-11-12T11:12:28-08:00Attila Vásárhelyihttp://code.activestate.com/recipes/users/770370/http://code.activestate.com/recipes/159974-sql-like-set-operations-with-list-comprehension-on/
<p style="color: grey">
Python
recipe 159974
by <a href="/recipes/users/770370/">Attila Vásárhelyi</a>
.
Revision 2.
</p>
<p>Sometimes it is needed to do set-like operations on database query results, or simple lists, without the burden of implementing a class for sets, or importing a separate module. List comprehensions are quick way to do this, here is a collection of them. Although most of them are banal, let us just collect them in one place. Also, they are not the fastest, nor the most elegant, but the quickest to drop into your code if you need a proof of concept.</p>