Popular recipes tagged "meta:requires=none"http://code.activestate.com/recipes/tags/meta:requires=none/2017-05-13T12:12:30-07:00ActiveState Code RecipesA white noise generator to sooth baby to sleep. (Bash)
2017-05-13T12:12:30-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/580801-a-white-noise-generator-to-sooth-baby-to-sleep/
<p style="color: grey">
Bash
recipe 580801
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/baby_alarm/">baby_alarm</a>, <a href="/recipes/tags/cygwin/">cygwin</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/noise/">noise</a>, <a href="/recipes/tags/sleep/">sleep</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/whitenoise/">whitenoise</a>).
</p>
<p>This is a simple BASH, DASH and SH script to sooth a newborn baby to sleep for a laptop with a builtin mic. Develeoped around an Apple MacBook Pro.</p>
<p>Usage:- [./]shush.sh <time in seconds from 18 to 2700> [sensitivity [Hh|Mm|Ll]]<CR></p>
<p>If time is omitted it defaults to 2 bursts of 9 seconds each and if sensitivity is omitted defaults to [M]edium.</p>
<p>It uses Quicktime Player for Apple OSX 10.12.4 minimum /dev/dsp for CygWin and some Linux flavours and arecored for Linux ALSA machines for baby awake detector.</p>
<p>Upon the two arguments the white noise generator runs for approximately the time given in $1 in bursts of 9 seconds until the time limit is reached.
$2 is used to detect of baby is awake and reruns the noise generator again with a new noise waveform.</p>
<p>Enjoy...</p>
Recursive fc/diff for Windows, optionally copy missing/different files (Tcl)
2017-04-08T16:40:25-07:00John Brearleyhttp://code.activestate.com/recipes/users/4184423/http://code.activestate.com/recipes/580776-recursive-fcdiff-for-windows-optionally-copy-missi/
<p style="color: grey">
Tcl
recipe 580776
by <a href="/recipes/users/4184423/">John Brearley</a>
(<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/tcl/">tcl</a>).
</p>
<p>Utility to add recursive capability to fc.exe on Windows. Will optionally copy/update missing or older files as needed. If you have a diff.exe in your path, say from having installed TkDiff utility, the diff.exe will be used as the prirmary compare tool, with fc.exe as the backup tool.</p>
diff_copy.tcl Utility for daily differential backups of large windows directory structures (Tcl)
2017-04-10T13:51:58-07:00John Brearleyhttp://code.activestate.com/recipes/users/4184423/http://code.activestate.com/recipes/580779-diff_copytcl-utility-for-daily-differential-backup/
<p style="color: grey">
Tcl
recipe 580779
by <a href="/recipes/users/4184423/">John Brearley</a>
(<a href="/recipes/tags/backup/">backup</a>, <a href="/recipes/tags/daily/">daily</a>, <a href="/recipes/tags/tcl/">tcl</a>).
</p>
<p>When you have terrabytes of data with 100,000+ files, it is no longer practical to blindly copy the entire data structure on a daily basis. I wrote this utility diff_copy.tcl to sort out what has been changed/updated and what new files have been added and only copy the changed & new items. If the date/time of the source file is newer, the file will be copied. If the date/time of the source file is the same as the destination, the file sizes in bytes are checked to decide if a copy is necessary. If the source file is not present on the destination directory, the file is copied. There are options to remove old files from the destination directory or show what would be copied, but not actually do the copy.</p>
Guess a number (Python)
2014-11-15T09:06:05-08:00Benoithttp://code.activestate.com/recipes/users/4191135/http://code.activestate.com/recipes/578962-guess-a-number/
<p style="color: grey">
Python
recipe 578962
by <a href="/recipes/users/4191135/">Benoit</a>
(<a href="/recipes/tags/function/">function</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/sample/">sample</a>).
</p>
<p>This is just a little game to explain some very basic function in Python for beginner. RANDOM, Loop, Try and except... </p>
Continous Fractions (Python)
2014-09-23T14:30:00-07:00juanhttp://code.activestate.com/recipes/users/4190606/http://code.activestate.com/recipes/578936-continous-fractions/
<p style="color: grey">
Python
recipe 578936
by <a href="/recipes/users/4190606/">juan</a>
.
Revision 2.
</p>
<p>Calculate the continous fraction from a fraction or decimal number</p>
Prime Factorization (Python)
2014-09-19T08:11:54-07:00juanhttp://code.activestate.com/recipes/users/4190606/http://code.activestate.com/recipes/578938-prime-factorization/
<p style="color: grey">
Python
recipe 578938
by <a href="/recipes/users/4190606/">juan</a>
.
</p>
<p>Calculates the prime factorization from a number.</p>
division digit-by digit calculation (Python)
2014-09-19T08:33:35-07:00juanhttp://code.activestate.com/recipes/users/4190606/http://code.activestate.com/recipes/578939-division-digit-by-digit-calculation/
<p style="color: grey">
Python
recipe 578939
by <a href="/recipes/users/4190606/">juan</a>
.
</p>
<p>Calculate a division digit by digit with t decimals</p>
Greatest common divisor (Python)
2014-09-19T08:03:02-07:00juanhttp://code.activestate.com/recipes/users/4190606/http://code.activestate.com/recipes/578937-greatest-common-divisor/
<p style="color: grey">
Python
recipe 578937
by <a href="/recipes/users/4190606/">juan</a>
.
</p>
<p>Calculate the Greatest common divisor from two numbers</p>
First n primes numbers (Python)
2014-09-20T19:33:41-07:00juanhttp://code.activestate.com/recipes/users/4190606/http://code.activestate.com/recipes/578923-first-n-primes-numbers/
<p style="color: grey">
Python
recipe 578923
by <a href="/recipes/users/4190606/">juan</a>
.
Revision 6.
</p>
<p>Using the Sieve of Eratosthenes find the first n primes numbers.</p>
wrist friendly dictionary (Python)
2013-08-18T22:54:26-07:00Ariel Keselmanhttp://code.activestate.com/recipes/users/4187559/http://code.activestate.com/recipes/578644-wrist-friendly-dictionary/
<p style="color: grey">
Python
recipe 578644
by <a href="/recipes/users/4187559/">Ariel Keselman</a>
(<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/interface/">interface</a>, <a href="/recipes/tags/nested/">nested</a>).
</p>
<p>this dictionary allows easy manual creation of nested hierarchies, like so:</p>
<p>window.style.width=5</p>
<p>or... </p>
<p>window['background-color'].rgb= 255,255,255</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>
Easy to use, easy to read, python based HTML generation (Python)
2013-06-21T14:47:21-07:00Pavloshttp://code.activestate.com/recipes/users/4185038/http://code.activestate.com/recipes/578436-easy-to-use-easy-to-read-python-based-html-generat/
<p style="color: grey">
Python
recipe 578436
by <a href="/recipes/users/4185038/">Pavlos</a>
(<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/template/">template</a>, <a href="/recipes/tags/text/">text</a>).
Revision 4.
</p>
<p>I was looking for a simple way to generate HTML directly in python that does not require learning a new template 'language' nor requires the installation of a big complex package. Closest thing I found was James Casbon's attempt(https://gist.github.com/1461441). This is my version of the same idea. </p>
<p>(2013-04-21) added some simplifications and support for switching off string interpolation. Added to github:</p>
<p><a href="https://github.com/pavlos-christoforou/web" rel="nofollow">https://github.com/pavlos-christoforou/web</a></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>
Determinant of matrix of any order (Python)
2012-04-24T10:49:00-07:00Sachin Joglekarhttp://code.activestate.com/recipes/users/4181845/http://code.activestate.com/recipes/578108-determinant-of-matrix-of-any-order/
<p style="color: grey">
Python
recipe 578108
by <a href="/recipes/users/4181845/">Sachin Joglekar</a>
(<a href="/recipes/tags/algebra/">algebra</a>, <a href="/recipes/tags/determinant/">determinant</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/order/">order</a>).
</p>
<p>A small snipet of code to find the determinant of a mtrix of any order.Input must be a list like [[1,2,3],[4,5,6],[7,8,9]] (for a matrix of order 3). Works fine.</p>
Output data in tabular form (Python)
2012-04-20T19:27:57-07:00srikantkthttp://code.activestate.com/recipes/users/4181723/http://code.activestate.com/recipes/578105-output-data-in-tabular-form/
<p style="color: grey">
Python
recipe 578105
by <a href="/recipes/users/4181723/">srikantkt</a>
(<a href="/recipes/tags/tabular/">tabular</a>).
Revision 4.
</p>
<p>Often times, data lists need to be output in tabular format. Here is a sample that allows specifying table heading and data rows. Came across <a href="http://code.activestate.com/recipes/577615/">recipe 577615</a> after I posted but I am still biased.</p>
Silmultaneous linear equation solver(any order) (Python)
2012-04-24T12:29:30-07:00Sachin Joglekarhttp://code.activestate.com/recipes/users/4181845/http://code.activestate.com/recipes/578109-silmultaneous-linear-equation-solverany-order/
<p style="color: grey">
Python
recipe 578109
by <a href="/recipes/users/4181845/">Sachin Joglekar</a>
(<a href="/recipes/tags/algebra/">algebra</a>, <a href="/recipes/tags/crammer/">crammer</a>, <a href="/recipes/tags/determinants/">determinants</a>, <a href="/recipes/tags/equation/">equation</a>, <a href="/recipes/tags/linear/">linear</a>, <a href="/recipes/tags/simultaneous/">simultaneous</a>).
</p>
<p>Solves simultaneous linear equations of any order using Crammer's rule. Required input is two lists..one for coefficients, and other for constants
eg. 2x+3y=8
x+4y=6 will be written as
simul([[2,3],[1,4]],[8,6])</p>
Finding complete loops in a map of connected nodes (Python)
2012-04-24T18:47:21-07:00Sachin Joglekarhttp://code.activestate.com/recipes/users/4181845/http://code.activestate.com/recipes/578110-finding-complete-loops-in-a-map-of-connected-nodes/
<p style="color: grey">
Python
recipe 578110
by <a href="/recipes/users/4181845/">Sachin Joglekar</a>
(<a href="/recipes/tags/circuit/">circuit</a>, <a href="/recipes/tags/connection/">connection</a>, <a href="/recipes/tags/loops/">loops</a>).
</p>
<p>This module finds loops in a given map.Input is a dictionary like</p>
<p>d={1:[2,4,5,6],2:[1,3],3:[2,4,5,6],4:[1,3,5],5:[1,3,4],6:[1,3]}</p>
<p>this means node 1 is connected to nodes 2,4,5 and 6 and so on..</p>
<p>Output is a list of complete loops.
for above examples,output is</p>
<p>[[1, 4, 5, 1], [3, 4, 5, 3], [1, 2, 3, 4, 1], [1, 2, 3, 5, 1], [1, 2, 3, 6, 1], [1, 4, 3, 5, 1], [1, 4, 3, 6, 1], [1, 5, 3, 6, 1], [1, 2, 3, 4, 5, 1], [1, 4, 5, 3, 6, 1]]</p>
Finding the GCD of a list of numbers (a.k.a. Reducing numbers in a list) (Python)
2010-07-06T18:52:55-07:00Stephen Akikihttp://code.activestate.com/recipes/users/4172143/http://code.activestate.com/recipes/577282-finding-the-gcd-of-a-list-of-numbers-aka-reducing-/
<p style="color: grey">
Python
recipe 577282
by <a href="/recipes/users/4172143/">Stephen Akiki</a>
(<a href="/recipes/tags/common/">common</a>, <a href="/recipes/tags/denominator/">denominator</a>, <a href="/recipes/tags/gcd/">gcd</a>, <a href="/recipes/tags/greatest/">greatest</a>, <a href="/recipes/tags/lisst/">lisst</a>, <a href="/recipes/tags/reduce/">reduce</a>).
</p>
<p><a href="http://akiscode.com/articles/gcd_of_a_list.shtml" rel="nofollow">http://akiscode.com/articles/gcd_of_a_list.shtml</a></p>
<p>This python code snippet allows you to find the GCD of a list of numbers, after this it is a simple matter of diving all the numbers in the list by the GCD to reduce it.</p>
<p>Why this works...</p>
<p>The GCD of a list of numbers [a, b, c] is GCD(GCD(a, b), c). The reduce function does exactly this and thus gives you the GCD of all the numbers in the list.</p>
Infinite Stream Divisor (Python)
2010-07-21T12:50:17-07:00Narayana Chikkamhttp://code.activestate.com/recipes/users/4174427/http://code.activestate.com/recipes/577326-infinite-stream-divisor/
<p style="color: grey">
Python
recipe 577326
by <a href="/recipes/users/4174427/">Narayana Chikkam</a>
(<a href="/recipes/tags/divisor/">divisor</a>, <a href="/recipes/tags/infinite/">infinite</a>, <a href="/recipes/tags/stream/">stream</a>).
</p>
<p>Maintain an F.S.A to keep track of the consequent remainders as states, input symbols as driving actions on each state. O(N) is the time complexity to find the given large string [in some radix(R), for some specific divisor(D)], where N is the length of the Input String which confirms to the Language Rules under the alphabet. O(R*D) is the space complexity to keep the F.S.A in memory for lookup!</p>
Eight Queens With out Permutations (Python)
2010-07-21T10:11:20-07:00Narayana Chikkamhttp://code.activestate.com/recipes/users/4174427/http://code.activestate.com/recipes/577325-eight-queens-with-out-permutations/
<p style="color: grey">
Python
recipe 577325
by <a href="/recipes/users/4174427/">Narayana Chikkam</a>
(<a href="/recipes/tags/eight/">eight</a>, <a href="/recipes/tags/queens/">queens</a>).
</p>
<p>Eight Queens is one of the popular algorithms in backtracking. The solution given below uses simple math to reduce the processing. The logic is keep placing the coins on the board with below rules:</p>
<ol>
<li>Don't place the coin if there is another coin present in the same row</li>
<li>Don't place the coin if there is another coin present in the same col</li>
<li>Don't place the coin if there is another coin present in any of the diagonal lines.</li>
</ol>
<p>Keep repeating the above 3 rules recursively until we keep all the coins.
Problem Definition:
<a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle" rel="nofollow">http://en.wikipedia.org/wiki/Eight_queens_puzzle</a></p>