April 25, 2010 0

Better than Bluetooth Console – PUTools

By in programming

Python on Symbian development can become very difficult, my typical routine goes like that:

  • conneting phone via USB
  • sending files
  • disconneting USB
  • setting up console
  • connecting via BT
  • testing
  • disconnecting

Too much time to lose in that process, so I made simple script:

import urllib

def update(host,dict):
    """ Function managing update via HTTP
    'host' is host where to look for files
    'dict' is dictionary composed from name of module,
    and place in file system for it"""for key in dict:
        code = urllib.urlopen(host+key).read()
        filename = u"%s%s" % (dict[key],key)
        f = file(filename, "w")
        f.write(code)
        f.close()
        print("module "+key+" updated")

URL = "http://192.168.1.2/mpm/code/"
MODULES = { u"mpmc.py" : u"E:\\Python\\",
           u"mpmdb.py": u"E:\\Python\\lib\\",
           u"mpmnet.py": u"E:\\Python\\lib\\",
           u"mpmgps.py": u"E:\\Python\\lib\\",
           u"mpmv.py": u"E:\\Python\\lib\\",
           u"mpmloc.py" : u"E:\\Python\\lib\\",
           u"updater.py" : u"E:\\Python\\",
           u"mpmcom.py" : u"E:\\Python\\lib\\",}

update(URL, MODULES)

But this still isn’t enough to ease the development process, that’s the place for PUTools. Documentation is written for Windows, but it’s easy to use on Linux, only differences there are is that to create BT serial port on PC:

#sudo sdptool add --channel=3 SP
#sudo rfcomm listen /dev/rfcomm2 3

and in the configuration com port should be set to full path to the device:

COM_PORT = /dev/rfcomm2'
April 1, 2010 0

PyS60 Links … Python On Symbian

By in programming

Usefull links:

March 23, 2010 0

Symbian Signing – certificate and tools

By in programming

Visit http://www.s60certkey.com and create account. When your account will be verified you will be able to input phone IMEI code and after aprox. one day you can obtain developer certificate.

Downloaded file preasumbly is going to contain certificate as key as well, and your will to split it into two files (the larger part is cert, the shorter is key file).

Next, your going to need a signing aplication. I would recommendSISContentshttp://symbiandev.cdtools.net/ as it has nice interface in english and it can pack and unpack sis, edit it’s contents and more.

February 2, 2010 0

Lighttpd & Django configuration

By in django, programming, pyton

Here sample configuration for configuration, where some static files with fixed url are rewrited to be servered by Django (ie. robots.txt):

$HTTP["host"] == "www.karolciba.pl" {
        url.redirect = (
                "^/(.*)" => "http://karolciba.pl/$1"
        )
}

$HTTP["host"] == "karolciba.pl" {
        server.document-root = "/var/www/karolciba_pl"
        url.rewrite-once = (
                "^/favicon\.ico$" => "/site_media/favicon.ico",
                "^/robots\.txt$" => "/site_media/robots.txt",

                "^/django.fcgi/(.*)$" => "/django.fcgi/$1",
                "^/(.*)$" => "/django.fcgi/$1"
        )
        fastcgi.server = (
                "/django.fcgi" => (
                "main" => (
                        "bin-path" => "/var/www/karolciba_pl/django.fcgi",
                        "socket" => "/tmp/django_karolciba.sock",
                        "check-local" => "disable",
                        "min-procs" => 1,
                        "max-procs" => 1,
                )
                )
        )
}
January 12, 2010 0

Java stacktrace when you need to know where you’d called

By in java, programming

Recently while I was working on some project, came out trouble with getting actual stacktrace.

Methods could be called from various places, and I needed to know, what’s the command flow. Because I couldn’t find any decent way to do this in Java, I thought I could just throw & catch exception:

try {
    throw new Exception();
} catch (Exception e) {
    e.printStackTrace();
}

In nice, templatable oneliner:

try { throw new Exception(); } catch(Exception e) { e.printStackTrace(); }
April 12, 2009 0

Cached Model in Django

By in django, programming, pyton

Modele w Django są, w mojej opinii, jak większość ORMów może i wygodne gdy chodzi o proste wyciąganie z pojedyńczych obiektów z bazy danych. Jednak w przypadku trochę trudniejszych zapytań lub chęci cachowania są dla mnie kulą u nogi. Postanowiłem więc przygotować sobie jakieś ułatwienie dla cachowania zapytań w SQL.

Na razie powala na zadawanie zapytań przy okazji cachując wyniki. Pozostało jeszcze:

  • przygotować mechanizm czyszczenia cache w przypadku zmiany danych
  • opakować w decorator lub klasę
  • a najlepiej zrobić z tego middleware :)
@staticmethod
def getNotesWithCommentsCountForCategory(categoryName,count = 10):
    cacheKey = "cacheKey_%s_count_%s" % (categoryName, count)
    rows = cache.get(cacheKey, 'Empty')
    if rows == 'Empty':
        cursor = connection.cursor()
        cursor.execute("""
            SELECT n.id, n.date, n.title, n.content, cat.name, count(c.id)
                FROM blog_note n
            JOIN blog_comment c
                ON c.note_id = n.id
            JOIN blog_category cat
             ON n.category_id=cat.id
            WHERE
                cat.name=%s
                AND n.visible = True
                AND cat.accessible = True
            ORDER BY n.date DESC
        """, [categoryName])
        rown = cursor.fetchall()
        col_names = [desc[0] for desc in cursor.description]
        rows = [dict(izip(col_names, row)) for row in rown]
        cache.set(cacheKey, rows)
    return rows