Most viewed recipes tagged "meta:license=mit"http://code.activestate.com/recipes/tags/meta:license=mit/views/2017-07-15T00:46:59-07:00ActiveState Code RecipesThe Game of Tic Tac Toe in Python (Python)
2014-01-31T02:39:48-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578816-the-game-of-tic-tac-toe-in-python/
<p style="color: grey">
Python
recipe 578816
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>I thought this is a fun game to program. Easy to program and can teach a lot. </p>
<p><a href="http://thelivingpearl.com">Captain DeadBones</a></p>
Snake the game (Python)
2015-01-03T02:04:02-08:00Burak Tandoganhttp://code.activestate.com/recipes/users/4191373/http://code.activestate.com/recipes/578996-snake-the-game/
<p style="color: grey">
Python
recipe 578996
by <a href="/recipes/users/4191373/">Burak Tandogan</a>
(<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/snake/">snake</a>, <a href="/recipes/tags/the/">the</a>).
Revision 3.
</p>
<p>Popular Snake game with Python-Pygame module. <strong>Important:</strong> If you try to run this script without special <strong>png-wav</strong> files it will fail, you have to put following files to a directory with this script. "apple.png","snakehead.png","intro.wav","dead.wav". They are basically apple picture, head of snake, intro sound and dead sound.Without them script will not run. Just make inactive the statements intro.wav and dead.wav, and find a little apple picture and snake head :).Or you can play the game just install it. <strong>Here is the installer:</strong> <a href="http://dosya.co/7c6f15c0f4d04514/Flafel-1.26-win32.rar" rel="nofollow">http://dosya.co/7c6f15c0f4d04514/Flafel-1.26-win32.rar</a>
It will install the game in program files, you can find it in search "Flafel" and click to Flafel.exe. </p>
A-star Shortest Path Algorithm (C++)
2010-12-25T23:36:35-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577457-a-star-shortest-path-algorithm/
<p style="color: grey">
C++
recipe 577457
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/graphs/">graphs</a>, <a href="/recipes/tags/routes/">routes</a>).
Revision 4.
</p>
<p>A-star (A*) is a shortest path algorithm widely used for RTS games, GPS navigation etc.</p>
Uno (Text-Based) (Python)
2017-07-15T00:46:59-07:00Brandon Martinhttp://code.activestate.com/recipes/users/4194238/http://code.activestate.com/recipes/580811-uno-text-based/
<p style="color: grey">
Python
recipe 580811
by <a href="/recipes/users/4194238/">Brandon Martin</a>
(<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/cards/">cards</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/text_game/">text_game</a>, <a href="/recipes/tags/uno/">uno</a>).
</p>
<p>A text based recreation of the classic card game featuring functional AIs to play with. Some rules have been modified. User interface is text based, non-curses, using only simple python commands to draw it. </p>
OrderedSet (Python)
2012-12-19T07:12:32-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/576694-orderedset/
<p style="color: grey">
Python
recipe 576694
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/ordered/">ordered</a>, <a href="/recipes/tags/set/">set</a>).
Revision 9.
</p>
<p>Set that remembers original insertion order.</p>
How to use super() effectively -- Python 2.7 version (Python)
2011-06-01T19:19:37-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577721-how-to-use-super-effectively-python-27-version/
<p style="color: grey">
Python
recipe 577721
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/cooperative/">cooperative</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/multiple/">multiple</a>, <a href="/recipes/tags/next_in_mro/">next_in_mro</a>, <a href="/recipes/tags/super/">super</a>).
Revision 8.
</p>
<p>Python's super() provides a unique and amazing capability. It allows subclasses to be written to reorder a chain method calls. The recipe demonstrates all of the tradecraft needed to get super() to do your bidding.</p>
Python Short URL Generator (Python)
2011-09-19T14:06:36-07:00Michael Foglemanhttp://code.activestate.com/recipes/users/4171845/http://code.activestate.com/recipes/576918-python-short-url-generator/
<p style="color: grey">
Python
recipe 576918
by <a href="/recipes/users/4171845/">Michael Fogleman</a>
(<a href="/recipes/tags/deterministic/">deterministic</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/short/">short</a>, <a href="/recipes/tags/tiny/">tiny</a>, <a href="/recipes/tags/unique/">unique</a>, <a href="/recipes/tags/url/">url</a>).
Revision 3.
</p>
<p>Python implementation for generating Tiny URL- and bit.ly-like URLs.</p>
Ordered Dictionary for Py2.4 (Python)
2011-04-24T03:20:45-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/576693-ordered-dictionary-for-py24/
<p style="color: grey">
Python
recipe 576693
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/linked_list/">linked_list</a>, <a href="/recipes/tags/ordered/">ordered</a>).
Revision 9.
</p>
<p>Drop-in substitute for Py2.7's new collections.OrderedDict. The recipe has big-oh performance that matches regular dictionaries (amortized O(1) insertion/deletion/lookup and O(n) iteration/repr/copy/equality_testing).</p>
subtract or add a month to a datetime.date or datetime.datetime (Python)
2010-06-25T18:41:19-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577274-subtract-or-add-a-month-to-a-datetimedate-or-datet/
<p style="color: grey">
Python
recipe 577274
by <a href="/recipes/users/4173505/">Trent Mick</a>
(<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/datetime/">datetime</a>, <a href="/recipes/tags/month/">month</a>).
</p>
<p>Adding or subtracting a month to a Python <code>datetime.date</code> or <code>datetime.datetime</code> is a little bit of a pain. Here is the code I use for that. These functions return the same datetime type as given. They preserve time of day data (if that is at all important to you).</p>
<p>See also: </p>
<ul>
<li><a href="http://code.activestate.com/recipes/476197/">Recipe 476197</a>: First / Last Day of the Month.</li>
<li><a href="http://packages.python.org/MonthDelta/">monthdelta module</a></li>
</ul>
Pass Javascript arrays to PHP (PHP)
2005-05-16T11:45:33-07:00Noah Spurrierhttp://code.activestate.com/recipes/users/103276/http://code.activestate.com/recipes/414334-pass-javascript-arrays-to-php/
<p style="color: grey">
PHP
recipe 414334
by <a href="/recipes/users/103276/">Noah Spurrier</a>
(<a href="/recipes/tags/session/">session</a>).
</p>
<p>This is a Javascript function that will convert a Javascript array to a string in PHP serialized format. You can pass this string to a PHP script and easily unserialize it to a PHP array.</p>
Conversion of PIL Image and numpy array (Python)
2011-03-05T03:47:56-08:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/577591-conversion-of-pil-image-and-numpy-array/
<p style="color: grey">
Python
recipe 577591
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/pil/">pil</a>).
Revision 2.
</p>
<p>The utility function that converts PIL image to numpy array and vice versa.</p>
Microsoft Access Database Connectivity (DSN-Less) (PHP)
2006-08-29T03:08:29-07:00Erick Guanlaohttp://code.activestate.com/recipes/users/670494/http://code.activestate.com/recipes/163447-microsoft-access-database-connectivity-dsn-less/
<p style="color: grey">
PHP
recipe 163447
by <a href="/recipes/users/670494/">Erick Guanlao</a>
(<a href="/recipes/tags/database/">database</a>).
Revision 4.
</p>
<p>An example of connecting to a Microsoft Access database, executing an SQL query, and displaying the results in HTML using PHP and COM (Windows only).</p>
<p>NOTE: This works with PHP 4.x. I have been unsuccessful with getting this to work with PHP 5.1.6 and Apache 2.0.59 on Windowx XP Professional.</p>
Copy files over SSH using paramiko (Python)
2015-12-06T14:19:15-08:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/576810-copy-files-over-ssh-using-paramiko/
<p style="color: grey">
Python
recipe 576810
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/paramiko/">paramiko</a>, <a href="/recipes/tags/scp/">scp</a>, <a href="/recipes/tags/ssh/">ssh</a>).
Revision 20.
</p>
<p>This script copies files in unattended mode over SSH using a glob pattern. It uses the <a href="http://www.lag.net/paramiko/">paramiko</a> module behind the scenes. It operates as an actual SSH client, and does <em>not</em> rely on any command line utilities, such as <code>scp</code>.</p>
<p>It first tries to connect using a key from a private key file or from an SSH agent. If RSA authentication fails, it will try to authenticate with a password if passwords are allowed on the SSH server.
Assumes the <code>rsa_private_key</code> was generated with an empty passphrase.</p>
<p>On most linux/unix-like systems paramiko can be installed with <code>sudo easy_install paramiko</code> or <code>pip install paramiko</code> or using the built-in system package manager.</p>
<p>See also <a href="http://www.paramiko.org/installing.html" rel="nofollow">http://www.paramiko.org/installing.html</a></p>
Discrete PID Controller (Python)
2015-12-18T20:59:43-08:00Canerhttp://code.activestate.com/recipes/users/4114638/http://code.activestate.com/recipes/577231-discrete-pid-controller/
<p style="color: grey">
Python
recipe 577231
by <a href="/recipes/users/4114638/">Caner</a>
(<a href="/recipes/tags/controller/">controller</a>, <a href="/recipes/tags/derivative/">derivative</a>, <a href="/recipes/tags/discrete/">discrete</a>, <a href="/recipes/tags/integral/">integral</a>, <a href="/recipes/tags/pid/">pid</a>, <a href="/recipes/tags/proportional/">proportional</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>The recipe gives simple implementation of a Discrete Proportional-Integral-Derivative (PID) controller. PID controller gives output value for error between desired reference input and measurement feedback to minimize error value.
More information: <a href="http://en.wikipedia.org/wiki/PID_controller" rel="nofollow">http://en.wikipedia.org/wiki/PID_controller</a></p>
<p><strong>For new version please check:</strong> <a href="https://github.com/ivmech/ivPID" rel="nofollow">https://github.com/ivmech/ivPID</a></p>
Compute Memory footprint of an object and its contents (Python)
2012-11-23T23:57:31-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577504-compute-memory-footprint-of-an-object-and-its-cont/
<p style="color: grey">
Python
recipe 577504
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/sizeof/">sizeof</a>).
Revision 3.
</p>
<p>Recursive version sys.getsizeof(). Extendable with custom handlers.</p>
LDAP Authentication (PHP)
2001-12-07T11:00:34-08:00Shane Caraveohttp://code.activestate.com/recipes/users/98233/http://code.activestate.com/recipes/101525-ldap-authentication/
<p style="color: grey">
PHP
recipe 101525
by <a href="/recipes/users/98233/">Shane Caraveo</a>
(<a href="/recipes/tags/security/">security</a>).
</p>
<p>A simple LDAP Authentication script.</p>
SortedCollection (Python)
2010-09-01T02:12:33-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577197-sortedcollection/
<p style="color: grey">
Python
recipe 577197
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/bisect/">bisect</a>, <a href="/recipes/tags/collection/">collection</a>, <a href="/recipes/tags/sorted/">sorted</a>).
Revision 9.
</p>
<p>Wraps bisect.bisect() in an easy to use class that supports key-functions and straight-forward search methods.</p>
BFS (breadth first search) graph traversal (Python)
2009-03-02T20:20:56-08:00mojave kidhttp://code.activestate.com/recipes/users/4169379/http://code.activestate.com/recipes/576675-bfs-breadth-first-search-graph-traversal/
<p style="color: grey">
Python
recipe 576675
by <a href="/recipes/users/4169379/">mojave kid</a>
(<a href="/recipes/tags/bfs/">bfs</a>, <a href="/recipes/tags/breath/">breath</a>).
Revision 4.
</p>
<p>Guido illustrated the DFS recursive traversal of a graph (<a href="http://www.python.org/doc/essays/graphs.html" rel="nofollow">http://www.python.org/doc/essays/graphs.html</a>)
However if the graph is too big, recursion error occurs.</p>
<p>Here im pitching in my recipe for an iterative BFS traversal.</p>
<p>Im using Guido's graph representation using dictionary.</p>
The Game of Battleships in Python (Python)
2014-02-22T06:13:41-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578836-the-game-of-battleships-in-python/
<p style="color: grey">
Python
recipe 578836
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Another fun game that is fun to program and play. No special AI (yet). But still and entertaining game. </p>
<p>For more info about <a href="http://thelivingpearl.com/2014/02/17/the-game-of-battleships-in-python/">Battleships in Python</a> follow the link. </p>
Simple Web Crawler (Python)
2011-01-31T21:57:58-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/576551-simple-web-crawler/
<p style="color: grey">
Python
recipe 576551
by <a href="/recipes/users/4167757/">James Mills</a>
(<a href="/recipes/tags/crawler/">crawler</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/web/">web</a>).
Revision 2.
</p>
<p>NOTE: This recipe has been updated with suggested improvements since the last revision.</p>
<p>This is a simple web crawler I wrote to
test websites and links. It will traverse
all links found to any given depth.</p>
<p>See --help for usage.</p>
<p>I'm posting this recipe as this kind of
problem has been asked on the Python
Mailing List a number of times... I
thought I'd share my simple little
implementation based on the standard
library and BeautifulSoup.</p>
<p>--JamesMills</p>