воскресенье, 18 апреля 2010 г.

воскресенье, 31 января 2010 г.

четверг, 28 января 2010 г.

Hibernate ResultTransformer and hand-coded mapping

I have noticed that fairly large number of people don't know about hibernate result transformers. Moreover I saw monsters like this:

Obviously it is not normal to do hand-coded mapping with Hibernate. There are several ways to avoid such a nasty code.
Call DTO class constructor directly from your request

It is not convenient to use constructor in case of many properties:

ResultTransformer can be used with native sql queries too:

It is much more easy to use constructors or ResultTransformer instead of hand-coded mapping, isn't it ?

воскресенье, 24 января 2010 г.

MySql create table error 150

ERROR 1005 (HY000): Can't create table '******' (errno: 150)
This is the first error in the MySql InnoDB error codes page.
Cannot create table. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error –1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table.
In my case foreign key was not the same type as the referenced key, stupid, nasty error...

пятница, 22 января 2010 г.

Vim macroses

In vim u can record a sequence of commands to a register. What does it mean for you? No more tedious text editing, you can record your work and replay it N times.
Assume you need a numbered list:
1
Write the following commands:
qaYp<ctrl a>q

  1. q - start recording
  2. a - write macros into register 'a'
  3. Y - yanks the line
  4. p - paste yanked on the line below
  5. <ctrl a> - increment value
  6. q - stop recording

Now you can write "10@a" to repeat macros from register 'a' 10 times.
The result will be the following:
1
2
3
4
5
6
7
8
9
11
12

воскресенье, 17 января 2010 г.

Debian ruby gems update

gem update --system
ERROR: While executing gem ... (RuntimeError)
gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get.

The workaround:
gem install rubygems-update
cd /var/lib/gems/1.8/gems/rubygems-update-1.3.5/
ruby setup.rb

Now you have gem v.1.3.5
P.S. But I got success only with v.1.3.4

Rails installation problem

I've got the following error message:
gem install rails
ERROR: Error installing rails:
actionpack requires rack (~> 1.0.0, runtime)
The problem is that the actionpack requires precisely 1.0.0 version of rack gem. To get rid of this error just do what "actionpack" want ;-)
gem install rack --version 1.0.0

That's all, now you can simply install rails us usual without any errors.

пятница, 1 января 2010 г.

Vim run command for all opened tabs

Simply

:tabdo syntax on
:tabdo %s/this/that/g

Vim rearranging tabs

You can move the tabs to a specific spot in the tab order using the command below

:tabm n

n starts from 0.

Vim tabs navigation

Ctrl+n and Ctrl+p for tab navigation in vim:

nnoremap <C-n> :tabnext <CR>
nnoremap <C-p> :tabprevious <CR>

To open vim with multiple files in separate tabs use the command below:

vim -p *.h *.c

Vim arrow keys for navigation

Add these lines to your .vimrc if u want to use arrow keys for navigation:

vnoremap <Left> h
vnoremap <Right> l
vnoremap <Up> k
vnoremap <Down> j