Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

watch -- execute commands over and over again.

* Fast and easy way of setting a reminder for yourself, while working in the command line: ( sleep 10 && echo -e "Tea is ready\a" ) & 10 is a number of secons to wait until fire up the alarm, "-e" argument to echo forces it to see the "\a" sequence, which is an alarm bell.
* execute commands over and over again - run fortune (program) every 20 seconds, run program 'w' every 2 seconds (default), keep track of filename.
 watch -n 20 fortune
watch w
watch ls -l filename

Watch a log and/or search for a certain term

If you're developing on a server that has all PHP errors turned off, you can still watch the error log (if you have access to this file). For example on a dreamhost account you could try this:

tail -f /home/account/logs/website.com/http/error.log

As the errors pour in, you will see them come by. Change 'account' to the username you have on dreamhost and website.com to the domainname you host there. If the errors come in large amounts you can filter them by using grep:

tail -f /home/account/logs/website.com/http/error.log | grep -i "search_term"


Now only errors containing 'search_term' will be shown.

Stopwatch

It can start, stop, start again, and reset.
Use 'select' key and menu.
from appuifw import *
from key_codes import *
import e32, time

class StopWatch:
    running = 0
    time_start = None
    elap = 0.0

    def __init__(self):
        self.canvas = Canvas(self.update)
        app.body = self.canvas
        self.canvas.bind(EKeySelect, self.toggle)
        self.update()

    def update(self, rect=None):
        if self.running:
            self.elap = time.clock() - self.time_start
            e32.ao_sleep(0.05, self.update)
        t = self.elap
        min = int(t / 60)
        sec =  int(t - min*60)
        hsec = int((t - min*60 - sec)*100)
        self.canvas.clear()
        self.canvas.text((20,40), u"%02d:%02d:%02d" % (min,sec,hsec), font='title')

    def toggle(self):
        if self.running:
            self.running = 0
            self.elap = time.clock() - self.time_start
        else:
            self.running = 1
            self.time_start = time.clock() - self.elap
            self.update()

    def reset(self):
        self.running = 0
        self.elap = 0.0
        self.update()


sw = StopWatch()
lock = e32.Ao_lock()
app.menu = [(u'Reset', sw.reset), (u'Close', lock.signal)]
app.exit_key_handler = lock.signal
lock.wait()

Screenshot

I am new to using class var and instance var.
But the code seems easier than the non-OO version I tried at first.
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS