Sunday, November 27, 2011

Anonymous asked: You call yourself 2kan? I think we may have the same alias..

Yes, i call myself 2kan %)

Thursday, October 6, 2011

Steve Jobs. 1955 - 2011

Now I have a Mac Book Pro (and two black Mac Books in my collection), iPhone 4, iPad and also an iPod. When I was young (remember I’m living in Russia and just few years ago it was really poor country) I was dreaming for a Mac. I was working on Debian for about 4 years as my main desktop system using ctwm and vim with my own large config files for zsh, ctwm, vim and xterm. But Mac… it was something I always wanted to have.

So when I was at fifth year at my University and got my first full time job I’ve bough a brand new Mac as soon as it was possible. From those time I can’t image using anything else.

So Steve Jobs was a great CEO, a great marketing man, a great keynote speaker. We were loving him because he have build an amazing business; because Apple have changed the world by their amazing products.

This fall is very sad: Mr. Putin announced himself to be a Russian Czar for next 12 years and Steve Jobs died today.

1955 - 2011.

Tuesday, July 26, 2011

Locking a file for writing.

I’m using ruby as a main language. And I needed to lock a file when writing to it because I can’t be sure that there is no concurrent processes trying to write to the same file.

For locking files you can use a flock method for the file object.

But I’ve found that if you open file for writing (‘w’ mode) and try to read it concurrently sometimes you will get 0 bytes file or even an error that file is busy by other process.

For example:

The reason of this problem is simple: when you use the ‘w’ mode at first it truncates the file and only then you get lock on it. So the correct code is:

P.S. Also you can find it in the docs for the flock method, in the comments for the example of using flock for writing to a file… but… em… do you read examples in the docs? %)

Friday, March 25, 2011
Typical Moscow (Russia) spring.

Typical Moscow (Russia) spring.

Friday, February 11, 2011

You should never copy paste a migration

This post is about a good practice or something. As I said in the subject:

You should never copy paste a migration

The reason is simple. Sometimes your copy paste a code from project to project and if this code wasn’t written by you you carefully read it to understand how it works and to find potential flows (here I assume that all of you are responsible and good developers). But migrations, they are silly and simple, it is boring to read them carefully and if it works for the project you copy paste from you assume and believe that it will work for you. And this is a big mistake. There are lot’s of places for flaws. The simplest one is there could be a wrong column types, for example there could be a float column where you need a decimal one.

If you’re a good developer you, I believe, will never do such mistake, but you can easily copy paste it as I did few days ago.

Also the indexing in such migrations could be not very good because some people when they open indexes in DBs for them at first time creates explicit low selectivity indexes.

The solution is only to write migrations by your self. This will reduce probability of getting such unexpected errors. Migration files are short and simple. It won’t get much time to write it yourself.

Tuesday, January 25, 2011
That’s my terminal in full screen mode with vim running. Old terminals for new technologies.

That’s my terminal in full screen mode with vim running. Old terminals for new technologies.

Monday, December 13, 2010

Make it sexy. Сделайте мне красиво

Был в роли гостя в 11 выпуске подкаста “Сделайте мне красиво”: http://makeitsexy.rpod.ru/196643.html

Всем слушать и подписываться.

Liquor is the best Liquid

I was writing about Liquid template language and also pre-announced its fork.

This fork now works in production in our projects, so I think I can write a post about it.

At first, here is our fork: https://github.com/evilmartians/liquor/

And here is a TextMate bundle for it: https://github.com/tukan/liquor-tmbundle

I had a speech about it on RailsClub Moscow. Here is the video (it is in Russian, but keynote is in English). I’m talking about why we have forked, what we have done and what kind of alcohol is the most important for all people on the Earth.

Our main idea was to make drops really powerful. Our projects were very flexible and we couldn’t define methods in drops for all purposes. We didn’t know what kind of data user wants to show on their pages. Wants he to show only rated posts using: site.blog.posts.rated.recent.limit(10) associations and scopes or just last 10 posts using: site.blog.posts.recent.limit(10).

So we decided to give an ability to define named_scopes and associations in drops. It looks like:

This works safe, so you will get a Liquor::Drop object or a collection of Liquor::Drop objects using scopes and/or relations.

About all changes you can read on github, Again, here is our repo: https://github.com/evilmartians/liquor/ And docs: https://github.com/evilmartians/liquor/blob/master/README.rdoc

Thursday, September 23, 2010
Wednesday, September 22, 2010

/lib in rails3

Yes, every barbers knows that in Rails3 lib directory files now need to be manually required. But I didn’t. That’s fun. I have no reasonable idea why but…

To require it you need to add /lib to autoload_path.

Add this to your application.rb: