Popular recipes tagged "meta:loc=119"http://code.activestate.com/recipes/tags/meta:loc=119/2012-09-09T19:25:00-07:00ActiveState Code RecipesFor AMIGA-Heads Only. Poking A HW, (Memory), Address On A Classic AMIGA, Inside Text Mode Python. (Python)
2012-09-09T19:25:00-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578255-for-amiga-heads-only-poking-a-hw-memory-address-on/
<p style="color: grey">
Python
recipe 578255
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/hardware/">hardware</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/poke/">poke</a>, <a href="/recipes/tags/winuae/">winuae</a>).
</p>
<p>For AMIGA-Heads Only...</p>
<p>This code is purely for a minimum of a stock Classic AMIGA A1200(HD), E-UAE, and WinUAE running AMIGA OS3.0x to 3.1x.
It will NOT work on any other platform!</p>
<p>(It MIGHT work on AMIGA OS3.5x and 3.9x with Python 2.4.6, but totally untested and I hold no responsibility for the outcome when trying it.)</p>
<p>It is a DEMO to poke a byte inside _ANY_ memory address inside the standard CPU 68EC020 16MB boundary.</p>
<p>This is not a function nor a class but just a DEMO to show how to write directly to HW, (or memory), addresses.</p>
<p>POKING memory or hardware addresses is not recommended for novices without studying the machine first, and, this code will ignore any _ENFORCER_hits_.</p>
<p>I experimented with this several years ago and have decided to finally release it. I do await the flak!</p>
<p>It works from Python Versions 1.4.0 to 2.0.1 for the classic AMIGA.</p>
<p>This is issued as Public Domain and you may do with it as you please.</p>
<p>Ensure that the T: Volume exists on the running machine.</p>
<p>See inside the code and text below it also as to how it works...</p>
<p>Bazza, G0LCU...</p>
Super Simple Sudoku Solver in Python source code (Python)
2012-06-23T14:56:05-07:00David Adlerhttp://code.activestate.com/recipes/users/4182015/http://code.activestate.com/recipes/578140-super-simple-sudoku-solver-in-python-source-code/
<p style="color: grey">
Python
recipe 578140
by <a href="/recipes/users/4182015/">David Adler</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/recursive/">recursive</a>, <a href="/recipes/tags/recurssion/">recurssion</a>, <a href="/recipes/tags/sodoku/">sodoku</a>, <a href="/recipes/tags/sudoku/">sudoku</a>).
Revision 5.
</p>
<p>A simple algorithm which uses a recursive function to solve the puzzle.</p>
<hr />
<p>THE ALGORITHM</p>
<p>The credit for this algorithm must go to Richard Buckland:
<a href="http://www.youtube.com/watch?v=bjObm0hxIYY&feature=autoplay&list=PL6B940F08B9773B9F&playnext=1" rel="nofollow">http://www.youtube.com/watch?v=bjObm0hxIYY&feature=autoplay&list=PL6B940F08B9773B9F&playnext=1</a></p>
<p>Takes a partially filled in grid, inserts the min value in a cell (could be a random cell, in this case the first free cell). If the min value is not legal it will increment until the max value is reached (number 9), checking each time if the incremented value is legal in that cell (ie does not clash with any already entered cells in square, col or row). If it is legal, it will call itself (the hasSolution function) thus using this slightly more filled in grid to find a new cell and check which value is legal in this next cell. If no values are legal in the next cell, it will clear the previous grid entry and try incrementing the value.</p>
<p>isLegal = does not conflict with any other numbers in the same row, column or square</p>
Simple LF Audio Oscilloscope Using Standard Text Mode Python. (Python)
2011-06-26T21:42:55-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577771-simple-lf-audio-oscilloscope-using-standard-text-m/
<p style="color: grey">
Python
recipe 577771
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/anim/">anim</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/oscilloscope/">oscilloscope</a>, <a href="/recipes/tags/scope/">scope</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>A Linux DEMO to show how to display a waveform using standard text mode Python.
The audio device /dev/dsp is used and must be available. Levels are set using the
standard audio mixers.</p>
<p>Just feed a signal of say 300Hz to 3KHz, (normal voice spectrum), using say, the
internal mic, and watch the waveform appear inside the X-Y graticule.</p>
<p>This method WILL be used for a program proper and may be uploaded to this site
in the future.</p>
<p>Read the code for more information.</p>
<p>This code is Public Domain and you may do with it as you please.</p>
<p>Enjoy finding simple solutions to often very difficult problems.</p>
Langton's Ant Automaton (Java)
2011-02-17T21:53:36-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577576-langtons-ant-automaton/
<p style="color: grey">
Java
recipe 577576
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>).
</p>
<p>(Generalized) Langton's Ant Automaton.</p>
<p>Langton's ant is a 2D Turing machine.
In this version, at each new x,y location the ant reads the byte value and replaces it w/ another, and chooses a new direction (one of 8 possible directions) to move.</p>
<p>Byte replacement and direction values are read from random arrays.</p>
Observer Design Pattern for python gevent coroutine package (Python)
2010-12-08T08:33:30-08:00Andrey Nikishaevhttp://code.activestate.com/recipes/users/4176176/http://code.activestate.com/recipes/577491-observer-design-pattern-for-python-gevent-coroutin/
<p style="color: grey">
Python
recipe 577491
by <a href="/recipes/users/4176176/">Andrey Nikishaev</a>
(<a href="/recipes/tags/event/">event</a>, <a href="/recipes/tags/gevent/">gevent</a>, <a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is simple implementation of the observer design pattern. Acting as a registration hub, it fires events when requested.
Also i have gevent.Timeout like interface in situations when you need to run event-method in the same greenlet. Example: </p>
<pre class="prettyprint"><code>e = Observer()
ev = e.wait('kill')
try:
gevent.sleep(3)
except FiredEvent:
print 'Fired!'
else:
print 'Not Fired!'
finally:
ev.cancel()
</code></pre>
<p>But rememeber, if you are using subscribe method, event-method will be executed in another greenlet.</p>
Python data structure to XML (serialization) (Python)
2010-06-16T20:26:21-07:00David McCuskeyhttp://code.activestate.com/recipes/users/4174198/http://code.activestate.com/recipes/577268-python-data-structure-to-xml-serialization/
<p style="color: grey">
Python
recipe 577268
by <a href="/recipes/users/4174198/">David McCuskey</a>
(<a href="/recipes/tags/serialize/">serialize</a>, <a href="/recipes/tags/xml/">xml</a>).
Revision 2.
</p>
<p>This code serializes Python data structure into XML.</p>
<p>This is one part of a trio of recipes:</p>
<ul>
<li><a href="http://code.activestate.com/recipes/577266">Simple API</a></li>
<li><a href="http://code.activestate.com/recipes/577267">XML2Py De-serialization</a></li>
<li><a href="http://code.activestate.com/recipes/577268">Py2XML Serialization</a></li>
</ul>
<h5>For more information</h5>
<p>See <a href="http://code.activestate.com/recipes/577266">XML to Python data structure <a href="http://code.activestate.com/recipes/577266/">Recipe #577266</a></a></p>
POSIX context manager to temporarily silence, or filter lines from stdout (Python)
2010-03-03T06:17:23-08:00pwallerhttp://code.activestate.com/recipes/users/4173218/http://code.activestate.com/recipes/577083-posix-context-manager-to-temporarily-silence-or-fi/
<p style="color: grey">
Python
recipe 577083
by <a href="/recipes/users/4173218/">pwaller</a>
(<a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/freopen/">freopen</a>, <a href="/recipes/tags/silence/">silence</a>, <a href="/recipes/tags/stdout/">stdout</a>, <a href="/recipes/tags/with/">with</a>).
Revision 2.
</p>
<p>Fed up with libraries you don't have control over emitting text into your precious stdout?</p>
<p>If they use stdout through python, then you can just change sys.stdout to be something else. If they are printing directly to stdout through a C module, or some other means, then you are stuck.</p>
<p>.. at least until you discover the <code>with silence():</code> block!</p>
<p>Caveats: Non-portable, tested only on 2.6 under Linux, uses threading.</p>
<p>Example output:</p>
<pre class="prettyprint"><code>$ python silence_file.py
Before with block..
Sensible stuff!
After the silence block
</code></pre>
Using Pexpect and netrc to automate commands which prompt for a password (Python)
2008-05-17T04:54:46-07:00John Landahlhttp://code.activestate.com/recipes/users/483216/http://code.activestate.com/recipes/572207-using-pexpect-and-netrc-to-automate-commands-which/
<p style="color: grey">
Python
recipe 572207
by <a href="/recipes/users/483216/">John Landahl</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
Revision 2.
</p>
<p>System administrators sometimes need to automate commands which prompt for a password (or any other single prompt) before they execute. This recipe demonstrates using Pexpect and the built-in netrc module to automate these commands easily and relatively securely.</p>
KR(MKv3) - install.py (Python)
2007-03-20T18:38:08-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/510394-krmkv3-installpy/
<p style="color: grey">
Python
recipe 510394
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>The following program shows sample usage of the _winreg Wrapper.</p>
Aens Time (Python)
2007-02-20T18:38:25-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/502238-aens-time/
<p style="color: grey">
Python
recipe 502238
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>This recipe demonstrates a fictional time system
from the world of Aens. It is mainly for showing
how, in a game, a new system of time could alter
a player's perspective of location in the game.</p>
Paypal IPN (Python)
2006-09-19T19:02:54-07:00Anthony Barkerhttp://code.activestate.com/recipes/users/122940/http://code.activestate.com/recipes/456361-paypal-ipn/
<p style="color: grey">
Python
recipe 456361
by <a href="/recipes/users/122940/">Anthony Barker</a>
(<a href="/recipes/tags/cgi/">cgi</a>).
Revision 2.
</p>
<p>This is a cgi script that allows you to log an ipn request from paypal. Basically if you configure your paypal account with an ipn url it will send a post to a script url. You need to respond with a post and then will receive a VERIFIED response.</p>
<p>I've included a subroutine to log the data to a database, but you could simply use a text file if that is all you need.</p>
Align text string using spaces between words to fit specified width (Python)
2010-03-09T07:04:19-08:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/414870-align-text-string-using-spaces-between-words-to-fi/
<p style="color: grey">
Python
recipe 414870
by <a href="/recipes/users/57155/">Denis Barmenkov</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 5.
</p>
<p>Python 2.3 module textwrap can justify text in three modes: left/right/center.
Sometimes 'align' mode become more useful.</p>
fileinput as a generator (Python)
2002-02-09T23:25:26-08:00Brett Cannonhttp://code.activestate.com/recipes/users/98030/http://code.activestate.com/recipes/112506-fileinput-as-a-generator/
<p style="color: grey">
Python
recipe 112506
by <a href="/recipes/users/98030/">Brett Cannon</a>
(<a href="/recipes/tags/files/">files</a>).
Revision 2.
</p>
<p>This is a basic re-implementation of fileinput using generators. It supports all basic functionality that the library module has (nextfile(), lineno(), filelineno(), close(), and filename()). It also adds an __iter__() method that is a generator.</p>
Latitude/longitude/map web-fetcher (Python)
2001-08-20T18:11:28-07:00Will Warehttp://code.activestate.com/recipes/users/98156/http://code.activestate.com/recipes/52548-latitudelongitudemap-web-fetcher/
<p style="color: grey">
Python
recipe 52548
by <a href="/recipes/users/98156/">Will Ware</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>Given a list of cities, this recipe fetches their latitudes and longitudes from
one website (a database used for astrology, of all things) and uses them to
build a URL for another website which creates a map highlighting the cities
against the outlines of continents. Maybe some day it will be clever enough to
load the latitudes and longitudes as waypoints into your GPS receiver.</p>