Thursday 19 November 2009

monitor long compilation time

For people who like me like to keep logs of everything they do, this little script can be used to automatically add entries into a log file before and after running a long command.

It fits nicely into my org-mode system, I put the logs entries into an org file and they then appear into my agenda :

=====================================================================
#
!/bin/bash

# Automatically logs the task given as argument into my org log file.
# This is useful when running long compilations.

LOG_FILE=/home/guillaume/Org/Logs.org
CMD=$@

TMP_FILE=$(tempfile)
LABEL=$(pwd)

echo "* start: ($LABEL) $CMD <$(date +'%F %a %R')>" >> $LOG_FILE

STAT_FORMAT="\
- time :: %E
- retun status :: %x
"


trap ctrl_c INT

function ctrl_c() {
echo "* killed: ($LABEL) $CMD <$(date +'%F %a %R')>" >> $LOG_FILE

exit -1
}

/usr/bin/time -o $TMP_FILE -f "$STAT_FORMAT" $CMD

echo "* end: ($LABEL) $CMD <$(date +'%F %a %R')>" >> $LOG_FILE

cat $TMP_FILE >> $LOG_FILE
rm $TMP_FILE
=========================================================================

Friday 7 August 2009

Check python coding style on the fly with emacs


A nice emacs trick : using flymake-mode and this python code styles PEP8 checker script written by Johann C. Rocholl, we can have automatic real time checking for standard python coding style.

To make this work I copied the script (pep8.py) in my PATH, and then I added this block of code in my .emac file :

(when (load "flymake" t)
(defun flymake-pylint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pep8.py" (list "--repeat" local-file))))

(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pylint-init)))

After this I can just enable flymake mode when I edit a python file, and every coding style error will be highlighted on the fly.

Saturday 13 June 2009

Fluid dynamics engine

After I read this paper I decided to try to write a small two dimensions fluid dynamics engine for video games. It is quite fun.

Now I need to see what I could use it for.

Sunday 31 May 2009

Tichy 1.1.0 released

Yesterday I released tichy 1.1.0. In this new release a lot of internal refactoring, improvement of the style system, the text editor, the terminal, and the PIM applications. I also added some unit tests using py.tests.

See the release notes.

Tuesday 5 May 2009

ditaa

Never used it nor planing to do so soon, but I like the idea a lot : ditaa.

Tichy's new style


Today I created a new style for tichy's widgets.

The way we can create widgets style is very simple : we create 32x32 sized png images for each frame. The image is cut so that each 8x8 sized corner will correspond to the associated widget frame corner, the top will be used to fill the top of the widget frame and so on (see the image.)

This is not very flexible because it only allows 8x8 corners size for all the widgets, but here simplicity beats flexibility.

My previous style was done using the gimp. This time I decided to use inkscape instead. Inskape is one of the best open source software I know. Perfect for this kind of job.

I went for a very bright style, so that we can read the phone screen even outside. I also decided to use no gradient or effect at all, this increases the feeling of simplicity that I want to have in Tichy.

Sunday 3 May 2009

Org-mode : will I finally get organized ?



I always had a love/hate relation to emacs, but recently I found a good reason to start using it a lot again : org-mode.

org mode allows to keep notes and TODO list using a simple text format. Basically you can type what you want and every line starting with "TODO" will be interpreted as a task, every date enclosed by "<" and ">" as an agenda entry, every text enclosed by "[[" and "]]" as a link. (Check the website for more detailed documentation).

It is a very complicated thing to find a way to keep organized and productive, specially when we have to deal with different projects, involving a lot of information.

One thing I did learn from the past is that online tools like google calendar or personal wiki don't work for me. I am just too lazy to take the time to go online to update my wiki or calendar. Very often when I think of a task I have to do, I am already working on something else, and I don't want to spend time going online and getting through a web interface just to write a few lines of text.

Until now my optimal solution for keeping organized was to use :
  1. A directory containing basic text files, one per project, idea or people.
  2. A TODO text file.
  3. A piece of paper on my desk where I would write every mornings the tasks for the day.
This worked fine as long as I didn't have to deal with complicated schedules and deadlines. It is not the case anymore and so I had to change my system. The system I am using now is :
  1. One org file per project I am working on.
  2. One org file for all my contacts information.
  3. One org file for other small tasks or ideas (things to buy, etc...)
I also created a cron job to email me everyday the weekly calendar as well as the list of pending tasks.

What I really appreciate with this new system is the fact that I can create TODO or agenda entries from anywhere. Org-mode will automatically harvest all the tasks and agenda entries and create a nice summary for me.

I have been using it for only a few weeks now, but I can already tell it makes things much easier than before.

Saturday 14 March 2009

Coroutines in C

this article by Simon tathan is fascinating.

Simon explains how we can use some very dirty tricks to create coroutines directly in C, without using the setcontext functions.
It relies on a very strange feature of C that I didn't know about : being able to put a case statement inside a sub-block of the matching switch statement !

I really recommend the lecture of the article to anybody interested in coroutines, even though as Simon says : "this trick violates every coding standard in the book. Try doing this in your company's code and you will probably be subject to a stern telling off if not disciplinary action!"

Thursday 22 January 2009

online javascript game, in python

Last time I spoke about pypy, which allow (among other things) to translate python code into other languages.

This week I wrote a small video game (inspired by the famous boulder dash game) in rpython and used pypy to create an online version of the game out of it.

You can play the game here.
The sources can be found here.

The game as it is now is not really fun, but I only wrote it as an example of using pypy.

What I like with this approach is that I can develop in rpython, and even run the game using python interpreter, and only before I publish it use pypy to create the javascript version.

I could also create a C version using the same code for the game engine (only the graphic functions would have to be rewritten for each backends.)

This open the door to a lot of interesting applications.

On a side note, the pypy javascript translation is really not optimised. For example, let's try to guess what this generated function does :

function (){
var v1086,v1087,self_145;
var block = 0;
for(;;){
switch(block){
case 0:
self_144 = this;
self_145 = self_144;
block = 1;
break;
case 1:
v1086 = 'H';
block = 2;
break;
case 2:
return ( v1086 );
}
}
}

I don't want to spoil the fun of figuring this out by giving the answer...

Sunday 11 January 2009

Pypy is great

Even though I was in holidays recently, I spent some time to have a look at the update from the pypy project.

I get really excited by what the project has achieved so far.

Pypy is a python interpreter written in python.
The most interesting part of the project is the ability to use it to translate python code into other languages, like C, java, javascript, and LLVM.

So far only a subset of python language is translatable (for example generators won't work.) [edit: as the pypy people pointed out, full python language will never be translatable, that is not the goal of the project.]

But this simplified python (called RPython) is already good enough for many projects. As an example pypy interpreter itself is written in RPython and so can be compiled into machine code.

The good thing about this is that you can develop an application totally in python and then use the translators to generate fast machine code. So python could become some sort of universal language that replaces all other languages.

An other interesting things about pypy is the ability to generate stackless code, that allow many cool things, like tasklets (see the documentation about this).

Now I can't help thinking about OpenMoko paroli project, that uses python and tasklets. Could it be possible to use pypy to translate the python code into machine code and so create optimized version of paroli ?

The idea is very seducing, but many problems would need to be solved before we can get to there. The first thing is that we would have to modify our code to remove all the things that are not supported by pypy.

The second things is that even though pypy supports tasklets, it is impossible to do it using the python yield statement and the trick explained in PEP342.

An other good use of pypy would be to create web application without having to write -quite ugly- javascript code.

Paroli get a website

Happy new year everybody !
I just come back from holidays, and haven't worked for a few weeks, but now I am back to Taipei where I still work for OpenMoko, with a few news about our next software stack :

The tichy project had a lot of modifications ; it is now entirely based on etk and edje (part of raster enlightenment windows manager). It has also been renamed "paroli-core". We loose the ability to use different graphic back-ends, but the other features are still presents. Paroli-core offers :
  • Signal / slot objects (à la Qt.)
  • A service system to allow user to register and retrieve python object based on there role.
  • A tasklet library for easy creation of chained callback function.
  • A plug-in system.
  • A set of services that create a layer between the plug-ins and Mikey FSO framework.

The Paroli project based on paroli-core started.
The project includes paroli-core (ex tichy), plus a set of applets that aim at providing basic telephony functionalities.

More information (and the sources) can be found from the paroli-project web site.