lorenzo bolla’s blog

April 22, 2008

python and vim

Filed under: links, programming — Tags: — lbolla @ 12:01 pm

just a reminder of a very useful set of tips to effectively use vim to edit python files:

http://henry.precheur.org/2008/4/18/Indenting%20Python%20with%20VIM.html

April 21, 2008

cvs behind a firewall through an http proxy

Filed under: links, programming — Tags: , , , — lbolla @ 1:45 pm

if you work in a company with a too restrictive firewall, but you still need to access a cvs repository like sourceforge, you can bypass it using the program connect.c.

from here:

connect.c is the simple relaying command to make network connection via SOCKS and https proxy. It is mainly intended to be used as proxy command of OpenSSH.

just download it and compile it (for windows users there is a precompiled connect.exe). then, if you want to use the SOCKS server “socks.local.net” to access the internet, add these two lines to your .ssh/config:

Host remote.outside.net
ProxyCommand connect -S socks.local.net %h %p

in my case, I use an http proxy to access the internet, instead of the SOCSK, and I do not
want to use connect.exe for internal repositories. hence, my .ssh/config file is:

Host empy.cvs.sourceforge.net
ProxyCommand connect -H proxy.company.net:80 %h %p

enjoy!

April 17, 2008

memoize

Filed under: programming — Tags: — lbolla @ 2:51 pm

recently, from a discussion on the scipy-user group I discovered a very elegant way to code a function with memory.

let’s state the problem. suppose you need a function that remembers, for each time it has been called, the input parameters and its output. this can be very useful in many different situations:

  • if it is very expensive to evaluate, you can check its memory to see if it has been previously evaluated and, if yes, get its return value without actually calling it.
  • inside an optimization loop, to remember all the intermediate steps of the optimization.
  • to accumulate data on the behaviour of the function itself.
  • to surprise friends ;-)

the function’s memory can be as long as the program’s running time, or it can be ‘permament’ if hard-coded in a file.

starting from here I’ve put together a couple of useful classes in python that can be used as decorators. they are use as follow:

# function to memoize
def f(x):
return x**2

# memoized function
memoized_f = memoize(f)

# memoized function on a file
memoized_persistent_f = memoize_persistent(f)

decorators can be used:

# function to memoize
@memoize # or @memoize_persistent
def f(x):
return x**2

which is equivalent to: f = memoize(f).

you can download the code here.

enjoy!

April 14, 2008

bvp

Filed under: programming — Tags: , , — lbolla @ 8:04 pm

for you, Python lover, who always needs Matlab functions: boundary value problems are not a problem anymore.

Googling for a bvp4c clone, I ended up here:

This is a Python wrapper for a modified version of the COLNEW boundary value problem solver by U. Ascher and G. Bader. Modifications made include vectorization over mesh points and better compatibility with Python.

there are little differences in the usage, though. I tried to reproduce the examples in this tutorial, to clarify things. You can download the first two examples here.

enjoy!

April 10, 2008

india!

Filed under: italiano, personal — Tags: — lbolla @ 2:13 pm

india

dopo lunghe pensate, ecco l’itinerario!

dal 26 aprile al 16 maggio.

Blog at WordPress.com.