lorenzo bolla’s blog

May 1, 2009

escape sequences for rxvt

Filed under: programming — Tags: , , , — lbolla @ 10:07 am

I’m posting this info because I had a hard time searching for it on the internet.

if you are using rxvt (or urxvt), and you want escape sequences to work as in xterm, you need to specify them in your .Xdefaults.

here are the codes I had to add to have vim working properly on rxvt (I use alt-left_arrow and alt-right_arrow to navigate through tabs):

*Rxvt*meta8: false
*Rxvt.keysym.C-Left: +033[1;5D
*Rxvt.keysym.C-Right: +033[1;5C
*Rxvt.keysym.M-Left: +033[1;3D
*Rxvt.keysym.M-Right: +033[1;3C
(substitute “+” with “\”)

enjoy!

April 7, 2009

blog post with charm

Filed under: programming — Tags: , , , — lbolla @ 5:52 pm

this is a test blog entry, posted with charm!

charm is a text-based client which uses the MetaWeblog API to post entries to WordPress powered blogs. it also implements other APIs.

I’m wondering if simple ASCII entries like this one will be properly formatted by the WordPress’ Intelligent Text Formatting feature. it would be nice to use vim to edit it…

enjoy!

January 31, 2009

command line html validator

Filed under: programming — Tags: , , — lbolla @ 11:00 pm

valid HTML is something we should strive to achieve.

W3C Validator is an invaluable tool to do just that.
unfortunately, validating a local file you are working on can be annoying after the 100th time you’ve uploaded it to the W3C website.

Here you can find a command line HTML validator that simply uploads anything passed to it from stdin to the W3C Validator.

The basic syntax is:
$> python validate.py < file_to_validate.html

enjoy!

Note: before using the file, rename it from validatepy.pdf to validate.py. unfortunately, I’m not allowed to post .py files on this website…

October 5, 2008

py2dot

Filed under: programming — Tags: — lbolla @ 2:17 pm
py2dot example

py2dot example

py2dot is a python script to generate graphs from a  python program.

it interprets a python program as a graphs of function calls. it can represent classes and imported modules.

py2dot is available from pypi.

more information are available here.

June 25, 2008

tab completion in python shell

Filed under: programming — Tags: , , — lbolla @ 11:52 am

recently I saw with this little piece of code to give the standard python shell tab completion capabilities:

# setup tab completion in python shell
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")

obviously, you can use the environmental variable PYTHONSTART to execute this few lines anytime you start your python shell.

enjoy!

June 11, 2008

numerical recipies

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

Numerical Recipies is a classic of Scientific Computing.
download here the whole book in ps or pdf.

a little story.

older versions are freely available here.

if you are lazy, like me, and you get bored of saving every single file by
hand, you can use this fantastic Firefox plugin.
or download them zipped here.

if you are lazy, like me, and you get bored of having to open a new file for
each chapter, you can merge them in one monolithic file.

if you are _really_ lazy, like I wish to be, you can use my job and
download the complete book in ps or pdf straight away.

enjoy!

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!

Older Posts »

Blog at WordPress.com.