mike watkins dot ca : Another Hello Meme Entry

Another Hello Meme Entry

Adding to my last entry, and inspired by Sam Bull's Django entry, following is a QP web application framework-based entry in Eric Florenzano's multi-language programming meme.

The Meme

  • Implement a program that takes in a user's name and their age, and prints hello to them once for every year that they have been alive.
  • Post these rules, the source code for your solution, and the following list (with you included) on your blog.
  • Bonus points if you implement it in a language not yet seen on the following list!
  1. [Python] http://www.eflorenzano.com/blog/post/trying-start-programming-meme
  2. [Bash] http://aartemenko.com/texts/bash-meme/
  3. [C] http://dakrauth.com/media/site/text/hello.c
  4. [Java] http://adoleo.com/blog/2008/nov/25/programming-meme/
  5. [Python 3] http://mikewatkins.ca/2008/11/25/hello-meme/
  6. [Ruby] http://stroky.l.googlepages.com/gem
  7. [Ruby] http://im.camronflanders.com/archive/meme/
  8. [Lisp] http://justinlilly.com/blog/2008/nov/25/back-on-the-horse/
  9. [JavaScript] http://www.taylanpince.com/blog/posts/responding-to-a-programming-meme/
  10. [Django] http://www.pocketuniverse.ca/archive/2008/november/27/florenzano-factor/
  11. [QP] http://mikewatkins.ca/2008/11/27/another-hello-meme-entry/

The Application

For a limited time you can access this "application" here: http://mikewatkins.ca:8111/

The Code

# ~/qp_sites/florenzano/slash.qpy
"""
An entry in Eric Florenzano's programming meme...
To run:
    qp florenzano start
"""
from qp.fill.css import BASIC_FORM_CSS
from qp.fill.directory import Directory
from qp.fill.form import Form
from qp.pub.common import header, footer, page
from qp.pub.publish import DurusPublisher

class SitePublisher (DurusPublisher):

    configuration = dict(
        live_host='your_live_host',
        durus_address=('localhost', 7011),
        http_address=('', 8011),
        )

class SiteDirectory(Directory):

    def get_exports(self):
        yield ('', 'hello', 'Hello', None)

    def hello:xml(self):
        form = Form()
        form.add_string("name", title="Your name", size=20,
                        required=True)
        form.add_int("age", title="Your age", required=True)
        form.add_submit("Say Hello")
        if not form.is_submitted() or form.has_errors():
            return page('Say hello', form.render(),
                        style=BASIC_FORM_CSS)

        # The form has been submitted
        header('QP hello example')
        '<ul>'
        for age in range(form.get('age')):
            '<li>%s) Hello, %s.</li>' % (age, form.get('name'))
        '</ul>'
        '<p><a href="">Try again...</a></p>'
        footer()