Saturday, December 25, 2010

How To Tease Everyone On Christmas

This project may never become a serious thing, but it is fun. I intend to write an introductory post on the project, but for now I just want to post two code examples that should peek some interest.

from trapdoor.extension import Extension, Factory

class Counter(Extension):

    value = 0

    def get(self):
        self._result = self.value

    def incr(self):
        self.value += 1

counter = Factory(Counter)


// counterdemo.js

document.write('<input id="a" />' +
'<br />'+
'<input onclick="window.t = window.t - 100;" name="faster" value="faster" type="button" />'+
'<input onclick="window.t = window.t + 100;" name="slower" value="slower" type="button" />'+
'<input id="t" />');

var t = 500;
var globalcounter = counter.create();

function update() {
    $('#t').val(typeof globalcounter.get);

    window.setTimeout(update, t);

window.setTimeout(update, t);

The result is a simple desktop app.

No comments:

I write here about programming, how to program better, things I think are neat and are related to programming. I might write other things at my personal website.

I am happily employed by the excellent Caktus Group, located in beautiful and friendly Carrboro, NC, where I work with Python, Django, and Javascript.

Blog Archive