Archive for the ‘Code’ Category

April 13th, 2008 @ 08:45

For a project of mine (involving LEJOS-OSEK, mostly), I’m forced (well, almost) to use Windows, which my dear VirtualBox virtualizes fairly well on my clean Linux host. I obviously setup vim for my coding needs, but its default behavior isn’t quite what we are used to on other platforms. For instance visual mode selection with arrows requires you to hold Shift, while it doesn’t elsewhere and backup files are created upon write.

So, let’s edit the .vimrc file, which actually is at VIM_INSTALL_PATH\_vimrc (for instance C:\Program Files\vim\_vimrc with the default install options).
Disabling backup files is as simple as adding

set nobackup

Getting visual mode arrows selection is a bit different, as explained in vim tip 864 comments, you can either add

set keymodel-=stopsel

around the end of the file
or drop the

behave mswin

line from the default vimrc.

Here are two other (non windows-specific) tips:
Bash like filename completion:

set wildmode=longest:full
set wildmenu

Pythonic smart indent:

autocmd BufRead *.py set ai et ts=4 sw=4 sts=4
autocmd FileType python set ai et ts=4 sw=4 sts=4
autocmd BufRead *.pyx set ai et ts=4 sw=4 sts=4
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class

See also this pretty Tango color scheme for vim.

April 12th, 2008 @ 08:24

Ever heard of Gogh? This is a really nice drawing tool for graphic tablets owner (such as those by Wacom). However it stopped working on my Hardy system after some recent update. After some investigation, it appeared that it was due to python-xml being moved away of Python path because it interfered with stuff in Python core ; the whole python-xml package being scheduled for deprecation as soon as the reverse depends would be cleared. I figured it out and dropped the reference to python-xml package in gogh/settingsmanager.py, using a method provided by Python core xml stuff instead. It seems that quite a bunch of people are currently using xml.doc.ext.PrettyPrint from pyxml to output an XML document to a file, so I figured that posting this little tip might help someone :)

So, let’s say you currently have something like this to output your xml document “doc” to a file at path “path”, doc being an xml.dom.minidom.Document object (or similar):

        f = open(path, "w")
        xml.dom.ext.PrettyPrint(doc, f)
        f.close()

All you need to change is PrettyPrint call to make use of the .toxml() method of your document object instead:

        f = open(path, "w")
        f.write(doc.toxml())
        f.close()

Here you go, hope this might save someone’s day someday :)

April 6th, 2008 @ 22:03

Building dynamic forms with Django newforms module is quite undocumented, though it’s quite easy to do. All you need to do is to hook up the __init__ function of the form, raise the __init__ to the parent forms.Form class and then add your dynamically generated fields to self.fields dict.

Here is a quick snippet demonstrating it, which will create a form with n integer fields named from 0 to (n – 1), but you will easily be able to heavily extend it.

from django import newforms as forms
 
class MyForm (forms.Form):
 
    def __init__ (self, n, *args, **kwargs):
        forms.Form.__init__ (self, *args, **kwargs)
        for i in range (0, n):
            field = forms.IntegerField (label = "%d" % i, required = True,
                                        min_value = 0, max_value = 200)
            self.fields["%d" % i] = field
March 31st, 2008 @ 23:00

Bah, it took so much time to get them, while it was just a matter of finding one or two dozens of hours to make them all :)

Well, I’m too lazy to do any screenshot now, so just check them out by yourselves :)

March 9th, 2008 @ 21:01

Months ago, we were setting up Shound.org‘s VPN and we were willing to produce a good looking map of the network status. We quickly chose weathermap4rrd, the software which is usually used for that kind of purpose. However the result looked graphically a bit rough, with aliases lines and so on, so that I had to fix it. I rewrote the rendering bits of the PHP version so that they use one of the PHP Cairo wrappers.

The usual sceenshot :

weathermap4rrd+cairo sample

I bundled the whole stuff you might need to deploy it with a howto and additional infos (sorry, the docs are written in French, I will translate them when I’ll have the time to) into this tarball, or you might just grab the weathermap4rrd patch.

March 6th, 2008 @ 21:29

It’s now official, Enso, a really awesome tool that integrates smoothly into your desktop and enables you to perform several otherwise boring actions by just using your keyboard in a very simple way (check Humanized website for a better description), has just been open sourced under a BSD-like license. It’s written in Python and uses Cairo for the rendering, and the end result is really neat.
One of the great news of this is that it’s going to work on Linux (and probably even BSD’s, though it requires compositing & a compositing manager for full functionnality, which is (afaik) only available on FreeBSD) very soon :) . I’ve got it working on my laptop right now, after some python-xlib/pycairo/pygtk love ; it just now needs some more testing and polish before it goes live, but it’s gonna be great :)

Enso on Linux

Long life Enso!

January 29th, 2008 @ 23:28

Paraboloid Rendered with Blender

Wrote a quick python script for blender to generate paraboloïds a while ago. Feared I might have lost them. Posting them here today. Could be reused as a base for any parametric surface as well. Three flavours included. Have fun.

Hyperboloic Paraboloid Mesh Script
Paraboloid Mesh Script (with basis)
Paraboloid Mesh Script (circular)

October 6th, 2007 @ 22:03

I just finished setting up a gitweb for my very own projects, it’ll be wayyyy nicer to browse code revisions and diffs of my various orphaned projects =)

October 6th, 2007 @ 14:22

Felt like coding a bit… Thought I’d code a PyGTK Game of Life just for fun (or just to prove myself I’m not _that_ bad at coding :roll: )

PyGTK Game of Life

The code is obviously available :

$ git clone http://guillaume.segu.in/code/gol.git
$ cd gol
$ python gol.py

September 16th, 2007 @ 12:01

xkcd rocks.
Orphaned projects