Top-rated recipes tagged "check"http://code.activestate.com/recipes/tags/check/top/2014-09-16T22:27:04-07:00ActiveState Code RecipesPerfect Square Checker (Python)
2014-09-10T02:21:27-07:00Ethan Hannhttp://code.activestate.com/recipes/users/4190746/http://code.activestate.com/recipes/578931-perfect-square-checker/
<p style="color: grey">
Python
recipe 578931
by <a href="/recipes/users/4190746/">Ethan Hann</a>
(<a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/checker/">checker</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/root/">root</a>, <a href="/recipes/tags/square/">square</a>).
</p>
<p>This program will take input from the user and either check if a number is a perfect square or square a number, depending on user's choice.</p>
Chek if a number is a power of two (Python)
2010-12-23T11:29:38-08:00A. Polinohttp://code.activestate.com/recipes/users/4176317/http://code.activestate.com/recipes/577514-chek-if-a-number-is-a-power-of-two/
<p style="color: grey">
Python
recipe 577514
by <a href="/recipes/users/4176317/">A. Polino</a>
(<a href="/recipes/tags/2/">2</a>, <a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/power/">power</a>, <a href="/recipes/tags/python/">python</a>).
Revision 2.
</p>
<p>Pretty good way to check if a number is a power of two or not.</p>
A Fun Perfect Square Checker Using Integer Arithmetic Only... ;o) (Bash)
2014-09-16T22:27:04-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578934-a-fun-perfect-square-checker-using-integer-arithme/
<p style="color: grey">
Bash
recipe 578934
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/arithmetic/">arithmetic</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/checker/">checker</a>, <a href="/recipes/tags/cygwin/">cygwin</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/perfect/">perfect</a>, <a href="/recipes/tags/root/">root</a>, <a href="/recipes/tags/square/">square</a>).
</p>
<p>A recent Python upload here gave me the inspiration to do a bash version...
This is a little tongue-in-cheek but an enjoyable bit of fun.</p>
<p>It took around 11 seconds to prove 90000000000 had a perfect square of 300000...</p>
<p>It is a stand alone program and has a degree of INPUT error correction...</p>
<p>It was done on a MacBook Pro, OSX 10.7.5, default bash terminal and should work on Linux flavours but it is untested...</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Bazza...</p>
Recipe With No Name Yet (Python)
2012-08-22T17:57:12-07:00Cyrilhttp://code.activestate.com/recipes/users/4182937/http://code.activestate.com/recipes/578221-recipe-with-no-name-yet/
<p style="color: grey">
Python
recipe 578221
by <a href="/recipes/users/4182937/">Cyril</a>
(<a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/wrapper/">wrapper</a>).
Revision 9.
</p>
<p>Not a very new recipe, but a short one and (I hope) useful :</p>
<ul>
<li>wrapping any function "f" with two decorators "enter_event" and "exit_event" that will trigger calling of user
functions when, ... hum ... evidently, <strong>just before entering and just after exiting the "f" function</strong>.</li>
</ul>
<p>Typical usages :</p>
<ul>
<li>debugging on a function by function basis :
<ul>
<li>emit a trace in log file to see when functions are called and check sequences correctness
(very usefull when programming by events)</li>
<li>feed a profile analyzer (by fine tuning which functions are enabled)</li>
<li>feed a code coverage analyzer ( " )</li>
</ul></li>
<li>kind of validator on function calling :
<ul>
<li>implement programming by contracts :
<ul>
<li>check that parameters values of "f" function will not have an unexpected value or be of an unexpected type</li>
<li>this allow to increase code robustness by narrowing </li>
</ul></li>
<li>implement invariants (eg. check that returned value is always in the excepted range, ...)</li>
<li>insure that a function follow specifications by meta-checking that has always predictable results
(eg. return the fixed expected value for each possible input value, ...)</li>
</ul></li>
<li>minimum modification of existing code</li>
<li><strong>in the same thinking line as the "monkey patching" concept</strong></li>
</ul>
<p>Notes on usage :</p>
<ul>
<li>recipe works on functions and any kind of methods (methods, class methods,
and static methods)</li>
<li>the usage order of "@enter_event" and "@exit_event" decorators doesn't
matter : the result will be the same</li>
</ul>
<ul>
<li><em>PLEASE VOTE FOR THIS RECIPE if you like it !</em></li>
</ul>
GTIN Validate Check Digit or Add Check Digit (Python)
2011-11-26T07:12:18-08:00Richard Thiemanhttp://code.activestate.com/recipes/users/4180084/http://code.activestate.com/recipes/577963-gtin-validate-check-digit-or-add-check-digit/
<p style="color: grey">
Python
recipe 577963
by <a href="/recipes/users/4180084/">Richard Thieman</a>
(<a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/digits/">digits</a>, <a href="/recipes/tags/gtin/">gtin</a>).
</p>
<p>A python class I wrote to add or validate a GTIN check digit.</p>
Type checking using Python 3.x annotations (Python)
2013-05-23T22:46:19-07:00David Mertzhttp://code.activestate.com/recipes/users/4173018/http://code.activestate.com/recipes/578528-type-checking-using-python-3x-annotations/
<p style="color: grey">
Python
recipe 578528
by <a href="/recipes/users/4173018/">David Mertz</a>
(<a href="/recipes/tags/annotations/">annotations</a>, <a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/type/">type</a>, <a href="/recipes/tags/typecheck/">typecheck</a>).
Revision 5.
</p>
<p>Some other recipes have been suggested to allow type checking by various means. Some of these require the use of type specification in a decorator itself. Others try to be much more elaborate in processing a large variety of annotations (but hence require much more and more convoluted code).</p>
<p>The recipe provided below is very short, and simply provides actual <strong>type</strong> checking of arguments and return values. It utilizes an unadorned decorator, rather than manufacture one that is parameterized by types or other arguments.</p>