Remember Remember

viernes, 22 de mayo de 2009

MoinMoin XMLRPC

Sweeet.

http://moinmo.in/WikiRpc

viernes, 15 de mayo de 2009

While "I'm compiling..." project?

"Smart playlist" generation based on last.fm

This may help
http://www.stats.ox.ac.uk/~davison/software/dbm/

miércoles, 13 de mayo de 2009

Escaping quotes in bash

A common problem I have.
The solution is (from here):

To single quotes work you need to break out of the single quoted string then escape your single quote. Like so:

sed -e 's/'\''a/b/g'

Because \' is not inside of single quotes the single-quote is properly escaped and the output is as we’d expect:

Passing variables to gawk

It can be necessary to pass a variable from the shell to a gawk session. I found three different ways of doing so:

echo message: | gawk '{print $0, var}' var=1234

echo message: | gawk -v var=1234 '{print $0, var}'

var=1234; echo message: | gawk '{print $0, "'"$var"'"}'

More tricks here

Incredible oneliner

This oneliner is incredibly useful:
gawk '{avg=avg+$2; sd2=sd2+($2*$2)} END{avg=avg/NR;sd2=sd2/NR; print avg" "sqrt(sd2-avg*avg)}'

It calculates the average and the standard deviation of a column in a set.

I know it may sound trivial, but I didn't know that you can calculate the sd by adding the square of each term (I always calculate it by adding the square of the difference with the average).

lunes, 11 de mayo de 2009

vim integration with MoinMoin

This allows gf to follow a link,
NOTE: I just realized that blogger doesnt like the greater than and lower than, (makes sense), I am gonna correct this later.

if !exists("loaded_moin")
set autowrite
let loaded_moin = 1
set isk=a-z,A-Z,/,-,_

autocmd BufWritePost * !editmoin -c ""

function! Moin_EditPage()
let url = "http://localhost:8000/".expand("")
"let url = strpart(getline(1),8).expand("")
new
execute "read !editmoin -f ".url
let filename = getline(".")
quit!
execute "edit ".filename
endfunction

map gf :call Moin_EditPage()

endif

ToDo: maybe a stack to navigate forward and backward

Personal wiki

So I want a personal wiki. First, I started using vim and plain-text files with the gf magic, the main problem arrives when you want (or need) to use non plain-text files (pics, plots, pdfs, etc).


As my main concern is to be able to track my research, the fact of being able to attach a pdf is very useful. Is this why I ended up with the idea of using a more powerful wiki. My first shoot is something called MoinMoin. Installation in standalone mode is pretty straightforward. It looks OK so far, it is written in python and seems very extensible (there are many plugins available).


After a couple of tests, I found myself writing too much. This made me wonder if it were possible to use an external editor to modify the pages. I tried the It's all text firefox extension, a extension that enables using any external program to edit HTML textareas. The extension work fine (I am using it actually to write this post), but I still wanted something I could edit directly from the command line.


After googling a little, I reach the editmoin page. Editmoin allows you edit
MoinMoin pages directly from the CLI: it fetches, opens an editor and
commits when you close the editor if there were any changes in the file.


The only but I found, was the impossibility of following links inside the
editor (VIM in my case), so I modified the editmoin script to add the
JustFetch or JustCommit actions. The corresponding diff for the script in the editmoin-1.10.1.tar.gz tarball is



71c71
< def __init__(self, filename, id, has_moin_session):
---
> def __init__(self, filename, id, has_moin_session,url=None):
76a77
> self.url = url
150a152
> file.write("@@ URL: %s\n"%self.url)
305c307
< return MoinFile(filename, id, has_moin_session)
---
> return MoinFile(filename, id, has_moin_session,url=url)
381a384,392
> extra_options = {"f":"Fetch","r":"Release","c":"Commit"}
> action = None
> filename = None
> if argv[0][1] in extra_options.keys():
> action = extra_options[argv[0][1]]
> argv = argv[1:]
> if action == "Commit":
> filename = argv[0]
> argv[0] = open(argv[0]).readlines()[0].split()[-1]
394,395c405,411
< if editfile(moinfile):
< sendfile(urlopener, url, moinfile)
---
> if action:
> if action == "Fetch":
> print moinfile.write_raw()
> sys.exit(0)
> if action == "Commit":
> moinfile.read_raw(filename)
> sendfile(urlopener, url, moinfile)
397c413,416
< sendcancel(urlopener, url, moinfile)
---
> if editfile(moinfile):
> sendfile(urlopener, url, moinfile)
> else:
> sendcancel(urlopener, url, moinfile)



It is not an elegant hack, but it works. Just

editmoin -f ThePage


and it will print the filename. Edit the file as much as you want, and then

editmoin -c TheFile


and it will commit the page (Attention, it wont delete the file).


The next step is to integrate it into VIM.