Popular recipes tagged "meta:requires=time"http://code.activestate.com/recipes/tags/meta:requires=time/popular/2017-07-15T00:46:59-07:00ActiveState Code RecipesUno (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>
Implementing function-based callbacks in Python (Python)
2017-04-19T18:03:11-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580787-implementing-function-based-callbacks-in-python/
<p style="color: grey">
Python
recipe 580787
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/callback/">callback</a>, <a href="/recipes/tags/function/">function</a>, <a href="/recipes/tags/functions/">functions</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/techniques/">techniques</a>).
</p>
<p>This recipe shows a simple way of implementing callbacks in Python. There are a few ways this can be done. The way shown here uses a simple function-based approach.</p>
<p>In a nutshell, a callback can be informally described like this: function <strong>a</strong> calls function <strong>b</strong>, and wants to make <strong>b</strong> run a specific independent chunk of code at some point during <strong>b</strong>'s execution. We want to be able to vary which chunk of code gets called in different calls to <strong>b</strong>, so it cannot be hard-coded inside <strong>b</strong>. So function <strong>a</strong> passes another function, <strong>c</strong>, to <strong>b</strong>, as one argument, and <strong>b</strong> uses that parameter <strong>c</strong> to call the functionality that <strong>a</strong> wants <strong>b</strong> to call. (Function <strong>b</strong> may pass some parameters to the function represented by <strong>c</strong>, when it calls it. These could be either internally generated, passed from <strong>a</strong>, or a combination of both). So, by changing the value of the function <strong>c</strong> that gets passed to <strong>b</strong> (on different calls to <strong>b</strong>), <strong>a</strong> can change what chunk of code <strong>b</strong> calls.</p>
<p>More details and full code, description and output here:</p>
<p><a href="https://jugad2.blogspot.in/2017/04/implementing-and-using-callbacks-in.html" rel="nofollow">https://jugad2.blogspot.in/2017/04/implementing-and-using-callbacks-in.html</a></p>
Implementing class-based callbacks in Python (Python)
2017-04-20T23:34:50-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580788-implementing-class-based-callbacks-in-python/
<p style="color: grey">
Python
recipe 580788
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/callbacks/">callbacks</a>, <a href="/recipes/tags/classes/">classes</a>, <a href="/recipes/tags/functions/">functions</a>, <a href="/recipes/tags/methods/">methods</a>, <a href="/recipes/tags/objects/">objects</a>, <a href="/recipes/tags/programming/">programming</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is a follow-on to this recently posted recipe:</p>
<p>Implementing function-based callbacks in Python:
<a href="https://code.activestate.com/recipes/580787-implementing-function-based-callbacks-in-python/?in=user-4173351" rel="nofollow">https://code.activestate.com/recipes/580787-implementing-function-based-callbacks-in-python/?in=user-4173351</a></p>
<p>This new recipe shows how to create and use callbacks in Python, using classes with methods, instead of plain functions, as was done in the recipe linked above. All other points such as reasons and benefits for using callbacks, are more or less the same as mentioned in the previous recipe, except that class instances can carry state around, so to that extent, the two approaches are different.</p>
<p><a href="https://jugad2.blogspot.in/2017/04/python-callbacks-using-classes-and.html" rel="nofollow">https://jugad2.blogspot.in/2017/04/python-callbacks-using-classes-and.html</a></p>
Lines Of Code (LOC) (Python)
2016-10-25T17:53:01-07:00Jean Brouwershttp://code.activestate.com/recipes/users/2984142/http://code.activestate.com/recipes/580709-lines-of-code-loc/
<p style="color: grey">
Python
recipe 580709
by <a href="/recipes/users/2984142/">Jean Brouwers</a>
(<a href="/recipes/tags/count/">count</a>, <a href="/recipes/tags/lines/">lines</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/source/">source</a>).
Revision 3.
</p>
<p>Count the number of lines (code, comment, blank) in one or several Python source files.</p>
A command-line musical alarm clock (Python)
2016-12-30T19:06:32-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580739-a-command-line-musical-alarm-clock/
<p style="color: grey">
Python
recipe 580739
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/clock/">clock</a>, <a href="/recipes/tags/multimedia/">multimedia</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/playsound/">playsound</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>).
</p>
<p>This is a simple musical alarm clock in Python. You pass a command-line argument specifying the time in minutes after which the alarm should go off. When that time arrives, it plays a musical sound.</p>
Publish a Windows Process List to PDF with xtopdf (Batch)
2015-12-27T20:45:32-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579142-publish-a-windows-process-list-to-pdf-with-xtopdf/
<p style="color: grey">
Batch
recipe 579142
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/processes/">processes</a>, <a href="/recipes/tags/process_management/">process_management</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how you can generate a Windows process list or task list (basically, a list of running processes, with some information about each of them), to a PDF file, using the Windows TASKLIST command along with the xtopdf toolkit. The list is sorted in ascending order of memory usage of the processes, before writing it to PDF.</p>
<p>It differs somewhat from other xtopdf recipes, in that no additional code needs to be written, over and above what is already in the xtopdf package. We just have to use the needed commands there, in a series of commands or a pipeline.</p>
<p>However, one can still write additional code, by modifying the program used (StdinToPDF.py), if needed, to customize the PDF output.</p>
Space Assault (Python)
2016-04-06T23:31:28-07:00Tage Burnetthttp://code.activestate.com/recipes/users/4193902/http://code.activestate.com/recipes/580636-space-assault/
<p style="color: grey">
Python
recipe 580636
by <a href="/recipes/users/4193902/">Tage Burnett</a>
(<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is a game I created on Python without the use of Pygame</p>
Simple command-line alarm clock in Python (Python)
2015-10-25T18:27:27-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579117-simple-command-line-alarm-clock-in-python/
<p style="color: grey">
Python
recipe 579117
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/clock/">clock</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple alarm clock in Python, that can be run from the command line in a terminal. It lets you specify the alarm time in minutes as a command line argument, and prints a wake-up message and beeps a few times, after that time arrives. You can use 0 for the minutes to test it immediately, including to adjust the volume using your speaker controls.</p>
Using ctypes to call C code from Python (Python)
2016-05-09T18:00:44-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580660-using-ctypes-to-call-c-code-from-python/
<p style="color: grey">
Python
recipe 580660
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/ffi/">ffi</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/time/">time</a>).
</p>
<p>This recipe shows basic usage of the ctypes module to call C code from Python code.</p>
LRU dictionary (Python)
2016-04-17T01:22:01-07:00Felixhttp://code.activestate.com/recipes/users/4193957/http://code.activestate.com/recipes/580644-lru-dictionary/
<p style="color: grey">
Python
recipe 580644
by <a href="/recipes/users/4193957/">Felix</a>
(<a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/expiration/">expiration</a>, <a href="/recipes/tags/expiring/">expiring</a>, <a href="/recipes/tags/lru/">lru</a>, <a href="/recipes/tags/lru_cache/">lru_cache</a>, <a href="/recipes/tags/python3/">python3</a>).
</p>
<p>For most cases where you want to store a limited amount of data, functools.partial is sufficient. However, if you want or need more control over your data, especially specifying an expiration date for your entries, this can come in handy.</p>
<p>Read the docstrings for implementation details.</p>
LRU dictionary (Python)
2016-04-17T01:22:51-07:00Felixhttp://code.activestate.com/recipes/users/4193957/http://code.activestate.com/recipes/580645-lru-dictionary/
<p style="color: grey">
Python
recipe 580645
by <a href="/recipes/users/4193957/">Felix</a>
(<a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/expires/">expires</a>, <a href="/recipes/tags/expiring/">expiring</a>, <a href="/recipes/tags/lru/">lru</a>, <a href="/recipes/tags/lru_cache/">lru_cache</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>).
</p>
<p>For most cases where you want to store a limited amount of data, functools.partial is sufficient. However, if you want or need more control over your data, especially specifying an expiration date for your entries, this can come in handy.</p>
<p>Read the docstrings for implementation details.</p>
Generate a PDF invoice with xtopdf and Python (Python)
2015-10-07T18:02:46-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579108-generate-a-pdf-invoice-with-xtopdf-and-python/
<p style="color: grey">
Python
recipe 579108
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows the basics of how to generate invoices as PDF documents, using xtopdf, a Python toolkit for PDF creation. An example of creating a simple invoice through Python and xtopdf code is shown. </p>
<p>xtopdf is available on Bitbucket at:</p>
<p><a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p>
<p>and you can find many links with examples of using xtopdf, how to install it, etc., from this Google search:</p>
<p><a href="https://google.com/search?q=xtopdf" rel="nofollow">https://google.com/search?q=xtopdf</a></p>
<p>This sub-feed of my blog:</p>
<p><a href="http://jugad2.blogspot.com/search/label/xtopdf" rel="nofollow">http://jugad2.blogspot.com/search/label/xtopdf</a></p>
<p>gives access to all my blog posts labelled xtopdf.</p>
Use PyAudio to play a list of WAV files (Python)
2015-10-22T18:24:08-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579116-use-pyaudio-to-play-a-list-of-wav-files/
<p style="color: grey">
Python
recipe 579116
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>This recipe shows how to use PyAudio, a 3rd-party Python audio toolkit, to play a list of WAV files on your computer. This is an enhanced version of a basic WAV code example on the PyAudio site. You can specify either one WAV filename on the command line, like this:</p>
<p>py pyaudio_play_wav.py chimes.wav</p>
<p>or specify a text file containing names of WAV files to play, like this:</p>
<p>py pyaudio_play_wav.py -f wav_fil_list.txt</p>
<p>The only dependency is PyAudio, which you can install with pip.</p>
Mandelbrot Set made simple (Python)
2015-12-28T17:56:08-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579143-mandelbrot-set-made-simple/
<p style="color: grey">
Python
recipe 579143
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/mandelbrot/">mandelbrot</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 2.
</p>
<p>This is a mini-framework for exploring the Mandelbrot Set.</p>
<p>It outputs to a Tkinter window or to a PNG file (Pillow package required). It includes a disk caching mechanism for saving and later retrieving Mandelbrot calculations to avoid recalculating the Set on each run.</p>
<p>See module documentation for further information. Compatible with Python 2 and 3.</p>
vlc.py stream capture scheduler script (Python)
2015-08-19T05:00:25-07:00jwhite88http://code.activestate.com/recipes/users/4192711/http://code.activestate.com/recipes/579096-vlcpy-stream-capture-scheduler-script/
<p style="color: grey">
Python
recipe 579096
by <a href="/recipes/users/4192711/">jwhite88</a>
(<a href="/recipes/tags/recording/">recording</a>, <a href="/recipes/tags/stream/">stream</a>, <a href="/recipes/tags/vlc/">vlc</a>).
</p>
<p>Capture network streams using vlc.py on a schedule.</p>
high precision FPS (Python)
2015-05-12T12:04:38-07:00Jiri Justrahttp://code.activestate.com/recipes/users/4192188/http://code.activestate.com/recipes/579053-high-precision-fps/
<p style="color: grey">
Python
recipe 579053
by <a href="/recipes/users/4192188/">Jiri Justra</a>
(<a href="/recipes/tags/fps/">fps</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/games/">games</a>, <a href="/recipes/tags/pure/">pure</a>).
Revision 2.
</p>
<p>This code adjust itself for set FPS value. It is much more precise that time.sleep fps implementation.</p>
Tail multiple pidgin IRC logfiles (Python)
2015-06-06T12:13:00-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/579066-tail-multiple-pidgin-irc-logfiles/
<p style="color: grey">
Python
recipe 579066
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/colorize/">colorize</a>, <a href="/recipes/tags/irc/">irc</a>, <a href="/recipes/tags/iterators/">iterators</a>, <a href="/recipes/tags/logfiles/">logfiles</a>, <a href="/recipes/tags/merging/">merging</a>, <a href="/recipes/tags/nonblocking/">nonblocking</a>, <a href="/recipes/tags/pidgin/">pidgin</a>, <a href="/recipes/tags/tail/">tail</a>, <a href="/recipes/tags/threads/">threads</a>).
Revision 2.
</p>
<p>Tail multiple pidgin IRC logfiles. </p>
<p>Pidgin should be connected to IRC with the channels one
wants to tail joined, and it should save logs as text.</p>
<p>The script needs two arguments:</p>
<pre class="prettyprint"><code>the directory containing the directories with channel logs
a list of channel names, quoted and separated by spaces
</code></pre>
<p>Example command:</p>
<p>python pidgin-irctail.py
-d <a href="mailto:~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net">~/.purple/logs/irc/YOUR_IRC_HANDLE@irc.freenode.net</a>
-c "#chan1 #chan2 #chan3"</p>
<p>Some text elements are higlighted, and channel names are
inserted into the log lines after the time info.</p>
<p>If more than one channel is entered, the output of the logs
is merged. </p>
Convert doc and docx files to pdf (Python)
2014-03-31T18:39:16-07:00Fabian Mayerhttp://code.activestate.com/recipes/users/4189629/http://code.activestate.com/recipes/578858-convert-doc-and-docx-files-to-pdf/
<p style="color: grey">
Python
recipe 578858
by <a href="/recipes/users/4189629/">Fabian Mayer</a>
(<a href="/recipes/tags/doc/">doc</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/win32com/">win32com</a>).
Revision 2.
</p>
<p>The Script converts all doc and docx files in a specified folder to pdf files. It checks whether the provided absolute path does actually exist and whether the specified folder contains any doc and docx files. It does not travers the directory recursively. The script is not portable and runs only a Windows machine. Based on the experience I made, I recommend closing MS Word before running the script.</p>
HANGMAN! (Python)
2015-09-21T20:49:41-07:00Burak Tandoganhttp://code.activestate.com/recipes/users/4191373/http://code.activestate.com/recipes/578984-hangman/
<p style="color: grey">
Python
recipe 578984
by <a href="/recipes/users/4191373/">Burak Tandogan</a>
(<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/hangman/">hangman</a>, <a href="/recipes/tags/python/">python</a>).
Revision 9.
</p>
<p>Classic Hangman on console, check how hang the man with codes! Click 'download' and left click the .py file, have fun!</p>
Rock,Paper,Scissors (Python)
2014-12-19T05:39:38-08:00Burak Tandoganhttp://code.activestate.com/recipes/users/4191373/http://code.activestate.com/recipes/578983-rockpaperscissors/
<p style="color: grey">
Python
recipe 578983
by <a href="/recipes/users/4191373/">Burak Tandogan</a>
(<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/paper/">paper</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/rock/">rock</a>, <a href="/recipes/tags/scissors/">scissors</a>).
Revision 2.
</p>
<p>A simple game :)</p>