Windows vagrant breaks sudoerc

Running vagrant on windows I bumped in the following issue doing sudo:

sudo: >>> /etc/sudoers.d/logreaders: syntax error near line 5 <<<

sudo: >>> /etc/sudoers.d/logreaders: syntax error near line 6 <<<

sudo: >>> /etc/sudoers.d/logreaders: syntax error near line 7 <<<

sudo: >>> /etc/sudoers.d/logreaders: syntax error near line 8 <<<


After some investigation I discovered that


got windows line endings.

Fixed by running:

sed -i 's/\r//g' /etc/sudoers.d/logreaders


Posted in Linux | Leave a comment

Global ANT or MAVEN build event notification

I want to get notified when the build is finished.

I prefer ANT to play a small sound saying that the build is finished so I can stop reading news, drinking coffee, doing self education of course.

Luckily ant and maven have global build callback support. Internally they call a batch file from user home dir in case a build finishes successfully.

So to have the sound played after the build define the following files in user home dir:


echo “hello from maverc_post.bat”

@echo off
set “file=C:\Windows\Media\tada.wav”
( echo Set Sound = CreateObject(“WMPlayer.OCX.7″^)
echo Sound.URL = “%file%”
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs


echo “hello from maverc_post.bat”

@echo off
set “file=C:\Windows\Media\tada.wav”
( echo Set Sound = CreateObject(“WMPlayer.OCX.7″^)
echo Sound.URL = “%file%”
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs


Posted in IT, Java | Leave a comment

Java webapp performance riddle

We have two servers: acceptance an production.

One day I noticed that an average page loading is 2 seconds on production while it is 0.5 seconds on acceptance.

Hm, fucking DB guys are fucking around with fucking DB. I thought.

I enabled log4jdbc. Checked DB query timings. And they were the same as on acceptance.

Then I put more logging to the controller. I understood that the controller works fast. Page rendering is slow.

I added more logging to the web layer. There is no decent bottleneck in the application. It is damn slow all around. I checked garbage collector – it was fine.

Then checked all the logic spread around the application: permissions, logging, i18n. I found and fixed numerous bugs. Did a pile of performance optimizations. But in the end prod was 2 times slower than acceptance still.

Then I though this is the hardware. I checked memory, CPU, HDD. The servers are the same.

I implemented a small arithmetic progression summing algorithm without any third party dependencies and ran them using java outside of tomcat. The are equally fast.

Running the same algorithm inside tomcat leads to 4 times difference on prod.

Then I decided – this is JVM.

I checked JVM parameters and found that it has the following on acceptance but not on production:

-XX:ReservedCodeCacheSize=256m -XX:+UseCodeCacheFlushing -XX:CodeCacheFlushingMinimumFreeSpace=20m

Fixing that fixed the half year problem.

Trying to do a retrospective I understand that there is no were no way to figure out that code cache region was exhausing.

Java specs promise to file a warning in this case

Java HotSpot(TM) 64-Bit Server VM warning: CodeCache is full. Compiler has been disabled.

But I have not see anything like that in logs.


UseCodeCacheFlushing. Remember. Always. Especially when you use Groovy in your application.

Posted in Uncategorized | Leave a comment

Safely get the first element from Groovy list

In Groovy it is safe to get the first collection element using standard bracket syntax even for empty collections. So you can use:


For example:

assert [][0] == null

Posted in Groovy | Tagged , | Leave a comment

Javascript !! construct

In JavaScript I often see the construct


The construct converts an object into boolean.

I remember it as “bang, bang, you are boolean

Posted in IT, JavaScript | Tagged | Leave a comment

Fighting SQL injection in hibernate may hit down the performance

The problem

A couple of days ago I found a query which hangs when running from the application but goes fine when running from a SQL client.

The problem was in the way I was calling the query. It was:

hibernateSession.createQuery(“from Product p inner join p.attributeValues av where av.value=:value”).setParameter(“value”, someValue)

Nothing wrong with it, isnt it?

DB server background

When you implement a parametrized query the DB (MSSQL server 2008R2 in my case) uses the same query execution plan for all parameter values. Unfortunately the plan may be not efficient. The execution plan may (and I think will) fit the first parameter value. But may not fit the second.

JDBC and Hibernate reality

Theoretically you can avoid execution plan reusing by using regular java.sql.Statement instead of java.sql.PreparedStatement. But this is not possible when you work with Hibernate. Hibernate uses java.sql.PreparedStatement only internally.

The solution:

hibernateSession.createQuery(“from Product p inner join p.attributeValues av where av.value=” + someValue)

Welcome hackers 😉


Posted in Java, MSSQL | Tagged , | Leave a comment

Mouse triple click

Most browsers and text processors support mouse triple click.

Triple clicking selects the entire paragraph. Very usefull in firefox if you want to select some word with underscores in a table cell.

Example: Let we have the following text in some table in firefox:



Single click on andrew – does nothing.

Double click on andrew – selects andrew.

Triple click on andrew – selects hello_andrew_osipenko.

Posted in IT, Lifechanger | Tagged | Leave a comment