Archive for the 'Python' Category
Pelikoodausta Pythonilla
Kävin tänään kertomassa peliohjelminnista Python-kielellä Oulun yliopiston ohjelmoinnin perusteet -kurssilaisille. Session tuloksena syntyi matopeli, jonka voi ladata alta:
Pelataksesi peliä tarvit Pythonin sekä pyglet-lisäkirjaston. Peli toimii Linuxilla, Windowsilla sekä Mac OS X:llä. Kiitokset Tommille musiikista ja ääniefekteistä.
English translation
Today I gave a presentation on game programming using Python to the students attending Programming 101 at the University of Oulu. The result of the session was a classic snake game, which you can download above.
In order to play the game you’ll need Python and the pyglet-module. The game works on Linux, Windows and Mac OS X. Thanks to Tommi for the music and sound effects.
4 commentsDisable mandatory screen saver
So you’re trying to watch a movie on your shiny new corporate laptop. Ten minutes into the film, the automatic screen saver kicks in, locks the machine and forces you to re-login. The little weasels at IT have even disabled the screen saver properties, so you can’t even turn it off.
Here’s a tiny python script that will fake keyboard activity every five minutes in order to prevent a screen saver from activating.
"""Fake keyboard activity to prevent screen
saver from activating."""
import win32api
import win32con
import time
while True:
print "Faking keyboard activity at", time.asctime()
win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
win32api.keybd_event(win32con.VK_SHIFT, 0, \\
win32con.KEYEVENTF_KEYUP, 0)
time.sleep(60 * 5)
Download:
2 commentsStakeout
This program monitors a bunch of files and runs a command when any of them changes.
The idea was pilfered from Pragmatic Automation. This program uses fcntl and thus only works on Unix derivatives.
Here’s how you might use it:
find -name \*.py | xargs ./stakeout.py src/TestAll.py
Download: Python source, Example shell script
No commentspyhtml
PHP-style inline code in Python.
Here’s a sample html file:
<html> <body> The square of 5 is <? print 5*5 ?> . </body> </html>
Note that the opening and closing tags (<? and ?>) must be in separate lines.
Installation for Apache
Add the following to your httpd.conf and copy this script into your
cgi-bin directory:
AddHandler python-parsed-html .pyhtml Action python-parsed-html /cgi-bin/pyhtml.py
Also, make sure you have the actions modules (mod_actions) loaded or the above won’t work.
Download: pyhtml.py
No comments
