Archive for the ‘Tips’ Category

July 16th, 2010 @ 05:46

Since Thunderbird 3 (or maybe before that), when you encounter an invalid SSL certificate, the GUI doesn’t even offer you to add an exception as in Firefox. Counter-intuitively, the same GUI than in Firefox is actually, available you just have to dig it through the menus. Here is a step-by-step tutorial with screenshots (had to do them for a doc, thought I’d share).

Go to Account Settings

In Security menu select View Certificates (alternatively, you can get there through Edit, Preferences, Advanced, Certificates, View Certificates if you have no Security menu here)

In Servers tab, hit Add Exception

Enter the address:port of the service you are using (without any protocol://) and hit Get Certificate

Hit Confirm Security Exception, and you're done !

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 11th, 2008 @ 18:07

Have you ever mistakenly shut down or rebooted your operation-critical server while you were willing to halt your desktop computer through ssh before going to bed, or anything like this? If so, and if you are on Debian/Ubuntu, molly-guard is designed for you: this nifty bash script gets between you and the shutdown/reboot/halt tools, checking if you are connecting through ssh and if so asking for the hostname of the machine before proceeding.

Wondering how it looks? Here is the output of a little test:

ixce@timmy:~$ sudo shutdown -r
W: molly-guard: SSH session detected!
Please type in hostname of the machine to shutdown: 
Good thing I asked; I won't shutdown timmy ...

Since it doesn’t correctly handle sudo yet (actually sudo is at fault here, since it drops SSH_CONNECTION environment variable when doing its stuff), you might want to add PRETEND_SSH around the beginning of /usr/sbin/shutdown as specified on Nico “nion” Golde’s blog.

You might also want to grab the molly-guard 0.3.2 etch package I backported from sid (all I changed is downgrade debhelper build-dep version and debhelper compatibility level in debian/compat since etch only has debhelper 5 and the sid package required debhelper 6 ; this shouldn’t break anything since the newer debhelper just seems to be needed to recognize a few fields in debian/control about where the package is maintained). Sources are also available, anyway.

Thanks hr for the tip :)

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
January 14th, 2008 @ 12:56

Dear Google friend,

Could you please keep this little tip safe and warm?
If your friendly Xen hypervisor stops outputting during the boot process at some point and completely freezes, or just stops until you get X or so, just add “console=vga vga=keep” to your Xen kernel line in your GRUB configuration, so that it looks like this:

title Xen 3.1
root (hd0,4)
kernel /xen-3.1.gz console=vga vga=keep noreboot
module /vmlinuz-2.6.19-4-generic root=/dev/mapper/lvm-root ro console=tty0
module /initrd.img-2.6.19-4-generic

Thanks dear.

July 31st, 2007 @ 15:30

Quick sed tip :
C++ // comments to C /* comments */ :
sed -e "s/\/\/\(.*\)$/\/*\1 *\//"(yes, I know that sed -r -e “s,//(.*),/*\1 */,” looks a lot better, but it’s just too obvious to read :p)