my row in your table

11Apr/120

great lecture for data-mining adepts

Model Thinking course (video lectures, quizzes).

Prof. Scott E. Page introduces all critical concepts for model building - decision trees, cellular automata, linear regression, diffusion model, Markov chains, Lyapunov function and more.

All in very layman-friendly way, in simple English and with lots of example models - mostly social and economic ones.

I think it's great for all people starting their adventure with modeling processes and finding regularities in data.

2Mar/120

Did you know GNU parallel?

From time to time I write about some sweet little Linux utilities.

This time let me introduce GNU parallel.

As name suggests, it makes possible to run almost every other command in parallel, on many CPU cores.

Let's give a simple example. Searching for a string in many files. A simple test, on a 2-core box:

$ time bzgrep -w word /u/logs/app*/2012/01/31_app.log.bz2 > word.log
real    1m33.492s
user    1m25.269s
sys     0m8.181s
 
$ time parallel bzgrep -w word ::: /u/logs/app*/2012/01/31_app.log.bz2 > word.log
real    0m34.267s
user    2m3.112s
sys     0m9.193s

For more, read the wonderful list of examples in GNU parallel man page, they speak for themselves.

Of course parallel execution is possible without GNU parallel (with a piece of scripting language, or with xargs)... but this tool is more powerful. See this summary for a list of features and comparison with xargs, pexec and other alternatives.

The great thing about GNU utilities is that they actually still evolve and get better. Every time I see a progress there, it makes me optimistic about the future of open source.

6Jan/120

Joanna Siedlecka – Jan Himilsbach

Znowu zapodam coś z nieocenionego archiwum Andrzeja Krzemińskiego:

Joanna Siedlecka - Jan Himilsbach.

Przeżył przyjaciela o lat jedenaście, zmarł jednak w okolicznościach dość podobnych, również przez wódę.

28Dec/110

vim as a pager for psql

I asked this question on stackexchange, about a pager with "freeze first line" support.

There was no easy answer, but someone hinted me at Emacs. My Emacs skill is close to zero, so I wanted to check if it's possible in Vim.

And yes it is! Here you are:

First, we need a Vim macro, which will do most of the work, I save it in ~/.vim/plugin/less.vim:

" :Less
" turn vim into a pager for psql aligned results 
fun! Less()
  set nocompatible
  set nowrap
  set scrollopt=hor
  set scrollbind
  set number
  execute 'above split'
  " resize upper window to one line; two lines are not needed because vim adds separating line
  execute 'resize 1'
  " switch to lower window and scroll 2 lines down 
  wincmd j
  execute 'norm! 2^E'
  " hide statusline in lower window
  set laststatus=0
  " hide contents of upper statusline. editor note: do not remove trailing spaces in next line!
  set statusline=\  
  " arrows do scrolling instead of moving
  nmap ^[OC zL
  nmap ^[OB ^E
  nmap ^[OD zH
  nmap ^[OA ^Y
  nmap <Space> <PageDown>
  " faster quit (I tend to forget about the upper panel)
  nmap q :qa^M
  nmap Q :qa^M
endfun
command! -nargs=0 Less call Less()

Second, to emulate a pager, I need to invoke vim so that it will:

  • read standard input
  • but if argument is given on command line, read whatever comes there
  • work in read-only mode
  • skip all init scripts, but instead execute Less macro defined above

I put this together as helper script in ~/bin/vimpager:

#!/bin/bash
what=-
test "$@" && what="$@"
exec vim -u NONE -R -S ~/.vim/plugin/less.vim -c Less $what

Third, I need to override environment variable $PAGER, but only for psql (add this to my ~/.bash_aliases):

if which vimpager &>/dev/null; then
  alias psql='PAGER=vimpager psql';
fi

Fourth, I disabled "\pset pager always" in my ~/.psqlrc file, because I don't need to invoke vim on small listings.

That's all - and it works for me.

PS. There is "vimpager" here, but mine is much simpler and specific to psql query results.

7Oct/11Off

Gugała vs Hofman

1...2...3...FIGHT!

Gugała jest zdeterminowany, wyprowadza duzo ciosów... ale słabiutkie te ciosy, jakby kogucik drapał niedźwiedzia...
Hofman spokojnie kontruje, i kilka prawych prostych ląduje na szczęce Gugały.

Po nokaucie technicznym trener zdejmuje Gugałę z kliku następnych meczy.

Oj Gugała, Gugała, w dyplomacji... TFU! w boksie to wy większej kariery już nie zrobicie...