jQuery short answers quiz

I’m developing a website containing my deutsch course lessons. Our teacher given us some exercises, and I had the need to render it on an interactive web page. How to accomplish this mission? Obviously using jQuery.
The main issue is to write in a simple way your “short answers” form, and leave the hard job to jQuery code. So the form need to looks like:

    The sky is <input type="text" answ="blue"/>.
    The pen is <input type="text" answ="on"/> the table.<br />
    Yes I, <input type="text" answ="am"/>.<br />
    <input type="button" class="subm" value="Verify"/>

As you can see, each <input> contains the attribute answ with the correct answer and the element you want to use to check needs to have class=”subm”. That’s all!

The JS code resizes all the text inputs using the answer’s length, and changes CSS class (answ_error, answ_ok) of the input element. Finally a couple of attributes (tot and ok) will be added to the form, containing the number of text inputs and the number correct answers.

Code is available here.


Corso inglese gratuito con Python

Con la scusa di iniziare ad apprendere Python ho realizzato un piccolo script per fare download automatico delle lezioni di eslpod.com (categoria “English cafe“).

#!/usr/bin/env python
#title           :eslpod_EC.py
#description     :This script downloads english cafe lesson from eslpod.com
#author          :Simone Vellei <henomis@gmail.com>
#date            :20120420
#version         :0.1
#usage           :python eslpod_EC.py
#notes           :
#python_version  :2.6.6

import sys
import re
import signal, os
import urllib
from subprocess import call

def wprint(a):

def handler(signum, frame):
        print "Interrupted!"

signal.signal(signal.SIGINT, handler)

f = urllib.urlopen("http://www.eslpod.com/website/show_all.php?cat_id=-39570")
s = f.read()

if s:
        wprint("Parsing HTML...")
        print "Error: download failed!"

chunk = re.match(r'.*<span class="pod_body">.*<b>([0-9]+)</b>&nbsp;Podcasts&nbsp;&nbsp;&nbsp;',s , re.M|re.S)

lenght = 0

if chunk:
        print "DONE"
        files = chunk.group(1)
        lenght = len(files)
        print lenght
        print "ERROR!"

# skip lesson 0
for i in range(int(files)-1):
        # insert padding
        s = 'wget "http://libsyn.com/media/eslpod/EC{0}.mp3" -c -O lesson_{1:0%d}.mp3'%lenght
        # format string
        s = s.format(i+1,i+1)
        # go, go, go...
        call(s, shell = True)

Lo script può essere lanciato settimanalmente (qualcuno ha detto cron?! :)) per aggiornare la directory con le nuove lezioni (wget -c farà il lavoro sporco). La prossima versione potrebbe supportare i thread per fare un download multiplo parallelo e il parsing dei parametri in input per nuove funzionalità.