Latest recipes tagged "programming" but not "methods"http://code.activestate.com/recipes/tags/programming-methods/new/2017-02-23T22:38:50-08:00ActiveState Code RecipesSimulating an unless (reverse if) statement in Python (Python) 2017-02-23T22:38:50-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580758-simulating-an-unless-reverse-if-statement-in-pytho/ <p style="color: grey"> Python recipe 580758 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/features/">features</a>, <a href="/recipes/tags/if/">if</a>, <a href="/recipes/tags/perl/">perl</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/trick/">trick</a>). </p> <p>This recipe shows how to simulate an unless statement (a sort of reverse if, like Perl has), in Python. It is just for fun and as an experiment, not meant for real use, because the effect of unless can easily be got by negating the sense of the condition in an if statement.</p> <p>More details and output here:</p> <p><a href="https://jugad2.blogspot.in/2017/02/perl-like-unless-reverse-if-feature-in.html" rel="nofollow">https://jugad2.blogspot.in/2017/02/perl-like-unless-reverse-if-feature-in.html</a></p> Python one-liner to compare two files (Python) 2016-03-28T21:36:31-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580632-python-one-liner-to-compare-two-files/ <p style="color: grey"> Python recipe 580632 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>As the title says ...</p> <p>It prints True if the files compared are the same, and False if they differ (either in size or in content).</p> Hamming Neighbors (Python) 2013-01-17T20:50:21-08:00Yong Shinhttp://code.activestate.com/recipes/users/4184933/http://code.activestate.com/recipes/578423-hamming-neighbors/ <p style="color: grey"> Python recipe 578423 by <a href="/recipes/users/4184933/">Yong Shin</a> (<a href="/recipes/tags/distance/">distance</a>, <a href="/recipes/tags/dynamic/">dynamic</a>, <a href="/recipes/tags/hamming/">hamming</a>, <a href="/recipes/tags/programming/">programming</a>). </p> <p>HammingNeighbors returns all integers that are k number of bits away (i.e. k Hamming distance away) from an integer. <br /> The algorithm uses dynamic programming.</p> Libreenect (OpenKinect) Minimum Value Joystick With Display - Kinect Demo Using OpenKinect SDK (Python) 2012-03-18T18:52:42-07:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/578080-libreenect-openkinect-minimum-value-joystick-with-/ <p style="color: grey"> Python recipe 578080 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/computer_vision/">computer_vision</a>, <a href="/recipes/tags/depth/">depth</a>, <a href="/recipes/tags/joystick/">joystick</a>, <a href="/recipes/tags/kinect/">kinect</a>, <a href="/recipes/tags/libfreenect/">libfreenect</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/opencv/">opencv</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/virtual_joystick/">virtual_joystick</a>). Revision 3. </p> <p>This demo requires you to be using a Linux machine and to have libfreenect installed with the python wrapper. This demo also requires you to have opencv, numpy, and pygame. They can all be installed using sudo apt-get install {PROGRAM NAME HERE}. Here are instructions on installing libfreenect: <a href="http://openkinect.org/wiki/Getting_Started" rel="nofollow">http://openkinect.org/wiki/Getting_Started</a>. Okay, so what this demo does is finds the minimum point on the depth image and uses the index of this minimum point to create a four button joystick that codes for 'A', 'B', 'X', 'Y'. It also uses the minimum point and the RGB image to put a circle on the minimum point on the screen. So basically a dot will follow your hand on the RGB image. If the minimum value is larger than 600 (arbitrary units), the color of the dot will change from red to purple and the dot will remain stationary. Also, if the Kinect is not properly opened the first time, unplug it and plug it back in and run in the terminal sudo freenect-glview. After try running the program again. One more thing, this code requires super user privileges so run it through the terminal. Here is how to do this for linux n00bs.</p> <ol> <li>Change your directory the the directory the code is in (use cd {PATH})</li> <li>Run the code using sudo python {FILENAME}</li> <li>Don't forget to add the the .py at the end</li> </ol>