Just got back home from DevOps Days Warsaw 2014. It was pretty good. Nice people, good talks, awesome after-parties. Found myself really enjoy attending conferences. May be I could present some stuff next times. Regards!
Sunday, September 28, 2014
Sunday, August 10, 2014
Functional Programming monthly challenge
First time participated in monthly Function Programming challenge (the August one). I've decided to pick Python as my favorite programming language. Here you could find the solution I've come with. Have to admit that it's robust, not much mem consuming. For n × m input matrix it takes O(n) memory with O(n × m) algorithm's complexity.
Waiting for Monday to check my solution on new input data.
Wednesday, October 02, 2013
Wednesday, January 30, 2013
List linearization. Part 2.
The previous post I've talked about tricky list comprehension:
>>> ll = [[1,2,3], [4,5,6], [7,8]]
>>> l = [i for j in l for i in j]
>>> print l
... [1, 2, 3, 4, 5, 6, 7, 8]
But there are another pretty interesting solution for this task. It's based on built-in sum function:
>>> sum(ll)
TypeError: unsupported operand type(s) for +: 'int' and 'list'
Not working... But sum has optional param called `start` (which is 0 by default). So we could pass empty list, so every element in ll will be +'ed to it:
>>> print sum(ll, [])
... [1, 2, 3, 4, 5, 6, 7, 8]
Hooray! It works! And it's elegant. ;)
>>> ll = [[1,2,3], [4,5,6], [7,8]]
>>> l = [i for j in l for i in j]
>>> print l
... [1, 2, 3, 4, 5, 6, 7, 8]
But there are another pretty interesting solution for this task. It's based on built-in sum function:
>>> sum(ll)
TypeError: unsupported operand type(s) for +: 'int' and 'list'
Not working... But sum has optional param called `start` (which is 0 by default). So we could pass empty list, so every element in ll will be +'ed to it:
>>> print sum(ll, [])
... [1, 2, 3, 4, 5, 6, 7, 8]
Hooray! It works! And it's elegant. ;)
Tuesday, July 19, 2011
One more tricky thing I like in python
For example, I've got the list of iterable objects:
>>> l = [[1,2,3], [4,5,6], [7,8]]
And I need to get linear list of all elements in those iterables. Here's the trick, related to the list comprehension, I've learned couple of weeks ago:
>>> ll = [i for j in l for i in j]
>>> print ll
... [1, 2, 3, 4, 5, 6, 7, 8]
This constuction may be found a bit complicated at the first glance, but if we'll look at it, we'll get that that's similar to the following code:
>>> for j in l:
>>> for i in j:
>>> yield i
>>> l = [[1,2,3], [4,5,6], [7,8]]
And I need to get linear list of all elements in those iterables. Here's the trick, related to the list comprehension, I've learned couple of weeks ago:
>>> ll = [i for j in l for i in j]
>>> print ll
... [1, 2, 3, 4, 5, 6, 7, 8]
This constuction may be found a bit complicated at the first glance, but if we'll look at it, we'll get that that's similar to the following code:
>>> for j in l:
>>> for i in j:
>>> yield i
Friday, June 24, 2011
zip / unzip
zip() is simple and tricky buit-in python function at the same time.
>>> zip(range(3), '123')
... [(0, '1'), (1, '2'), (2, '3')]
That's simple, heh. :)
The trickest part is when you've got the result of your zip(a, b), but you want to unzip it.
>>> a1 = (1, 2, 3)
>>> b1 = (4, 5, 6)
>>> c = zip(a1, c1)
>>> # woo-a la
>>> a2, b2 = zip(*c)
>>> print a1 == a2 and b1 == b2
... True
We've got the origial values. Congrats!
BTW, unzip is described in python documentation http://docs.python.org/library/functions.html#zip
>>> zip(range(3), '123')
... [(0, '1'), (1, '2'), (2, '3')]
That's simple, heh. :)
The trickest part is when you've got the result of your zip(a, b), but you want to unzip it.
>>> a1 = (1, 2, 3)
>>> b1 = (4, 5, 6)
>>> c = zip(a1, c1)
>>> # woo-a la
>>> a2, b2 = zip(*c)
>>> print a1 == a2 and b1 == b2
... True
We've got the origial values. Congrats!
BTW, unzip is described in python documentation http://docs.python.org/library/functions.html#zip
Wednesday, January 12, 2011
psi+
I always used psi as jabber-client for linux, but there were some feelings that it needs something more for comfortable usage. And couple weeks ago I've found that there are some russian guys who work on psi+ (based on psi) that already has lot's of customizable things. I really love it.
In Debian (and may be Ubuntu, but I haven't checked) it's available in repos, so you could install it:
apt-get install psi-plus
Monday, December 27, 2010
VMWare Player
I wanted to figure out how to work with my tablet (Wacom Intuos 4) using virtual machine. I tried VirtualBox4, but nothing worked out (mb I'm too stupid). After that I download "VMWare Player" and installed it.
Everything but vmmon module started well. `dmesg | tail` said:
kernel: [214725.964887] vmmon: disagrees about version of symbol smp_opskernel: [214725.964896] vmmon: Unknown symbol smp_ops
After googled for a while, I've found that `smp_ops` is not available at debian 2.6.32 kernel ( http://lists.debian.org/debian-kernel/2010/12/msg00507.html )
Finally solution was found:
wget http://files.archlinux.org.il/vmmon_fix_2.6.36.sh
chmod +x vmmon_fix_2.6.36.sh
./vmmon_fix_2.6.36.sh ( as root )
P.S. Tablet works well! I have lots of fun with it.
Thursday, March 25, 2010
PyFlakes.
1. There is wonderful command line utility that checks python code called pyflakes.
Here text from pyflakes man page:
Pyflakes is a simple program which checks Python source files for errors. It is similar to PyChecker in scope, but differs in that it does not execute the modules to check them. This is both safer and faster, although it does not perform as many checks. Unlike PyLint, Pyflakes checks only for logical errors in programs; it does not perform any checks on style.All commandline arguments are checked, which have to be either regular files or directories. If a directory is given, every .py file within will be checked.When no commandline arguments are given, data will be read from standard input.
2. There's vim filetype plugin that uses pyflakes utility: http://www.vim.org/scripts/script.php?script_id=2441
p.s. Это фрагмент письма в рабочую рассылку. Переводить не стал. :)
Thursday, March 18, 2010
amarok 2.2.2

В чудном музыкальном комбайне под названием Amarok есть поддержка «панели настроений» (moodbar). Что это такое? Это когда вместо унылого прогресс-бара появляется расчудесно-цветной прогресс-бар, в котором визуализирован аудио контент. Сложно сказано, но выглядит просто офигенно.
Как это устанавливается:
- в настройках amarok ставим "панель настроения";
- ставим moodbar: apt-get install moodbar;
- запускаем нижеописанный скрипт в директории с музыкой:
#!/bin/bashNUMCPU="`cat /proc/cpuinfo | grep processor | wc -l`"find . -type f -regextype posix-awk -iregex '.*\.(mp3|ogg|flac|wma)' |while read i ; doif [ `jobs -p | wc -l` -ge $NUMCPU ] ; thenwaitfiTEMP="${i%.*}.mood"OUTF=`echo "$TEMP" | sed 's#\(.*\)/\([^,]*\)#\1/.\2#'`if [ ! -e "$OUTF" ] ; thenmoodbar -o "$OUTF" "$i" &fidone
Subscribe to:
Posts (Atom)