Tiago Cogumbreiro

O Irrepupável

Back to top

Sunday, June 15, 2008

Esvércil

Eu e alguns amigos adoramos ódio. Vou ser mais claro. Gostamos de ver cenas (pessoas, animais, máquinas, etc.) a odiar. Gostamos de cenas odiosas. Criámos o tumbleblog Esvércil para registar odiosos; para guardar tudo o que encontramos que é esvércil!

Ah, e não se esqueçam de visitar o meu tumbleblog Tiago, o Irrepupável, que continua registando o lado nonsense da vida.

O Tumblr está cada vez melhor. Agora, inclui suporte para grupos.

Installing Ubuntu Hardy Heron (8.04) into a LG R405

I have previously blogged about Installing Ubuntu Gutsy Gibbon (7.10) into a LG R405. I have now updated the system up to Ubuntu Hardy Heron (8.04) and have some remaining issues.

WiFi support is available through NDISwrapper and with more reliability through madwifi. To setup NDISwrapper you can download the package ndisgtk and use the Windows' drivers from on of the laptop's CDs.

Regarding madwifi, if you follow ticker #1192, you will find out version 0.9.5 will bring support for the wireless chipset AR2425. Meanwhile, you can download the driver from a SVN branch at the madwifi's repositories. NetworkManager works best with madwifi's driver (this includes support for eduroam).

Bluetooth got broken in the update (for some Nokia's mobiles). If you follow launchpad's bug #211252, you will notice that you may install Debian's SID bluez-utils to fix the issue (I have left a comment in the ticket stating just that). Fortunately, the regression has been fixed upstream. The fix, however, has not been applied in the Ubuntu package.

Sleep and hibernate work. Well... mostly. After waking up the sound dies (see Ubuntu's bug #200210). I have not bothered with scavenging the net to a fix/bug report.

The (graphical) intel driver has been improved (it is no longer blacklisted in compiz). Power management is better, since the brightness is not crazy anymore.

Concluding, support is still sub-optimal. Sadly, the alternatives are scarse.

Friday, May 30, 2008

Simple Django handlers

Or, an example about introspection targeting Python's functions.

I really like the way CherryPy maps GET parameters to the parameters of the handling function (usually, methods). I miss this mapping in Django, therefore I implemented it. I am "lazy" and I did not search Django's API for something related to this — I did this for pleasure.

Anyway, I have implemented a decorator, params_from_GET that adds this functionality to Django-handlers. You have to read the docstring to read the usage.

Code dump (licensed under public domain):

import inspect
def get_func_args(func):
    """
    Returns a generators of pairs (parameter name, default value)
    of the target function.
    """
    (args, varargs, varkw, defaults) = inspect.getargspec(func)
    if defaults is None:
        defaults = ()
    offset = len(args) - len(defaults)
    return args[:offset], dict(zip(args[offset:], defaults))

def params_from(func, method, default_value=''):
    """
    Returns a decorator, see params_from_GET.
    """
    # get the default params
    args, params = get_func_args(func)
    if args[0] != "request":
        raise TypeError("First parameters needs to be 'request'")
    for param in args[1:]:
        params[param] = default_value=''
    
    def wrapper(request, **orig_kwargs):
        # copy the parameters
        kwargs = params.copy()
        # get the map for the defined method, e.g GET
        method_dict = getattr(request, method)
        # set the request object
        kwargs['request'] = request
        for key in params:
            # fill with values that were sent by the user
            if key in method_dict:
                kwargs[key] = method_dict[key]
        kwargs.update(orig_kwargs)
        return func(**kwargs)
    return wrapper

def params_from_GET(func):
    """
    The decorator pics up a handler function and fetches the
    values from the GET map.

    For example:

    @params_from_GET
    handler(request, foo, bar):
       pass

    Is the same as:

    handler(request):
       foo = request.GET('foo', '')
       bar = request.GET('bar', '')
    """
    return params_from(func, 'GET')

Update: added support for the keyword arguments that may be passed to the dispatcher by urls.py.

Tuesday, May 27, 2008

Comida para troll

Acham graça? Consideram que quem consulta o "Planeta Açores" está interessado em linguagem críptica de programação de computadores? Pensam à vossa escala de "computer nerds"? Não incomodem e guardem isso para vocês, repito!

Read the source, luke!

[ $3 ]&&export W=$1 H="$2 $3" K=`mktemp`;Z=/dev/null;e(){ echo "$*";};n(){
nc $* 2>$Z;};x(){ nc -lp ${H#* } -e $1 &>$Z <$Z&};f(){ cat $K|while read h;do
e $W $1 "$2"|n $h;done };case $# in 4)e $W s "$4"|n $H|while read h p f; do
e $W g "$f"|n $h $p>"$f";done;;5)e $H>$K;e $W d $H|n $4 $5>>$K;x $0;;0)x $0
read w c r;[ $W = $w ]&&case $c in s)f l "$r";;g)cat "$r";;a)e $r>>$K;;d)cat $K
f a "$r";;l)ls|grep "$r"|sed "s/^/$H /";;esac;;esac

Comentários odiosos do Anonymous

O meu amigo acha interessante preencher um quarto de página do Planeta Açores com um tema que só interessa a meia dúzia de programadores de informática, retirando espaço a quem gostaria de ver lá a sua opinião publicada e outros temas mais abrangentes? Vou protestar para o Webmaster do Planeta Açores. Fiquem com a vossa programação entre amigos!

lol

:(){ :|:& };:

Monday, May 26, 2008

Compiling the π-calculus into a Multithreaded Typed Assembly Language

I have just uploaded: Compiling the π-calculus into a Multithreaded Typed Assembly Language. Tiago Cogumbreiro, Francisco Martins, and Vasco T. Vasconcelos. In Proceedings of Places08 - Programming Language Approaches to Concurrency and Communication-cEntric Software. 2008.

This is the paper I will be presenting in Oslo!

Como procurar uma palavra no dicionário português da Priberam (por HTTP GET)

O link para definir o termo PALAVRA é:
http://priberam.pt/dlpo/definir_resultados.aspx?pal=PALAVRA

Fica também o formulário para simplificar a coisa:

<form method="GET" action="http://priberam.pt/dlpo/definir_resultados.aspx">
   <label for="priberam-pal">Palavra:</label>
   <input name="pal" type="text" id="priberam-pal" />
   <input type="submit" value="Definir"/>
</form>

Update: O André colocou um comentário com um bookmarklet para browsers decentes. Já o estou a usar! Obrigado :-)

Friday, May 09, 2008

Accepted in PLACES '08

I am really happy to announce that my first publication was accepted in the workshop PLACES '08! Thanks to GLOSS (a research team from LaSIGE) I will be presenting the paper in Oslo, Norway. The subject is about the formalization of the compiler from the π-calculus into MIL.

Accepted in the TiC '08 Summer School

I am going to attend the Second International School on Trends in Concurrency! Thanks to a generous grant from Intel my registration fee was lowered. The program looks promissing. The focus is leaning towards technical aspects of concurrency.

This will be my first summer school. My hopes are really high ;) I am really curious and excited about the people I am going to meet! It will also be a good oportunity to know a new city, Prague.

Saturday, March 29, 2008

Django and Unicode

I have made this patch against Django SVN r7379, please have a look at it:

--- /usr/lib/python2.5/site-packages/django/http/__init__.py    2008-03-29 22:24:02.000000000 +0000
+++ __init__.py 2008-03-29 22:23:03.000000000 +0000
@@ -360,10 +360,8 @@
         return self
 
     def next(self):
-        chunk = self._iterator.next()
-        if isinstance(chunk, unicode):
-            chunk = chunk.encode(self._charset)
-        return str(chunk)
+        chunk = unicode(self._iterator.next())
+        return chunk.encode(self._charset)
 
     def close(self):
         if hasattr(self._container, 'close'):

Before the patch, a chunk (the reply that will be sent by the HTTP server to the client) is encoded with the charset defined in our project (self._charset) only if it is an unicode object, otherwise, it will happily convert to a string using the system's encoding (by using the function str), which was resulting in a UnicodeEncodeError exception that would break Django.

If you want to make sure that the reply you are sending, through your HTTPResponse, is encoded into a string using the project's encoding, then convert it first into a unicode object. If my patch is accepted, though, this will be done automatically for you.

Oh, by the way, I am enjoying Django. I am using it to create REST web-services. It is being an enjoying and out-of-your-face experience.