Popular recipes by Stephen Chappell http://code.activestate.com/recipes/users/2608421/2015-06-25T17:55:33-07:00ActiveState Code RecipesExamples for random float between 0 and 1 (Python) 2015-06-25T17:55:33-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/579072-examples-for-random-float-between-0-and-1/ <p style="color: grey"> Python recipe 579072 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/example/">example</a>, <a href="/recipes/tags/random/">random</a>). </p> <p>I was researching how floats are stored in a computer and was trying to think up a way to generate random values between 0 and 1. Python already provides an implementation allowing this already, and two of the functions below are directly inspired by that code, but the third is a slightly different way of doing the same thing. A similar version of this code has been used to implement similar functionality in C# at one time. Others might also find it useful if they want to create equivalent code in a separate language while having access to random bytes but not random floats. It should be noted that the various implementations get slower as you go down the list.</p> Draw a diamond with asterisks using recursion (Python) 2014-11-07T17:51:32-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578959-draw-a-diamond-with-asterisks-using-recursion/ <p style="color: grey"> Python recipe 578959 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/drawing/">drawing</a>). </p> <p>Given the following function header:</p> <pre class="prettyprint"><code>def triangles(n): </code></pre> <p>If n for example is 5, then the drawing would be like this:</p> <pre class="prettyprint"><code> * * * * * * * * * * * * * </code></pre> Self Counter (Python) 2013-08-02T03:15:12-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578621-self-counter/ <p style="color: grey"> Python recipe 578621 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/counter/">counter</a>). </p> <p>This script was written as a revision of <a href="http://code.activestate.com/recipes/577456/">recipe 577456</a> as a variation on a theme.</p> Text Editor in Python 3.3 (Python) 2013-06-19T15:58:17-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578569-text-editor-in-python-33/ <p style="color: grey"> Python recipe 578569 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_processing/">text_processing</a>). </p> <p>This is a simple text editor written in Python using <code>tkinter</code> for graphics.</p> <p>Check out Captain DeadBones' <a href="http://thelivingpearl.com/">Chronicles</a> blog.</p> The Easy Cow (Python) 2012-12-06T14:22:36-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578367-the-easy-cow/ <p style="color: grey"> Python recipe 578367 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>If you thought the programs for <a href="http://code.activestate.com/recipes/578366/">recipe 578366</a> were too difficult to understand, you have just found an upgrade to the COW language: mnemonics humans can understand. This recipe makes a slight alteration to the interpreter so as to take the decoded instructions instead of the COW (moo) instructions.</p> War Game (Version 5) (Python) 2012-12-07T01:40:06-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578369-war-game-version-5/ <p style="color: grey"> Python recipe 578369 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>Part of the War Game set, this version of War Game further advanced the program in an environment without curses. Showing another iteration of development, the recipe here program for more fun with a virtual card game and ASCII graphic card representations while playing.</p> Profile Manager (Cave Story) (Python) 2012-12-07T01:21:04-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578368-profile-manager-cave-story/ <p style="color: grey"> Python recipe 578368 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/manager/">manager</a>, <a href="/recipes/tags/profile/">profile</a>). </p> <p>If you have ever played a game that only had one save slot and wanted to be able to manage profiles, the following code written for Cave Story may be of use to you. The recipe provides a starting point for how one might go about writing a profile manager for such a program that runs through a command interface.</p> War 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> The Normal Cow (Python) 2012-12-06T14:14:28-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578366-the-normal-cow/ <p style="color: grey"> Python recipe 578366 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>Ever heard of an esoteric language named COW or wanted to run a program written with just the letters M and O? This recipe provides a COW interpreter that is able to run such programs and decodes them so that they are much easier to read for those who do not know the common bovine tongue.</p> Byte Frequency Analyzer (Python) 2012-12-05T23:48:53-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578361-byte-frequency-analyzer/ <p style="color: grey"> Python recipe 578361 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>). </p> <p>When beginning to compress a file or studying it to break certain forms of encryption, sometimes it is helpful to know how many bytes of a certain category are in a file. This recipe is a simple frequency analysis tool that may be helpful towards that end and can provide a starting point for those interested tools for such fields.</p> Load Runner for the Console (Python) 2012-12-07T02:05:40-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578371-load-runner-for-the-console/ <p style="color: grey"> Python recipe 578371 by <a href="/recipes/users/2608421/">Stephen Chappell</a> . </p> <p>Part of a tutorial of programming Load Runner in Python, this code shows the evolution to creating a simple game in the language that should be able to run on Windows. The original code was supposed to run on Linux, but this recipe takes the idea in another direction and shows that programs can be created incrementally. Please note the various file divisions: <code>load1</code>, <code>load2</code>, <code>load3</code>, <code>load4</code>, <code>load5</code>, and <code>Extended Demo (Sound)</code>.</p> Averaging Literal Numbers (Python) 2012-12-06T13:44:42-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578365-averaging-literal-numbers/ <p style="color: grey"> Python recipe 578365 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/numbers/">numbers</a>). </p> <p>One program that a teacher may assign to beginning programming students would be to take a list of numbers and average them together. This recipe does just that and is designed to be easy to read and follow, showing what is possible with a few lines of Python.</p> EZ DDX COW (Python) 2012-12-07T02:21:51-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578373-ez-ddx-cow/ <p style="color: grey"> Python recipe 578373 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>As with the original easy cow in <a href="http://code.activestate.com/recipes/578367/">recipe 578367</a>, a simple change to the original program allows for programming in a much more human-readable way. This recipe also allows for DDX programming and provides two more example COW programs below it as a demonstration of what may be done with the interesting language.</p> Samuel F. B. Morse's Code (Python) 2012-12-06T04:20:31-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578364-samuel-f-b-morses-code/ <p style="color: grey"> Python recipe 578364 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/code/">code</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/morse/">morse</a>, <a href="/recipes/tags/morse_code/">morse_code</a>, <a href="/recipes/tags/morse_practice_oscillator/">morse_practice_oscillator</a>, <a href="/recipes/tags/sound/">sound</a>). </p> <p>Many people have heard of Morse['s] Code, and it still is a helpful skill to have in certain context, as advanced as technology has become. The following recipe shows two sample ways that it can be implemented and shows some diversity in how problems can be solved in Python or many other languages for that matter.</p> Command Line Windows Alarm Clock (Python) 2012-12-05T23:53:49-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578362-command-line-windows-alarm-clock/ <p style="color: grey"> Python recipe 578362 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/clock/">clock</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>Using primitive but simple calculations, the alarm program below will find the offset to the time specified, sleep, and awake to run an alarm until terminated. This Windows recipe utilizes the <code>msvcrt</code> and <code>winsound</code> modules to operate and has limited use elsewhere.</p> COW with DDX (Python) 2012-12-07T02:17:19-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578372-cow-with-ddx/ <p style="color: grey"> Python recipe 578372 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>Once you get bored with <a href="http://code.activestate.com/recipes/578366/">recipe 578366</a>, extending COW with DDX (Distributed Digestion eXtentions) provides a way to enhance program and replace instructions with more powerful options. This recipe provides a COW interpreter that utilities extra stomachs for the bovines to do their processing in.</p> Countdown Timer (Python) 2012-12-06T03:24:35-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578363-countdown-timer/ <p style="color: grey"> Python recipe 578363 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/timer/">timer</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>Ever wanted to set a timer that went off after a specified number of hours / minutes / seconds? This Windows recipe runs on the command line and does that with the arguments it accepts. Simple but effective, the program works well for remembering food in the oven among other things.</p> Directory Cleaner (Python) 2012-12-05T20:56:05-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578357-directory-cleaner/ <p style="color: grey"> Python recipe 578357 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>). </p> <p>If there is a particular directory that you want purged of its files and want a solution in Python, this simple program is designed to do just that. This recipe is just meant as a starting point for those wondering how to delete all files and sub-folders from a central folder.</p> Media File Renamer (Python) 2012-12-05T21:04:38-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578359-media-file-renamer/ <p style="color: grey"> Python recipe 578359 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>). </p> <p>Have you ever been annoyed with the names digital cameras give to their pictures? After considering the problem and wanting to standardize filenames, the following program was written to give files in their respective directories similar names according to a convention. For those who may be just starting out with programming and have a similar objective, this recipe may help show some of what may be involved in the process.</p> File Path Logger (Python) 2012-12-05T20:59:38-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578358-file-path-logger/ <p style="color: grey"> Python recipe 578358 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>). </p> <p>If you want a list of directories and the files they contain, this program will log such information to a file for you. For those wondering how to walk directories and their contents, this little recipe provides an <code>engine</code> function that provides a simple demonstration of the <code>os.walk</code> function.</p>