Popular recipes tagged "meta:loc=175"http://code.activestate.com/recipes/tags/meta:loc=175/2012-12-07T01:49:19-08:00ActiveState Code RecipesWar Game (Version 6) (Python)
2012-12-07T01:49:19-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578370-war-game-version-6/
<p style="color: grey">
Python
recipe 578370
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/card/">card</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/game/">game</a>).
</p>
<p>As the final version of the War Game, development finally came to a halt as the prototype exceeded it bounds for design. Yes, you can write your program as one large function, but should you? This recipe demonstrates that program without proper style can lead to a mess very quickly. Practice good coding standards, or you can easily loose focus and the ability to maintain your code.</p>
OpenKinect Mouse Control Using Python (Python)
2012-04-15T18:49:00-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578104-openkinect-mouse-control-using-python/
<p style="color: grey">
Python
recipe 578104
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/computer/">computer</a>, <a href="/recipes/tags/computer_vision/">computer_vision</a>, <a href="/recipes/tags/depth/">depth</a>, <a href="/recipes/tags/hand_tracking/">hand_tracking</a>, <a href="/recipes/tags/kinect/">kinect</a>, <a href="/recipes/tags/mouse/">mouse</a>, <a href="/recipes/tags/opencv/">opencv</a>, <a href="/recipes/tags/openkinect/">openkinect</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tracking/">tracking</a>, <a href="/recipes/tags/vision/">vision</a>).
Revision 2.
</p>
<p>This is a simple code that lets a user control the mouse and left-click using the Microsoft Kinect, Python, and OpenKinect. </p>
<pre class="prettyprint"><code>Computer Prerequisites:
-OpenKinect
-Python Wrapper for OpenKinect
-A Linux machine using Ubuntu
-OpenCV 2.1
-OpenCV 2.3
-Python 2.7.2
-A Microsoft Kinect
-A Microsoft Kinect USB Adapter
-PyGame
-Xlib for Python
</code></pre>
<p>To run this code you either need to start it in the terminal or you need to write a short bash script that runs the code. This is necessary because it requires super-user privileges.</p>
<p>The Bash script is (Assuming the code is saved by the name 'Hand Tracking.py' in /home/$USER directory:</p>
<pre class="prettyprint"><code>#!bin/bash
cd 'home/$USER'
gksudo python 'Hand Tracking.py'
</code></pre>
<p>The code is heavily commented and most of what you will need to know is there. </p>
Rsync Algorithm (Python)
2011-01-09T16:32:22-08:00Eric Pruitthttp://code.activestate.com/recipes/users/4170757/http://code.activestate.com/recipes/577518-rsync-algorithm/
<p style="color: grey">
Python
recipe 577518
by <a href="/recipes/users/4170757/">Eric Pruitt</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/delta/">delta</a>, <a href="/recipes/tags/diff/">diff</a>, <a href="/recipes/tags/patch/">patch</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/rsync/">rsync</a>).
Revision 4.
</p>
<p>This is a pure Python implementation of the <a href="http://samba.anu.edu.au/rsync/">rsync algorithm</a>. On my desktop (3.0GHz dual core, 7200RPM), best case throughput for target file hash generation and delta generation is around 2.9MB/s. Absolute worst case scenario (no blocks in common) throughput for delta generation is 200KB/s to 300KB/s on the same system.</p>
<p>Tested in Python 2.5, 2.6, and 3.1. In 2.7, io.BufferedReader should yield the best throughput. On all other versions use __builtin__.open.</p>
The Matrix Effect (JavaScript)
2009-07-28T10:13:20-07:00Panda Moniomhttp://code.activestate.com/recipes/users/4171270/http://code.activestate.com/recipes/576861-the-matrix-effect/
<p style="color: grey">
JavaScript
recipe 576861
by <a href="/recipes/users/4171270/">Panda Moniom</a>
(<a href="/recipes/tags/dynamic_drive/">dynamic_drive</a>, <a href="/recipes/tags/effect/">effect</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/text/">text</a>).
</p>
<p>This code is and opensource code from Dynamic Drive.</p>
<p>Add the Matrix effect to any text. I have displayed the code for and entire demo page. Any text that you want to have the Matrix effect, put it inside <div id="matrix> and </div>.</p>
regexplace: regular expression search and replace (Python)
2006-02-08T00:44:06-08:00Stefano Spinuccihttp://code.activestate.com/recipes/users/787328/http://code.activestate.com/recipes/473828-regexplace-regular-expression-search-and-replace/
<p style="color: grey">
Python
recipe 473828
by <a href="/recipes/users/787328/">Stefano Spinucci</a>
(<a href="/recipes/tags/text/">text</a>).
Revision 4.
</p>
<p>This script search and replace files in a directory, recursively.</p>
<p>file name and search string can be a regular expression.</p>
<p>Execution can be simulated, step by step, and are always shown changed files/lines.</p>
BaseDict -- a dict that (1) accesses data thru attributing (2) copy correctly (Python)
2006-01-27T06:44:54-08:00runsun panhttp://code.activestate.com/recipes/users/2638612/http://code.activestate.com/recipes/473790-basedict-a-dict-that-1-accesses-data-thru-attribut/
<p style="color: grey">
Python
recipe 473790
by <a href="/recipes/users/2638612/">runsun pan</a>
(<a href="/recipes/tags/shortcuts/">shortcuts</a>).
Revision 3.
</p>
<p><code>A dict extension that has the following features:</p>
<pre class="prettyprint"><code>1. dual data storages: use 'bd.x' or 'bd["x"]' for one,
and bd.getDict() for another.
2. All the followings are equivalent::
bd['x']= val
bd.x = val
bd.setItem('x', val) # Return bd
3. bd.setDict('x',val) will save 'x' to bd.__dict__,
but not bd.items
4. When copy, copy the internal object correctly.
</code></pre>
<p></code></p>