English


22
Oct 11

Virtualization with vagrant @ PyCon Ukraine 2011

I attended PyCon Ukraine 2011 today, and gave a brief talk about usage of VMs in development. Although presentation itself was based on my previous one made for CQG, it was significantly reworked for wide audience.

Let me know if I missed anything.



And here is screencast of demo project deployment with help of Vagrant and Fabric.


3
Oct 11

Using git to get version information

From time to time you need to get project version information and use it somewhere – in project documentation, in About box or include it in website footer.

I use git for my projects, and find it very convenient to let git to provide version info instead of hardcoding it into the source code. There are several possible ways to ask git for version information, including keyword expansion – and some of them are described in this stackoverflow post. For me, git describe works best, since it doesn’t modify sources on checkout (comparing to keyword expansion) and provides version information in format that could be used in other git commands such as git diff.

Sidenote: git describe

git describe returns information about state of working tree or any particular commit. There are several command line switches to consider, but in most cases “git describe –tags –always” will work just fine for everyone. The command finds the most recent tag that is reachable from a commit, and if the commit itself is pointed at by the tag, shows the tag. Otherwise, it suffixes the tag name with the number of additional commits and the abbreviated object name of the commit.

$ git describe --tags --always
v0.1.3-16-ge1b5922

Note on performance

Keep in mind that running git every time you need version information may not be the best idea. When source code changes are rare and performance is important (e.g. production website) it is wise to get information only once, then store it for later use. In other cases, when changes are often and performance is not critical, it may be ok to query git every time.

Example: including version information in Sphinx documentation

Sphinx is a tool that makes it easy to create intelligent and beautiful documentation, and it is often used in Python world. Project version information is stored in Sphinx configuration file and is embedded auto-generated project documentation. Since Sphinx itself is written in Python, getting version info is simple. First, add the following lines to your docs/conf.py:

from subprocess import Popen, PIPE

def get_version():
  """ Returns project version as string from 'git describe' command. """
  pipe = Popen('git describe --tags --always', stdout=PIPE, shell=True)
  version = pipe.stdout.read()

if version:
  return version
else:
  return 'X.Y'

Then, replace hardcoded version and release values:

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = get_version().lstrip('v')
# The full version, including alpha/beta/rc tags.
release = version

16
Mar 10

Why can’t programmers.. program?

Русская версия этого поста здесь.

As you may already know, our company is running internship programs for young developers in Ukraine (as well as in Russia and Armenia). This is a second year in a row we do it in Kiev, and we are quite happy with the results we achieved in 2009.

From time to time, to keep students low-fat and for pure entertainment, we replace random lecture with coding exercises. Hack hours.

Last time we decided that it’s time to ask our students to create a small program, that will

  • read text from stdin
  • split it into words (word is defined as a sequence of [A-Za-z0-9] characters)
  • .. and print out A-Z sorted list ow lowercased words along with lines these words were met on

Pretty and simple, huh? Since I want to be sure that this task has no hidden pitfalls and that I can answer common questions that may arise, I also solved this problem in pure C++ style. Took 25 minutes or so. Thus, we expected to see most students do this assignment in a hour, so we can get back to the lecture for the second hour.

Well, life brings surprises.

Continue reading →


7
Mar 10

My friend’s blog

A friend appreciation post.

Last year we were skiing on a ski resort of Zakopane, Poland. Usually, if you are open and friendly enough (and we definitely are), you may expect to meet new interesting people on such trips. Sometimes new people stay in your life or just a few days – like these interesting Swiss girls we met on Sziget fest in 2008, but it may happen that you continue to talk over long time since you met. What, actually, happened in that particular Poland trip.

Gubalowka

Let me introduce friend of mine, fellow Englishman Boaz Odier. Boaz lives in London, prefers to travel light, speaks several languages and plays ukulele for fun. And, if I recall our beer chats correctly, he also spent plenty of time living in Brazil once. I am looking forward to see some travel notes in his blog soon.


22
Feb 10

Quote of the Hour, дизайн интерфейса

В результате создания парсера на Python у меня на руках появилось около 3 тысяч разнообразных цитат, и теперь пришло время их использовать.

Идея для прототипа – приложение под Windows, которое будет периодически показывать всплывающее окошко со случайной цитатой. В качестве бонуса пользователь сможет заменить цитаты на любой текст. Усложняем задачу – окно с текстом я хочу видеть красиво оформленным.

Немного прототипирования в Balsamiq Mockups, несколько неудачных вариантов интерфейса и вот набросок готов.

Interface sketch

Continue reading →


19
Feb 10

Quote of the day parser

I constructed a small parser in Python which extracts different quotations from MotivatingQuotes.com (not too much for a start, take it as of Python learning course and general practice). I’m going to use these quotations in the next small utility, so stay tuned.

Parser is able to extract quotations from pre-fetched html pages (use wget or any other similar tool) and store them in output file in CSV format (Category, Quote, Author). Fancy details like color highlight for console output, automatic encoding detection and command line options are included.

Source code is generic enough to adopt it for any format with little help of regex tweaking.

Usage: motivatingquotes.py [options] [-h]

Options:
  -h, --help            show this help message and exit
  -q, --quiet           Quiet mode
  -f WILDCARD, --from=WILDCARD
                        Files to extract quotes information from, e.g "*.html"
  -o FILE, --out=FILE   Save extracted qutoes to file in CSV format, e.g
                        "quotes.csv"

Downloads for this app


16
Feb 10

F = ma

Have just created 2 stickers for MacBook, inspired by magnificent MacBook cover art.

Newton's Apple

Creation of Apple


5
Feb 10

Welcome aboard

Welcome, reader.

Since I’m not a blogger-type person, don’t expect to see much updates here. This site was create mostly to serve as placeholder and testing range for my personal projects.

And now a word of appreciation to my hoster – WebFaction. I tried a number of hosting solutions over the years, and was impressed with price, speed and convenience of WebFaction solution. If you’re looking for hosting for small to medium website which is based on Python or Ruby and don’t want to spend a fortune on dedicated server – this might be your Holy Grail.