22. December 2012

HTML5 Game: Snowman’s teleport – PF 2013

Help little snowman to find Xmas tree. ;-)

Source code available at GitHub.

You can find more games at georgik.rocks/tag/games/

31. December 2011

HTML5 Game: Maze Pathfinder – PF 2012

Find a path to the treasure.

Note: Map is based on one geocache puzzle. Written as PF’2012.

You can find more games at georgik.rocks/tag/games/

20. November 2011

Unexpected token ILLEGAL in jQuery.i18n.properties

jQuery.i18n.properties is useful library based on jQuery. You can use it to load .properties files with localization to web application.

I made upgrade of jQuery in my application from version 1.6.2 and application failed with error:

Uncaught SyntaxError: Unexpected token ILLEGAL

I spent some time debugging jQuery and i18n and I found out that one of .properties file contains weird property with name:

1_guide=1 guide

Problem was in numeric prefix. Solution is quite easy: fix property.

one_guide=1 guide

This problem occurs when you upgrade jQuery to 1.6.3 and higher.

7. January 2011

How to dump POST request with Python

Python contains one helpful module: SimpleHTTPServer. You can expose local directory via HTTP by the following command:

python -m SimpleHTTPServer

Python will start HTTP server at http://localhost:8000

It is very worthy when you’re doing some tests of web application.

The only problem is that SimpleHTTPServer does not support POST. Sometimes it’s very useful to see the content of POST request.

Is there any simple way how to achieve this in Python?

Here is a small extension of SimpleHTTPServer with do_POST handler:

import SimpleHTTPServer
import SocketServer
import logging
import cgi

PORT = 8000

class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

    def do_GET(self):
        logging.error(self.headers)
        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

    def do_POST(self):
        logging.error(self.headers)
        form = cgi.FieldStorage(
            fp=self.rfile,
            headers=self.headers,
            environ={'REQUEST_METHOD':'POST',
                     'CONTENT_TYPE':self.headers['Content-Type'],
                     })
        for item in form.list:
            logging.error(item)
        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

Handler = ServerHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

You can download SimpleServer.py here and start it with command:

python SimpleServer.py

24. December 2010

HTML5 Game: Winter puzzle – PF 2011

You can find more games at georgik.rocks/tag/games/